]> git.saurik.com Git - wxWidgets.git/blob - src/motif/dc.cpp
final sweep over docs - replace & with \&
[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::DoGetSize( int* width, int* height ) const
94 {
95 if ( width )
96 *width = m_maxX - m_minX;
97 if ( height )
98 *height = m_maxY - m_minY;
99 }
100
101 void wxDC::DoGetSizeMM( int* width, int* height ) const
102 {
103 int w, h;
104 GetSize( &w, &h );
105
106 if ( width )
107 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
108 if ( height )
109 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
110 }
111
112 // Resolution in pixels per logical inch
113 wxSize wxDC::GetPPI() const
114 {
115 // TODO (should probably be pure virtual)
116 return wxSize(0, 0);
117 }
118
119 void wxDC::SetMapMode( int mode )
120 {
121 switch (mode)
122 {
123 case wxMM_TWIPS:
124 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
125 break;
126 case wxMM_POINTS:
127 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
128 break;
129 case wxMM_METRIC:
130 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
131 break;
132 case wxMM_LOMETRIC:
133 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
134 break;
135 default:
136 case wxMM_TEXT:
137 SetLogicalScale( 1.0, 1.0 );
138 break;
139 }
140 if (mode != wxMM_TEXT)
141 {
142 m_needComputeScaleX = TRUE;
143 m_needComputeScaleY = TRUE;
144 }
145 }
146
147 void wxDC::SetUserScale( double x, double y )
148 {
149 // allow negative ? -> no
150 m_userScaleX = x;
151 m_userScaleY = y;
152 ComputeScaleAndOrigin();
153 }
154
155 void wxDC::SetLogicalScale( double x, double y )
156 {
157 // allow negative ?
158 m_logicalScaleX = x;
159 m_logicalScaleY = y;
160 ComputeScaleAndOrigin();
161 }
162
163 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
164 {
165 m_logicalOriginX = x * m_signX; // is this still correct ?
166 m_logicalOriginY = y * m_signY;
167 ComputeScaleAndOrigin();
168 }
169
170 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
171 {
172 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
173 m_deviceOriginX = x;
174 m_deviceOriginY = y;
175 ComputeScaleAndOrigin();
176 }
177
178 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
179 {
180 m_signX = xLeftRight ? 1 : -1;
181 m_signY = yBottomUp ? -1 : 1;
182 ComputeScaleAndOrigin();
183 }
184
185 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
186 {
187 return ((wxDC *)this)->XDEV2LOG(x);
188 }
189
190 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
191 {
192 return ((wxDC *)this)->YDEV2LOG(y);
193 }
194
195 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
196 {
197 return ((wxDC *)this)->XDEV2LOGREL(x);
198 }
199
200 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
201 {
202 return ((wxDC *)this)->YDEV2LOGREL(y);
203 }
204
205 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
206 {
207 return ((wxDC *)this)->XLOG2DEV(x);
208 }
209
210 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
211 {
212 return ((wxDC *)this)->YLOG2DEV(y);
213 }
214
215 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
216 {
217 return ((wxDC *)this)->XLOG2DEVREL(x);
218 }
219
220 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
221 {
222 return ((wxDC *)this)->YLOG2DEVREL(y);
223 }
224
225 void wxDC::ComputeScaleAndOrigin()
226 {
227 m_scaleX = m_logicalScaleX * m_userScaleX;
228 m_scaleY = m_logicalScaleY * m_userScaleY;
229 }
230