Merge branch 'gtk-dc-ppi'

Return display DPI from display-related wxDC classes in wxGTK3.

See https://github.com/wxWidgets/wxWidgets/pull/680
This commit is contained in:
Vadim Zeitlin 2018-01-27 19:24:33 +01:00
commit 1d45a8e50a
3 changed files with 70 additions and 57 deletions

View File

@ -199,6 +199,7 @@ wxGTK:
- Add a native implementation for clearing bitmap/window wxGraphicsContexts
- Implement XYToPosition() for single-line wxTextCtrl.
- Implement ShowPosition() for single-line wxTextCtrl.
- Improve wx{Client,Paint,Screen,Window}DC::GetPPI() (GTK+ 3).
wxMSW:

View File

@ -15,10 +15,8 @@
class wxGTKCairoDCImpl: public wxGCDCImpl
{
typedef wxGCDCImpl base_type;
public:
wxGTKCairoDCImpl(wxDC* owner);
wxGTKCairoDCImpl(wxDC* owner, int);
wxGTKCairoDCImpl(wxDC* owner, double scaleFactor);
wxGTKCairoDCImpl(wxDC* owner, wxWindow* window);
@ -33,8 +31,13 @@ public:
virtual bool DoStretchBlit(int xdest, int ydest, int dstWidth, int dstHeight, wxDC* source, int xsrc, int ysrc, int srcWidth, int srcHeight, wxRasterOperationMode rop, bool useMask, int xsrcMask, int ysrcMask) wxOVERRIDE;
virtual void* GetCairoContext() const wxOVERRIDE;
virtual wxSize GetPPI() const wxOVERRIDE;
protected:
int m_width, m_height;
// Set m_size from the given (valid) GdkWindow.
void InitSize(GdkWindow* window);
wxSize m_size;
wxDECLARE_NO_COPY_CLASS(wxGTKCairoDCImpl);
};
@ -42,7 +45,6 @@ protected:
class wxWindowDCImpl: public wxGTKCairoDCImpl
{
typedef wxGTKCairoDCImpl base_type;
public:
wxWindowDCImpl(wxWindowDC* owner, wxWindow* window);
@ -52,7 +54,6 @@ public:
class wxClientDCImpl: public wxGTKCairoDCImpl
{
typedef wxGTKCairoDCImpl base_type;
public:
wxClientDCImpl(wxClientDC* owner, wxWindow* window);
@ -62,7 +63,6 @@ public:
class wxPaintDCImpl: public wxGTKCairoDCImpl
{
typedef wxGTKCairoDCImpl base_type;
public:
wxPaintDCImpl(wxPaintDC* owner, wxWindow* window);
@ -72,17 +72,17 @@ public:
class wxScreenDCImpl: public wxGTKCairoDCImpl
{
typedef wxGTKCairoDCImpl base_type;
public:
wxScreenDCImpl(wxScreenDC* owner);
virtual wxSize GetPPI() const wxOVERRIDE;
wxDECLARE_NO_COPY_CLASS(wxScreenDCImpl);
};
//-----------------------------------------------------------------------------
class wxMemoryDCImpl: public wxGTKCairoDCImpl
{
typedef wxGTKCairoDCImpl base_type;
public:
wxMemoryDCImpl(wxMemoryDC* owner);
wxMemoryDCImpl(wxMemoryDC* owner, wxBitmap& bitmap);
@ -102,7 +102,6 @@ private:
class WXDLLIMPEXP_CORE wxGTKCairoDC: public wxDC
{
typedef wxDC base_type;
public:
wxGTKCairoDC(cairo_t* cr, wxWindow* window);

View File

@ -15,43 +15,40 @@
#include "wx/dcclient.h"
#include "wx/dcmemory.h"
#include "wx/dcscreen.h"
#include "wx/gdicmn.h"
#include "wx/icon.h"
#include "wx/gtk/dc.h"
#include <gtk/gtk.h>
wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner)
: base_type(owner)
: wxGCDCImpl(owner)
{
m_width = 0;
m_height = 0;
}
wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, int)
: base_type(owner, 0)
{
m_width = 0;
m_height = 0;
}
wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, double scaleFactor)
: base_type(owner, 0)
: wxGCDCImpl(owner, 0)
{
m_width = 0;
m_height = 0;
m_contentScaleFactor = scaleFactor;
}
wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, wxWindow* window)
: base_type(owner, 0)
: wxGCDCImpl(owner, 0)
{
m_window = window;
m_font = window->GetFont();
m_textForegroundColour = window->GetForegroundColour();
m_textBackgroundColour = window->GetBackgroundColour();
m_width = 0;
m_height = 0;
m_contentScaleFactor = window->GetContentScaleFactor();
if ( window )
{
m_window = window;
m_font = window->GetFont();
m_textForegroundColour = window->GetForegroundColour();
m_textBackgroundColour = window->GetBackgroundColour();
m_contentScaleFactor = window->GetContentScaleFactor();
}
}
void wxGTKCairoDCImpl::InitSize(GdkWindow* window)
{
m_size.x = gdk_window_get_width(window);
m_size.y = gdk_window_get_height(window);
}
void wxGTKCairoDCImpl::DoDrawBitmap(const wxBitmap& bitmap, int x, int y, bool useMask)
@ -118,9 +115,9 @@ bool wxGTKCairoDCImpl::DoGetPixel(int x, int y, wxColour* col) const
void wxGTKCairoDCImpl::DoGetSize(int* width, int* height) const
{
if (width)
*width = m_width;
*width = m_size.x;
if (height)
*height = m_height;
*height = m_size.y;
}
bool wxGTKCairoDCImpl::DoStretchBlit(int xdest, int ydest, int dstWidth, int dstHeight, wxDC* source, int xsrc, int ysrc, int srcWidth, int srcHeight, wxRasterOperationMode rop, bool useMask, int xsrcMask, int ysrcMask)
@ -236,10 +233,23 @@ void* wxGTKCairoDCImpl::GetCairoContext() const
cr = static_cast<cairo_t*>(m_graphicContext->GetNativeContext());
return cr;
}
wxSize wxGTKCairoDCImpl::GetPPI() const
{
if ( m_window )
{
return wxGetDisplayPPI();
}
// For a non-window-based DC the concept of PPI doesn't make much sense
// anyhow, so just return the hardcoded value used by the base class.
return wxGCDCImpl::GetPPI();
}
//-----------------------------------------------------------------------------
wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window)
: base_type(owner, window)
: wxGTKCairoDCImpl(owner, window)
{
GtkWidget* widget = window->m_wxwindow;
if (widget == NULL)
@ -262,15 +272,15 @@ wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window)
int x, y;
if (gtk_widget_get_has_window(widget))
{
m_width = gdk_window_get_width(gdkWindow);
m_height = gdk_window_get_height(gdkWindow);
x = m_width - a.width;
y = m_height - a.height;
m_size.x = gdk_window_get_width(gdkWindow);
m_size.y = gdk_window_get_height(gdkWindow);
x = m_size.x - a.width;
y = m_size.y - a.height;
}
else
{
m_width = a.width;
m_height = a.height;
m_size.x = a.width;
m_size.y = a.height;
x = a.x;
y = a.y;
cairo_rectangle(cr, a.x, a.y, a.width, a.height);
@ -285,7 +295,7 @@ wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window)
//-----------------------------------------------------------------------------
wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window)
: base_type(owner, window)
: wxGTKCairoDCImpl(owner, window)
{
GtkWidget* widget = window->m_wxwindow;
if (widget == NULL)
@ -305,15 +315,15 @@ wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window)
SetGraphicsContext(gc);
if (gtk_widget_get_has_window(widget))
{
m_width = gdk_window_get_width(gdkWindow);
m_height = gdk_window_get_height(gdkWindow);
m_size.x = gdk_window_get_width(gdkWindow);
m_size.y = gdk_window_get_height(gdkWindow);
}
else
{
GtkAllocation a;
gtk_widget_get_allocation(widget, &a);
m_width = a.width;
m_height = a.height;
m_size.x = a.width;
m_size.y = a.height;
cairo_rectangle(cr, a.x, a.y, a.width, a.height);
cairo_clip(cr);
SetDeviceLocalOrigin(a.x, a.y);
@ -325,13 +335,11 @@ wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window)
//-----------------------------------------------------------------------------
wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window)
: base_type(owner, window)
: wxGTKCairoDCImpl(owner, window)
{
cairo_t* cr = window->GTKPaintContext();
wxCHECK_RET(cr, "using wxPaintDC without being in a native paint event");
GdkWindow* gdkWindow = gtk_widget_get_window(window->m_wxwindow);
m_width = gdk_window_get_width(gdkWindow);
m_height = gdk_window_get_height(gdkWindow);
InitSize(gtk_widget_get_window(window->m_wxwindow));
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc);
@ -339,34 +347,40 @@ wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window)
//-----------------------------------------------------------------------------
wxScreenDCImpl::wxScreenDCImpl(wxScreenDC* owner)
: base_type(owner, 0)
: wxGTKCairoDCImpl(owner, static_cast<wxWindow*>(NULL))
{
GdkWindow* window = gdk_get_default_root_window();
m_width = gdk_window_get_width(window);
m_height = gdk_window_get_height(window);
InitSize(window);
cairo_t* cr = gdk_cairo_create(window);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
cairo_destroy(cr);
gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc);
}
wxSize wxScreenDCImpl::GetPPI() const
{
return wxGetDisplayPPI();
}
//-----------------------------------------------------------------------------
wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC* owner)
: base_type(owner)
: wxGTKCairoDCImpl(owner)
{
m_ok = false;
}
wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC* owner, wxBitmap& bitmap)
: base_type(owner, 0)
: wxGTKCairoDCImpl(owner, static_cast<wxWindow*>(NULL))
, m_bitmap(bitmap)
{
Setup();
}
wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC* owner, wxDC*)
: base_type(owner)
: wxGTKCairoDCImpl(owner)
{
m_ok = false;
}
@ -398,8 +412,7 @@ void wxMemoryDCImpl::Setup()
m_ok = m_bitmap.IsOk();
if (m_ok)
{
m_width = int(m_bitmap.GetScaledWidth());
m_height = int(m_bitmap.GetScaledHeight());
m_size = m_bitmap.GetScaledSize();
m_contentScaleFactor = m_bitmap.GetScaleFactor();
cairo_t* cr = m_bitmap.CairoCreate();
gc = wxGraphicsContext::CreateFromNative(cr);
@ -411,7 +424,7 @@ void wxMemoryDCImpl::Setup()
//-----------------------------------------------------------------------------
wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr, wxWindow* window)
: base_type(new wxGTKCairoDCImpl(this, window->GetContentScaleFactor()))
: wxDC(new wxGTKCairoDCImpl(this, window->GetContentScaleFactor()))
{
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(window->GetContentScaleFactor() <= 1);