]> git.saurik.com Git - wxWidgets.git/commitdiff
move default button handling code from wxControlContainer to wxTLW (patch 1524441)
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 25 Jul 2006 01:31:13 +0000 (01:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 25 Jul 2006 01:31:13 +0000 (01:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

30 files changed:
include/wx/containr.h
include/wx/toplevel.h
include/wx/window.h
src/common/containr.cpp
src/common/dlgcmn.cpp
src/common/pickerbase.cpp
src/common/toplvcmn.cpp
src/common/wincmn.cpp
src/generic/panelg.cpp
src/generic/splitter.cpp
src/gtk/button.cpp
src/gtk1/button.cpp
src/mac/carbon/app.cpp
src/mac/carbon/button.cpp
src/mac/carbon/combobox.cpp
src/mac/carbon/combobxc.cpp
src/mac/carbon/spinctrl.cpp
src/mac/carbon/textctrl.cpp
src/mac/carbon/window.cpp
src/mac/classic/app.cpp
src/mac/classic/button.cpp
src/mac/classic/combobox.cpp
src/mac/classic/control.cpp
src/mac/classic/listbox.cpp
src/mac/classic/textctrl.cpp
src/motif/button.cpp
src/msw/button.cpp
src/msw/window.cpp
src/os2/button.cpp
src/os2/window.cpp

index 34823cfab31c839b280b31835c3912c0ffab301b..1bf91cfef58c78a467d6b64473f36a3f7676599b 100644 (file)
@@ -38,28 +38,6 @@ public:
     wxControlContainer(wxWindow *winParent = NULL);
     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
     void HandleOnNavigationKey(wxNavigationKeyEvent& event);
     void HandleOnFocus(wxFocusEvent& event);
@@ -86,12 +64,6 @@ protected:
     // the child which had the focus last time this panel was activated
     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
     bool m_inSetFocus;
 
@@ -115,10 +87,6 @@ public: \
     virtual void SetFocus(); \
     virtual void SetFocusIgnoringChildren(); \
     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; \
 \
 protected: \
@@ -131,27 +99,7 @@ protected: \
     EVT_NAVIGATION_KEY(classname::OnNavigationKey)
 
 // implement the methods forwarding to the wxControlContainer
-#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname)  \
-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(); \
-} \
- \
+#define WX_DELEGATE_TO_CONTROL_CONTAINER(classname, basename)  \
 void classname::OnNavigationKey( wxNavigationKeyEvent& event ) \
 { \
     m_container.HandleOnNavigationKey(event); \
@@ -161,18 +109,18 @@ void classname::RemoveChild(wxWindowBase *child) \
 { \
     m_container.HandleOnWindowDestroy(child); \
  \
-    wxWindow::RemoveChild(child); \
+    basename::RemoveChild(child); \
 } \
  \
 void classname::SetFocus() \
 { \
     if ( !m_container.DoSetFocus() ) \
-        wxWindow::SetFocus(); \
+        basename::SetFocus(); \
 } \
  \
 void classname::SetFocusIgnoringChildren() \
 { \
-        wxWindow::SetFocus(); \
+        basename::SetFocus(); \
 } \
  \
 void classname::OnChildFocus(wxChildFocusEvent& event) \
index 8881631c5c91b83733b0ab3c1c81d3a04e91b433..e9be5bb46048319e86db63c196cf9625a3ba9d31 100644 (file)
@@ -200,7 +200,33 @@ public:
     virtual bool SetTransparent(wxByte WXUNUSED(alpha)) { 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
     // -------------------------------
 
@@ -264,6 +290,12 @@ protected:
     // the frame icon
     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_EVENT_TABLE()
 };
index 9ac9397953b80cb583efd5c7659f955cd2b81036..9f852eec40fec708ad517c03b366d231b647c880 100644 (file)
@@ -514,23 +514,6 @@ public:
         // click it
     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
     virtual bool Navigate(int flags = wxNavigationKeyEvent::IsForward);
 
index 020bc20ca1223c6a59baad20e283822bc44d08f6..0a034ba01e9d673fa28953d77653a2df9a9bf35b 100644 (file)
 wxControlContainer::wxControlContainer(wxWindow *winParent)
 {
     m_winParent = winParent;
-
-    m_winLastFocused =
-    m_winTmpDefault =
-    m_winDefault = NULL;
+    m_winLastFocused = NULL;
     m_inSetFocus = false;
 }
 
@@ -504,12 +501,6 @@ void wxControlContainer::HandleOnWindowDestroy(wxWindowBase *child)
 {
     if ( child == m_winLastFocused )
         m_winLastFocused = NULL;
-
-    if ( child == m_winDefault )
-        m_winDefault = NULL;
-
-    if ( child == m_winTmpDefault )
-        m_winTmpDefault = NULL;
 }
 
 // ----------------------------------------------------------------------------
index 56f113c20a7484c97975014f805eb2ac8b82cda7..c6c995cf30ddd728f07127a4d4e67e3834b931b3 100644 (file)
@@ -104,7 +104,7 @@ BEGIN_EVENT_TABLE(wxDialogBase, wxTopLevelWindow)
     WX_EVENT_TABLE_CONTROL_CONTAINER(wxDialogBase)
 END_EVENT_TABLE()
 
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase)
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxDialogBase, wxTopLevelWindow)
 #endif
 
 void wxDialogBase::Init()
index c714fc13c411c12df0dfdbee69a48a7516e52604..e550e651c77c069d5baa959bd01aaa2cc23c55ae 100644 (file)
@@ -45,7 +45,7 @@ BEGIN_EVENT_TABLE(wxPickerBase, wxControl)
     EVT_SIZE(wxPickerBase::OnSize)
     WX_EVENT_TABLE_CONTROL_CONTAINER(wxPickerBase)
 END_EVENT_TABLE()
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase)
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxPickerBase, wxControl)
 
 
 // ----------------------------------------------------------------------------
index a6c9133dbdbf11b649a7d883bb339c4920df0620..60376d3ebcb84e678230fd2e034a8efdb00a881e 100644 (file)
@@ -55,6 +55,8 @@ wxTopLevelWindowBase::wxTopLevelWindowBase()
 {
     // Unlike windows, top level windows are created hidden by default.
     m_isShown = false;
+    m_winDefault = NULL;
+    m_winTmpDefault = NULL;
 }
 
 wxTopLevelWindowBase::~wxTopLevelWindowBase()
@@ -393,3 +395,14 @@ void wxTopLevelWindowBase::RequestUserAttention(int WXUNUSED(flags))
     // it's probably better than do nothing, isn't it?
     Raise();
 }
+
+void wxTopLevelWindowBase::RemoveChild(wxWindowBase *child)
+{
+    if ( child == m_winDefault )
+        m_winDefault = NULL;
+
+    if ( child == m_winTmpDefault )
+        m_winTmpDefault = NULL;
+
+    wxWindow::RemoveChild(child);
+}
index ea7f5ced34d6c2f2dfdeb03df202055d157d5ab6..7ce145ca2482df539fa538e4fad26913eab01472 100644 (file)
@@ -291,11 +291,6 @@ wxWindowBase::~wxWindowBase()
     // reset the dangling pointer our parent window may keep to us
     if ( m_parent )
     {
-        if ( m_parent->GetDefaultItem() == this )
-        {
-            m_parent->SetDefaultItem(NULL);
-        }
-
         m_parent->RemoveChild(this);
     }
 
index e15d79bf81037271dd68ebd03b8c8d5c0fbbc32e..34c59bb52da38761e7f6dc4126ecd59fd9d9d0db 100644 (file)
@@ -97,7 +97,7 @@ END_EVENT_TABLE()
 // implementation
 // ============================================================================
 
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel)
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxPanel, wxWindow)
 
 // ----------------------------------------------------------------------------
 // wxPanel creation
index d3ed2d45c91fe0bf3349f1c06cd01d953085d0a5..9e357621d6aba958ba3c1a2f94779758fd804250 100644 (file)
@@ -69,7 +69,7 @@ BEGIN_EVENT_TABLE(wxSplitterWindow, wxWindow)
     WX_EVENT_TABLE_CONTROL_CONTAINER(wxSplitterWindow)
 END_EVENT_TABLE()
 
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow)
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxSplitterWindow, wxWindow)
 
 bool wxSplitterWindow::Create(wxWindow *parent, wxWindowID id,
                                    const wxPoint& pos,
index 74281019ca41bd0e4f7ef05a59a4d2a69d90aae1..a9631c7958321f30b53b4830f2aca4cf3d13efd8 100644 (file)
@@ -165,10 +165,10 @@ bool wxButton::Create(  wxWindow *parent, wxWindowID id, const wxString &label,
 
 void wxButton::SetDefault()
 {
-    wxWindow *parent = GetParent();
-    wxCHECK_RET( parent, _T("button without parent?") );
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    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_grab_default( m_widget );
index c84debc53d2710540c53b85bac7255d1695dd252..b3898b46b0c459830abe422ca1812863edf00849 100644 (file)
@@ -154,10 +154,10 @@ bool wxButton::Create(  wxWindow *parent, wxWindowID id, const wxString &label,
 
 void wxButton::SetDefault()
 {
-    wxWindow *parent = GetParent();
-    wxCHECK_RET( parent, _T("button without parent?") );
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    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_grab_default( m_widget );
index 3a350c95023f9c9e61ab322db1872a6ac6036d75..154369334d552aa03a7661534254c59dcbbfaae1 100644 (file)
@@ -1576,14 +1576,18 @@ bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers
         {
             if ( keyval == WXK_RETURN )
             {
-                wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxButton);
-                if ( def && def->IsEnabled() )
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(focus), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
                 {
-                    wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
-                    event.SetEventObject(def);
-                    def->Command(event);
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+                    if ( def && def->IsEnabled() )
+                    {
+                        wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+                        event.SetEventObject(def);
+                        def->Command(event);
 
-                    return true ;
+                        return true ;
+                    }
                 }
             }
             else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
index c5a3f521bdb67a90f8a1f707c512a0f05eb6a0e5..b1d1f7228f83c5b4ba039886cfddfec9feaec490 100644 (file)
@@ -102,13 +102,12 @@ bool wxButton::Create(wxWindow *parent,
 
 void wxButton::SetDefault()
 {
-    wxWindow *parent = GetParent();
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
     wxButton *btnOldDefault = NULL;
-
-    if ( parent )
+    if ( tlw )
     {
-        btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), wxButton);
-        parent->SetDefaultItem(this);
+        btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+        tlw->SetDefaultItem(this);
     }
 
     if ( btnOldDefault )
index 331103395af5ca0de612572cfbbb7f7243873ff4..fc840bdec813741cbfb7b955413a844035a3a658 100644 (file)
@@ -25,7 +25,7 @@
 
 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
 
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxComboBox)
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxComboBox, wxControl)
 
 BEGIN_EVENT_TABLE(wxComboBox, wxControl)
     WX_EVENT_TABLE_CONTROL_CONTAINER(wxComboBox)
@@ -109,13 +109,10 @@ protected:
             // such as the clicking the default button.
             if (!m_cb->GetEventHandler()->ProcessEvent( event ))
             {
-                wxWindow *parent = GetParent();
-                while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
-                    parent = parent->GetParent() ;
-
-                if ( parent && parent->GetDefaultItem() )
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
                 {
-                    wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton);
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                     if ( def && def->IsEnabled() )
                     {
                         wxCommandEvent event( wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
index fff4f2e43a18771a68343335469a6759cc415dfb..dc03529a981e4af5b46ceb1fab8e8757cbc2a2f2 100644 (file)
@@ -147,14 +147,10 @@ protected:
                 // This will invoke the dialog default action, such
                 // as the clicking the default button.
 
-                wxWindow *parent = GetParent();
-                while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
-                    parent = parent->GetParent();
-                }
-                if ( parent && parent->GetDefaultItem() )
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
                 {
-                    wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
-                                                          wxButton);
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                     if ( def && def->IsEnabled() )
                     {
                         wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
index a4dd944e312a3e4031ef142b582f39721e678d3b..8702e0bd874d31dc05a6872a64f0736b68cb8f91 100644 (file)
@@ -146,7 +146,7 @@ BEGIN_EVENT_TABLE(wxSpinCtrl, wxControl)
     WX_EVENT_TABLE_CONTROL_CONTAINER(wxSpinCtrl)
 END_EVENT_TABLE()
 
-WX_DELEGATE_TO_CONTROL_CONTAINER(wxSpinCtrl)
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxSpinCtrl, wxControl)
 
 
 // ============================================================================
index 24f9fdf83ecd86bd6a06a6d63c8e76d9a123ae20..c84b8fa71497f3154454e628229fd43d8596c08b 100644 (file)
@@ -962,15 +962,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
 
             if ( !(m_windowStyle & wxTE_MULTILINE) )
             {
-                wxWindow *parent = GetParent();
-                while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                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() )
                     {
                         wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
index 7b4445cc308a214b1d2372cdfbc3532a901be7d8..ef5d9dc053148675141996670c923b159ec47913 100644 (file)
@@ -993,11 +993,11 @@ wxWindowMac::~wxWindowMac()
     // wxRemoveMacControlAssociation( this ) ;
     // If we delete an item, we should initialize the parent panel,
     // because it could now be invalid.
-    wxWindow *parent = GetParent() ;
-    if ( parent )
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    if ( tlw )
     {
-        if (parent->GetDefaultItem() == (wxButton*) this)
-            parent->SetDefaultItem(NULL);
+        if ( tlw->GetDefaultItem() == (wxButton*) this)
+            tlw->SetDefaultItem(NULL);
     }
 
     if ( m_peer && m_peer->Ok() )
index c2f121a0f46b49a247382466c362ea62ec9cbb1b..16f2be2066d6e1eab4adaf3bdba437c9e50c1726 100644 (file)
@@ -2015,31 +2015,34 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
     // backdoor handler for default return and command escape
     if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
     {
-          // if window is not having a focus still testing for default enter or cancel
-          // TODO add the UMA version for ActiveNonFloatingWindow
-          wxWindow* focus = wxFindWinFromMacWindow( (WXWindow) FrontWindow() ) ;
-          if ( focus )
-          {
+        // if window is not having a focus still testing for default enter or cancel
+        // TODO add the UMA version for ActiveNonFloatingWindow
+        wxWindow* focus = wxFindWinFromMacWindow( (WXWindow) FrontWindow() ) ;
+        if ( focus )
+        {
             if ( keyval == WXK_RETURN )
             {
-                 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
-                                                       wxButton);
-                 if ( def && def->IsEnabled() )
-                 {
-                     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
-                     event.SetEventObject(def);
-                     def->Command(event);
-                     return true ;
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
+                {
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+                    if ( def && def->IsEnabled() )
+                    {
+                        wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+                        event.SetEventObject(def);
+                        def->Command(event);
+                        return true ;
+                    }
                 }
             }
             /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
             else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
             {
-                  wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
-                  new_event.SetEventObject( focus );
-                  handled = focus->GetEventHandler()->ProcessEvent( new_event );
+                wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
+                new_event.SetEventObject( focus );
+                handled = focus->GetEventHandler()->ProcessEvent( new_event );
             }
-          }
+        }
     }
     return handled ;
 }
index a12aa3a9b9e3212bb4131b9cc0d9cd8ca8910414..714983c2fa028b4a97c985493f8b7b7f94964418 100644 (file)
@@ -66,13 +66,12 @@ bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl,
 
 void wxButton::SetDefault()
 {
-    wxWindow *parent = GetParent();
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
     wxButton *btnOldDefault = NULL;
-    if ( parent )
+    if ( tlw )
     {
-        btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
-           wxButton);
-        parent->SetDefaultItem(this);
+        btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+        tlw->SetDefaultItem(this);
     }
 
     Boolean inData;
index aba551e2f3e9ee30acd9c1afe5927110aafe29ed..2879e2a3eb5920b3190e79c170f9b896c53ba865 100644 (file)
@@ -94,14 +94,10 @@ protected:
                 // This will invoke the dialog default action, such
                 // as the clicking the default button.
 
-                wxWindow *parent = GetParent();
-                while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
-                    parent = parent->GetParent() ;
-                }
-                if ( parent && parent->GetDefaultItem() )
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
                 {
-                    wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
-                                                          wxButton);
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                     if ( def && def->IsEnabled() )
                     {
                         wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
index 449a49b2851795ebfe4853d23f237f87f84044fd..5edc253f73bf1c1e5a6d7d1f72cf9844b03c5bf4 100644 (file)
@@ -190,11 +190,11 @@ wxControl::~wxControl()
     wxRemoveMacControlAssociation( this ) ;
     // If we delete an item, we should initialize the parent panel,
     // because it could now be invalid.
-    wxWindow *parent = GetParent() ;
-    if ( parent )
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    if ( tlw )
     {
-        if (parent->GetDefaultItem() == (wxButton*) this)
-            parent->SetDefaultItem(NULL);
+        if ( tlw->GetDefaultItem() == (wxButton*) this)
+            tlw->SetDefaultItem(NULL);
     }
     if ( (ControlHandle) m_macControl )
     {
index 613d60912c216609690f5996a19ab07afe171cc2..d0de7211908e92d497b629330f176f01ea67a927 100644 (file)
@@ -924,14 +924,10 @@ void wxListBox::OnChar(wxKeyEvent& event)
 {
     if ( event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_NUMPAD_ENTER)
     {
-        wxWindow* parent = GetParent() ;
-        while( parent  && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL )
-            parent = parent->GetParent() ;
-
-        if ( parent && parent->GetDefaultItem() )
+        wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+        if ( tlw && tlw->GetDefaultItem() )
         {
-            wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
-                wxButton);
+            wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
             if ( def && def->IsEnabled() )
             {
                 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
index cae116ab4337e9d2dcf32ea6ef8013326cebe758..076e53e031cf4e9936789c72f4a71ffc99bd6e65 100644 (file)
@@ -1622,14 +1622,10 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
             }
             if ( !(m_windowStyle & wxTE_MULTILINE) )
             {
-                wxWindow *parent = GetParent();
-                while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
-                  parent = parent->GetParent() ;
-                }
-                if ( parent && parent->GetDefaultItem() )
+                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                if ( tlw && tlw->GetDefaultItem() )
                 {
-                    wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
-                                                          wxButton);
+                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                     if ( def && def->IsEnabled() )
                     {
                         wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
index af7a37ac49308a07ca2de03b7d2916935b921e9f..ed2ded5373472d57b5aef4b547c23947ff0ad4f1 100644 (file)
@@ -123,9 +123,9 @@ void wxButton::SetDefaultShadowThicknessAndResize()
 
 void wxButton::SetDefault()
 {
-    wxWindow *parent = GetParent();
-    if ( parent )
-        parent->SetDefaultItem(this);
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    if ( tlw )
+        tlw->SetDefaultItem(this);
 
     // We initially do not set XmNdefaultShadowThickness, to have
     // 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
     // resource for all wxButton in this parent (but not sub panels)
 
+    wxWindow *parent = GetParent();
     for (wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst ();
          node; node = node->GetNext ())
     {
index 08361d58b6da5d404e9cc6964e8f127a8e615897..0729c9eea0a7ff5a0b0517bfdef376d6e4c51e9d 100644 (file)
@@ -197,8 +197,8 @@ bool wxButton::Create(wxWindow *parent,
 
 wxButton::~wxButton()
 {
-    wxWindow *parent = GetParent();
-    if ( parent && parent->GetTmpDefaultItem() == this )
+    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+    if ( tlw && tlw->GetTmpDefaultItem() == this )
     {
         UnsetTmpDefault();
     }
@@ -344,12 +344,12 @@ wxSize wxButtonBase::GetDefaultSize()
 // set this button as the (permanently) default one in its panel
 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 ...
-    wxWindow *winOldDefault = parent->SetDefaultItem(this);
+    wxWindow *winOldDefault = tlw->SetDefaultItem(this);
 
     // ... and Windows
     SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false);
@@ -359,12 +359,12 @@ void wxButton::SetDefault()
 // set this button as being currently default
 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();
-    parent->SetTmpDefaultItem(this);
+    wxWindow *winOldDefault = tlw->GetDefaultItem();
+    tlw->SetTmpDefaultItem(this);
 
     SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false);
     SetDefaultStyle(this, true);
@@ -373,13 +373,13 @@ void wxButton::SetTmpDefault()
 // unset this button as currently default, it may still stay permanent default
 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(wxDynamicCast(winOldDefault, wxButton), true);
@@ -402,10 +402,10 @@ wxButton::SetDefaultStyle(wxButton *btn, bool on)
         if ( !wxTheApp->IsActive() )
             return;
 
-        wxWindow * const parent = btn->GetParent();
-        wxCHECK_RET( parent, _T("button without parent?") );
+        wxWindow * const tlw = wxGetTopLevelParent(btn);
+        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
         // BS_DEFPUSHBUTTON so there is nothing more to do
@@ -817,10 +817,10 @@ bool wxButton::MSWOnDraw(WXDRAWITEMSTRUCT *wxdis)
         bool selected = (state & ODS_SELECTED) != 0;
         if ( !selected )
         {
-            wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
-            if ( panel )
+            wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+            if ( tlw )
             {
-                selected = panel->GetDefaultItem() == this;
+                selected = tlw->GetDefaultItem() == this;
             }
         }
         bool pushed = (SendMessage(GetHwnd(), BM_GETSTATE, 0, 0) & BST_PUSHED) != 0;
index 32facca38443fc382a1c13d2559326c713154722..0515fe88be44d7bea076d5e4aab2b57e8213ebbe 100644 (file)
@@ -2146,14 +2146,17 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                         else // not a button itself
                         {
 #if wxUSE_BUTTON
-                            wxButton *btn = wxDynamicCast(GetDefaultItem(),
-                                                          wxButton);
-                            if ( btn && btn->IsEnabled() )
+                            wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                            if ( tlw )
                             {
-                                // if we do have a default button, do press it
-                                btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+                                wxButton *btn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+                                if ( btn && btn->IsEnabled() )
+                                {
+                                    // if we do have a default button, do press it
+                                    btn->MSWCommand(BN_CLICKED, 0 /* unused */);
 
-                                return true;
+                                    return true;
+                                }
                             }
                             else // no default button
 #endif // wxUSE_BUTTON
index 2e9a10d57821fe280818521f3d5b154b1cc321e1..7f02cfd61fab7ee48a0db8a59cc9ae1e408ec5a5 100644 (file)
@@ -116,16 +116,16 @@ bool wxButton::Create( wxWindow*          pParent,
 
 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
             //
-            pPanel->SetDefaultItem(NULL);
+            tlw->SetDefaultItem(NULL);
         }
     }
 } // end of wxButton::~wxButton
@@ -232,14 +232,14 @@ bool wxButton::SendClickEvent()
 
 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
     //
-    wxWindow*                       pWinOldDefault = pParent->SetDefaultItem(this);
+    wxWindow*                       pWinOldDefault = tlw->SetDefaultItem(this);
 
     SetDefaultStyle( wxDynamicCast(pWinOldDefault, wxButton), false);
     SetDefaultStyle( this, true );
@@ -247,26 +247,26 @@ void wxButton::SetDefault()
 
 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( this, true );
 } // end of wxButton::SetTmpDefault
 
 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( wxDynamicCast(pWinOldDefault, wxButton), true );
index 61dd62db3173a29ee55d3d378dd2eeda5fc7697d..2db19422f6d64662e5e418efe2e6d06c5cf9e17a 100644 (file)
@@ -2021,9 +2021,13 @@ bool wxWindowOS2::OS2ProcessMessage( WXMSG* pMsg )
                         }
                         else
                         {
-                            wxButton*   pBtn = wxDynamicCast( GetDefaultItem()
-                                                             ,wxButton
-                                                            );
+                            wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
+                            wxButton*   pBtn = NULL;
+
+                            if (tlw)
+                            {
+                                pBtn = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
+                            }
 
                             if (pBtn && pBtn->IsEnabled())
                             {