]> git.saurik.com Git - wxWidgets.git/blob - include/wx/dcmirror.h
#4479: wx.ComboBox needs a SetFont method
[wxWidgets.git] / include / wx / dcmirror.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dcmirror.h
3 // Purpose: wxMirrorDC class
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 21.07.2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_DCMIRROR_H_
13 #define _WX_DCMIRROR_H_
14
15 #include "wx/dc.h"
16
17 // ----------------------------------------------------------------------------
18 // wxMirrorDC allows to write the same code for horz/vertical layout
19 // ----------------------------------------------------------------------------
20
21 class WXDLLIMPEXP_CORE wxMirrorDCImpl : public wxDCImpl
22 {
23 public:
24 // constructs a mirror DC associated with the given real DC
25 //
26 // if mirror parameter is true, all vertical and horizontal coordinates are
27 // exchanged, otherwise this class behaves in exactly the same way as a
28 // plain DC
29 wxMirrorDCImpl(wxDC *owner, wxDCImpl& dc, bool mirror)
30 : wxDCImpl(owner),
31 m_dc(dc)
32 {
33 m_mirror = mirror;
34 }
35
36 // wxDCBase operations
37 virtual void Clear() { m_dc.Clear(); }
38 virtual void SetFont(const wxFont& font) { m_dc.SetFont(font); }
39 virtual void SetPen(const wxPen& pen) { m_dc.SetPen(pen); }
40 virtual void SetBrush(const wxBrush& brush) { m_dc.SetBrush(brush); }
41 virtual void SetBackground(const wxBrush& brush)
42 { m_dc.SetBackground(brush); }
43 virtual void SetBackgroundMode(int mode) { m_dc.SetBackgroundMode(mode); }
44 #if wxUSE_PALETTE
45 virtual void SetPalette(const wxPalette& palette)
46 { m_dc.SetPalette(palette); }
47 #endif // wxUSE_PALETTE
48 virtual void DestroyClippingRegion() { m_dc.DestroyClippingRegion(); }
49 virtual wxCoord GetCharHeight() const { return m_dc.GetCharHeight(); }
50 virtual wxCoord GetCharWidth() const { return m_dc.GetCharWidth(); }
51 virtual bool CanDrawBitmap() const { return m_dc.CanDrawBitmap(); }
52 virtual bool CanGetTextExtent() const { return m_dc.CanGetTextExtent(); }
53 virtual int GetDepth() const { return m_dc.GetDepth(); }
54 virtual wxSize GetPPI() const { return m_dc.GetPPI(); }
55 virtual bool IsOk() const { return m_dc.IsOk(); }
56 virtual void SetMapMode(int mode) { m_dc.SetMapMode(mode); }
57 virtual void SetUserScale(double x, double y)
58 { m_dc.SetUserScale(GetX(x, y), GetY(x, y)); }
59 virtual void SetLogicalOrigin(wxCoord x, wxCoord y)
60 { m_dc.SetLogicalOrigin(GetX(x, y), GetY(x, y)); }
61 virtual void SetDeviceOrigin(wxCoord x, wxCoord y)
62 { m_dc.SetDeviceOrigin(GetX(x, y), GetY(x, y)); }
63 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
64 { m_dc.SetAxisOrientation(GetX(xLeftRight, yBottomUp),
65 GetY(xLeftRight, yBottomUp)); }
66 virtual void SetLogicalFunction(int function)
67 { m_dc.SetLogicalFunction(function); }
68
69 protected:
70 // returns x and y if not mirroring or y and x if mirroring
71 wxCoord GetX(wxCoord x, wxCoord y) const { return m_mirror ? y : x; }
72 wxCoord GetY(wxCoord x, wxCoord y) const { return m_mirror ? x : y; }
73 double GetX(double x, double y) const { return m_mirror ? y : x; }
74 double GetY(double x, double y) const { return m_mirror ? x : y; }
75 bool GetX(bool x, bool y) const { return m_mirror ? y : x; }
76 bool GetY(bool x, bool y) const { return m_mirror ? x : y; }
77
78 // same thing but for pointers
79 wxCoord *GetX(wxCoord *x, wxCoord *y) const { return m_mirror ? y : x; }
80 wxCoord *GetY(wxCoord *x, wxCoord *y) const { return m_mirror ? x : y; }
81
82 // exchange x and y unconditionally
83 static void Swap(wxCoord& x, wxCoord& y)
84 {
85 wxCoord t = x;
86 x = y;
87 y = t;
88 }
89
90 // exchange x and y components of all points in the array if necessary
91 void Mirror(int n, wxPoint points[]) const
92 {
93 if ( m_mirror )
94 {
95 for ( int i = 0; i < n; i++ )
96 {
97 Swap(points[i].x, points[i].y);
98 }
99 }
100 }
101
102
103 // wxDCBase functions
104 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
105 int style = wxFLOOD_SURFACE)
106 {
107 return m_dc.DoFloodFill(GetX(x, y), GetY(x, y), col, style);
108 }
109
110 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
111 {
112 return m_dc.DoGetPixel(GetX(x, y), GetY(x, y), col);
113 }
114
115
116 virtual void DoDrawPoint(wxCoord x, wxCoord y)
117 {
118 m_dc.DoDrawPoint(GetX(x, y), GetY(x, y));
119 }
120
121 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
122 {
123 m_dc.DoDrawLine(GetX(x1, y1), GetY(x1, y1), GetX(x2, y2), GetY(x2, y2));
124 }
125
126 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
127 wxCoord x2, wxCoord y2,
128 wxCoord xc, wxCoord yc)
129 {
130 wxFAIL_MSG( _T("this is probably wrong") );
131
132 m_dc.DoDrawArc(GetX(x1, y1), GetY(x1, y1),
133 GetX(x2, y2), GetY(x2, y2),
134 xc, yc);
135 }
136
137 virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
138 wxCoord w, wxCoord h)
139 {
140 m_dc.DoDrawCheckMark(GetX(x, y), GetY(x, y),
141 GetX(w, h), GetY(w, h));
142 }
143
144 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
145 double sa, double ea)
146 {
147 wxFAIL_MSG( _T("this is probably wrong") );
148
149 m_dc.DoDrawEllipticArc(GetX(x, y), GetY(x, y),
150 GetX(w, h), GetY(w, h),
151 sa, ea);
152 }
153
154 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
155 {
156 m_dc.DoDrawRectangle(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h));
157 }
158
159 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
160 wxCoord w, wxCoord h,
161 double radius)
162 {
163 m_dc.DoDrawRoundedRectangle(GetX(x, y), GetY(x, y),
164 GetX(w, h), GetY(w, h),
165 radius);
166 }
167
168 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
169 {
170 m_dc.DoDrawEllipse(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h));
171 }
172
173 virtual void DoCrossHair(wxCoord x, wxCoord y)
174 {
175 m_dc.DoCrossHair(GetX(x, y), GetY(x, y));
176 }
177
178 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
179 {
180 m_dc.DoDrawIcon(icon, GetX(x, y), GetY(x, y));
181 }
182
183 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
184 bool useMask = false)
185 {
186 m_dc.DoDrawBitmap(bmp, GetX(x, y), GetY(x, y), useMask);
187 }
188
189 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y)
190 {
191 // this is never mirrored
192 m_dc.DoDrawText(text, x, y);
193 }
194
195 virtual void DoDrawRotatedText(const wxString& text,
196 wxCoord x, wxCoord y, double angle)
197 {
198 // this is never mirrored
199 m_dc.DoDrawRotatedText(text, x, y, angle);
200 }
201
202 virtual bool DoBlit(wxCoord xdest, wxCoord ydest,
203 wxCoord w, wxCoord h,
204 wxDC *source, wxCoord xsrc, wxCoord ysrc,
205 int rop = wxCOPY, bool useMask = false,
206 wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord)
207 {
208 return m_dc.DoBlit(GetX(xdest, ydest), GetY(xdest, ydest),
209 GetX(w, h), GetY(w, h),
210 source, GetX(xsrc, ysrc), GetY(xsrc, ysrc),
211 rop, useMask,
212 GetX(xsrcMask, ysrcMask), GetX(xsrcMask, ysrcMask));
213 }
214
215 virtual void DoGetSize(int *w, int *h) const
216 {
217 m_dc.DoGetSize(GetX(w, h), GetY(w, h));
218 }
219
220 virtual void DoGetSizeMM(int *w, int *h) const
221 {
222 m_dc.DoGetSizeMM(GetX(w, h), GetY(w, h));
223 }
224
225 virtual void DoDrawLines(int n, wxPoint points[],
226 wxCoord xoffset, wxCoord yoffset)
227 {
228 Mirror(n, points);
229
230 m_dc.DoDrawLines(n, points,
231 GetX(xoffset, yoffset), GetY(xoffset, yoffset));
232
233 Mirror(n, points);
234 }
235
236 virtual void DoDrawPolygon(int n, wxPoint points[],
237 wxCoord xoffset, wxCoord yoffset,
238 int fillStyle = wxODDEVEN_RULE)
239 {
240 Mirror(n, points);
241
242 m_dc.DoDrawPolygon(n, points,
243 GetX(xoffset, yoffset), GetY(xoffset, yoffset),
244 fillStyle);
245
246 Mirror(n, points);
247 }
248
249 virtual void DoSetDeviceClippingRegion(const wxRegion& WXUNUSED(region))
250 {
251 wxFAIL_MSG( _T("not implemented") );
252 }
253
254 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
255 wxCoord w, wxCoord h)
256 {
257 m_dc.DoSetClippingRegion(GetX(x, y), GetY(x, y), GetX(w, h), GetY(w, h));
258 }
259
260 virtual void DoGetTextExtent(const wxString& string,
261 wxCoord *x, wxCoord *y,
262 wxCoord *descent = NULL,
263 wxCoord *externalLeading = NULL,
264 const wxFont *theFont = NULL) const
265 {
266 // never mirrored
267 m_dc.DoGetTextExtent(string, x, y, descent, externalLeading, theFont);
268 }
269
270 private:
271 wxDCImpl& m_dc;
272
273 bool m_mirror;
274
275 DECLARE_NO_COPY_CLASS(wxMirrorDCImpl)
276 };
277
278 class WXDLLIMPEXP_CORE wxMirrorDC : public wxDC
279 {
280 public:
281 wxMirrorDC(wxDC& dc, bool mirror)
282 : wxDC(new wxMirrorDCImpl(this, *dc.GetImpl(), mirror))
283 {
284 m_mirror = mirror;
285 }
286
287 // helper functions which may be useful for the users of this class
288 wxSize Reflect(const wxSize& sizeOrig)
289 {
290 return m_mirror ? wxSize(sizeOrig.y, sizeOrig.x) : sizeOrig;
291 }
292
293 private:
294 bool m_mirror;
295
296 DECLARE_NO_COPY_CLASS(wxMirrorDC)
297 };
298
299 #endif // _WX_DCMIRROR_H_
300