move default button handling code from wxControlContainer to wxTLW (patch 1524441)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-07-25 01:31:13 +00:00
parent 0c9d7ace58
commit 6c20e8f816
30 changed files with 181 additions and 230 deletions

View File

@@ -38,28 +38,6 @@ public:
wxControlContainer(wxWindow *winParent = NULL); wxControlContainer(wxWindow *winParent = NULL);
void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; } void SetContainerWindow(wxWindow *winParent) { m_winParent = winParent; }
// default item access: we have a permanent default item which is the one
// set by the user code but we may also have a temporary default item which
// would be chosen if the user pressed "Enter" now but the default action
// reverts to the "permanent" default as soon as this temporary default
// item lsoes focus
// get the default item, temporary or permanent
wxWindow *GetDefaultItem() const
{ return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
// set the permanent default item, return its old value
wxWindow *SetDefaultItem(wxWindow *win)
{ wxWindow *winOld = m_winDefault; m_winDefault = win; return winOld; }
// set a temporary default item, SetTmpDefaultItem(NULL) should be called
// soon after a call to SetTmpDefaultItem(window)
void SetTmpDefaultItem(wxWindow *win) { m_winTmpDefault = win; }
// return the temporary default item, can be NULL
wxWindow *GetTmpDefaultItem() const { return m_winTmpDefault; }
// the methods to be called from the window event handlers // the methods to be called from the window event handlers
void HandleOnNavigationKey(wxNavigationKeyEvent& event); void HandleOnNavigationKey(wxNavigationKeyEvent& event);
void HandleOnFocus(wxFocusEvent& event); void HandleOnFocus(wxFocusEvent& event);
@@ -86,12 +64,6 @@ protected:
// the child which had the focus last time this panel was activated // the child which had the focus last time this panel was activated
wxWindow *m_winLastFocused; wxWindow *m_winLastFocused;
// a default window (usually a button) or NULL
wxWindow *m_winDefault;
// a temporary override of m_winDefault, use the latter if NULL
wxWindow *m_winTmpDefault;
// a guard against infinite recursion // a guard against infinite recursion
bool m_inSetFocus; bool m_inSetFocus;
@@ -115,10 +87,6 @@ public: \
virtual void SetFocus(); \ virtual void SetFocus(); \
virtual void SetFocusIgnoringChildren(); \ virtual void SetFocusIgnoringChildren(); \
virtual void RemoveChild(wxWindowBase *child); \ virtual void RemoveChild(wxWindowBase *child); \
virtual wxWindow *GetDefaultItem() const; \
virtual wxWindow *SetDefaultItem(wxWindow *child); \
virtual void SetTmpDefaultItem(wxWindow *win); \
virtual wxWindow *GetTmpDefaultItem() const; \
virtual bool AcceptsFocus() const; \ virtual bool AcceptsFocus() const; \
\ \
protected: \ protected: \
@@ -131,27 +99,7 @@ protected: \
EVT_NAVIGATION_KEY(classname::OnNavigationKey) EVT_NAVIGATION_KEY(classname::OnNavigationKey)
// implement the methods forwarding to the wxControlContainer // implement the methods forwarding to the wxControlContainer
#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname) \ #define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename) \
wxWindow *classname::SetDefaultItem(wxWindow *child) \
{ \
return m_container.SetDefaultItem(child); \
} \
\
void classname::SetTmpDefaultItem(wxWindow *child) \
{ \
m_container.SetTmpDefaultItem(child); \
} \
\
wxWindow *classname::GetDefaultItem() const \
{ \
return m_container.GetDefaultItem(); \
} \
\
wxWindow *classname::GetTmpDefaultItem() const \
{ \
return m_container.GetTmpDefaultItem(); \
} \
\
void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \ void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
{ \ { \
m_container.HandleOnNavigationKey(event); \ m_container.HandleOnNavigationKey(event); \
@@ -161,18 +109,18 @@ void classname::RemoveChild(wxWindowBase *child) \
{ \ { \
m_container.HandleOnWindowDestroy(child); \ m_container.HandleOnWindowDestroy(child); \
\ \
wxWindow::RemoveChild(child); \ basename::RemoveChild(child); \
} \ } \
\ \
void classname::SetFocus() \ void classname::SetFocus() \
{ \ { \
if ( !m_container.DoSetFocus() ) \ if ( !m_container.DoSetFocus() ) \
wxWindow::SetFocus(); \ basename::SetFocus(); \
} \ } \
\ \
void classname::SetFocusIgnoringChildren() \ void classname::SetFocusIgnoringChildren() \
{ \ { \
wxWindow::SetFocus(); \ basename::SetFocus(); \
} \ } \
\ \
void classname::OnChildFocus(wxChildFocusEvent& event) \ void classname::OnChildFocus(wxChildFocusEvent& event) \

View File

@@ -201,6 +201,32 @@ public:
virtual bool CanSetTransparent() { return false; } virtual bool CanSetTransparent() { return false; }
// default item access: we have a permanent default item which is the one
// set by the user code but we may also have a temporary default item which
// would be chosen if the user pressed "Enter" now but the default action
// reverts to the "permanent" default as soon as this temporary default
// item loses focus
// used to reset default if pointing to removed child
virtual void RemoveChild(wxWindowBase *child);
// get the default item, temporary or permanent
wxWindow *GetDefaultItem() const
{ return m_winTmpDefault ? m_winTmpDefault : m_winDefault; }
// set the permanent default item, return the old default
wxWindow *SetDefaultItem(wxWindow *win)
{ wxWindow *old = GetDefaultItem(); m_winDefault = win; return old; }
// return the temporary default item, can be NULL
wxWindow *GetTmpDefaultItem() const { return m_winTmpDefault; }
// set a temporary default item, SetTmpDefaultItem(NULL) should be called
// soon after a call to SetTmpDefaultItem(window), return the old default
wxWindow *SetTmpDefaultItem(wxWindow *win)
{ wxWindow *old = GetDefaultItem(); m_winTmpDefault = win; return old; }
// implementation only from now on // implementation only from now on
// ------------------------------- // -------------------------------
@@ -264,6 +290,12 @@ protected:
// the frame icon // the frame icon
wxIconBundle m_icons; wxIconBundle m_icons;
// a default window (usually a button) or NULL
wxWindow *m_winDefault;
// a temporary override of m_winDefault, use the latter if NULL
wxWindow *m_winTmpDefault;
DECLARE_NO_COPY_CLASS(wxTopLevelWindowBase) DECLARE_NO_COPY_CLASS(wxTopLevelWindowBase)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -514,23 +514,6 @@ public:
// click it // click it
virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); } virtual bool AcceptsFocusFromKeyboard() const { return AcceptsFocus(); }
// NB: these methods really don't belong here but with the current
// class hierarchy there is no other place for them :-(
// get the default child of this parent, i.e. the one which is
// activated by pressing <Enter>
virtual wxWindow *GetDefaultItem() const { return NULL; }
// set this child as default, return the old default
virtual wxWindow *SetDefaultItem(wxWindow * WXUNUSED(child))
{ return NULL; }
// set this child as temporary default
virtual void SetTmpDefaultItem(wxWindow * WXUNUSED(win)) { }
// return the temporary default item, can be NULL
virtual wxWindow *GetTmpDefaultItem() const { return NULL; }
// navigates in the specified direction by sending a wxNavigationKeyEvent // navigates in the specified direction by sending a wxNavigationKeyEvent
virtual bool Navigate(int flags = wxNavigationKeyEvent::IsForward); virtual bool Navigate(int flags = wxNavigationKeyEvent::IsForward);

View File

@@ -43,10 +43,7 @@
wxControlContainer::wxControlContainer(wxWindow *winParent) wxControlContainer::wxControlContainer(wxWindow *winParent)
{ {
m_winParent = winParent; m_winParent = winParent;
m_winLastFocused = NULL;
m_winLastFocused =
m_winTmpDefault =
m_winDefault = NULL;
m_inSetFocus = false; m_inSetFocus = false;
} }
@@ -504,12 +501,6 @@ void wxControlContainer::HandleOnWindowDestroy(wxWindowBase *child)
{ {
if ( child == m_winLastFocused ) if ( child == m_winLastFocused )
m_winLastFocused = NULL; m_winLastFocused = NULL;
if ( child == m_winDefault )
m_winDefault = NULL;
if ( child == m_winTmpDefault )
m_winTmpDefault = NULL;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -104,7 +104,7 @@ BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase) WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
END_EVENT_TABLE() END_EVENT_TABLE()
WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase) WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase, wxTopLevelWindow)
#endif #endif
void wxDialogBase::Init() void wxDialogBase::Init()

View File

@@ -45,7 +45,7 @@ BEGIN_EVENT_TABLE(wxPickerBase, wxControl)
EVT_SIZE(wxPickerBase::OnSize) EVT_SIZE(wxPickerBase::OnSize)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase) WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase)
END_EVENT_TABLE() END_EVENT_TABLE()
WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase) WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase, wxControl)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -55,6 +55,8 @@ wxTopLevelWindowBase::wxTopLevelWindowBase()
{ {
// Unlike windows, top level windows are created hidden by default. // Unlike windows, top level windows are created hidden by default.
m_isShown = false; m_isShown = false;
m_winDefault = NULL;
m_winTmpDefault = NULL;
} }
wxTopLevelWindowBase::~wxTopLevelWindowBase() wxTopLevelWindowBase::~wxTopLevelWindowBase()
@@ -393,3 +395,14 @@ void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags))
// it's probably better than do nothing, isn't it? // it's probably better than do nothing, isn't it?
Raise(); Raise();
} }
void wxTopLevelWindowBase::RemoveChild(wxWindowBase *child)
{
if ( child == m_winDefault )
m_winDefault = NULL;
if ( child == m_winTmpDefault )
m_winTmpDefault = NULL;
wxWindow::RemoveChild(child);
}

View File

@@ -291,11 +291,6 @@ wxWindowBase::~wxWindowBase()
// reset the dangling pointer our parent window may keep to us // reset the dangling pointer our parent window may keep to us
if ( m_parent ) if ( m_parent )
{ {
if ( m_parent->GetDefaultItem() == this )
{
m_parent->SetDefaultItem(NULL);
}
m_parent->RemoveChild(this); m_parent->RemoveChild(this);
} }

View File

@@ -97,7 +97,7 @@ END_EVENT_TABLE()
// implementation // implementation
// ============================================================================ // ============================================================================
WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel) WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, wxWindow)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxPanel creation // wxPanel creation

View File

@@ -69,7 +69,7 @@ BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow) WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow) WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow, wxWindow)
bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id, bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,

View File

@@ -165,10 +165,10 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( parent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
parent->SetDefaultItem(this); tlw->SetDefaultItem(this);
GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
gtk_widget_grab_default( m_widget ); gtk_widget_grab_default( m_widget );

View File

@@ -154,10 +154,10 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( parent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
parent->SetDefaultItem(this); tlw->SetDefaultItem(this);
GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT );
gtk_widget_grab_default( m_widget ); gtk_widget_grab_default( m_widget );

View File

@@ -1576,7 +1576,10 @@ bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers
{ {
if ( keyval == WXK_RETURN ) if ( keyval == WXK_RETURN )
{ {
wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxButton); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(focus), wxTopLevelWindow);
if ( tlw && tlw->GetDefaultItem() )
{
wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
@@ -1586,6 +1589,7 @@ bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers
return true ; return true ;
} }
} }
}
else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
{ {
// generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs)

View File

@@ -102,13 +102,12 @@ bool wxButton::Create(wxWindow *parent,
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxButton *btnOldDefault = NULL; wxButton *btnOldDefault = NULL;
if ( tlw )
if ( parent )
{ {
btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), wxButton); btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
parent->SetDefaultItem(this); tlw->SetDefaultItem(this);
} }
if ( btnOldDefault ) if ( btnOldDefault )

View File

@@ -25,7 +25,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
WX_DELEGATE_TO_CONTROL_CONTAINER(wxComboBox) WX_DELEGATE_TO_CONTROL_CONTAINER(wxComboBox, wxControl)
BEGIN_EVENT_TABLE(wxComboBox, wxControl) BEGIN_EVENT_TABLE(wxComboBox, wxControl)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxComboBox) WX_EVENT_TABLE_CONTROL_CONTAINER(wxComboBox)
@@ -109,13 +109,10 @@ protected:
// such as the clicking the default button. // such as the clicking the default button.
if (!m_cb->GetEventHandler()->ProcessEvent( event )) if (!m_cb->GetEventHandler()->ProcessEvent( event ))
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) if ( tlw && tlw->GetDefaultItem() )
parent = parent->GetParent() ;
if ( parent && parent->GetDefaultItem() )
{ {
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton); wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );

View File

@@ -147,14 +147,10 @@ protected:
// This will invoke the dialog default action, such // This will invoke the dialog default action, such
// as the clicking the default button. // as the clicking the default button.
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { if ( tlw && tlw->GetDefaultItem() )
parent = parent->GetParent();
}
if ( parent && parent->GetDefaultItem() )
{ {
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );

View File

@@ -146,7 +146,7 @@ BEGIN_EVENT_TABLE(wxSpinCtrl, wxControl)
WX_EVENT_TABLE_CONTROL_CONTAINER(wxSpinCtrl) WX_EVENT_TABLE_CONTROL_CONTAINER(wxSpinCtrl)
END_EVENT_TABLE() END_EVENT_TABLE()
WX_DELEGATE_TO_CONTROL_CONTAINER(wxSpinCtrl) WX_DELEGATE_TO_CONTROL_CONTAINER(wxSpinCtrl, wxControl)
// ============================================================================ // ============================================================================

View File

@@ -962,15 +962,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
if ( !(m_windowStyle & wxTE_MULTILINE) ) if ( !(m_windowStyle & wxTE_MULTILINE) )
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) if ( tlw && tlw->GetDefaultItem() )
{ {
parent = parent->GetParent() ; wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
}
if ( parent && parent->GetDefaultItem() )
{
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );

View File

@@ -993,11 +993,11 @@ wxWindowMac::~wxWindowMac()
// wxRemoveMacControlAssociation( this ) ; // wxRemoveMacControlAssociation( this ) ;
// If we delete an item, we should initialize the parent panel, // If we delete an item, we should initialize the parent panel,
// because it could now be invalid. // because it could now be invalid.
wxWindow *parent = GetParent() ; wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
if ( parent ) if ( tlw )
{ {
if (parent->GetDefaultItem() == (wxButton*) this) if ( tlw->GetDefaultItem() == (wxButton*) this)
parent->SetDefaultItem(NULL); tlw->SetDefaultItem(NULL);
} }
if ( m_peer && m_peer->Ok() ) if ( m_peer && m_peer->Ok() )

View File

@@ -2022,8 +2022,10 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
{ {
if ( keyval == WXK_RETURN ) if ( keyval == WXK_RETURN )
{ {
wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxButton); if ( tlw && tlw->GetDefaultItem() )
{
wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
@@ -2032,6 +2034,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
return true ; return true ;
} }
} }
}
/* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
{ {

View File

@@ -66,13 +66,12 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxButton *btnOldDefault = NULL; wxButton *btnOldDefault = NULL;
if ( parent ) if ( tlw )
{ {
btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
wxButton); tlw->SetDefaultItem(this);
parent->SetDefaultItem(this);
} }
Boolean inData; Boolean inData;

View File

@@ -94,14 +94,10 @@ protected:
// This will invoke the dialog default action, such // This will invoke the dialog default action, such
// as the clicking the default button. // as the clicking the default button.
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { if ( tlw && tlw->GetDefaultItem() )
parent = parent->GetParent() ;
}
if ( parent && parent->GetDefaultItem() )
{ {
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );

View File

@@ -190,11 +190,11 @@ wxControl::~wxControl()
wxRemoveMacControlAssociation( this ) ; wxRemoveMacControlAssociation( this ) ;
// If we delete an item, we should initialize the parent panel, // If we delete an item, we should initialize the parent panel,
// because it could now be invalid. // because it could now be invalid.
wxWindow *parent = GetParent() ; wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
if ( parent ) if ( tlw )
{ {
if (parent->GetDefaultItem() == (wxButton*) this) if ( tlw->GetDefaultItem() == (wxButton*) this)
parent->SetDefaultItem(NULL); tlw->SetDefaultItem(NULL);
} }
if ( (ControlHandle) m_macControl ) if ( (ControlHandle) m_macControl )
{ {

View File

@@ -924,14 +924,10 @@ void wxListBox::OnChar(wxKeyEvent& event)
{ {
if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER) if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER)
{ {
wxWindow* parent = GetParent() ; wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) if ( tlw && tlw->GetDefaultItem() )
parent = parent->GetParent() ;
if ( parent && parent->GetDefaultItem() )
{ {
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );

View File

@@ -1622,14 +1622,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
} }
if ( !(m_windowStyle & wxTE_MULTILINE) ) if ( !(m_windowStyle & wxTE_MULTILINE) )
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { if ( tlw && tlw->GetDefaultItem() )
parent = parent->GetParent() ;
}
if ( parent && parent->GetDefaultItem() )
{ {
wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
wxButton);
if ( def && def->IsEnabled() ) if ( def && def->IsEnabled() )
{ {
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );

View File

@@ -123,9 +123,9 @@ void wxButton::SetDefaultShadowThicknessAndResize()
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
if ( parent ) if ( tlw )
parent->SetDefaultItem(this); tlw->SetDefaultItem(this);
// We initially do not set XmNdefaultShadowThickness, to have // We initially do not set XmNdefaultShadowThickness, to have
// small buttons. Unfortunately, buttons are now mis-aligned. We // small buttons. Unfortunately, buttons are now mis-aligned. We
@@ -134,6 +134,7 @@ void wxButton::SetDefault()
// wxButton in the same row, correction is straighforward: we set // wxButton in the same row, correction is straighforward: we set
// resource for all wxButton in this parent (but not sub panels) // resource for all wxButton in this parent (but not sub panels)
wxWindow *parent = GetParent();
for (wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst (); for (wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst ();
node; node = node->GetNext ()) node; node = node->GetNext ())
{ {

View File

@@ -197,8 +197,8 @@ bool wxButton::Create(wxWindow *parent,
wxButton::~wxButton() wxButton::~wxButton()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
if ( parent && parent->GetTmpDefaultItem() == this ) if ( tlw && tlw->GetTmpDefaultItem() == this )
{ {
UnsetTmpDefault(); UnsetTmpDefault();
} }
@@ -344,12 +344,12 @@ wxSize wxButtonBase::GetDefaultSize()
// set this button as the (permanently) default one in its panel // set this button as the (permanently) default one in its panel
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( parent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
// set this one as the default button both for wxWidgets ... // set this one as the default button both for wxWidgets ...
wxWindow *winOldDefault = parent->SetDefaultItem(this); wxWindow *winOldDefault = tlw->SetDefaultItem(this);
// ... and Windows // ... and Windows
SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false); SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false);
@@ -359,12 +359,12 @@ void wxButton::SetDefault()
// set this button as being currently default // set this button as being currently default
void wxButton::SetTmpDefault() void wxButton::SetTmpDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( parent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
wxWindow *winOldDefault = parent->GetDefaultItem(); wxWindow *winOldDefault = tlw->GetDefaultItem();
parent->SetTmpDefaultItem(this); tlw->SetTmpDefaultItem(this);
SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false); SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false);
SetDefaultStyle(this, true); SetDefaultStyle(this, true);
@@ -373,13 +373,13 @@ void wxButton::SetTmpDefault()
// unset this button as currently default, it may still stay permanent default // unset this button as currently default, it may still stay permanent default
void wxButton::UnsetTmpDefault() void wxButton::UnsetTmpDefault()
{ {
wxWindow *parent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( parent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
parent->SetTmpDefaultItem(NULL); tlw->SetTmpDefaultItem(NULL);
wxWindow *winOldDefault = parent->GetDefaultItem(); wxWindow *winOldDefault = tlw->GetDefaultItem();
SetDefaultStyle(this, false); SetDefaultStyle(this, false);
SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), true); SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), true);
@@ -402,10 +402,10 @@ wxButton::SetDefaultStyle(wxButton *btn, bool on)
if ( !wxTheApp->IsActive() ) if ( !wxTheApp->IsActive() )
return; return;
wxWindow * const parent = btn->GetParent(); wxWindow * const tlw = wxGetTopLevelParent(btn);
wxCHECK_RET( parent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
::SendMessage(GetHwndOf(parent), DM_SETDEFID, btn->GetId(), 0L); ::SendMessage(GetHwndOf(tlw), DM_SETDEFID, btn->GetId(), 0L);
// sending DM_SETDEFID also changes the button style to // sending DM_SETDEFID also changes the button style to
// BS_DEFPUSHBUTTON so there is nothing more to do // BS_DEFPUSHBUTTON so there is nothing more to do
@@ -817,10 +817,10 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
bool selected = (state & ODS_SELECTED) != 0; bool selected = (state & ODS_SELECTED) != 0;
if ( !selected ) if ( !selected )
{ {
wxPanel *panel = wxDynamicCast(GetParent(), wxPanel); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
if ( panel ) if ( tlw )
{ {
selected = panel->GetDefaultItem() == this; selected = tlw->GetDefaultItem() == this;
} }
} }
bool pushed = (SendMessage(GetHwnd(), BM_GETSTATE, 0, 0) & BST_PUSHED) != 0; bool pushed = (SendMessage(GetHwnd(), BM_GETSTATE, 0, 0) & BST_PUSHED) != 0;

View File

@@ -2146,8 +2146,10 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
else // not a button itself else // not a button itself
{ {
#if wxUSE_BUTTON #if wxUSE_BUTTON
wxButton *btn = wxDynamicCast(GetDefaultItem(), wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxButton); if ( tlw )
{
wxButton *btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
if ( btn && btn->IsEnabled() ) if ( btn && btn->IsEnabled() )
{ {
// if we do have a default button, do press it // if we do have a default button, do press it
@@ -2155,6 +2157,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
return true; return true;
} }
}
else // no default button else // no default button
#endif // wxUSE_BUTTON #endif // wxUSE_BUTTON
{ {

View File

@@ -116,16 +116,16 @@ bool wxButton::Create( wxWindow* pParent,
wxButton::~wxButton() wxButton::~wxButton()
{ {
wxPanel* pPanel = wxDynamicCast(GetParent(), wxPanel); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
if (pPanel) if (tlw)
{ {
if (pPanel->GetDefaultItem() == this) if (tlw->GetDefaultItem() == this)
{ {
// //
// Don't leave the panel with invalid default item // Don't leave the panel with invalid default item
// //
pPanel->SetDefaultItem(NULL); tlw->SetDefaultItem(NULL);
} }
} }
} // end of wxButton::~wxButton } // end of wxButton::~wxButton
@@ -232,14 +232,14 @@ bool wxButton::SendClickEvent()
void wxButton::SetDefault() void wxButton::SetDefault()
{ {
wxWindow* pParent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( pParent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
// //
// Set this one as the default button both for wxWidgets and Windows // Set this one as the default button both for wxWidgets and Windows
// //
wxWindow* pWinOldDefault = pParent->SetDefaultItem(this); wxWindow* pWinOldDefault = tlw->SetDefaultItem(this);
SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), false); SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), false);
SetDefaultStyle( this, true ); SetDefaultStyle( this, true );
@@ -247,26 +247,26 @@ void wxButton::SetDefault()
void wxButton::SetTmpDefault() void wxButton::SetTmpDefault()
{ {
wxWindow* pParent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( pParent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
wxWindow* pWinOldDefault = pParent->GetDefaultItem(); wxWindow* pWinOldDefault = tlw->GetDefaultItem();
pParent->SetTmpDefaultItem(this); tlw->SetTmpDefaultItem(this);
SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), false); SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), false);
SetDefaultStyle( this, true ); SetDefaultStyle( this, true );
} // end of wxButton::SetTmpDefault } // end of wxButton::SetTmpDefault
void wxButton::UnsetTmpDefault() void wxButton::UnsetTmpDefault()
{ {
wxWindow* pParent = GetParent(); wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
wxCHECK_RET( pParent, _T("button without parent?") ); wxCHECK_RET( tlw, _T("button without top level window?") );
pParent->SetTmpDefaultItem(NULL); tlw->SetTmpDefaultItem(NULL);
wxWindow* pWinOldDefault = pParent->GetDefaultItem(); wxWindow* pWinOldDefault = tlw->GetDefaultItem();
SetDefaultStyle( this, false ); SetDefaultStyle( this, false );
SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), true ); SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), true );

View File

@@ -2021,9 +2021,13 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg )
} }
else else
{ {
wxButton* pBtn = wxDynamicCast( GetDefaultItem() wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
,wxButton wxButton* pBtn = NULL;
);
if (tlw)
{
pBtn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
}
if (pBtn && pBtn->IsEnabled()) if (pBtn && pBtn->IsEnabled())
{ {