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);
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) \

View 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()
};

View 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);

View File

@ -43,10 +43,7 @@
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;
}
// ----------------------------------------------------------------------------

View 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()

View 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)
// ----------------------------------------------------------------------------

View 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);
}

View 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);
}

View File

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

View 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,

View 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 );

View 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 );

View 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 ) )

View 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 )

View 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() );

View 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() );

View 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)
// ============================================================================

View 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() );

View 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() )

View 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 ;
}

View 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;

View 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() );

View 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 )
{

View 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() );

View 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() );

View 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 ())
{

View 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;

View 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

View 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 );

View 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())
{