From 2d9c9d9689aa431a7c1072c1758670fea9d0a9a8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 16 Jun 2021 19:12:32 +0100 Subject: [PATCH] Fix handling of ampersands in wxCheckListBox under MSW They were incorrectly interpreted as mnemonics when drawing wxCheckListBox items, which didn't make sense and was inconsistent with the other ports and even wxListBox in wxMSW itself. It also affected wxRearrangeCtrl under MSW, which uses wxCheckListBox for its implementation. Closes #19201. --- include/wx/msw/ownerdrw.h | 6 ++++++ src/msw/checklst.cpp | 9 +++++++++ src/msw/ownerdrw.cpp | 8 +++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/include/wx/msw/ownerdrw.h b/include/wx/msw/ownerdrw.h index 336da97216..5c70add41c 100644 --- a/include/wx/msw/ownerdrw.h +++ b/include/wx/msw/ownerdrw.h @@ -21,6 +21,12 @@ public: virtual bool OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction act, wxODStatus stat) wxOVERRIDE; + +protected: + // get the type of the text to draw in OnDrawItem(), by default is + // DST_PREFIXTEXT but can be overridden to return DST_TEXT when not using + // mnemonics + virtual int MSWGetTextType() const; }; #endif // wxUSE_OWNER_DRAWN diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index b23cb38f11..8f16bdb5f3 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -100,6 +100,15 @@ public: void Toggle() { Check(!IsChecked()); } +protected: + virtual int MSWGetTextType() const wxOVERRIDE + { + // Don't handle mnemonics in the label specially, they don't make sense + // for the listbox items that can't be activated from keyboard using + // them. + return DST_TEXT; + } + private: wxCheckListBox *m_parent; bool m_checked; diff --git a/src/msw/ownerdrw.cpp b/src/msw/ownerdrw.cpp index d47223ff95..c0673f95a9 100644 --- a/src/msw/ownerdrw.cpp +++ b/src/msw/ownerdrw.cpp @@ -24,6 +24,12 @@ // implementation of wxOwnerDrawn class // ============================================================================ +int wxOwnerDrawn::MSWGetTextType() const +{ + // By default, handle the mnemonics. + return DST_PREFIXTEXT; +} + // draw the item bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, wxODAction, wxODStatus stat) @@ -64,7 +70,7 @@ bool wxOwnerDrawn::OnDrawItem(wxDC& dc, const wxRect& rc, SIZE sizeRect; ::GetTextExtentPoint32(hdc, text.c_str(), text.length(), &sizeRect); - int flags = DST_PREFIXTEXT; + int flags = MSWGetTextType(); if ( (stat & wxODDisabled) && !(stat & wxODSelected) ) flags |= DSS_DISABLED;