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