diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 0ab59936ef..0bc3ea10d3 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -5479,6 +5479,7 @@ protected: void OnKeyDown(wxKeyEvent& evt); void OnLoseFocus(wxFocusEvent& evt); void OnGainFocus(wxFocusEvent& evt); + void OnDPIChanged(wxDPIChangedEvent& evt); void OnSysColourChanged(wxSysColourChangedEvent& evt); void OnEraseBackground(wxEraseEvent& evt); void OnMenu(wxCommandEvent& evt); diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index a397d65673..226839a2c6 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -159,6 +159,7 @@ wxBEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) + EVT_DPI_CHANGED (wxStyledTextCtrl::OnDPIChanged) EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu) @@ -239,6 +240,16 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT); #endif +#ifdef __WXMSW__ + // Set zoom for DPI + double baseDPI = ::GetDeviceCaps(WindowHDC(parent->GetHWND()), LOGPIXELSY); + double activeDPI = parent->GetDPI().y; + + int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); + int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, activeDPI, baseDPI); + SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); +#endif + return true; } @@ -5432,6 +5443,19 @@ 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)); + + for ( int i = 0; i < SC_MAX_MARGIN; ++i ) + { + SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); + } +} + + void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { m_swx->DoSysColourChange(); } @@ -5467,7 +5491,7 @@ wxSize wxStyledTextCtrl::DoGetBestSize() const { // What would be the best size for a wxSTC? // Just give a reasonable minimum until something else can be figured out. - return wxSize(200,100); + return FromDIP(wxSize(200,100)); } diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 7a211c5545..83d8f4bf4c 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -159,6 +159,7 @@ wxBEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) + EVT_DPI_CHANGED (wxStyledTextCtrl::OnDPIChanged) EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu) @@ -239,6 +240,16 @@ bool wxStyledTextCtrl::Create(wxWindow *parent, SetFontQuality(wxSTC_EFF_QUALITY_DEFAULT); #endif +#ifdef __WXMSW__ + // Set zoom for DPI + double baseDPI = ::GetDeviceCaps(WindowHDC(parent->GetHWND()), LOGPIXELSY); + double activeDPI = parent->GetDPI().y; + + int ptSizeOld = StyleGetSize(wxSTC_STYLE_DEFAULT); + int ptSizeNew = (int)wxMulDivInt32(ptSizeOld, activeDPI, baseDPI); + SetZoom(GetZoom() + (ptSizeNew - ptSizeOld)); +#endif + return true; } @@ -959,6 +970,19 @@ 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)); + + for ( int i = 0; i < SC_MAX_MARGIN; ++i ) + { + SetMarginWidth(i, (int)wxMulDivInt32(GetMarginWidth(i), evt.GetNewDPI().y, evt.GetOldDPI().y)); + } +} + + void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { m_swx->DoSysColourChange(); } @@ -994,7 +1018,7 @@ wxSize wxStyledTextCtrl::DoGetBestSize() const { // What would be the best size for a wxSTC? // Just give a reasonable minimum until something else can be figured out. - return wxSize(200,100); + return FromDIP(wxSize(200,100)); } diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 0713ec6212..925f4b9b1d 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -597,6 +597,7 @@ protected: void OnKeyDown(wxKeyEvent& evt); void OnLoseFocus(wxFocusEvent& evt); void OnGainFocus(wxFocusEvent& evt); + void OnDPIChanged(wxDPIChangedEvent& evt); void OnSysColourChanged(wxSysColourChangedEvent& evt); void OnEraseBackground(wxEraseEvent& evt); void OnMenu(wxCommandEvent& evt);