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