From edc513440242bb3f1dc8fe215b129a2ac4b7c692 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 21 Jun 2008 17:17:00 +0000 Subject: [PATCH] initialize wx{Client,Paint,Window}DC with fonts/colours of its window git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/dc.h | 23 ++++++++++++++++------- interface/dc.h | 8 ++++++-- interface/dcclient.h | 9 +++++++++ src/common/dcbase.cpp | 22 +++++++++++++++++++--- src/msw/dcclient.cpp | 3 --- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index c376363159..650b4af487 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -301,6 +301,7 @@ All (GUI): - Added wxWrapSizer (Arne Steinarson) - Added wxSpinCtrlDouble (John Labenski) - Added multisample (anti-aliasing) support to wxGLCanvas (Olivier Playez). +- Initialize wx{Client,Paint,Window}DC with fonts/colours of its window. - Added wxNativeContainerWindow to allow embedding wx into native windows - Added custom controls support to wxFileDialog (Diaa Sami and Marcin Wojdyr) - Added wxDC::StretchBlit() for wxMac and wxMSW (Vince Harron). diff --git a/include/wx/dc.h b/include/wx/dc.h index 9c8974f8ae..10e091b228 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -163,7 +163,7 @@ class WXDLLIMPEXP_CORE wxDCImpl: public wxObject { public: wxDCImpl( wxDC *owner ); - ~wxDCImpl(); + virtual ~wxDCImpl(); wxDC *GetOwner() const { return m_owner; } @@ -255,32 +255,41 @@ public: // setters and getters virtual void SetFont(const wxFont& font) = 0; - virtual const wxFont& GetFont() const { return m_font; } + virtual const wxFont& GetFont() const { return m_font; } virtual void SetPen(const wxPen& pen) = 0; - virtual const wxPen& GetPen() const { return m_pen; } + virtual const wxPen& GetPen() const { return m_pen; } virtual void SetBrush(const wxBrush& brush) = 0; - virtual const wxBrush& GetBrush() const { return m_brush; } + virtual const wxBrush& GetBrush() const { return m_brush; } virtual void SetBackground(const wxBrush& brush) = 0; - virtual const wxBrush& GetBackground() const { return m_backgroundBrush; } + virtual const wxBrush& GetBackground() const { return m_backgroundBrush; } virtual void SetBackgroundMode(int mode) = 0; virtual int GetBackgroundMode() const { return m_backgroundMode; } virtual void SetTextForeground(const wxColour& colour) { m_textForegroundColour = colour; } - virtual const wxColour& GetTextForeground() const { return m_textForegroundColour; } + virtual const wxColour& GetTextForeground() const + { return m_textForegroundColour; } virtual void SetTextBackground(const wxColour& colour) { m_textBackgroundColour = colour; } - virtual const wxColour& GetTextBackground() const { return m_textBackgroundColour; } + virtual const wxColour& GetTextBackground() const + { return m_textBackgroundColour; } #if wxUSE_PALETTE virtual void SetPalette(const wxPalette& palette) = 0; #endif // wxUSE_PALETTE + // inherit the DC attributes (font and colours) from the given window + // + // this is called automatically when a window, client or paint DC is + // created + virtual void InheritAttributes(wxWindow *win); + + // logical functions virtual void SetLogicalFunction(int function) = 0; diff --git a/interface/dc.h b/interface/dc.h index 1467bff0c1..107cc06058 100644 --- a/interface/dc.h +++ b/interface/dc.h @@ -13,7 +13,7 @@ A wxDC is a @e "device context" onto which graphics and text can be drawn. It is intended to represent different output devices and offers a common abstract API for drawing on any of them. - + wxWidgets offers an alternative drawing API based on the modern drawing backends GDI+, CoreGraphics and Cairo. See wxGraphicsContext, wxGraphicsRenderer and related classes. There is also a wxGCDC linking the APIs by offering @@ -21,7 +21,11 @@ wxDC is an abstract base class and cannot be created directly. Use wxPaintDC, wxClientDC, wxWindowDC, wxScreenDC, wxMemoryDC or - wxPrinterDC. + wxPrinterDC. Notice that device contexts which are associated with windows + (i.e. wxClientDC, wxWindowDC and wxPaintDC) use the window font and colours + by default (starting with wxWidgets 2.9.0) but the other device context + classes use system-default values so you always must set the appropriate + fonts and colours before using them. In addition to the versions of the methods documented below, there are also versions which accept single wxPoint parameter instead diff --git a/interface/dcclient.h b/interface/dcclient.h index 5047ac053a..17f39ca1a8 100644 --- a/interface/dcclient.h +++ b/interface/dcclient.h @@ -26,6 +26,9 @@ To draw on the whole window including decorations, construct a wxWindowDC object (Windows only). + A wxPaintDC object is initialized to use the same font and colours as the + window it is associated with. + @library{wxcore} @category{dc} @@ -57,6 +60,9 @@ public: To draw on the whole window including decorations, construct a wxWindowDC object (Windows only). + A wxClientDC object is initialized to use the same font and colours as the + window it is associated with. + @library{wxcore} @category{dc} @@ -87,6 +93,9 @@ public: To draw on the client area of a window from outside an EVT_PAINT() handler, construct a wxClientDC object. + A wxWindowDC object is initialized to use the same font and colours as the + window it is associated with. + @library{wxcore} @category{dc} diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index ee83c03fda..168ea59a21 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -133,17 +133,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxDCFactoryCleanupModule, wxModule) wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner, wxWindow *window ) { - return new wxWindowDCImpl( owner, window ); + wxDCImpl * const impl = new wxWindowDCImpl( owner, window ); + impl->InheritAttributes(window); + return impl; } wxDCImpl* wxNativeDCFactory::CreateClientDC( wxClientDC *owner, wxWindow *window ) { - return new wxClientDCImpl( owner, window ); + wxDCImpl * const impl = new wxClientDCImpl( owner, window ); + impl->InheritAttributes(window); + return impl; } wxDCImpl* wxNativeDCFactory::CreatePaintDC( wxPaintDC *owner, wxWindow *window ) { - return new wxPaintDCImpl( owner, window ); + wxDCImpl * const impl = new wxPaintDCImpl( owner, window ); + impl->InheritAttributes(window); + return impl; } wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner ) @@ -1092,6 +1098,16 @@ void wxDCImpl::DoGradientFillConcentric(const wxRect& rect, m_pen.SetColour(oldPenColour); } +void wxDCImpl::InheritAttributes(wxWindow *win) +{ + wxCHECK_RET( win, "window can't be NULL" ); + + SetFont(win->GetFont()); + SetTextForeground(win->GetForegroundColour()); + SetTextBackground(win->GetBackgroundColour()); + SetBackground(wxBrush(win->GetBackgroundColour())); +} + //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- diff --git a/src/msw/dcclient.cpp b/src/msw/dcclient.cpp index e97fe01af2..1e667aa704 100644 --- a/src/msw/dcclient.cpp +++ b/src/msw/dcclient.cpp @@ -109,9 +109,6 @@ void wxWindowDCImpl::InitDC() // DrawText() to OPAQUE as required, otherwise always TRANSPARENT, ::SetBkMode(GetHdc(), TRANSPARENT); - // default bg colour is pne of the window - SetBackground(wxBrush(m_window->GetBackgroundColour(), wxBRUSHSTYLE_SOLID)); - // since we are a window dc we need to grab the palette from the window #if wxUSE_PALETTE InitializePalette(); -- 2.47.2