From 5166ddea2bf02dc422b70824f121d65e23b56427 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:16:20 +0200 Subject: [PATCH 01/14] Create cursors with correct size when DPI changes GetIconInfo does not return DPI aware results. Adjust it to the DPI of the display that shows the cursor. --- src/msw/cursor.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/msw/cursor.cpp b/src/msw/cursor.cpp index d57f980ea5..47b0caeed1 100644 --- a/src/msw/cursor.cpp +++ b/src/msw/cursor.cpp @@ -36,6 +36,8 @@ #include "wx/module.h" #endif +#include "wx/display.h" + #include "wx/msw/private.h" #include "wx/msw/missing.h" // IDC_HAND @@ -263,12 +265,20 @@ wxPoint wxCursor::GetHotSpot() const namespace { -void ReverseBitmap(HBITMAP bitmap, int width, int height) +wxSize ScaleAndReverseBitmap(HBITMAP& bitmap, float scale) { + BITMAP bmp; + if ( !::GetObject(bitmap, sizeof(bmp), &bmp) ) + return wxSize(); + wxSize cs(bmp.bmWidth * scale, bmp.bmHeight * scale); + MemoryHDC hdc; SelectInHDC selBitmap(hdc, bitmap); - ::StretchBlt(hdc, width - 1, 0, -width, height, - hdc, 0, 0, width, height, SRCCOPY); + if ( scale != 1 ) + ::SetStretchBltMode(hdc, HALFTONE); + ::StretchBlt(hdc, cs.x - 1, 0, -cs.x, cs.y, hdc, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY); + + return cs; } HCURSOR CreateReverseCursor(HCURSOR cursor) @@ -277,14 +287,15 @@ HCURSOR CreateReverseCursor(HCURSOR cursor) if ( !info.GetFrom(cursor) ) return NULL; - BITMAP bmp; - if ( !::GetObject(info.hbmMask, sizeof(bmp), &bmp) ) - return NULL; + const unsigned displayID = (unsigned)wxDisplay::GetFromPoint(wxGetMousePosition()); + wxDisplay disp(displayID == 0u || displayID < wxDisplay::GetCount() ? displayID : 0u); + const float scale = (float)disp.GetPPI().y / wxGetDisplayPPI().y; - ReverseBitmap(info.hbmMask, bmp.bmWidth, bmp.bmHeight); + wxSize cursorSize = ScaleAndReverseBitmap(info.hbmMask, scale); if ( info.hbmColor ) - ReverseBitmap(info.hbmColor, bmp.bmWidth, bmp.bmHeight); - info.xHotspot = (DWORD)bmp.bmWidth - 1 - info.xHotspot; + ScaleAndReverseBitmap(info.hbmColor, scale); + info.xHotspot = (DWORD)(cursorSize.x - 1 - info.xHotspot * scale); + info.yHotspot = (DWORD)(info.yHotspot * scale); return ::CreateIconIndirect(&info); } From 9b0cdc8d7d238d39959c3dfba14c90124f6b661d Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:17:03 +0200 Subject: [PATCH 02/14] Only create the wxSTC cursor when it is needed --- src/stc/PlatWX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 359b5c4383..5b4ed4af35 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -1975,9 +1975,9 @@ void Window::SetCursor(Cursor curs) { break; } - wxCursor wc = wxCursor(cursorId); if(curs != cursorLast) { + wxCursor wc = wxCursor(cursorId); GETWIN(wid)->SetCursor(wc); cursorLast = curs; } From 6eb357f038d77b86e6c0749ca5b11f0cd4284174 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:23:50 +0200 Subject: [PATCH 03/14] Improve DPI handling in wxSTC Adjusting the zoom level does not work correctly. It could lead to ever increasing zoom. Instead, set the correct DPI of the underlying device context. --- samples/stc/edit.cpp | 2 +- src/stc/PlatWX.cpp | 24 ++++++++---------------- src/stc/ScintillaWX.cpp | 2 +- src/stc/ScintillaWX.h | 2 +- src/stc/stc.cpp | 22 ++++------------------ src/stc/stc.cpp.in | 22 ++++------------------ 6 files changed, 19 insertions(+), 55 deletions(-) diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp index 0900639684..c2d94cf933 100644 --- a/samples/stc/edit.cpp +++ b/samples/stc/edit.cpp @@ -196,7 +196,7 @@ Edit::Edit (wxWindow *parent, wxWindowID id, // miscellaneous m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, "_999999"); - m_FoldingMargin = 16; + m_FoldingMargin = FromDIP(16); CmdKeyClear (wxSTC_KEY_TAB, 0); // this is done by the menu accelerator key SetLayoutCache (wxSTC_CACHE_PAGE); UsePopUp(wxSTC_POPUP_ALL); diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 5b4ed4af35..3ab15eb9d3 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -103,6 +103,8 @@ wxColour wxColourFromCDandAlpha(ColourDesired& cd, int alpha) { namespace { +inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } + // wxFont with ascent cached, a pointer to this type is stored in Font::fid. class wxFontWithAscent : public wxFont { @@ -295,15 +297,15 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface, WindowID w hdc = new wxMemoryDC(static_cast(surface)->hdc); else hdc = new wxMemoryDC(); + ((wxMemoryDC*)hdc)->GetImpl()->SetWindow(GETWIN(winid)); hdcOwned = true; if (width < 1) width = 1; if (height < 1) height = 1; #ifdef __WXMSW__ bitmap = new wxBitmap(width, height); - wxUnusedVar(winid); #else bitmap = new wxBitmap(); - bitmap->CreateScaled(width, height,wxBITMAP_SCREEN_DEPTH,((wxWindow*)winid)->GetContentScaleFactor()); + bitmap->CreateScaled(width, height,wxBITMAP_SCREEN_DEPTH,(GETWIN(winid))->GetContentScaleFactor()); #endif ((wxMemoryDC*)hdc)->SelectObject(*bitmap); } @@ -999,7 +1001,6 @@ public: // helpers void SetFont(Font &font_); - void SetScale(wxDC* dc); HRESULT FlushDrawing(); void D2DPenColour(ColourDesired fore, int alpha=255); void DrawTextCommon(PRectangle rc, Font &font_, XYPOSITION ybase, @@ -1057,19 +1058,18 @@ SurfaceD2D::~SurfaceD2D() Release(); } -void SurfaceD2D::Init(WindowID WXUNUSED(wid)) +void SurfaceD2D::Init(WindowID wid) { Release(); - wxScreenDC sdc; - SetScale(&sdc); + m_logPixelsY = GETWIN(wid)->GetDPI().GetY(); } void SurfaceD2D::Init(SurfaceID sid, WindowID wid) { Release(); - wxWindow* win = wxDynamicCast(wid,wxWindow); + wxWindow* win = GETWIN(wid); if ( win && win->GetName() == "wxSTCCallTip" ) win = win->GetParent(); @@ -1078,7 +1078,7 @@ void SurfaceD2D::Init(SurfaceID sid, WindowID wid) { wxDC* const dc = static_cast(sid); const wxSize sz = dc->GetSize(); - SetScale(dc); + m_logPixelsY = win->GetDPI().GetY(); ScintillaWX* const sciwx = reinterpret_cast(stc->GetDirectPointer()); m_surfaceData = static_cast(sciwx->GetSurfaceData()); @@ -1773,12 +1773,6 @@ void SurfaceD2D::SetFont(Font &font_) } } -void SurfaceD2D::SetScale(wxDC* dc) -{ - wxSize sz = dc->GetPPI(); - m_logPixelsY = sz.GetY(); -} - HRESULT SurfaceD2D::FlushDrawing() { return m_pRenderTarget->Flush(); @@ -1861,8 +1855,6 @@ Surface *Surface::Allocate(int technology) { //---------------------------------------------------------------------- -inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; } - Window::~Window() { } diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 74f446229d..7b7a7ef033 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -1039,7 +1039,7 @@ void ScintillaWX::DoGainFocus(){ CreateSystemCaret(); } -void ScintillaWX::DoSysColourChange() { +void ScintillaWX::DoInvalidateStyleData() { InvalidateStyleData(); } diff --git a/src/stc/ScintillaWX.h b/src/stc/ScintillaWX.h index dfe97e1d4f..cee2409998 100644 --- a/src/stc/ScintillaWX.h +++ b/src/stc/ScintillaWX.h @@ -161,7 +161,7 @@ public: void DoSize(int width, int height); void DoLoseFocus(); void DoGainFocus(); - void DoSysColourChange(); + void DoInvalidateStyleData(); void DoLeftButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoRightButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, bool alt); void DoLeftButtonUp(Point pt, unsigned int curTime, bool ctrl); diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 2ae931b4e1..a0ed931021 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -240,18 +240,6 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT); #endif -#ifdef __WXMSW__ - // Set initial zoom for active DPI - const HDC hdc = ::GetDC(parent->GetHWND()); - const int baseDPI = ::GetDeviceCaps(hdc, LOGPIXELSY); - const int activeDPI = parent->GetDPI().y; - ::ReleaseDC(parent->GetHWND(), hdc); - - const int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - const int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, activeDPI, baseDPI); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); -#endif - return true; } @@ -5445,12 +5433,10 @@ void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { } -void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) -{ - int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, evt.GetNewDPI().y, evt.GetOldDPI().y); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); +void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { + m_swx->DoInvalidateStyleData(); + // adjust the margins to the new DPI for ( int i = 0; i < SC_MAX_MARGIN; ++i ) { SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); @@ -5459,7 +5445,7 @@ void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { - m_swx->DoSysColourChange(); + m_swx->DoInvalidateStyleData(); } diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 63db3db362..4ea7df2d78 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -240,18 +240,6 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT); #endif -#ifdef __WXMSW__ - // Set initial zoom for active DPI - const HDC hdc = ::GetDC(parent->GetHWND()); - const int baseDPI = ::GetDeviceCaps(hdc, LOGPIXELSY); - const int activeDPI = parent->GetDPI().y; - ::ReleaseDC(parent->GetHWND(), hdc); - - const int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - const int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, activeDPI, baseDPI); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); -#endif - return true; } @@ -972,12 +960,10 @@ void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { } -void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) -{ - int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); - int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, evt.GetNewDPI().y, evt.GetOldDPI().y); - SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); +void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { + m_swx->DoInvalidateStyleData(); + // adjust the margins to the new DPI for ( int i = 0; i < SC_MAX_MARGIN; ++i ) { SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); @@ -986,7 +972,7 @@ void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { - m_swx->DoSysColourChange(); + m_swx->DoInvalidateStyleData(); } From 951974f8084ba8b1e8c0fa93f706c3e820256b84 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:37:08 +0200 Subject: [PATCH 04/14] Reset the wxSTC cursor when the DPI changes This causes the cursor to be recreated (when necessary) at the correct DPI. --- src/stc/stc.cpp | 5 +++++ src/stc/stc.cpp.in | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index a0ed931021..b2578a4bd8 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -5436,6 +5436,11 @@ void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { m_swx->DoInvalidateStyleData(); + // trigger a cursor change, so any cursors created by wxWidgets (like reverse arrow) will be recreated + const int oldCursor = GetSTCCursor(); + SetSTCCursor(-1); + SetSTCCursor(oldCursor); + // adjust the margins to the new DPI for ( int i = 0; i < SC_MAX_MARGIN; ++i ) { diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 4ea7df2d78..35210cbf1b 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -963,6 +963,11 @@ void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { m_swx->DoInvalidateStyleData(); + // trigger a cursor change, so any cursors created by wxWidgets (like reverse arrow) will be recreated + const int oldCursor = GetSTCCursor(); + SetSTCCursor(-1); + SetSTCCursor(oldCursor); + // adjust the margins to the new DPI for ( int i = 0; i < SC_MAX_MARGIN; ++i ) { From 0195d828324585886ce8995590cda3051a42de53 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:37:44 +0200 Subject: [PATCH 05/14] Remove unimplemented functions and code from STC example --- samples/stc/defsext.h | 19 ------------------- samples/stc/edit.h | 1 - samples/stc/stctest.cpp | 12 ------------ 3 files changed, 32 deletions(-) diff --git a/samples/stc/defsext.h b/samples/stc/defsext.h index f046ecdbf2..a46b24ae9a 100644 --- a/samples/stc/defsext.h +++ b/samples/stc/defsext.h @@ -24,11 +24,6 @@ //============================================================================ #define DEFAULT_LANGUAGE "" - -#define PAGE_COMMON _("Common") -#define PAGE_LANGUAGES _("Languages") -#define PAGE_STYLE_TYPES _("Style types") - #define STYLE_TYPES_COUNT 32 @@ -47,7 +42,6 @@ enum { myID_REPLACENEXT, myID_BRACEMATCH, myID_GOTO, - myID_PAGEACTIVE, myID_DISPLAYEOL, myID_INDENTGUIDE, myID_LINENUMBER, @@ -80,25 +74,12 @@ enum { myID_USECHARSET, myID_CHARSETANSI, myID_CHARSETMAC, - myID_PAGEPREV, - myID_PAGENEXT, myID_SELECTLINE, myID_EDIT_LAST = myID_SELECTLINE, myID_WINDOW_MINIMAL, // other IDs - myID_STATUSBAR, - myID_TITLEBAR, myID_ABOUTTIMER, - myID_UPDATETIMER, - - // dialog find IDs - myID_DLG_FIND_TEXT, - - // preferences IDs - myID_PREFS_LANGUAGE, - myID_PREFS_STYLETYPE, - myID_PREFS_KEYWORDS, }; // ---------------------------------------------------------------------------- diff --git a/samples/stc/edit.h b/samples/stc/edit.h index 09ca020847..23263dd7f8 100644 --- a/samples/stc/edit.h +++ b/samples/stc/edit.h @@ -115,7 +115,6 @@ public: //! language/lexer wxString DeterminePrefs (const wxString &filename); bool InitializePrefs (const wxString &filename); - bool UserSettings (const wxString &filename); LanguageInfo const* GetLanguageInfo () {return m_language;} //! load/save file diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 9c4f95c11b..c6f9d67bd0 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -63,12 +63,6 @@ #define APP_LICENCE "wxWidgets" #define APP_VERSION "0.1.alpha" -#define APP_BUILD __DATE__ - -#define APP_WEBSITE "http://www.wxWidgets.org" -#define APP_MAIL "mailto://???" - -#define NONAME _("") class AppBook; @@ -132,12 +126,8 @@ public: void OnClose (wxCloseEvent &event); void OnAbout (wxCommandEvent &event); void OnExit (wxCommandEvent &event); - void OnTimerEvent (wxTimerEvent &event); //! file - void OnFileNew (wxCommandEvent &event); - void OnFileNewFrame (wxCommandEvent &event); void OnFileOpen (wxCommandEvent &event); - void OnFileOpenFrame (wxCommandEvent &event); void OnFileSave (wxCommandEvent &event); void OnFileSaveAs (wxCommandEvent &event); void OnFileClose (wxCommandEvent &event); @@ -586,8 +576,6 @@ void AppFrame::CreateMenu () // Window menu wxMenu *menuWindow = new wxMenu; - menuWindow->Append (myID_PAGEPREV, _("&Previous\tCtrl+Shift+Tab")); - menuWindow->Append (myID_PAGENEXT, _("&Next\tCtrl+Tab")); menuWindow->Append(myID_WINDOW_MINIMAL, _("&Minimal editor")); // Help menu From a500c60feb37572a8c10fb98a1898afb64b0bc4a Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:42:33 +0200 Subject: [PATCH 06/14] Add option to STC example to select drawing technology --- samples/stc/defsext.h | 2 ++ samples/stc/edit.cpp | 7 +++++++ samples/stc/edit.h | 1 + samples/stc/stctest.cpp | 9 ++++++++- 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/samples/stc/defsext.h b/samples/stc/defsext.h index a46b24ae9a..f0c3189b46 100644 --- a/samples/stc/defsext.h +++ b/samples/stc/defsext.h @@ -70,6 +70,8 @@ enum { myID_MULTIPLE_SELECTIONS, myID_MULTI_PASTE, myID_MULTIPLE_SELECTIONS_TYPING, + myID_TECHNOLOGY_DEFAULT, + myID_TECHNOLOGY_DIRECTWRITE, myID_CUSTOM_POPUP, myID_USECHARSET, myID_CHARSETANSI, diff --git a/samples/stc/edit.cpp b/samples/stc/edit.cpp index c2d94cf933..25b143eb93 100644 --- a/samples/stc/edit.cpp +++ b/samples/stc/edit.cpp @@ -128,6 +128,8 @@ wxBEGIN_EVENT_TABLE (Edit, wxStyledTextCtrl) EVT_MENU(myID_MULTI_PASTE, Edit::OnMultiPaste) EVT_MENU(myID_MULTIPLE_SELECTIONS_TYPING, Edit::OnMultipleSelectionsTyping) EVT_MENU(myID_CUSTOM_POPUP, Edit::OnCustomPopup) + EVT_MENU(myID_TECHNOLOGY_DEFAULT, Edit::OnTechnology) + EVT_MENU(myID_TECHNOLOGY_DIRECTWRITE, Edit::OnTechnology) // stc EVT_STC_MARGINCLICK (wxID_ANY, Edit::OnMarginClick) EVT_STC_CHARADDED (wxID_ANY, Edit::OnCharAdded) @@ -480,6 +482,11 @@ void Edit::OnCustomPopup(wxCommandEvent& evt) UsePopUp(evt.IsChecked() ? wxSTC_POPUP_NEVER : wxSTC_POPUP_ALL); } +void Edit::OnTechnology(wxCommandEvent& event) +{ + SetTechnology(event.GetId() == myID_TECHNOLOGY_DIRECTWRITE ? wxSTC_TECHNOLOGY_DIRECTWRITE : wxSTC_TECHNOLOGY_DEFAULT); +} + //! misc void Edit::OnMarginClick (wxStyledTextEvent &event) { if (event.GetMargin() == 2) { diff --git a/samples/stc/edit.h b/samples/stc/edit.h index 23263dd7f8..6465d0d9a0 100644 --- a/samples/stc/edit.h +++ b/samples/stc/edit.h @@ -102,6 +102,7 @@ public: void OnMultiPaste(wxCommandEvent& event); void OnMultipleSelectionsTyping(wxCommandEvent& event); void OnCustomPopup(wxCommandEvent& evt); + void OnTechnology(wxCommandEvent& event); // stc void OnMarginClick (wxStyledTextEvent &event); void OnCharAdded (wxStyledTextEvent &event); diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index c6f9d67bd0..300470883b 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -572,7 +572,14 @@ void AppFrame::CreateMenu () menuExtra->AppendCheckItem(myID_MULTI_PASTE, _("Toggle multi-&paste")); menuExtra->AppendCheckItem(myID_MULTIPLE_SELECTIONS_TYPING, _("Toggle t&yping on multiple selections")); menuExtra->AppendSeparator(); - menuExtra->AppendCheckItem (myID_CUSTOM_POPUP, _("C&ustom popup menu")); +#if defined(__WXMSW__) && wxUSE_GRAPHICS_DIRECT2D + wxMenu* menuTechnology = new wxMenu; + menuTechnology->AppendRadioItem(myID_TECHNOLOGY_DEFAULT, _("&Default")); + menuTechnology->AppendRadioItem(myID_TECHNOLOGY_DIRECTWRITE, _("Direct&Write")); + menuExtra->AppendSubMenu(menuTechnology, _("&Technology")); + menuExtra->AppendSeparator(); +#endif + menuExtra->AppendCheckItem (myID_CUSTOM_POPUP, _("C&ustom context menu")); // Window menu wxMenu *menuWindow = new wxMenu; From a29aae25fcd458109dbdc2e5e62994ba0ab6ce64 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 31 May 2020 23:44:52 +0200 Subject: [PATCH 07/14] Use a different font for the MinimalEditor in the STC example wxSYS_ANSI_FIXED_FONT uses 'Courier' font, which is rendered small on high DPI displays. Use wxFONTFAMILY_TELETYPE instead, which will use font 'Courier New'. --- samples/stc/stctest.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/stc/stctest.cpp b/samples/stc/stctest.cpp index 300470883b..d7aef83b25 100644 --- a/samples/stc/stctest.cpp +++ b/samples/stc/stctest.cpp @@ -758,7 +758,7 @@ public: } virtual bool SetFont(const wxFont& font) wxOVERRIDE { - StyleSetFont(wxSTC_STYLE_DEFAULT, (wxFont&)font); + StyleSetFont(wxSTC_STYLE_DEFAULT, font); return wxStyledTextCtrl::SetFont(font); } void SetLexerXml() @@ -818,7 +818,7 @@ public: MinimalEditorFrame() : wxFrame(NULL, wxID_ANY, _("Minimal Editor")) { MinimalEditor* editor = new MinimalEditor(this); - editor->SetFont(wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT)); + editor->SetFont(wxFontInfo().Family(wxFONTFAMILY_TELETYPE)); wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(editor, 1, wxEXPAND); SetSizer(sizer); From 4700298c2667bee149b17e2ccbb21b816639cc7e Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Mon, 1 Jun 2020 13:58:12 +0200 Subject: [PATCH 08/14] Move DPI handling from wxTopLevelWindow to wxNonOwnedWindow This way, other windows (like wxPopupWindow) will also be able to handle DPI events. Override InheritAttributes() and use it to set the initial DPI values. --- include/wx/msw/nonownedwnd.h | 16 +++++ include/wx/msw/toplevel.h | 14 +---- src/msw/nonownedwnd.cpp | 119 ++++++++++++++++++++++++++++++----- src/msw/toplevel.cpp | 80 +---------------------- 4 files changed, 122 insertions(+), 107 deletions(-) diff --git a/include/wx/msw/nonownedwnd.h b/include/wx/msw/nonownedwnd.h index c5d40bfa97..a3f8aa4274 100644 --- a/include/wx/msw/nonownedwnd.h +++ b/include/wx/msw/nonownedwnd.h @@ -27,11 +27,27 @@ protected: virtual bool DoSetRegionShape(const wxRegion& region) wxOVERRIDE; #if wxUSE_GRAPHICS_CONTEXT virtual bool DoSetPathShape(const wxGraphicsPath& path) wxOVERRIDE; +#endif // wxUSE_GRAPHICS_CONTEXT + + virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; + virtual void InheritAttributes() wxOVERRIDE; private: + bool HandleDPIChange(const wxSize& newDPI, const wxRect& newRect); + +#if wxUSE_GRAPHICS_CONTEXT wxNonOwnedWindowShapeImpl* m_shapeImpl; #endif // wxUSE_GRAPHICS_CONTEXT + // Keep track of the DPI used in this window. So when per-monitor dpi + // awareness is enabled, both old and new DPI are known for + // wxDPIChangedEvent and wxWindow::MSWUpdateOnDPIChange. + wxSize m_activeDPI; + + // This window supports handling per-monitor DPI awareness when the + // application manifest contains PerMonitorV2. + bool m_perMonitorDPIaware; + wxDECLARE_NO_COPY_CLASS(wxNonOwnedWindow); }; diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h index d32764bb1f..5412de421e 100644 --- a/include/wx/msw/toplevel.h +++ b/include/wx/msw/toplevel.h @@ -115,7 +115,7 @@ public: virtual WXHWND MSWGetParent() const wxOVERRIDE; // window proc for the frames - WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; + virtual WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE; // returns true if the platform should explicitly apply a theme border virtual bool CanApplyThemeBorder() const wxOVERRIDE { return false; } @@ -166,9 +166,6 @@ protected: int& x, int& y, int& w, int& h) const wxOVERRIDE; - // WM_DPICHANGED handler. - bool HandleDPIChange(const wxSize& newDPI, const wxRect& newRect); - // This field contains the show command to use when showing the window the // next time and also indicates whether the window should be considered // being iconized or maximized (which may be different from whether it's @@ -195,15 +192,6 @@ protected: wxWindowRef m_winLastFocused; private: - // Keep track of the DPI used in this window. So when per-monitor dpi - // awareness is enabled, both old and new DPI are known for - // wxDPIChangedEvent and wxWindow::MSWUpdateOnDPIChange. - wxSize m_activeDPI; - - // This window supports handling per-monitor DPI awareness when the - // application manifest contains PerMonitorV2. - bool m_perMonitorDPIaware; - // The system menu: initially NULL but can be set (once) by // MSWGetSystemMenu(). Owned by this window. wxMenu *m_menuSystem; diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index 3876870071..16ca7ae585 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -36,6 +36,7 @@ #include "wx/graphics.h" #endif // wxUSE_GRAPHICS_CONTEXT +#include "wx/dynlib.h" #include "wx/scopedptr.h" // ============================================================================ @@ -128,16 +129,6 @@ private: wxDECLARE_NO_COPY_CLASS(wxNonOwnedWindowShapeImpl); }; -wxNonOwnedWindow::wxNonOwnedWindow() -{ - m_shapeImpl = NULL; -} - -wxNonOwnedWindow::~wxNonOwnedWindow() -{ - delete m_shapeImpl; -} - bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) { delete m_shapeImpl; @@ -146,17 +137,115 @@ bool wxNonOwnedWindow::DoSetPathShape(const wxGraphicsPath& path) return true; } -#else // !wxUSE_GRAPHICS_CONTEXT +#endif // wxUSE_GRAPHICS_CONTEXT -// Trivial ctor and dtor as we don't have anything to do when wxGraphicsContext -// is not used but still define them here to avoid adding even more #if checks -// to the header, it it doesn't do any harm even though it's not needed. wxNonOwnedWindow::wxNonOwnedWindow() { +#if wxUSE_GRAPHICS_CONTEXT + m_shapeImpl = NULL; +#endif // wxUSE_GRAPHICS_CONTEXT + + m_activeDPI = wxDefaultSize; + m_perMonitorDPIaware = false; } wxNonOwnedWindow::~wxNonOwnedWindow() { +#if wxUSE_GRAPHICS_CONTEXT + delete m_shapeImpl; +#endif // wxUSE_GRAPHICS_CONTEXT } -#endif // wxUSE_GRAPHICS_CONTEXT/!wxUSE_GRAPHICS_CONTEXT +namespace +{ + +static bool IsPerMonitorDPIAware(HWND hwnd) +{ + bool dpiAware = false; + + // Determine if 'Per Monitor v2' DPI awareness is enabled in the + // applications manifest. +#if wxUSE_DYNLIB_CLASS + #define WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((WXDPI_AWARENESS_CONTEXT)-4) + typedef WXDPI_AWARENESS_CONTEXT(WINAPI * GetWindowDpiAwarenessContext_t)(HWND hwnd); + typedef BOOL(WINAPI * AreDpiAwarenessContextsEqual_t)(WXDPI_AWARENESS_CONTEXT dpiContextA, WXDPI_AWARENESS_CONTEXT dpiContextB); + static GetWindowDpiAwarenessContext_t s_pfnGetWindowDpiAwarenessContext = NULL; + static AreDpiAwarenessContextsEqual_t s_pfnAreDpiAwarenessContextsEqual = NULL; + static bool s_initDone = false; + + if ( !s_initDone ) + { + wxLoadedDLL dllUser32("user32.dll"); + wxDL_INIT_FUNC(s_pfn, GetWindowDpiAwarenessContext, dllUser32); + wxDL_INIT_FUNC(s_pfn, AreDpiAwarenessContextsEqual, dllUser32); + s_initDone = true; + } + + if ( s_pfnGetWindowDpiAwarenessContext && s_pfnAreDpiAwarenessContextsEqual ) + { + WXDPI_AWARENESS_CONTEXT dpiAwarenessContext = s_pfnGetWindowDpiAwarenessContext(hwnd); + + if ( s_pfnAreDpiAwarenessContextsEqual(dpiAwarenessContext, WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE ) + { + dpiAware = true; + } + } +#endif // wxUSE_DYNLIB_CLASS + + return dpiAware; +} + +} + +void wxNonOwnedWindow::InheritAttributes() +{ + m_activeDPI = GetDPI(); + m_perMonitorDPIaware = IsPerMonitorDPIAware(GetHwnd()); + + wxNonOwnedWindowBase::InheritAttributes(); +} + +WXLRESULT wxNonOwnedWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +{ + WXLRESULT rc = 0; + bool processed = false; + + switch ( message ) + { + case WM_DPICHANGED: + { + const RECT* const prcNewWindow = + reinterpret_cast(lParam); + + processed = HandleDPIChange(wxSize(LOWORD(wParam), + HIWORD(wParam)), + wxRectFromRECT(*prcNewWindow)); + } + break; + } + + if (!processed) + rc = wxNonOwnedWindowBase::MSWWindowProc(message, wParam, lParam); + + return rc; +} + +bool wxNonOwnedWindow::HandleDPIChange(const wxSize& newDPI, const wxRect& newRect) +{ + if ( !m_perMonitorDPIaware ) + { + return false; + } + + if ( newDPI != m_activeDPI ) + { + MSWUpdateOnDPIChange(m_activeDPI, newDPI); + m_activeDPI = newDPI; + } + + SetSize(newRect); + + Refresh(); + + return true; +} diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 2ede920e8b..4c552f2604 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -37,7 +37,6 @@ #include "wx/module.h" #endif //WX_PRECOMP -#include "wx/dynlib.h" #include "wx/scopeguard.h" #include "wx/tooltip.h" @@ -104,9 +103,6 @@ void wxTopLevelWindowMSW::Init() m_fsIsShowing = false; m_menuSystem = NULL; - - m_activeDPI = wxDefaultSize; - m_perMonitorDPIaware = false; } WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const @@ -249,26 +245,6 @@ WXHWND wxTopLevelWindowMSW::MSWGetParent() const return (WXHWND)hwndParent; } -bool wxTopLevelWindowMSW::HandleDPIChange(const wxSize& newDPI, const wxRect& newRect) -{ - if ( !m_perMonitorDPIaware ) - { - return false; - } - - if ( newDPI != m_activeDPI ) - { - MSWUpdateOnDPIChange(m_activeDPI, newDPI); - m_activeDPI = newDPI; - } - - SetSize(newRect); - - Refresh(); - - return true; -} - WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { WXLRESULT rc = 0; @@ -329,17 +305,6 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX #endif // #ifndef __WXUNIVERSAL__ } break; - - case WM_DPICHANGED: - { - const RECT* const prcNewWindow = - reinterpret_cast(lParam); - - processed = HandleDPIChange(wxSize(LOWORD(wParam), - HIWORD(wParam)), - wxRectFromRECT(*prcNewWindow)); - } - break; } if ( !processed ) @@ -348,47 +313,6 @@ WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WX return rc; } -namespace -{ - -static bool IsPerMonitorDPIAware(HWND hwnd) -{ - bool dpiAware = false; - - // Determine if 'Per Monitor v2' DPI awareness is enabled in the - // applications manifest. -#if wxUSE_DYNLIB_CLASS - #define WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((WXDPI_AWARENESS_CONTEXT)-4) - typedef WXDPI_AWARENESS_CONTEXT(WINAPI * GetWindowDpiAwarenessContext_t)(HWND hwnd); - typedef BOOL(WINAPI * AreDpiAwarenessContextsEqual_t)(WXDPI_AWARENESS_CONTEXT dpiContextA, WXDPI_AWARENESS_CONTEXT dpiContextB); - static GetWindowDpiAwarenessContext_t s_pfnGetWindowDpiAwarenessContext = NULL; - static AreDpiAwarenessContextsEqual_t s_pfnAreDpiAwarenessContextsEqual = NULL; - static bool s_initDone = false; - - if ( !s_initDone ) - { - wxLoadedDLL dllUser32("user32.dll"); - wxDL_INIT_FUNC(s_pfn, GetWindowDpiAwarenessContext, dllUser32); - wxDL_INIT_FUNC(s_pfn, AreDpiAwarenessContextsEqual, dllUser32); - s_initDone = true; - } - - if ( s_pfnGetWindowDpiAwarenessContext && s_pfnAreDpiAwarenessContextsEqual ) - { - WXDPI_AWARENESS_CONTEXT dpiAwarenessContext = s_pfnGetWindowDpiAwarenessContext(hwnd); - - if ( s_pfnAreDpiAwarenessContextsEqual(dpiAwarenessContext, WXDPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) == TRUE ) - { - dpiAware = true; - } - } -#endif // wxUSE_DYNLIB_CLASS - - return dpiAware; -} - -} - bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, const wxString& title, const wxPoint& pos, @@ -559,9 +483,7 @@ bool wxTopLevelWindowMSW::Create(wxWindow *parent, EnableCloseButton(false); } - m_activeDPI = GetDPI(); - - m_perMonitorDPIaware = IsPerMonitorDPIAware(GetHwnd()); + InheritAttributes(); // for standard dialogs the dialog manager generates WM_CHANGEUISTATE // itself but for custom windows we have to do it ourselves in order to From 83a98e1a3c2d48cc6c44f3b5da4972c5feb6c6a1 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Mon, 1 Jun 2020 15:56:06 +0200 Subject: [PATCH 09/14] Handle DPI change in wxSTCListBox popup --- src/stc/PlatWX.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 3ab15eb9d3..07d5f238f8 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -2649,6 +2649,7 @@ protected: void OnSelection(wxCommandEvent&); void OnDClick(wxCommandEvent&); void OnSysColourChanged(wxSysColourChangedEvent& event); + void OnDPIChanged(wxDPIChangedEvent& event); void OnMouseMotion(wxMouseEvent& event); void OnMouseLeaveWindow(wxMouseEvent& event); @@ -2704,6 +2705,7 @@ wxSTCListBox::wxSTCListBox(wxWindow* parent, wxSTCListBoxVisualData* v, int ht) Bind(wxEVT_LISTBOX, &wxSTCListBox::OnSelection, this); Bind(wxEVT_LISTBOX_DCLICK, &wxSTCListBox::OnDClick, this); Bind(wxEVT_SYS_COLOUR_CHANGED, &wxSTCListBox::OnSysColourChanged, this); + Bind(wxEVT_DPI_CHANGED, &wxSTCListBox::OnDPIChanged, this); if ( m_visualData->HasListCtrlAppearance() ) { @@ -2943,6 +2945,18 @@ void wxSTCListBox::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) GetParent()->Refresh(); } +void wxSTCListBox::OnDPIChanged(wxDPIChangedEvent& WXUNUSED(event)) +{ + m_imagePadding = FromDIP(1); + m_textBoxToTextGap = FromDIP(3); + m_textExtraVerticalPadding = FromDIP(1); + + int w; + GetTextExtent(EXTENT_TEST, &w, &m_textHeight); + + RecalculateItemHeight(); +} + void wxSTCListBox::OnMouseLeaveWindow(wxMouseEvent& event) { const int old = m_currentRow; From 54e0521fd726e53fcb0a81308f57f6a1358fdae5 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Mon, 1 Jun 2020 15:56:15 +0200 Subject: [PATCH 10/14] Improve setting wxSTCPopupWindow size DoSetSize needs to accept absolute size, because other code can call it. --- src/stc/PlatWX.cpp | 23 +++++++++++------------ src/stc/PlatWX.h | 3 ++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 07d5f238f8..6940a74028 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -1906,7 +1906,6 @@ void Window::SetPositionRelative(PRectangle rc, Window relativeTo) { if (position.y + height > displayRect.GetBottom()) position.y = displayRect.GetBottom() - height; - position = relativeWin->ScreenToClient(position); wxWindow *window = GETWIN(wid); window->SetSize(position.x, position.y, width, height); } @@ -2219,7 +2218,9 @@ PRectangle Window::GetMonitorRect(Point pt) { #endif // __WXOSX_COCOA__ wxSTCPopupWindow::wxSTCPopupWindow(wxWindow* parent) - :wxSTCPopupBase(parent), m_lastKnownPosition(wxDefaultPosition) + : wxSTCPopupBase(parent) + , m_relPos(wxDefaultPosition) + , m_absPos(wxDefaultPosition) { #if !wxSTC_POPUP_IS_CUSTOM Bind(wxEVT_SET_FOCUS, &wxSTCPopupWindow::OnFocus, this); @@ -2270,22 +2271,20 @@ bool wxSTCPopupWindow::AcceptsFocus() const void wxSTCPopupWindow::DoSetSize(int x, int y, int width, int height, int flags) { - m_lastKnownPosition = wxPoint(x, y); + wxPoint pos(x, y); + if ( pos.IsFullySpecified() && !m_relPos.IsFullySpecified() ) + { + m_relPos = GetParent()->ScreenToClient(pos); + } - // convert coords to screen coords since we're a top-level window - if (x != wxDefaultCoord) - GetParent()->ClientToScreen(&x, NULL); + m_absPos = GetParent()->ClientToScreen(m_relPos); - if (y != wxDefaultCoord) - GetParent()->ClientToScreen(NULL, &y); - - wxSTCPopupBase::DoSetSize(x, y, width, height, flags); + wxSTCPopupBase::DoSetSize(m_absPos.x, m_absPos.y, width, height, flags); } void wxSTCPopupWindow::OnParentMove(wxMoveEvent& event) { - if ( m_lastKnownPosition.IsFullySpecified() ) - SetPosition(m_lastKnownPosition); + SetPosition(m_absPos); event.Skip(); } diff --git a/src/stc/PlatWX.h b/src/stc/PlatWX.h index 31a11dbf4d..bdaf7fef4b 100644 --- a/src/stc/PlatWX.h +++ b/src/stc/PlatWX.h @@ -150,7 +150,8 @@ protected: #endif private: - wxPoint m_lastKnownPosition; + wxPoint m_relPos; + wxPoint m_absPos; wxWindow* m_tlw; }; From 5fa8280fd8d94006b9ad75ab924bc287df41afb3 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Mon, 1 Jun 2020 15:56:30 +0200 Subject: [PATCH 11/14] Hide wxSTC popup when the DPI changes After a DPI change, the position of the popup is wrong. It is not shown at the cursor position anymore. The correct size and position are calculated by scintilla, and there is no easy way to access this without modifying scintilla sources. --- src/stc/stc.cpp | 7 +++++++ src/stc/stc.cpp.in | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index b2578a4bd8..8e3820d162 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -5446,6 +5446,13 @@ void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { { SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); } + + // Hide auto-complete popup, there is no (easy) way to set it to the correct size + // and position + if ( AutoCompActive() ) + { + AutoCompCancel(); + } } diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 35210cbf1b..a3987c47fe 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -973,6 +973,13 @@ void wxStyledTextCtrl::OnDPIChanged(wxDPIChangedEvent& evt) { { SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); } + + // Hide auto-complete popup, there is no (easy) way to set it to the correct size + // and position + if ( AutoCompActive() ) + { + AutoCompCancel(); + } } From 379cff7d197b49ea9c3ebeb80bebd76500b8e7bb Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Mon, 1 Jun 2020 15:56:41 +0200 Subject: [PATCH 12/14] Fix building with wxUSE_POPUP==0 --- include/wx/chkconf.h | 11 +++++++++++ src/msw/window.cpp | 2 ++ src/stc/PlatWX.cpp | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index 9d0e7f743c..ff7cf9da65 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -2392,6 +2392,17 @@ # endif #endif /* wxUSE_RICHTEXT */ +#if wxUSE_RICHTOOLTIP +# if !wxUSE_POPUPWIN +# ifdef wxABORT_ON_CONFIG_ERROR +# error "wxRichToolTip requires wxUSE_POPUPWIN" +# else +# undef wxUSE_POPUPWIN +# define wxUSE_POPUPWIN 1 +# endif +# endif +#endif /* wxUSE_RICHTOOLTIP */ + #if wxUSE_PROPGRID # if !wxUSE_VARIANT # ifdef wxABORT_ON_CONFIG_ERROR diff --git a/src/msw/window.cpp b/src/msw/window.cpp index eeeb4f3793..2e5be999d9 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -3696,6 +3696,7 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, } break; +#if wxUSE_POPUPWIN case WM_NCACTIVATE: // When we're losing activation to our own popup window, we want to // retain the "active" appearance of the title bar, as dropping @@ -3712,6 +3713,7 @@ wxWindowMSW::MSWHandleMessage(WXLRESULT *result, processed = true; } break; +#endif #if wxUSE_UXTHEME // If we want the default themed border then we need to draw it ourselves diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 6940a74028..2adfead2a6 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -2161,7 +2161,7 @@ PRectangle Window::GetMonitorRect(Point pt) { #ifdef __WXMSW__ // Use ShowWithoutActivating instead of show. - bool wxSTCPopupBase::Show(bool show) wxOVERRIDE + bool wxSTCPopupBase::Show(bool show) { if ( show ) { @@ -2179,7 +2179,7 @@ PRectangle Window::GetMonitorRect(Point pt) { // Do not activate in response to mouse clicks on this window. bool wxSTCPopupBase::MSWHandleMessage(WXLRESULT *res, WXUINT msg, - WXWPARAM wParam, WXLPARAM lParam) wxOVERRIDE + WXWPARAM wParam, WXLPARAM lParam) { if ( msg == WM_MOUSEACTIVATE ) { From 71773d40ab61993979207dbbd37e5a8824e28c9b Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 7 Jun 2020 19:14:05 +0200 Subject: [PATCH 13/14] Avoid ugly casts to wxMemoryDC --- src/stc/PlatWX.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 2adfead2a6..ce4e7e2bff 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -293,11 +293,11 @@ void SurfaceImpl::Init(SurfaceID hdc_, WindowID) { void SurfaceImpl::InitPixMap(int width, int height, Surface *surface, WindowID winid) { Release(); - if (surface) - hdc = new wxMemoryDC(static_cast(surface)->hdc); - else - hdc = new wxMemoryDC(); - ((wxMemoryDC*)hdc)->GetImpl()->SetWindow(GETWIN(winid)); + wxMemoryDC* mdc = surface + ? new wxMemoryDC(static_cast(surface)->hdc) + : new wxMemoryDC(); + mdc->GetImpl()->SetWindow(GETWIN(winid)); + hdc = mdc; hdcOwned = true; if (width < 1) width = 1; if (height < 1) height = 1; @@ -307,7 +307,7 @@ void SurfaceImpl::InitPixMap(int width, int height, Surface *surface, WindowID w bitmap = new wxBitmap(); bitmap->CreateScaled(width, height,wxBITMAP_SCREEN_DEPTH,(GETWIN(winid))->GetContentScaleFactor()); #endif - ((wxMemoryDC*)hdc)->SelectObject(*bitmap); + mdc->SelectObject(*bitmap); } From 9b8cc49568e8d183a43faba76b563ad3ea432c94 Mon Sep 17 00:00:00 2001 From: Maarten Bent Date: Sun, 7 Jun 2020 19:14:36 +0200 Subject: [PATCH 14/14] Fix missing include for WM_DPICHANGED --- src/msw/nonownedwnd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/msw/nonownedwnd.cpp b/src/msw/nonownedwnd.cpp index 16ca7ae585..15f4f89a83 100644 --- a/src/msw/nonownedwnd.cpp +++ b/src/msw/nonownedwnd.cpp @@ -38,6 +38,7 @@ #include "wx/dynlib.h" #include "wx/scopedptr.h" +#include "wx/msw/missing.h" // ============================================================================ // wxNonOwnedWindow implementation