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