From 29cd13cc8f06eab726d3b774e057b64c94570923 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 5 Dec 2014 22:19:25 +0000 Subject: [PATCH] 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. Closes #12989. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78248 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/toolbar.cpp | 33 +++++++++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index d905100266..a8397090f8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -124,6 +124,7 @@ wxMSW: - Fix wxMenuEvent::GetMenu() for wxEVT_MENU_{OPEN,CLOSE} in MDI frames. - Added support for reading multi string values to wxRegKey (Carl Godkin). - Fix updating wxSpinCtrlDouble tooltip text (Laurent Poujoulat). +- Fix appearance of checked disabled wxToolBar tools with custom images. wxOSX/Cocoa: diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index 71ec043e76..6e1fb5e751 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -288,6 +288,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 // ============================================================================ @@ -976,7 +993,7 @@ bool wxToolBar::Realize() if ( tool->IsEnabled() ) button.fsState |= TBSTATE_ENABLED; - if ( tool->IsToggled() ) + if ( MSWShouldBeChecked(tool) ) button.fsState |= TBSTATE_CHECKED; switch ( tool->GetKind() ) @@ -1346,7 +1363,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; @@ -1359,7 +1376,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; @@ -1574,12 +1592,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))