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