]> git.saurik.com Git - wxWidgets.git/commitdiff
initialize wx{Client,Paint,Window}DC with fonts/colours of its window
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 21 Jun 2008 17:17:00 +0000 (17:17 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 21 Jun 2008 17:17:00 +0000 (17:17 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/dc.h
interface/dc.h
interface/dcclient.h
src/common/dcbase.cpp
src/msw/dcclient.cpp

index c37636315988504ed9d8853a9e1cb95824ce6147..650b4af487ef6989315d1f549b1d8e463aac35d6 100644 (file)
@@ -301,6 +301,7 @@ All (GUI):
 - Added wxWrapSizer (Arne Steinarson)
 - Added wxSpinCtrlDouble (John Labenski)
 - Added multisample (anti-aliasing) support to wxGLCanvas (Olivier Playez).
 - 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).
 - 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).
index 9c8974f8ae5a0e0d87febed09ed98b8bf0abd5d5..10e091b2289f53cbd5c036c06529b27d2eb51257 100644 (file)
@@ -163,7 +163,7 @@ class WXDLLIMPEXP_CORE wxDCImpl: public wxObject
 {
 public:
     wxDCImpl( wxDC *owner );
 {
 public:
     wxDCImpl( wxDC *owner );
-    ~wxDCImpl();
+    virtual ~wxDCImpl();
 
     wxDC *GetOwner() const { return m_owner; }
 
 
     wxDC *GetOwner() const { return m_owner; }
 
@@ -255,32 +255,41 @@ public:
     // setters and getters
 
     virtual void SetFont(const wxFont& font) = 0;
     // 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 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 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 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 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 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
 
 
 #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;
     // logical functions
 
     virtual void SetLogicalFunction(int function) = 0;
index 1467bff0c1930ca4d07fd1e43d42c5f45cfa5c8c..107cc0605886a7199b65e3963270b091e61df7af 100644 (file)
@@ -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.
     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
     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
 
     wxDC is an abstract base class and cannot be created directly.
     Use wxPaintDC, wxClientDC, wxWindowDC, wxScreenDC, wxMemoryDC or
 
     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
 
     In addition to the versions of the methods documented below, there
     are also versions which accept single wxPoint parameter instead
index 5047ac053a6b49650d5b6b433914c55cc0febf09..17f39ca1a84d4cfea2285b464e0e49c7dea15064 100644 (file)
@@ -26,6 +26,9 @@
     To draw on the whole window including decorations, construct a wxWindowDC
     object (Windows only).
 
     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}
 
     @library{wxcore}
     @category{dc}
 
@@ -57,6 +60,9 @@ public:
     To draw on the whole window including decorations, construct a wxWindowDC
     object (Windows only).
 
     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}
 
     @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.
 
     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}
 
     @library{wxcore}
     @category{dc}
 
index ee83c03fdabe2f1b6c59134b5fe4783ac0834dc4..168ea59a211720df41edfed4e8374575006c04eb 100644 (file)
@@ -133,17 +133,23 @@ IMPLEMENT_DYNAMIC_CLASS(wxDCFactoryCleanupModule, wxModule)
 
 wxDCImpl* wxNativeDCFactory::CreateWindowDC( wxWindowDC *owner, wxWindow *window )
 {
 
 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 )
 {
 }
 
 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 )
 {
 }
 
 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 )
 }
 
 wxDCImpl* wxNativeDCFactory::CreateMemoryDC( wxMemoryDC *owner )
@@ -1092,6 +1098,16 @@ void wxDCImpl::DoGradientFillConcentric(const wxRect& rect,
     m_pen.SetColour(oldPenColour);
 }
 
     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
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // wxDC
 //-----------------------------------------------------------------------------
index e97fe01af2b2a691b9c822bcd73d0db792bc2bb2..1e667aa7044f22eca12710c980ce2d167508c930 100644 (file)
@@ -109,9 +109,6 @@ void wxWindowDCImpl::InitDC()
     // DrawText() to OPAQUE as required, otherwise always TRANSPARENT,
     ::SetBkMode(GetHdc(), TRANSPARENT);
 
     // 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();
     // since we are a window dc we need to grab the palette from the window
 #if wxUSE_PALETTE
     InitializePalette();