bool toggled = false; // just to suppress warnings
+ LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
+
if ( tool->CanBeToggled() )
{
- LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
toggled = (state & TBSTATE_CHECKED) != 0;
// ignore the event when a radio button is released, as this doesn't
UnToggleRadioGroup(tool);
}
+ // Without the two lines of code below, if the toolbar was repainted during
+ // OnLeftClick(), then it could end up without the tool bitmap temporarily
+ // (see http://lists.nongnu.org/archive/html/lmi/2008-10/msg00014.html).
+ // The Update() call bellow ensures that this won't happen, by repainting
+ // invalidated areas of the toolbar immediately.
+ //
+ // To complicate matters, the tool would be drawn in depressed state (this
+ // code is called when mouse button is released, not pressed). That's not
+ // ideal, having the tool pressed for the duration of OnLeftClick()
+ // provides the user with useful visual clue that the app is busy reacting
+ // to the event. So we manually put the tool into pressed state, handle the
+ // event and then finally restore tool's original state.
+ ::SendMessage(GetHwnd(), TB_SETSTATE, id, MAKELONG(state | TBSTATE_PRESSED, 0));
+ Update();
+
+ bool allowLeftClick = OnLeftClick(id, toggled);
+
+ // Restore the unpressed state. Enabled/toggled state might have been
+ // changed since so take care of it.
+ if (tool->IsEnabled())
+ state |= TBSTATE_ENABLED;
+ else
+ state &= ~TBSTATE_ENABLED;
+ if (tool->IsToggled())
+ state |= TBSTATE_CHECKED;
+ else
+ state &= ~TBSTATE_CHECKED;
+ ::SendMessage(GetHwnd(), TB_SETSTATE, id, MAKELONG(state, 0));
+
// OnLeftClick() can veto the button state change - for buttons which
// may be toggled only, of couse
- if ( !OnLeftClick(id, toggled) && tool->CanBeToggled() )
+ if ( !allowLeftClick && tool->CanBeToggled() )
{
// revert back
tool->Toggle(!toggled);
void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap )
{
- wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+ wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
if ( tool )
{
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap )
{
- wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id));
+ wxToolBarTool* tool = static_cast<wxToolBarTool*>(FindById(id));
if ( tool )
{
wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools."));
#ifndef __WXWINCE__
case WM_PAINT:
- if ( HandlePaint(wParam, lParam) )
+ // refreshing the controls in the toolbar inside a composite window
+ // results in an endless stream of WM_PAINT messages -- and seems
+ // to be unnecessary anyhow as everything works just fine without
+ // any special workarounds in this case
+ if ( !IsDoubleBuffered() && HandlePaint(wParam, lParam) )
return 0;
-#endif
-
- default:
break;
+#endif // __WXWINCE__
}
return wxControl::MSWWindowProc(nMsg, wParam, lParam);