]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dc.cpp
Attempting to restore the binary files that got trashed earlier today.
[wxWidgets.git] / src / motif / dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.cpp
3 // Purpose: wxDC class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "dc.h"
14 #endif
15
16 #include "wx/dc.h"
17 #include "wx/dcmemory.h"
18
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
21 #endif
22
23 //-----------------------------------------------------------------------------
24 // constants
25 //-----------------------------------------------------------------------------
26
27 #define mm2inches 0.0393700787402
28 #define inches2mm 25.4
29 #define mm2twips 56.6929133859
30 #define twips2mm 0.0176388888889
31 #define mm2pt 2.83464566929
32 #define pt2mm 0.352777777778
33
34 //-----------------------------------------------------------------------------
35 // wxDC
36 //-----------------------------------------------------------------------------
37
38 wxDC::wxDC()
39 {
40 m_ok = FALSE;
41
42 m_mm_to_pix_x = 1.0;
43 m_mm_to_pix_y = 1.0;
44
45 m_backgroundMode = wxTRANSPARENT;
46
47 m_isInteractive = FALSE;
48 }
49
50 void wxDC::DoDrawIcon( const wxIcon &icon, long x, long y)
51 {
52 wxCHECK_RET( Ok(), "invalid dc" );
53 wxCHECK_RET( icon.Ok(), "invalid icon" );
54
55 DoDrawBitmap(icon, x, y, TRUE);
56 }
57
58 void wxDC::DoDrawBitmap( const wxBitmap& bitmap, long x, long y, bool useMask )
59 {
60 wxCHECK_RET( bitmap.Ok(), "invalid bitmap" );
61
62 wxMemoryDC memDC;
63 memDC.SelectObject(bitmap);
64
65 #if 0
66 // Not sure if we need this. The mask should leave the masked areas as per
67 // the original background of this DC.
68 if (useMask)
69 {
70 // There might be transparent areas, so make these the same colour as this
71 // DC
72 memDC.SetBackground(* GetBackground());
73 memDC.Clear();
74 }
75 #endif // 0
76
77 Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, useMask);
78
79 memDC.SelectObject(wxNullBitmap);
80 }
81
82 void wxDC::DoSetClippingRegion( long x, long y, long width, long height )
83 {
84 m_clipping = TRUE;
85 m_clipX1 = x;
86 m_clipY1 = y;
87 m_clipX2 = x + width;
88 m_clipY2 = y + height;
89 }
90
91 void wxDC::DestroyClippingRegion()
92 {
93 m_clipping = FALSE;
94 }
95
96 void wxDC::DoGetSize( int* width, int* height ) const
97 {
98 if ( width )
99 *width = m_maxX - m_minX;
100 if ( height )
101 *height = m_maxY - m_minY;
102 }
103
104 void wxDC::DoGetSizeMM( int* width, int* height ) const
105 {
106 int w, h;
107 GetSize( &w, &h );
108
109 if ( width )
110 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
111 if ( height )
112 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
113 }
114
115 // Resolution in pixels per logical inch
116 wxSize wxDC::GetPPI() const
117 {
118 // TODO (should probably be pure virtual)
119 return wxSize(0, 0);
120 }
121
122 void wxDC::SetMapMode( int mode )
123 {
124 switch (mode)
125 {
126 case wxMM_TWIPS:
127 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
128 break;
129 case wxMM_POINTS:
130 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
131 break;
132 case wxMM_METRIC:
133 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
134 break;
135 case wxMM_LOMETRIC:
136 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
137 break;
138 default:
139 case wxMM_TEXT:
140 SetLogicalScale( 1.0, 1.0 );
141 break;
142 }
143 if (mode != wxMM_TEXT)
144 {
145 m_needComputeScaleX = TRUE;
146 m_needComputeScaleY = TRUE;
147 }
148 }
149
150 void wxDC::SetUserScale( double x, double y )
151 {
152 // allow negative ? -> no
153 m_userScaleX = x;
154 m_userScaleY = y;
155 ComputeScaleAndOrigin();
156 }
157
158 void wxDC::SetLogicalScale( double x, double y )
159 {
160 // allow negative ?
161 m_logicalScaleX = x;
162 m_logicalScaleY = y;
163 ComputeScaleAndOrigin();
164 }
165
166 void wxDC::SetLogicalOrigin( long x, long y )
167 {
168 m_logicalOriginX = x * m_signX; // is this still correct ?
169 m_logicalOriginY = y * m_signY;
170 ComputeScaleAndOrigin();
171 }
172
173 void wxDC::SetDeviceOrigin( long x, long y )
174 {
175 m_externalDeviceOriginX = x;
176 m_externalDeviceOriginY = y;
177 ComputeScaleAndOrigin();
178 }
179
180 void wxDC::SetInternalDeviceOrigin( long x, long y )
181 {
182 m_internalDeviceOriginX = x;
183 m_internalDeviceOriginY = y;
184 ComputeScaleAndOrigin();
185 }
186
187 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
188 {
189 if (x) *x = m_internalDeviceOriginX;
190 if (y) *y = m_internalDeviceOriginY;
191 }
192
193 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
194 {
195 m_signX = xLeftRight ? 1 : -1;
196 m_signY = yBottomUp ? -1 : 1;
197 ComputeScaleAndOrigin();
198 }
199
200 long wxDCBase::DeviceToLogicalX(long x) const
201 {
202 return ((wxDC *)this)->XDEV2LOG(x);
203 }
204
205 long wxDCBase::DeviceToLogicalY(long y) const
206 {
207 return ((wxDC *)this)->YDEV2LOG(y);
208 }
209
210 long wxDCBase::DeviceToLogicalXRel(long x) const
211 {
212 return ((wxDC *)this)->XDEV2LOGREL(x);
213 }
214
215 long wxDCBase::DeviceToLogicalYRel(long y) const
216 {
217 return ((wxDC *)this)->YDEV2LOGREL(y);
218 }
219
220 long wxDCBase::LogicalToDeviceX(long x) const
221 {
222 return ((wxDC *)this)->XLOG2DEV(x);
223 }
224
225 long wxDCBase::LogicalToDeviceY(long y) const
226 {
227 return ((wxDC *)this)->YLOG2DEV(y);
228 }
229
230 long wxDCBase::LogicalToDeviceXRel(long x) const
231 {
232 return ((wxDC *)this)->XLOG2DEVREL(x);
233 }
234
235 long wxDCBase::LogicalToDeviceYRel(long y) const
236 {
237 return ((wxDC *)this)->YLOG2DEVREL(y);
238 }
239
240 void wxDC::ComputeScaleAndOrigin()
241 {
242 // CMB: copy scale to see if it changes
243 double origScaleX = m_scaleX;
244 double origScaleY = m_scaleY;
245
246 m_scaleX = m_logicalScaleX * m_userScaleX;
247 m_scaleY = m_logicalScaleY * m_userScaleY;
248
249 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
250 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
251
252 // CMB: if scale has changed call SetPen to recalulate the line width
253 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
254 {
255 // this is a bit artificial, but we need to force wxDC to think
256 // the pen has changed
257 wxPen* pen = & GetPen();
258 wxPen tempPen;
259 m_pen = tempPen;
260 SetPen(* pen);
261 }
262 }
263