]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dc.cpp
Added #include wx/dcclient.h and wx/settings.h for Vadims new code under
[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 = *wxTRANSPARENT_BRUSH;
52}
53
54void wxDC::DoSetClippingRegion( long x, long y, long width, long 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::DoGetSize( int* width, int* height ) const
73{
74 if (width) *width = m_maxX-m_minX;
75 if (height) *height = m_maxY-m_minY;
76}
77
78void wxDC::DoGetSizeMM( int* width, int* height ) const
79{
80 int w = 0;
81 int h = 0;
82 GetSize( &w, &h );
83 if (width) *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
84 if (height) *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
85}
86
87// Resolution in pixels per logical inch
88wxSize wxDC::GetPPI() const
89{
90 // TODO (should probably be pure virtual)
91 return wxSize(0, 0);
92}
93
94// ---------------------------------------------------------------------------
95// set various DC parameters
96// ---------------------------------------------------------------------------
97
98void wxDC::ComputeScaleAndOrigin()
99{
100 m_scaleX = m_logicalScaleX * m_userScaleX;
101 m_scaleY = m_logicalScaleY * m_userScaleY;
102}
103
104void wxDC::SetMapMode( int mode )
105{
106 switch (mode)
107 {
108 case wxMM_TWIPS:
109 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
110 break;
111 case wxMM_POINTS:
112 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
113 break;
114 case wxMM_METRIC:
115 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
116 break;
117 case wxMM_LOMETRIC:
118 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
119 break;
120 default:
121 case wxMM_TEXT:
122 SetLogicalScale( 1.0, 1.0 );
123 break;
124 }
125 m_mappingMode = mode;
126
127/* we don't do this mega optimisation
128 if (mode != wxMM_TEXT)
129 {
130 m_needComputeScaleX = TRUE;
131 m_needComputeScaleY = TRUE;
132 }
133*/
134}
135
136void wxDC::SetUserScale( double x, double y )
137{
138 // allow negative ? -> no
139 m_userScaleX = x;
140 m_userScaleY = y;
141 ComputeScaleAndOrigin();
142}
143
144void wxDC::SetLogicalScale( double x, double y )
145{
146 // allow negative ?
147 m_logicalScaleX = x;
148 m_logicalScaleY = y;
149 ComputeScaleAndOrigin();
150}
151
152void wxDC::SetLogicalOrigin( long x, long y )
153{
154 m_logicalOriginX = x * m_signX; // is this still correct ?
155 m_logicalOriginY = y * m_signY;
156 ComputeScaleAndOrigin();
157}
158
159void wxDC::SetDeviceOrigin( long x, long y )
160{
161 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
162 m_deviceOriginX = x;
163 m_deviceOriginY = y;
164 ComputeScaleAndOrigin();
165}
166
167void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
168{
169 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
170 m_signX = (xLeftRight ? 1 : -1);
171 m_signY = (yBottomUp ? -1 : 1);
172 ComputeScaleAndOrigin();
173}
174
175// ---------------------------------------------------------------------------
176// coordinates transformations
177// ---------------------------------------------------------------------------
178
179long wxDCBase::DeviceToLogicalX(long x) const
180{
181 return ((wxDC *)this)->XDEV2LOG(x);
182}
183
184long wxDCBase::DeviceToLogicalY(long y) const
185{
186 return ((wxDC *)this)->YDEV2LOG(y);
187}
188
189long wxDCBase::DeviceToLogicalXRel(long x) const
190{
191 return ((wxDC *)this)->XDEV2LOGREL(x);
192}
193
194long wxDCBase::DeviceToLogicalYRel(long y) const
195{
196 return ((wxDC *)this)->YDEV2LOGREL(y);
197}
198
199long wxDCBase::LogicalToDeviceX(long x) const
200{
201 return ((wxDC *)this)->XLOG2DEV(x);
202}
203
204long wxDCBase::LogicalToDeviceY(long y) const
205{
206 return ((wxDC *)this)->YLOG2DEV(y);
207}
208
209long wxDCBase::LogicalToDeviceXRel(long x) const
210{
211 return ((wxDC *)this)->XLOG2DEVREL(x);
212}
213
214long wxDCBase::LogicalToDeviceYRel(long y) const
215{
216 return ((wxDC *)this)->YLOG2DEVREL(y);
217}
218