]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mgl/dc.h
setting foreground colour for wxCheckBox now works when using XP themes too
[wxWidgets.git] / include / wx / mgl / dc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.h
3 // Purpose: wxDC class
4 // Author: Vaclav Slavik
5 // Created: 2001/03/09
6 // RCS-ID: $Id$
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_DC_H_
12 #define _WX_DC_H_
13
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "dc.h"
16 #endif
17
18 #include "wx/defs.h"
19 #include "wx/region.h"
20
21 //-----------------------------------------------------------------------------
22 // classes
23 //-----------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxDC;
26
27 //-----------------------------------------------------------------------------
28 // constants
29 //-----------------------------------------------------------------------------
30
31 #ifndef MM_TEXT
32 #define MM_TEXT 0
33 #define MM_ISOTROPIC 1
34 #define MM_ANISOTROPIC 2
35 #define MM_LOMETRIC 3
36 #define MM_HIMETRIC 4
37 #define MM_TWIPS 5
38 #define MM_POINTS 6
39 #define MM_METRIC 7
40 #endif
41
42 //-----------------------------------------------------------------------------
43 // wxDC
44 //-----------------------------------------------------------------------------
45
46
47 // MGL fwd declarations:
48 class MGLDevCtx;
49 class MGLRegion;
50 struct font_t;
51
52 class WXDLLEXPORT wxDC : public wxDCBase
53 {
54 DECLARE_DYNAMIC_CLASS(wxDC)
55
56 public:
57 wxDC();
58 ~wxDC();
59
60 // implement base class pure virtuals
61 // ----------------------------------
62
63 virtual void Clear();
64
65 virtual bool StartDoc(const wxString& message);
66 virtual void EndDoc();
67
68 virtual void StartPage();
69 virtual void EndPage();
70
71 virtual void SetFont(const wxFont& font);
72 virtual void SetPen(const wxPen& pen);
73 virtual void SetBrush(const wxBrush& brush);
74 virtual void SetBackground(const wxBrush& brush);
75 virtual void SetBackgroundMode(int mode);
76 virtual void SetPalette(const wxPalette& palette);
77
78 virtual void DestroyClippingRegion();
79
80 virtual wxCoord GetCharHeight() const;
81 virtual wxCoord GetCharWidth() const;
82 virtual void DoGetTextExtent(const wxString& string,
83 wxCoord *x, wxCoord *y,
84 wxCoord *descent = NULL,
85 wxCoord *externalLeading = NULL,
86 wxFont *theFont = NULL) const;
87
88 virtual bool CanDrawBitmap() const;
89 virtual bool CanGetTextExtent() const;
90 virtual int GetDepth() const;
91 virtual wxSize GetPPI() const;
92
93 virtual void SetMapMode(int mode);
94 virtual void SetUserScale(double x, double y);
95 virtual void SetLogicalScale(double x, double y);
96 virtual void SetLogicalOrigin(wxCoord x, wxCoord y);
97 virtual void SetDeviceOrigin(wxCoord x, wxCoord y);
98 virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
99 virtual void SetLogicalFunction(int function);
100
101 // implementation from now on
102 // --------------------------
103
104 virtual void ComputeScaleAndOrigin();
105
106 wxCoord XDEV2LOG(wxCoord x) const
107 {
108 wxCoord new_x = x - m_deviceOriginX;
109 if (new_x > 0)
110 return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX;
111 else
112 return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX;
113 }
114 wxCoord XDEV2LOGREL(wxCoord x) const
115 {
116 if (x > 0)
117 return (wxCoord)((double)(x) / m_scaleX + 0.5);
118 else
119 return (wxCoord)((double)(x) / m_scaleX - 0.5);
120 }
121 wxCoord YDEV2LOG(wxCoord y) const
122 {
123 wxCoord new_y = y - m_deviceOriginY;
124 if (new_y > 0)
125 return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY;
126 else
127 return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY;
128 }
129 wxCoord YDEV2LOGREL(wxCoord y) const
130 {
131 if (y > 0)
132 return (wxCoord)((double)(y) / m_scaleY + 0.5);
133 else
134 return (wxCoord)((double)(y) / m_scaleY - 0.5);
135 }
136 wxCoord XLOG2DEV(wxCoord x) const
137 {
138 wxCoord new_x = x - m_logicalOriginX;
139 if (new_x > 0)
140 return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX;
141 else
142 return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
143 }
144 wxCoord XLOG2DEVREL(wxCoord x) const
145 {
146 if (x > 0)
147 return (wxCoord)((double)(x) * m_scaleX + 0.5);
148 else
149 return (wxCoord)((double)(x) * m_scaleX - 0.5);
150 }
151 wxCoord YLOG2DEV(wxCoord y) const
152 {
153 wxCoord new_y = y - m_logicalOriginY;
154 if (new_y > 0)
155 return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY;
156 else
157 return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
158 }
159 wxCoord YLOG2DEVREL(wxCoord y) const
160 {
161 if (y > 0)
162 return (wxCoord)((double)(y) * m_scaleY + 0.5);
163 else
164 return (wxCoord)((double)(y) * m_scaleY - 0.5);
165 }
166
167 MGLDevCtx *GetMGLDC() const { return m_MGLDC; }
168 void SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC = false);
169
170 protected:
171 virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
172 int style = wxFLOOD_SURFACE);
173
174 virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
175
176 virtual void DoDrawPoint(wxCoord x, wxCoord y);
177 virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
178
179 virtual void DoDrawArc(wxCoord x1, wxCoord y1,
180 wxCoord x2, wxCoord y2,
181 wxCoord xc, wxCoord yc);
182 virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
183 double sa, double ea);
184
185 virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
186 virtual void DoDrawRoundedRectangle(wxCoord x, wxCoord y,
187 wxCoord width, wxCoord height,
188 double radius);
189 virtual void DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
190
191 virtual void DoCrossHair(wxCoord x, wxCoord y);
192
193 virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
194 virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
195 bool useMask = false);
196
197 virtual void DoDrawText(const wxString& text, wxCoord x, wxCoord y);
198 virtual void DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
199 double angle);
200
201 virtual bool DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
202 wxDC *source, wxCoord xsrc, wxCoord ysrc,
203 int rop = wxCOPY, bool useMask = false, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1);
204
205 // this is gnarly - we can't even call this function DoSetClippingRegion()
206 // because of virtual function hiding
207 virtual void DoSetClippingRegionAsRegion(const wxRegion& region);
208 virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
209 wxCoord width, wxCoord height);
210
211 virtual void DoGetSize(int *width, int *height) const;
212 virtual void DoGetSizeMM(int* width, int* height) const;
213
214 virtual void DoDrawLines(int n, wxPoint points[],
215 wxCoord xoffset, wxCoord yoffset);
216 virtual void DoDrawPolygon(int n, wxPoint points[],
217 wxCoord xoffset, wxCoord yoffset,
218 int fillStyle = wxODDEVEN_RULE);
219
220 // implementation from now on:
221
222 protected:
223 // setup newly attached MGLDevCtx for wxDC's use
224 // (does things like setting RGB blending mode for antialiased texts):
225 void InitializeMGLDC();
226
227 // common part of DoDrawText() and DoDrawRotatedText()
228 void DrawAnyText(const wxString& text, wxCoord x, wxCoord y);
229
230 // MGL uses pens as both wxPens and wxBrushes, so we have to
231 // switch them as needed:
232 void SelectPen();
233 void SelectBrush();
234 void SelectMGLStipplePen(int style);
235 void SelectMGLFatPen(int style, int flag);
236
237 // Select m_font into m_MGLDC:
238 bool SelectMGLFont();
239
240 // Convert wxWin logical function to MGL rop:
241 int LogicalFunctionToMGLRop(int logFunc) const;
242
243 // Unified implementation of DrawIcon, DrawBitmap and Blit:
244 void DoDrawSubBitmap(const wxBitmap &bmp,
245 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
246 wxCoord destx, wxCoord desty, int rop, bool useMask);
247
248 // MGL DC class we use:
249 MGLDevCtx *m_MGLDC;
250 bool m_OwnsMGLDC:1;
251
252 // helper variables for SelectXXXX():
253 bool m_penSelected;
254 bool m_brushSelected;
255 bool m_downloadedPatterns[2];
256
257 // MGL does not render lines with width>1 with endings centered
258 // at given coords but with top left corner of the pen at them,
259 // these offsets are used to correct it. They are computed by
260 // SelectPen.
261 int m_penOfsX, m_penOfsY;
262
263 double m_mm_to_pix_x, m_mm_to_pix_y;
264
265 wxPalette m_oldPalette;
266
267 wxRegion m_currentClippingRegion;
268 wxRegion m_globalClippingRegion;
269
270 // wxDC::Blit handles memoryDCs as special cases :(
271 bool m_isMemDC;
272
273 font_t *m_mglFont;
274 };
275
276 #endif
277 // _WX_DC_H_