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