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