From e56fee472c0a59f9b1d45c84a8439e37a1f9925d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 9 Feb 2013 00:35:58 +0000 Subject: [PATCH] Fix pulsing of bitmaps in focused buttons under Windows 7. It turns out that the actual bitmap shown in this case varies between the bitmaps at PBS_DEFAULTED and PBS_STYLUSHOT, so that it's invisible half of the time if we don't specify the value for the latter. Do it now to fix unwanted pulsing of the bitmap in the focused button. Closes #15034. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73486 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/anybutton.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index d50ccb9..1cc4395 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -635,6 +635,7 @@ wxGTK: wxMSW: +- Fix pulsing of bitmaps in focused buttons under Windows 7 (Catalin Raceanu). - Fix setting colours for the text part of wxComboBox (Igor Korot). - Add support for CURRENCY and SCODE types to OLE Automation helpers (PB). - Allow setting LCID used by wxAutomationObject (PB). diff --git a/src/msw/anybutton.cpp b/src/msw/anybutton.cpp index b8fc1ad..cf561b5 100644 --- a/src/msw/anybutton.cpp +++ b/src/msw/anybutton.cpp @@ -217,7 +217,7 @@ public: // the image list wxXPButtonImageData(wxAnyButton *btn, const wxBitmap& bitmap) : m_iml(bitmap.GetWidth(), bitmap.GetHeight(), true /* use mask */, - wxAnyButton::State_Max), + wxAnyButton::State_Max + 1 /* see "pulse" comment below */), m_hwndBtn(GetHwndOf(btn)) { // initialize all bitmaps except for the disabled one to normal state @@ -231,6 +231,20 @@ public: #endif } + // In addition to the states supported by wxWidgets such as normal, + // hot, pressed, disabled and focused, we need to add bitmap for + // another state when running under Windows 7 -- the so called "stylus + // hot" state corresponding to PBS_STYLUSHOT constant. While it's + // documented in MSDN as being only used with tablets, it is a lie as + // a focused button actually alternates between the image list elements + // with PBS_DEFAULTED and PBS_STYLUSHOT indices and, in particular, + // just disappears during half of the time if the latter is not set so + // we absolutely must set it. + // + // This also explains why we need to allocate an extra slot in the + // image list ctor above, the slot State_Max is used for this one. + m_iml.Add(bitmap); + m_data.himl = GetHimagelistOf(&m_iml); // no margins by default @@ -254,6 +268,11 @@ public: { m_iml.Replace(which, bitmap); + // As we want the focused button to always show its bitmap, we need to + // update the "stylus hot" one to match it to avoid any pulsing. + if ( which == wxAnyButton::State_Focused ) + m_iml.Replace(wxAnyButton::State_Max, bitmap); + UpdateImageInfo(); } -- 2.7.4