From f86190702bb433f139dc2c335e2c551755def81f Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Mon, 17 Jun 2013 17:41:34 +0000 Subject: [PATCH] adding magnification API into the wxWindow classes for best retina support git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74247 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/osx/cocoa/private.h | 2 ++ include/wx/osx/core/private.h | 2 ++ include/wx/osx/nonownedwnd.h | 2 ++ include/wx/osx/window.h | 2 ++ include/wx/window.h | 5 +++++ src/osx/cocoa/nonownedwnd.mm | 5 +++++ src/osx/nonownedwnd_osx.cpp | 5 +++++ src/osx/window_osx.cpp | 7 +++++++ 8 files changed, 30 insertions(+) diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index b99e9dae19..d5008ee052 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -247,6 +247,8 @@ public : virtual void WindowToScreen( int *x, int *y ); + virtual double GetMagnificationFactor() const; + virtual bool IsActive(); virtual void SetModified(bool modified); diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index f6fe11ee68..c93a02c7ea 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -873,6 +873,8 @@ public : virtual void ScreenToWindow( int *x, int *y ) = 0; virtual void WindowToScreen( int *x, int *y ) = 0; + + virtual double GetMagnificationFactor() const { return 1.0; } virtual bool IsActive() = 0; diff --git a/include/wx/osx/nonownedwnd.h b/include/wx/osx/nonownedwnd.h index a972612b2b..273cf5ddc0 100644 --- a/include/wx/osx/nonownedwnd.h +++ b/include/wx/osx/nonownedwnd.h @@ -65,6 +65,8 @@ public: virtual void UnsubclassWin(); virtual wxPoint GetClientAreaOrigin() const; + + virtual double GetMagnificationFactor() const; // implement base class pure virtuals diff --git a/include/wx/osx/window.h b/include/wx/osx/window.h index 57afc42463..69f910a574 100644 --- a/include/wx/osx/window.h +++ b/include/wx/osx/window.h @@ -97,6 +97,8 @@ public: virtual int GetCharHeight() const; virtual int GetCharWidth() const; + + virtual double GetMagnificationFactor() const; public: virtual void SetScrollbar( int orient, int pos, int thumbVisible, diff --git a/include/wx/window.h b/include/wx/window.h index a5cc6c4fa5..8376fb7731 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -521,6 +521,11 @@ public: return wxSize( wxMax( client.x, best.x ), wxMax( client.y, best.y ) ); } + // returns the magnification of the backing store of this window + // eg 2.0 for a window on a retina screen + virtual double GetMagnificationFactor() const + { return 1.0; } + // return the size of the left/right and top/bottom borders in x and y // components of the result respectively virtual wxSize GetWindowBorderSize() const; diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 030b1e6a23..7ca8cf85f5 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -1035,6 +1035,11 @@ void wxNonOwnedWindowCocoaImpl::WindowToScreen( int *x, int *y ) *y = p.y; } +double wxNonOwnedWindowCocoaImpl::GetMagnificationFactor() const +{ + return [m_macWindow backingScaleFactor]; +} + bool wxNonOwnedWindowCocoaImpl::IsActive() { return [m_macWindow isKeyWindow]; diff --git a/src/osx/nonownedwnd_osx.cpp b/src/osx/nonownedwnd_osx.cpp index edcba5d9ce..183fe42d7f 100644 --- a/src/osx/nonownedwnd_osx.cpp +++ b/src/osx/nonownedwnd_osx.cpp @@ -478,6 +478,11 @@ void wxNonOwnedWindow::DoGetClientSize( int *width, int *height ) const *height = h ; } +double wxNonOwnedWindow::GetMagnificationFactor() const +{ + return m_nowpeer->GetMagnificationFactor(); +} + void wxNonOwnedWindow::WindowWasPainted() { s_lastFlush = clock(); diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 33e376ad8d..1a44f25e42 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -877,6 +877,13 @@ void wxWindowMac::DoGetClientSize( int *x, int *y ) const *y = hh; } +double wxWindowMac::GetMagnificationFactor() const +{ + wxNonOwnedWindow* tlw = MacGetTopLevelWindow() ; + wxCHECK_MSG( tlw , 1.0, wxT("TopLevel Window missing") ) ; + return tlw->GetMagnificationFactor(); +} + bool wxWindowMac::SetCursor(const wxCursor& cursor) { if (m_cursor.IsSameAs(cursor))