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(); }