]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/private/dc.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/private/dc.h
3 // Purpose: private wxMSW helpers for working with HDCs
4 // Author: Vadim Zeitlin
5 // Created: 2009-06-16 (extracted from src/msw/dc.cpp)
6 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _MSW_PRIVATE_DC_H_
11 #define _MSW_PRIVATE_DC_H_
13 #include "wx/msw/dc.h"
14 #include "wx/msw/wrapwin.h"
19 // various classes to change some DC property temporarily
21 // text background and foreground colours
22 class wxTextColoursChanger
25 wxTextColoursChanger(HDC hdc
, const wxMSWDCImpl
& dc
)
28 Change(dc
.GetTextForeground(), dc
.GetTextBackground());
31 wxTextColoursChanger(HDC hdc
, const wxColour
& colFg
, const wxColour
& colBg
)
37 wxTextColoursChanger(HDC hdc
, COLORREF colFg
, COLORREF colBg
)
43 ~wxTextColoursChanger()
45 if ( m_oldColFg
!= CLR_INVALID
)
46 ::SetTextColor(m_hdc
, m_oldColFg
);
47 if ( m_oldColBg
!= CLR_INVALID
)
48 ::SetBkColor(m_hdc
, m_oldColBg
);
52 // this ctor doesn't change mode immediately, call Change() later to do it
54 wxTextColoursChanger(HDC hdc
)
58 m_oldColBg
= CLR_INVALID
;
61 void Change(const wxColour
& colFg
, const wxColour
& colBg
)
63 Change(colFg
.IsOk() ? colFg
.GetPixel() : CLR_INVALID
,
64 colBg
.IsOk() ? colBg
.GetPixel() : CLR_INVALID
);
67 void Change(COLORREF colFg
, COLORREF colBg
)
69 if ( colFg
!= CLR_INVALID
)
71 m_oldColFg
= ::SetTextColor(m_hdc
, colFg
);
72 if ( m_oldColFg
== CLR_INVALID
)
74 wxLogLastError(wxT("SetTextColor"));
79 m_oldColFg
= CLR_INVALID
;
82 if ( colBg
!= CLR_INVALID
)
84 m_oldColBg
= ::SetBkColor(m_hdc
, colBg
);
85 if ( m_oldColBg
== CLR_INVALID
)
87 wxLogLastError(wxT("SetBkColor"));
92 m_oldColBg
= CLR_INVALID
;
101 wxDECLARE_NO_COPY_CLASS(wxTextColoursChanger
);
105 class wxBkModeChanger
108 // set background mode to opaque if mode != wxBRUSHSTYLE_TRANSPARENT
109 wxBkModeChanger(HDC hdc
, int mode
)
118 ::SetBkMode(m_hdc
, m_oldMode
);
122 // this ctor doesn't change mode immediately, call Change() later to do it
124 wxBkModeChanger(HDC hdc
) : m_hdc(hdc
) { m_oldMode
= 0; }
126 void Change(int mode
)
128 m_oldMode
= ::SetBkMode(m_hdc
, mode
== wxBRUSHSTYLE_TRANSPARENT
133 wxLogLastError(wxT("SetBkMode"));
141 wxDECLARE_NO_COPY_CLASS(wxBkModeChanger
);
144 } // namespace wxMSWImpl
146 #endif // _MSW_PRIVATE_DC_H_