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