]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/private/dc.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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)
7 // Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _MSW_PRIVATE_DC_H_
12 #define _MSW_PRIVATE_DC_H_
14 #include "wx/msw/dc.h"
15 #include "wx/msw/wrapwin.h"
20 // various classes to change some DC property temporarily
22 // text background and foreground colours
23 class wxTextColoursChanger
26 wxTextColoursChanger(HDC hdc
, const wxMSWDCImpl
& dc
)
29 Change(dc
.GetTextForeground(), dc
.GetTextBackground());
32 wxTextColoursChanger(HDC hdc
, const wxColour
& colFg
, const wxColour
& colBg
)
38 wxTextColoursChanger(HDC hdc
, COLORREF colFg
, COLORREF colBg
)
44 ~wxTextColoursChanger()
46 if ( m_oldColFg
!= CLR_INVALID
)
47 ::SetTextColor(m_hdc
, m_oldColFg
);
48 if ( m_oldColBg
!= CLR_INVALID
)
49 ::SetBkColor(m_hdc
, m_oldColBg
);
53 // this ctor doesn't change mode immediately, call Change() later to do it
55 wxTextColoursChanger(HDC hdc
)
59 m_oldColBg
= CLR_INVALID
;
62 void Change(const wxColour
& colFg
, const wxColour
& colBg
)
64 Change(colFg
.IsOk() ? colFg
.GetPixel() : CLR_INVALID
,
65 colBg
.IsOk() ? colBg
.GetPixel() : CLR_INVALID
);
68 void Change(COLORREF colFg
, COLORREF colBg
)
70 if ( colFg
!= CLR_INVALID
)
72 m_oldColFg
= ::SetTextColor(m_hdc
, colFg
);
73 if ( m_oldColFg
== CLR_INVALID
)
75 wxLogLastError(wxT("SetTextColor"));
80 m_oldColFg
= CLR_INVALID
;
83 if ( colBg
!= CLR_INVALID
)
85 m_oldColBg
= ::SetBkColor(m_hdc
, colBg
);
86 if ( m_oldColBg
== CLR_INVALID
)
88 wxLogLastError(wxT("SetBkColor"));
93 m_oldColBg
= CLR_INVALID
;
102 wxDECLARE_NO_COPY_CLASS(wxTextColoursChanger
);
106 class wxBkModeChanger
109 // set background mode to opaque if mode != wxBRUSHSTYLE_TRANSPARENT
110 wxBkModeChanger(HDC hdc
, int mode
)
119 ::SetBkMode(m_hdc
, m_oldMode
);
123 // this ctor doesn't change mode immediately, call Change() later to do it
125 wxBkModeChanger(HDC hdc
) : m_hdc(hdc
) { m_oldMode
= 0; }
127 void Change(int mode
)
129 m_oldMode
= ::SetBkMode(m_hdc
, mode
== wxBRUSHSTYLE_TRANSPARENT
134 wxLogLastError(wxT("SetBkMode"));
142 wxDECLARE_NO_COPY_CLASS(wxBkModeChanger
);
145 } // namespace wxMSWImpl
147 #endif // _MSW_PRIVATE_DC_H_