fixes to radio button handling (patch 803360)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23941 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-09-26 19:43:47 +00:00
parent 3bf4189d96
commit 6bb7cee4e9
5 changed files with 53 additions and 17 deletions

View 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 <20>gren)
wxMSW:

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

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

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

View File

@@ -915,29 +915,31 @@ 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;
tool->Toggle(toggled);
UnToggleRadioGroup(tool);
}
bool toggled = tool->IsToggled();
// 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() )
{
// revert back
toggled = !toggled;
tool->SetToggle(toggled);
tool->Toggle(!toggled);
::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(toggled, 0));
}
}
return TRUE;
}