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
This commit is contained in:
Vadim Zeitlin 2008-06-21 17:17:00 +00:00
parent 9928536b3a
commit edc5134402
6 changed files with 51 additions and 15 deletions

View File

@ -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).

View File

@ -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;

View 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.
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

View File

@ -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}

View File

@ -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
//-----------------------------------------------------------------------------

View File

@ -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();