]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dc.cpp
fixed incorrect GetTextExtent for wxTELETYPE font
[wxWidgets.git] / src / gtk / dc.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.cpp
3// Purpose:
4// Author: Robert Roebling
5// RCS-ID: $Id$
6// Copyright: (c) 1998 Robert Roebling, Markus Holzem
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12 #pragma implementation "dc.h"
13#endif
14
15#include "wx/dc.h"
16
17#include <gdk/gdk.h>
18#include <gtk/gtk.h>
19
20//-----------------------------------------------------------------------------
21// constants
22//-----------------------------------------------------------------------------
23
24#define mm2inches 0.0393700787402
25#define inches2mm 25.4
26#define mm2twips 56.6929133859
27#define twips2mm 0.0176388888889
28#define mm2pt 2.83464566929
29#define pt2mm 0.352777777778
30
31//-----------------------------------------------------------------------------
32// wxDC
33//-----------------------------------------------------------------------------
34
35IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
36
37wxDC::wxDC()
38{
39 m_ok = FALSE;
40
41 m_mm_to_pix_x = 1.0;
42 m_mm_to_pix_y = 1.0;
43
44 m_needComputeScaleX = FALSE; /* not used yet */
45 m_needComputeScaleY = FALSE; /* not used yet */
46
47 m_logicalFunction = wxCOPY;
48
49 m_pen = *wxBLACK_PEN;
50 m_font = *wxNORMAL_FONT;
51 m_brush = *wxWHITE_BRUSH;
52}
53
54void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
55{
56 m_clipping = TRUE;
57 m_clipX1 = x;
58 m_clipY1 = y;
59 m_clipX2 = x + width;
60 m_clipY2 = y + height;
61}
62
63void wxDC::DestroyClippingRegion()
64{
65 m_clipping = FALSE;
66}
67
68// ---------------------------------------------------------------------------
69// get DC capabilities
70// ---------------------------------------------------------------------------
71
72void wxDC::DoGetSizeMM( int* width, int* height ) const
73{
74 int w = 0;
75 int h = 0;
76 GetSize( &w, &h );
77 if (width) *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
78 if (height) *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
79}
80
81// Resolution in pixels per logical inch
82wxSize wxDC::GetPPI() const
83{
84 // TODO (should probably be pure virtual)
85 return wxSize(0, 0);
86}
87
88// ---------------------------------------------------------------------------
89// set various DC parameters
90// ---------------------------------------------------------------------------
91
92void wxDC::ComputeScaleAndOrigin()
93{
94 m_scaleX = m_logicalScaleX * m_userScaleX;
95 m_scaleY = m_logicalScaleY * m_userScaleY;
96}
97
98void wxDC::SetMapMode( int mode )
99{
100 switch (mode)
101 {
102 case wxMM_TWIPS:
103 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
104 break;
105 case wxMM_POINTS:
106 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
107 break;
108 case wxMM_METRIC:
109 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
110 break;
111 case wxMM_LOMETRIC:
112 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
113 break;
114 default:
115 case wxMM_TEXT:
116 SetLogicalScale( 1.0, 1.0 );
117 break;
118 }
119 m_mappingMode = mode;
120
121/* we don't do this mega optimisation
122 if (mode != wxMM_TEXT)
123 {
124 m_needComputeScaleX = TRUE;
125 m_needComputeScaleY = TRUE;
126 }
127*/
128}
129
130void wxDC::SetUserScale( double x, double y )
131{
132 // allow negative ? -> no
133 m_userScaleX = x;
134 m_userScaleY = y;
135 ComputeScaleAndOrigin();
136}
137
138void wxDC::SetLogicalScale( double x, double y )
139{
140 // allow negative ?
141 m_logicalScaleX = x;
142 m_logicalScaleY = y;
143 ComputeScaleAndOrigin();
144}
145
146void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
147{
148 m_logicalOriginX = x * m_signX; // is this still correct ?
149 m_logicalOriginY = y * m_signY;
150 ComputeScaleAndOrigin();
151}
152
153void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
154{
155 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
156 m_deviceOriginX = x;
157 m_deviceOriginY = y;
158 ComputeScaleAndOrigin();
159}
160
161void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
162{
163 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
164 m_signX = (xLeftRight ? 1 : -1);
165 m_signY = (yBottomUp ? -1 : 1);
166 ComputeScaleAndOrigin();
167}
168
169// ---------------------------------------------------------------------------
170// coordinates transformations
171// ---------------------------------------------------------------------------
172
173wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
174{
175 return ((wxDC *)this)->XDEV2LOG(x);
176}
177
178wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
179{
180 return ((wxDC *)this)->YDEV2LOG(y);
181}
182
183wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
184{
185 return ((wxDC *)this)->XDEV2LOGREL(x);
186}
187
188wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
189{
190 return ((wxDC *)this)->YDEV2LOGREL(y);
191}
192
193wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
194{
195 return ((wxDC *)this)->XLOG2DEV(x);
196}
197
198wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
199{
200 return ((wxDC *)this)->YLOG2DEV(y);
201}
202
203wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
204{
205 return ((wxDC *)this)->XLOG2DEVREL(x);
206}
207
208wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
209{
210 return ((wxDC *)this)->YLOG2DEVREL(y);
211}
212