fix toolbar buttons so that they don't disappear temporarily when clicked if the event handler causes window update
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@56618 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -115,6 +115,8 @@ wxMSW:
|
|||||||
- Fixed bug with using non default encoding in wxTextCtrl in ANSI build.
|
- Fixed bug with using non default encoding in wxTextCtrl in ANSI build.
|
||||||
- Restored generation of events for accelerators when there is no menu bar.
|
- Restored generation of events for accelerators when there is no menu bar.
|
||||||
- Fixed wxArtProvider::GetSizeHint() to return 16x16 for wxART_FRAME_ICON.
|
- Fixed wxArtProvider::GetSizeHint() to return 16x16 for wxART_FRAME_ICON.
|
||||||
|
- Fixed toolbar buttons so that they don't disappear temporarily when clicked
|
||||||
|
if the event handler causes window update.
|
||||||
|
|
||||||
wxGTK:
|
wxGTK:
|
||||||
|
|
||||||
|
@@ -1129,9 +1129,10 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id)
|
|||||||
|
|
||||||
bool toggled = false; // just to suppress warnings
|
bool toggled = false; // just to suppress warnings
|
||||||
|
|
||||||
|
LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
|
||||||
|
|
||||||
if ( tool->CanBeToggled() )
|
if ( tool->CanBeToggled() )
|
||||||
{
|
{
|
||||||
LRESULT state = ::SendMessage(GetHwnd(), TB_GETSTATE, id, 0);
|
|
||||||
toggled = (state & TBSTATE_CHECKED) != 0;
|
toggled = (state & TBSTATE_CHECKED) != 0;
|
||||||
|
|
||||||
// ignore the event when a radio button is released, as this doesn't
|
// ignore the event when a radio button is released, as this doesn't
|
||||||
@@ -1143,9 +1144,29 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id)
|
|||||||
UnToggleRadioGroup(tool);
|
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((int)id, toggled);
|
||||||
|
|
||||||
|
// restore the unpressed state
|
||||||
|
::SendMessage(GetHwnd(), TB_SETSTATE, id, MAKELONG(state, 0));
|
||||||
|
|
||||||
// OnLeftClick() can veto the button state change - for buttons which
|
// OnLeftClick() can veto the button state change - for buttons which
|
||||||
// may be toggled only, of couse
|
// may be toggled only, of couse
|
||||||
if ( !OnLeftClick((int)id, toggled) && tool->CanBeToggled() )
|
if ( !allowLeftClick && tool->CanBeToggled() )
|
||||||
{
|
{
|
||||||
// revert back
|
// revert back
|
||||||
tool->Toggle(!toggled);
|
tool->Toggle(!toggled);
|
||||||
|
Reference in New Issue
Block a user