fixes to radio button handling (patch 803360)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 26 Sep 2003 19:43:47 +0000 (19:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 26 Sep 2003 19:43:47 +0000 (19:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23941 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/tbarbase.h
src/gtk/tbargtk.cpp
src/gtk1/tbargtk.cpp
src/msw/tbar95.cpp

index b8d25c07fc8bfa2f2872cfa43763c001f81abffd..9615494b60779755610c50b066cb739addaa0b64 100644 (file)
@@ -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:
 
index 076620e4471c768eb6e3380d9d8507ad61e0c117..30396a4b077500dc01bca1c422cb3e1b1e35de5a 100644 (file)
@@ -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;
 
index 0802257cccd7838b698a96beb86cec5f99d68cdb..4755e17a0e16c75c2aca7d42daf8d82f878bd9ff 100644 (file)
@@ -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 );
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
index 0802257cccd7838b698a96beb86cec5f99d68cdb..4755e17a0e16c75c2aca7d42daf8d82f878bd9ff 100644 (file)
@@ -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 );
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
index 263ff804adfcd5ae6700c8697287c21bb96d006f..230bddb9eb80eddea82e518c57686660aeca8b77 100644 (file)
@@ -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;