Fix checked disabled wxToolBar tools with custom images in wxMSW
Windows doesn't use the correct image for checked disabled tools, at least
up to and including Windows 7, so don't put such tools in the "checked"
state at all: this doesn't matter as they are disabled anyhow, but shows
the correct image for them.
See #12989.
(cherry picked from commit 29cd13cc8f
)
This commit is contained in:
committed by
Dimitri Schoolwerth
parent
fd95ab5615
commit
cfe9625a0d
@@ -715,6 +715,7 @@ wxMSW:
|
||||
- Fix using Esc as accelerator in the menus.
|
||||
- Fix wrong initial status bar height in some cases (Artur Wieczorek).
|
||||
- Correct wxGetOsDescription() for Windows 10 (Tobias Taschner).
|
||||
- Fix appearance of checked disabled wxToolBar tools with custom images.
|
||||
|
||||
|
||||
3.0.1: (released 2014-06-15)
|
||||
|
@@ -296,6 +296,23 @@ static RECT wxGetTBItemRect(HWND hwnd, int index, int id = wxID_NONE)
|
||||
return r;
|
||||
}
|
||||
|
||||
inline bool MSWShouldBeChecked(const wxToolBarToolBase *tool)
|
||||
{
|
||||
// Apparently, "checked" state image overrides the "disabled" image
|
||||
// so we need to enforce our custom "disabled" image (if there is any)
|
||||
// to be drawn for checked and disabled button tool.
|
||||
// Note: We believe this erroneous overriding is fixed in MSW 8.
|
||||
if ( wxGetWinVersion() <= wxWinVersion_7 &&
|
||||
tool->GetKind() == wxITEM_CHECK &&
|
||||
tool->GetDisabledBitmap().IsOk() &&
|
||||
!tool->IsEnabled() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return tool->IsToggled();
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
@@ -1011,7 +1028,7 @@ bool wxToolBar::Realize()
|
||||
|
||||
if ( tool->IsEnabled() )
|
||||
button.fsState |= TBSTATE_ENABLED;
|
||||
if ( tool->IsToggled() )
|
||||
if ( MSWShouldBeChecked(tool) )
|
||||
button.fsState |= TBSTATE_CHECKED;
|
||||
|
||||
switch ( tool->GetKind() )
|
||||
@@ -1415,7 +1432,7 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_)
|
||||
state |= TBSTATE_ENABLED;
|
||||
else
|
||||
state &= ~TBSTATE_ENABLED;
|
||||
if (tool->IsToggled())
|
||||
if ( MSWShouldBeChecked(tool) )
|
||||
state |= TBSTATE_CHECKED;
|
||||
else
|
||||
state &= ~TBSTATE_CHECKED;
|
||||
@@ -1428,7 +1445,8 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_)
|
||||
// revert back
|
||||
tool->Toggle(!toggled);
|
||||
|
||||
::SendMessage(GetHwnd(), TB_CHECKBUTTON, id, MAKELONG(!toggled, 0));
|
||||
::SendMessage(GetHwnd(), TB_CHECKBUTTON, id,
|
||||
MAKELONG(MSWShouldBeChecked(tool), 0));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -1672,12 +1690,19 @@ void wxToolBar::DoEnableTool(wxToolBarToolBase *tool, bool enable)
|
||||
{
|
||||
::SendMessage(GetHwnd(), TB_ENABLEBUTTON,
|
||||
(WPARAM)tool->GetId(), (LPARAM)MAKELONG(enable, 0));
|
||||
|
||||
// Adjust displayed checked state -- it could have changed if the tool is
|
||||
// disabled and has a custom "disabled state" bitmap.
|
||||
DoToggleTool(tool, tool->IsToggled());
|
||||
}
|
||||
|
||||
void wxToolBar::DoToggleTool(wxToolBarToolBase *tool, bool toggle)
|
||||
{
|
||||
wxASSERT_MSG( tool->IsToggled() == toggle, wxT("Inconsistent tool state") );
|
||||
|
||||
::SendMessage(GetHwnd(), TB_CHECKBUTTON,
|
||||
(WPARAM)tool->GetId(), (LPARAM)MAKELONG(toggle, 0));
|
||||
(WPARAM)tool->GetId(),
|
||||
(LPARAM)MAKELONG(MSWShouldBeChecked(tool), 0));
|
||||
}
|
||||
|
||||
void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle))
|
||||
|
Reference in New Issue
Block a user