]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/dc.cpp
fixed bug with using wxCommandEvent::GetInt() instead of GetId()
[wxWidgets.git] / src / stubs / dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.cpp
3 // Purpose: wxDC class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "dc.h"
14 #endif
15
16 #include "wx/dc.h"
17
18 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
19
20 //-----------------------------------------------------------------------------
21 // constants
22 //-----------------------------------------------------------------------------
23
24 #define mm2inches 0.0393700787402
25 #define inches2mm 25.4
26 #define mm2twips 56.6929133859
27 #define twips2mm 0.0176388888889
28 #define mm2pt 2.83464566929
29 #define pt2mm 0.352777777778
30
31 //-----------------------------------------------------------------------------
32 // wxDC
33 //-----------------------------------------------------------------------------
34
35 wxDC::wxDC(void)
36 {
37 m_ok = FALSE;
38 m_optimize = FALSE;
39 m_autoSetting = FALSE;
40 m_colour = TRUE;
41 m_clipping = FALSE;
42
43 m_mm_to_pix_x = 1.0;
44 m_mm_to_pix_y = 1.0;
45
46 m_logicalOriginX = 0;
47 m_logicalOriginY = 0;
48 m_deviceOriginX = 0;
49 m_deviceOriginY = 0;
50 m_internalDeviceOriginX = 0;
51 m_internalDeviceOriginY = 0;
52 m_externalDeviceOriginX = 0;
53 m_externalDeviceOriginY = 0;
54
55 m_logicalScaleX = 1.0;
56 m_logicalScaleY = 1.0;
57 m_userScaleX = 1.0;
58 m_userScaleY = 1.0;
59 m_scaleX = 1.0;
60 m_scaleY = 1.0;
61
62 m_mappingMode = wxMM_TEXT;
63 m_needComputeScaleX = FALSE;
64 m_needComputeScaleY = FALSE;
65
66 m_signX = 1; // default x-axis left to right
67 m_signY = 1; // default y-axis top down
68
69 m_maxX = m_maxY = -100000;
70 m_minY = m_minY = 100000;
71
72 m_logicalFunction = wxCOPY;
73 // m_textAlignment = wxALIGN_TOP_LEFT;
74 m_backgroundMode = wxTRANSPARENT;
75
76 m_textForegroundColour = *wxBLACK;
77 m_textBackgroundColour = *wxWHITE;
78 m_pen = *wxBLACK_PEN;
79 m_font = *wxNORMAL_FONT;
80 m_brush = *wxTRANSPARENT_BRUSH;
81 m_backgroundBrush = *wxWHITE_BRUSH;
82
83 // m_palette = wxAPP_COLOURMAP;
84 };
85
86 wxDC::~wxDC(void)
87 {
88 };
89
90 void wxDC::DrawIcon( const wxIcon &WXUNUSED(icon), long WXUNUSED(x), long WXUNUSED(y), bool WXUNUSED(useMask) )
91 {
92 };
93
94 void wxDC::DrawPoint( wxPoint& point )
95 {
96 DrawPoint( point.x, point.y );
97 };
98
99 void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle )
100 {
101 int n = list->Number();
102 wxPoint *points = new wxPoint[n];
103
104 int i = 0;
105 for( wxNode *node = list->First(); node; node = node->Next() )
106 {
107 wxPoint *point = (wxPoint *)node->Data();
108 points[i].x = point->x;
109 points[i++].y = point->y;
110 };
111 DrawPolygon( n, points, xoffset, yoffset, fillStyle );
112 delete[] points;
113 };
114
115 void wxDC::DrawLines( wxList *list, long xoffset, long yoffset )
116 {
117 int n = list->Number();
118 wxPoint *points = new wxPoint[n];
119
120 int i = 0;
121 for( wxNode *node = list->First(); node; node = node->Next() )
122 {
123 wxPoint *point = (wxPoint *)node->Data();
124 points[i].x = point->x;
125 points[i++].y = point->y;
126 };
127 DrawLines( n, points, xoffset, yoffset );
128 delete []points;
129 };
130
131 void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 )
132 {
133 wxList list;
134 list.Append( (wxObject*)new wxPoint(x1, y1) );
135 list.Append( (wxObject*)new wxPoint(x2, y2) );
136 list.Append( (wxObject*)new wxPoint(x3, y3) );
137 DrawSpline(&list);
138 wxNode *node = list.First();
139 while (node)
140 {
141 wxPoint *p = (wxPoint*)node->Data();
142 delete p;
143 node = node->Next();
144 };
145 };
146
147 void wxDC::DrawSpline( int n, wxPoint points[] )
148 {
149 wxList list;
150 for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] );
151 DrawSpline( &list );
152 };
153
154 void wxDC::SetClippingRegion( long x, long y, long width, long height )
155 {
156 m_clipping = TRUE;
157 m_clipX1 = x;
158 m_clipY1 = y;
159 m_clipX2 = x + width;
160 m_clipY2 = y + height;
161 };
162
163 void wxDC::DestroyClippingRegion(void)
164 {
165 m_clipping = FALSE;
166 };
167
168 void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const
169 {
170 if (m_clipping)
171 {
172 if (x) *x = m_clipX1;
173 if (y) *y = m_clipY1;
174 if (width) *width = (m_clipX2 - m_clipX1);
175 if (height) *height = (m_clipY2 - m_clipY1);
176 }
177 else
178 *x = *y = *width = *height = 0;
179 };
180
181 void wxDC::GetSize( int* width, int* height ) const
182 {
183 *width = m_maxX-m_minX;
184 *height = m_maxY-m_minY;
185 };
186
187 void wxDC::GetSizeMM( long* width, long* height ) const
188 {
189 int w = 0;
190 int h = 0;
191 GetSize( &w, &h );
192 *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) );
193 *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) );
194 };
195
196 void wxDC::SetTextForeground( const wxColour &col )
197 {
198 if (!Ok()) return;
199 m_textForegroundColour = col;
200 };
201
202 void wxDC::SetTextBackground( const wxColour &col )
203 {
204 if (!Ok()) return;
205 m_textBackgroundColour = col;
206 };
207
208 void wxDC::SetMapMode( int mode )
209 {
210 switch (mode)
211 {
212 case wxMM_TWIPS:
213 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
214 break;
215 case wxMM_POINTS:
216 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
217 break;
218 case wxMM_METRIC:
219 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
220 break;
221 case wxMM_LOMETRIC:
222 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
223 break;
224 default:
225 case wxMM_TEXT:
226 SetLogicalScale( 1.0, 1.0 );
227 break;
228 };
229 if (mode != wxMM_TEXT)
230 {
231 m_needComputeScaleX = TRUE;
232 m_needComputeScaleY = TRUE;
233 };
234 };
235
236 void wxDC::SetUserScale( double x, double y )
237 {
238 // allow negative ? -> no
239 m_userScaleX = x;
240 m_userScaleY = y;
241 ComputeScaleAndOrigin();
242 };
243
244 void wxDC::GetUserScale( double *x, double *y )
245 {
246 if (x) *x = m_userScaleX;
247 if (y) *y = m_userScaleY;
248 };
249
250 void wxDC::SetLogicalScale( double x, double y )
251 {
252 // allow negative ?
253 m_logicalScaleX = x;
254 m_logicalScaleY = y;
255 ComputeScaleAndOrigin();
256 };
257
258 void wxDC::GetLogicalScale( double *x, double *y )
259 {
260 if (x) *x = m_logicalScaleX;
261 if (y) *y = m_logicalScaleY;
262 };
263
264 void wxDC::SetLogicalOrigin( long x, long y )
265 {
266 m_logicalOriginX = x * m_signX; // is this still correct ?
267 m_logicalOriginY = y * m_signY;
268 ComputeScaleAndOrigin();
269 };
270
271 void wxDC::GetLogicalOrigin( long *x, long *y )
272 {
273 if (x) *x = m_logicalOriginX;
274 if (y) *y = m_logicalOriginY;
275 };
276
277 void wxDC::SetDeviceOrigin( long x, long y )
278 {
279 m_externalDeviceOriginX = x;
280 m_externalDeviceOriginY = y;
281 ComputeScaleAndOrigin();
282 };
283
284 void wxDC::GetDeviceOrigin( long *x, long *y )
285 {
286 // if (x) *x = m_externalDeviceOriginX;
287 // if (y) *y = m_externalDeviceOriginY;
288 if (x) *x = m_deviceOriginX;
289 if (y) *y = m_deviceOriginY;
290 };
291
292 void wxDC::SetInternalDeviceOrigin( long x, long y )
293 {
294 m_internalDeviceOriginX = x;
295 m_internalDeviceOriginY = y;
296 ComputeScaleAndOrigin();
297 };
298
299 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
300 {
301 if (x) *x = m_internalDeviceOriginX;
302 if (y) *y = m_internalDeviceOriginY;
303 };
304
305 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
306 {
307 m_signX = (xLeftRight ? 1 : -1);
308 m_signY = (yBottomUp ? -1 : 1);
309 ComputeScaleAndOrigin();
310 };
311
312 long wxDC::DeviceToLogicalX(long x) const
313 {
314 return XDEV2LOG(x);
315 };
316
317 long wxDC::DeviceToLogicalY(long y) const
318 {
319 return YDEV2LOG(y);
320 };
321
322 long wxDC::DeviceToLogicalXRel(long x) const
323 {
324 return XDEV2LOGREL(x);
325 };
326
327 long wxDC::DeviceToLogicalYRel(long y) const
328 {
329 return YDEV2LOGREL(y);
330 };
331
332 long wxDC::LogicalToDeviceX(long x) const
333 {
334 return XLOG2DEV(x);
335 };
336
337 long wxDC::LogicalToDeviceY(long y) const
338 {
339 return YLOG2DEV(y);
340 };
341
342 long wxDC::LogicalToDeviceXRel(long x) const
343 {
344 return XLOG2DEVREL(x);
345 };
346
347 long wxDC::LogicalToDeviceYRel(long y) const
348 {
349 return YLOG2DEVREL(y);
350 };
351
352 void wxDC::CalcBoundingBox( long x, long y )
353 {
354 if (x < m_minX) m_minX = x;
355 if (y < m_minY) m_minY = y;
356 if (x > m_maxX) m_maxX = x;
357 if (y > m_maxY) m_maxY = y;
358 };
359
360 void wxDC::ComputeScaleAndOrigin(void)
361 {
362 // CMB: copy scale to see if it changes
363 double origScaleX = m_scaleX;
364 double origScaleY = m_scaleY;
365
366 m_scaleX = m_logicalScaleX * m_userScaleX;
367 m_scaleY = m_logicalScaleY * m_userScaleY;
368
369 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
370 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
371
372 // CMB: if scale has changed call SetPen to recalulate the line width
373 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
374 {
375 // this is a bit artificial, but we need to force wxDC to think
376 // the pen has changed
377 wxPen* pen = & GetPen();
378 wxPen tempPen;
379 m_pen = tempPen;
380 SetPen(* pen);
381 }
382 };
383