]> git.saurik.com Git - wxWidgets.git/blame - src/motif/dc.cpp
VC++ 1.5 makefile fixes (lib split, C objs)
[wxWidgets.git] / src / motif / dc.cpp
CommitLineData
4bb6408c
JS
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
af0bb3b1 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
af0bb3b1 13 #pragma implementation "dc.h"
4bb6408c
JS
14#endif
15
16#include "wx/dc.h"
a367b9b3 17#include "wx/dcmemory.h"
7b65ea1a 18#include "wx/defs.h"
4bb6408c
JS
19
20#if !USE_SHARED_LIBRARY
af0bb3b1 21 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
4bb6408c
JS
22#endif
23
24//-----------------------------------------------------------------------------
25// constants
26//-----------------------------------------------------------------------------
27
af0bb3b1
VZ
28#define mm2inches 0.0393700787402
29#define inches2mm 25.4
30#define mm2twips 56.6929133859
31#define twips2mm 0.0176388888889
32#define mm2pt 2.83464566929
33#define pt2mm 0.352777777778
4bb6408c
JS
34
35//-----------------------------------------------------------------------------
36// wxDC
37//-----------------------------------------------------------------------------
38
af0bb3b1 39wxDC::wxDC()
4bb6408c 40{
2d120f83 41 m_ok = FALSE;
af0bb3b1 42
2d120f83
JS
43 m_mm_to_pix_x = 1.0;
44 m_mm_to_pix_y = 1.0;
af0bb3b1 45
2d120f83 46 m_backgroundMode = wxTRANSPARENT;
af0bb3b1 47
2d120f83 48 m_isInteractive = FALSE;
af0bb3b1 49}
4bb6408c 50
7b65ea1a 51void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y)
4bb6408c 52{
af0bb3b1
VZ
53 wxCHECK_RET( Ok(), "invalid dc" );
54 wxCHECK_RET( icon.Ok(), "invalid icon" );
4bb6408c 55
af0bb3b1
VZ
56 DoDrawBitmap(icon, x, y, TRUE);
57}
4bb6408c 58
7b65ea1a 59void wxDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
a367b9b3 60{
af0bb3b1
VZ
61 wxCHECK_RET( bitmap.Ok(), "invalid bitmap" );
62
a367b9b3
JS
63 wxMemoryDC memDC;
64 memDC.SelectObject(bitmap);
af0bb3b1
VZ
65
66#if 0
67 // Not sure if we need this. The mask should leave the masked areas as per
68 // the original background of this DC.
a367b9b3
JS
69 if (useMask)
70 {
af0bb3b1
VZ
71 // There might be transparent areas, so make these the same colour as this
72 // DC
73 memDC.SetBackground(* GetBackground());
74 memDC.Clear();
a367b9b3 75 }
af0bb3b1 76#endif // 0
a367b9b3 77
af0bb3b1 78 Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, useMask);
4bb6408c 79
af0bb3b1
VZ
80 memDC.SelectObject(wxNullBitmap);
81}
4bb6408c 82
7b65ea1a 83void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
4bb6408c 84{
2d120f83
JS
85 m_clipping = TRUE;
86 m_clipX1 = x;
87 m_clipY1 = y;
88 m_clipX2 = x + width;
89 m_clipY2 = y + height;
af0bb3b1 90}
4bb6408c 91
af0bb3b1 92void wxDC::DestroyClippingRegion()
4bb6408c 93{
2d120f83 94 m_clipping = FALSE;
af0bb3b1 95}
4bb6408c 96
af0bb3b1 97void wxDC::DoGetSize( int* width, int* height ) const
4bb6408c 98{
af0bb3b1
VZ
99 if ( width )
100 *width = m_maxX - m_minX;
101 if ( height )
102 *height = m_maxY - m_minY;
103}
4bb6408c 104
af0bb3b1 105void wxDC::DoGetSizeMM( int* width, int* height ) const
4bb6408c 106{
af0bb3b1 107 int w, h;
2d120f83 108 GetSize( &w, &h );
af0bb3b1
VZ
109
110 if ( width )
111 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
112 if ( height )
113 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
114}
4bb6408c 115
7bcb11d3 116// Resolution in pixels per logical inch
af0bb3b1 117wxSize wxDC::GetPPI() const
7bcb11d3
JS
118{
119 // TODO (should probably be pure virtual)
120 return wxSize(0, 0);
121}
122
4bb6408c
JS
123void wxDC::SetMapMode( int mode )
124{
af0bb3b1 125 switch (mode)
2d120f83 126 {
e3065973 127 case wxMM_TWIPS:
2d120f83
JS
128 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
129 break;
e3065973 130 case wxMM_POINTS:
2d120f83
JS
131 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
132 break;
e3065973 133 case wxMM_METRIC:
2d120f83
JS
134 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
135 break;
e3065973 136 case wxMM_LOMETRIC:
2d120f83
JS
137 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
138 break;
4bb6408c 139 default:
e3065973 140 case wxMM_TEXT:
2d120f83
JS
141 SetLogicalScale( 1.0, 1.0 );
142 break;
af0bb3b1 143 }
e3065973 144 if (mode != wxMM_TEXT)
2d120f83
JS
145 {
146 m_needComputeScaleX = TRUE;
147 m_needComputeScaleY = TRUE;
af0bb3b1
VZ
148 }
149}
4bb6408c
JS
150
151void wxDC::SetUserScale( double x, double y )
152{
96f201da
RR
153 // allow negative ? -> no
154 m_userScaleX = x;
155 m_userScaleY = y;
2d120f83 156 ComputeScaleAndOrigin();
af0bb3b1 157}
4bb6408c
JS
158
159void wxDC::SetLogicalScale( double x, double y )
160{
96f201da
RR
161 // allow negative ?
162 m_logicalScaleX = x;
163 m_logicalScaleY = y;
2d120f83 164 ComputeScaleAndOrigin();
af0bb3b1 165}
4bb6408c 166
7b65ea1a 167void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
4bb6408c 168{
2d120f83
JS
169 m_logicalOriginX = x * m_signX; // is this still correct ?
170 m_logicalOriginY = y * m_signY;
171 ComputeScaleAndOrigin();
af0bb3b1 172}
4bb6408c 173
7b65ea1a 174void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
4bb6408c 175{
2d120f83
JS
176 m_externalDeviceOriginX = x;
177 m_externalDeviceOriginY = y;
178 ComputeScaleAndOrigin();
af0bb3b1 179}
4bb6408c 180
7b65ea1a 181void wxDC::SetInternalDeviceOrigin( wxCoord x, wxCoord y )
4bb6408c 182{
2d120f83
JS
183 m_internalDeviceOriginX = x;
184 m_internalDeviceOriginY = y;
185 ComputeScaleAndOrigin();
af0bb3b1 186}
4bb6408c 187
7b65ea1a 188void wxDC::GetInternalDeviceOrigin( wxCoord *x, wxCoord *y )
4bb6408c 189{
2d120f83
JS
190 if (x) *x = m_internalDeviceOriginX;
191 if (y) *y = m_internalDeviceOriginY;
af0bb3b1 192}
4bb6408c
JS
193
194void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
195{
af0bb3b1
VZ
196 m_signX = xLeftRight ? 1 : -1;
197 m_signY = yBottomUp ? -1 : 1;
2d120f83 198 ComputeScaleAndOrigin();
af0bb3b1 199}
4bb6408c 200
7b65ea1a 201wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
4bb6408c 202{
af0bb3b1
VZ
203 return ((wxDC *)this)->XDEV2LOG(x);
204}
4bb6408c 205
7b65ea1a 206wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
4bb6408c 207{
af0bb3b1
VZ
208 return ((wxDC *)this)->YDEV2LOG(y);
209}
4bb6408c 210
7b65ea1a 211wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
4bb6408c 212{
af0bb3b1
VZ
213 return ((wxDC *)this)->XDEV2LOGREL(x);
214}
4bb6408c 215
7b65ea1a 216wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
4bb6408c 217{
af0bb3b1
VZ
218 return ((wxDC *)this)->YDEV2LOGREL(y);
219}
4bb6408c 220
7b65ea1a 221wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
4bb6408c 222{
af0bb3b1
VZ
223 return ((wxDC *)this)->XLOG2DEV(x);
224}
4bb6408c 225
7b65ea1a 226wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
4bb6408c 227{
af0bb3b1
VZ
228 return ((wxDC *)this)->YLOG2DEV(y);
229}
4bb6408c 230
7b65ea1a 231wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
4bb6408c 232{
af0bb3b1
VZ
233 return ((wxDC *)this)->XLOG2DEVREL(x);
234}
2d120f83 235
7b65ea1a 236wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
4bb6408c 237{
af0bb3b1
VZ
238 return ((wxDC *)this)->YLOG2DEVREL(y);
239}
4bb6408c 240
af0bb3b1 241void wxDC::ComputeScaleAndOrigin()
4bb6408c 242{
2d120f83
JS
243 // CMB: copy scale to see if it changes
244 double origScaleX = m_scaleX;
245 double origScaleY = m_scaleY;
af0bb3b1 246
2d120f83
JS
247 m_scaleX = m_logicalScaleX * m_userScaleX;
248 m_scaleY = m_logicalScaleY * m_userScaleY;
af0bb3b1 249
2d120f83
JS
250 m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX;
251 m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY;
af0bb3b1
VZ
252
253 // CMB: if scale has changed call SetPen to recalulate the line width
2d120f83
JS
254 if (m_scaleX != origScaleX || m_scaleY != origScaleY)
255 {
256 // this is a bit artificial, but we need to force wxDC to think
257 // the pen has changed
258 wxPen* pen = & GetPen();
259 wxPen tempPen;
260 m_pen = tempPen;
261 SetPen(* pen);
262 }
af0bb3b1 263}
4bb6408c 264