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