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