Precompiled headers support.
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dc.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #include "wx/dc.h"
20 #include "wx/dcmemory.h"
21 #include "wx/defs.h"
22
23 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
24
25 //-----------------------------------------------------------------------------
26 // constants
27 //-----------------------------------------------------------------------------
28
29 #define mm2inches 0.0393700787402
30 #define inches2mm 25.4
31 #define mm2twips 56.6929133859
32 #define twips2mm 0.0176388888889
33 #define mm2pt 2.83464566929
34 #define pt2mm 0.352777777778
35
36 //-----------------------------------------------------------------------------
37 // wxDC
38 //-----------------------------------------------------------------------------
39
40 wxDC::wxDC()
41 {
42 m_ok = FALSE;
43
44 m_mm_to_pix_x = 1.0;
45 m_mm_to_pix_y = 1.0;
46
47 m_backgroundMode = wxTRANSPARENT;
48
49 m_isInteractive = FALSE;
50 }
51
52 void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y)
53 {
54 wxCHECK_RET( Ok(), "invalid dc" );
55 wxCHECK_RET( icon.Ok(), "invalid icon" );
56
57 DoDrawBitmap(icon, x, y, TRUE);
58 }
59
60 void wxDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
61 {
62 wxCHECK_RET( bitmap.Ok(), "invalid bitmap" );
63
64 wxMemoryDC memDC;
65 memDC.SelectObject(bitmap);
66
67 #if 0
68 // Not sure if we need this. The mask should leave the masked areas as per
69 // the original background of this DC.
70 if (useMask)
71 {
72 // There might be transparent areas, so make these the same colour as this
73 // DC
74 memDC.SetBackground(* GetBackground());
75 memDC.Clear();
76 }
77 #endif // 0
78
79 Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, useMask);
80
81 memDC.SelectObject(wxNullBitmap);
82 }
83
84 void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
85 {
86 m_clipping = TRUE;
87 m_clipX1 = x;
88 m_clipY1 = y;
89 m_clipX2 = x + width;
90 m_clipY2 = y + height;
91 }
92
93 void wxDC::DestroyClippingRegion()
94 {
95 m_clipping = FALSE;
96 }
97
98 void wxDC::DoGetSize( int* width, int* height ) const
99 {
100 if ( width )
101 *width = m_maxX - m_minX;
102 if ( height )
103 *height = m_maxY - m_minY;
104 }
105
106 void wxDC::DoGetSizeMM( int* width, int* height ) const
107 {
108 int w, h;
109 GetSize( &w, &h );
110
111 if ( width )
112 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
113 if ( height )
114 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
115 }
116
117 // Resolution in pixels per logical inch
118 wxSize wxDC::GetPPI() const
119 {
120 // TODO (should probably be pure virtual)
121 return wxSize(0, 0);
122 }
123
124 void wxDC::SetMapMode( int mode )
125 {
126 switch (mode)
127 {
128 case wxMM_TWIPS:
129 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
130 break;
131 case wxMM_POINTS:
132 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
133 break;
134 case wxMM_METRIC:
135 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
136 break;
137 case wxMM_LOMETRIC:
138 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
139 break;
140 default:
141 case wxMM_TEXT:
142 SetLogicalScale( 1.0, 1.0 );
143 break;
144 }
145 if (mode != wxMM_TEXT)
146 {
147 m_needComputeScaleX = TRUE;
148 m_needComputeScaleY = TRUE;
149 }
150 }
151
152 void wxDC::SetUserScale( double x, double y )
153 {
154 // allow negative ? -> no
155 m_userScaleX = x;
156 m_userScaleY = y;
157 ComputeScaleAndOrigin();
158 }
159
160 void wxDC::SetLogicalScale( double x, double y )
161 {
162 // allow negative ?
163 m_logicalScaleX = x;
164 m_logicalScaleY = y;
165 ComputeScaleAndOrigin();
166 }
167
168 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
169 {
170 m_logicalOriginX = x * m_signX; // is this still correct ?
171 m_logicalOriginY = y * m_signY;
172 ComputeScaleAndOrigin();
173 }
174
175 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
176 {
177 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
178 m_deviceOriginX = x;
179 m_deviceOriginY = y;
180 ComputeScaleAndOrigin();
181 }
182
183 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
184 {
185 m_signX = xLeftRight ? 1 : -1;
186 m_signY = yBottomUp ? -1 : 1;
187 ComputeScaleAndOrigin();
188 }
189
190 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
191 {
192 return ((wxDC *)this)->XDEV2LOG(x);
193 }
194
195 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
196 {
197 return ((wxDC *)this)->YDEV2LOG(y);
198 }
199
200 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
201 {
202 return ((wxDC *)this)->XDEV2LOGREL(x);
203 }
204
205 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
206 {
207 return ((wxDC *)this)->YDEV2LOGREL(y);
208 }
209
210 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
211 {
212 return ((wxDC *)this)->XLOG2DEV(x);
213 }
214
215 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
216 {
217 return ((wxDC *)this)->YLOG2DEV(y);
218 }
219
220 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
221 {
222 return ((wxDC *)this)->XLOG2DEVREL(x);
223 }
224
225 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
226 {
227 return ((wxDC *)this)->YLOG2DEVREL(y);
228 }
229
230 void wxDC::ComputeScaleAndOrigin()
231 {
232 m_scaleX = m_logicalScaleX * m_userScaleX;
233 m_scaleY = m_logicalScaleY * m_userScaleY;
234 }
235