]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dc.cpp
wxWindow::Fit() infinite loop bug fixed
[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 wxDCBase::SetUserScale(x, y);
153 ComputeScaleAndOrigin();
154 }
155
156 void wxDC::SetLogicalScale( double x, double y )
157 {
158 wxDCBase::SetLogicalScale(x, y);
159 ComputeScaleAndOrigin();
160 }
161
162 void wxDC::SetLogicalOrigin( long x, long y )
163 {
164 m_logicalOriginX = x * m_signX; // is this still correct ?
165 m_logicalOriginY = y * m_signY;
166 ComputeScaleAndOrigin();
167 }
168
169 void wxDC::SetDeviceOrigin( long x, long y )
170 {
171 m_externalDeviceOriginX = x;
172 m_externalDeviceOriginY = y;
173 ComputeScaleAndOrigin();
174 }
175
176 void wxDC::SetInternalDeviceOrigin( long x, long y )
177 {
178 m_internalDeviceOriginX = x;
179 m_internalDeviceOriginY = y;
180 ComputeScaleAndOrigin();
181 }
182
183 void wxDC::GetInternalDeviceOrigin( long *x, long *y )
184 {
185 if (x) *x = m_internalDeviceOriginX;
186 if (y) *y = m_internalDeviceOriginY;
187 }
188
189 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
190 {
191 m_signX = xLeftRight ? 1 : -1;
192 m_signY = yBottomUp ? -1 : 1;
193 ComputeScaleAndOrigin();
194 }
195
196 long wxDCBase::DeviceToLogicalX(long x) const
197 {
198 return ((wxDC *)this)->XDEV2LOG(x);
199 }
200
201 long wxDCBase::DeviceToLogicalY(long y) const
202 {
203 return ((wxDC *)this)->YDEV2LOG(y);
204 }
205
206 long wxDCBase::DeviceToLogicalXRel(long x) const
207 {
208 return ((wxDC *)this)->XDEV2LOGREL(x);
209 }
210
211 long wxDCBase::DeviceToLogicalYRel(long y) const
212 {
213 return ((wxDC *)this)->YDEV2LOGREL(y);
214 }
215
216 long wxDCBase::LogicalToDeviceX(long x) const
217 {
218 return ((wxDC *)this)->XLOG2DEV(x);
219 }
220
221 long wxDCBase::LogicalToDeviceY(long y) const
222 {
223 return ((wxDC *)this)->YLOG2DEV(y);
224 }
225
226 long wxDCBase::LogicalToDeviceXRel(long x) const
227 {
228 return ((wxDC *)this)->XLOG2DEVREL(x);
229 }
230
231 long wxDCBase::LogicalToDeviceYRel(long y) const
232 {
233 return ((wxDC *)this)->YLOG2DEVREL(y);
234 }
235
236 void wxDC::ComputeScaleAndOrigin()
237 {
238 // CMB: copy scale to see if it changes
239 double origScaleX = m_scaleX;
240 double origScaleY = m_scaleY;
241
242 m_scaleX = m_logicalScaleX * m_userScaleX;
243 m_scaleY = m_logicalScaleY * m_userScaleY;
244
245 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
246 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
247
248 // CMB: if scale has changed call SetPen to recalulate the line width
249 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
250 {
251 // this is a bit artificial, but we need to force wxDC to think
252 // the pen has changed
253 wxPen* pen = & GetPen();
254 wxPen tempPen;
255 m_pen = tempPen;
256 SetPen(* pen);
257 }
258 }
259