From: Vadim Zeitlin Date: Fri, 26 Sep 2003 19:43:47 +0000 (+0000) Subject: fixes to radio button handling (patch 803360) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6bb7cee4e942e5816a02e03dcd4d13d5cfa91f19?ds=sidebyside fixes to radio button handling (patch 803360) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23941 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index b8d25c07fc..9615494b60 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -69,6 +69,7 @@ All (GUI): - added some support for C++ exceptions in the library (do read the manual!) - added wxListCtrl::GetViewRect() - added wxTextCtrl::MarkDirty() +- wxToolBar::ToggleTool() now works for radio buttons (Dag Ă…gren) wxMSW: diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index 076620e447..30396a4b07 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -575,6 +575,9 @@ protected: // find the tool by id wxToolBarToolBase *FindById(int toolid) const; + // un-toggle all buttons in the same radio group + void UnToggleRadioGroup(wxToolBarToolBase *tool); + // the list of all our tools wxToolBarToolsList m_tools; diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 0802257ccc..4755e17a0e 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -184,7 +184,22 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), } } - tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ); + if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() ) + { + // revert back + tool->Toggle(); + + wxBitmap bitmap = tool->GetBitmap(); + if ( bitmap.Ok() ) + { + GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap ); + + GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() + : (GdkBitmap *)NULL; + + gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask ); + } + } } //----------------------------------------------------------------------------- diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index 0802257ccc..4755e17a0e 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -184,7 +184,22 @@ static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), } } - tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ); + if( !tbar->OnLeftClick( tool->GetId(), tool->IsToggled() ) && tool->CanBeToggled() ) + { + // revert back + tool->Toggle(); + + wxBitmap bitmap = tool->GetBitmap(); + if ( bitmap.Ok() ) + { + GtkPixmap *pixmap = GTK_PIXMAP( tool->m_pixmap ); + + GdkBitmap *mask = bitmap.GetMask() ? bitmap.GetMask()->GetBitmap() + : (GdkBitmap *)NULL; + + gtk_pixmap_set( pixmap, bitmap.GetPixmap(), mask ); + } + } } //----------------------------------------------------------------------------- diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 263ff804ad..230bddb9eb 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -915,28 +915,30 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id) if ( !tool ) return FALSE; + bool toggled; + if ( tool->CanBeToggled() ) { LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0); - tool->Toggle((state & TBSTATE_CHECKED) != 0); - } + toggled = (state & TBSTATE_CHECKED) != 0; + + // ignore the event when a radio button is released, as this doesn't seem to + // happen at all, and is handled otherwise + if ( tool->GetKind() == wxITEM_RADIO && !toggled ) + return TRUE; - bool toggled = tool->IsToggled(); + tool->Toggle(toggled); + UnToggleRadioGroup(tool); + } - // avoid sending the event when a radio button is released, this is not - // interesting - if ( !tool->CanBeToggled() || tool->GetKind() != wxITEM_RADIO || toggled ) + // OnLeftClick() can veto the button state change - for buttons which + // may be toggled only, of couse + if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) { - // OnLeftClick() can veto the button state change - for buttons which - // may be toggled only, of couse - if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() ) - { - // revert back - toggled = !toggled; - tool->SetToggle(toggled); + // revert back + tool->Toggle(!toggled); - ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); - } + ::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0)); } return TRUE;