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.
This commit is contained in:
@@ -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);
|
||||
|
@@ -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<SurfaceImpl*>(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<wxDC*>(sid);
|
||||
const wxSize sz = dc->GetSize();
|
||||
SetScale(dc);
|
||||
m_logPixelsY = win->GetDPI().GetY();
|
||||
ScintillaWX* const
|
||||
sciwx = reinterpret_cast<ScintillaWX*>(stc->GetDirectPointer());
|
||||
m_surfaceData = static_cast<SurfaceDataD2D*>(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() {
|
||||
}
|
||||
|
||||
|
@@ -1039,7 +1039,7 @@ void ScintillaWX::DoGainFocus(){
|
||||
CreateSystemCaret();
|
||||
}
|
||||
|
||||
void ScintillaWX::DoSysColourChange() {
|
||||
void ScintillaWX::DoInvalidateStyleData() {
|
||||
InvalidateStyleData();
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user