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