]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dc.cpp
wxMenuItem::GetLabelFromText() added/documented, bug in wxMenu::FindItem() fixed
[wxWidgets.git] / src / gtk / dc.cpp
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
35 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
36
37 wxDC::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
54 void 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
63 void wxDC::DestroyClippingRegion()
64 {
65 m_clipping = FALSE;
66 }
67
68 // ---------------------------------------------------------------------------
69 // get DC capabilities
70 // ---------------------------------------------------------------------------
71
72 void 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
78 void 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
88 wxSize 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
98 void wxDC::ComputeScaleAndOrigin()
99 {
100 m_scaleX = m_logicalScaleX * m_userScaleX;
101 m_scaleY = m_logicalScaleY * m_userScaleY;
102 }
103
104 void 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
136 void wxDC::SetUserScale( double x, double y )
137 {
138 // allow negative ? -> no
139 m_userScaleX = x;
140 m_userScaleY = y;
141 ComputeScaleAndOrigin();
142 }
143
144 void wxDC::SetLogicalScale( double x, double y )
145 {
146 // allow negative ?
147 m_logicalScaleX = x;
148 m_logicalScaleY = y;
149 ComputeScaleAndOrigin();
150 }
151
152 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
153 {
154 m_logicalOriginX = x * m_signX; // is this still correct ?
155 m_logicalOriginY = y * m_signY;
156 ComputeScaleAndOrigin();
157 }
158
159 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord 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
167 void 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
179 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
180 {
181 return ((wxDC *)this)->XDEV2LOG(x);
182 }
183
184 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
185 {
186 return ((wxDC *)this)->YDEV2LOG(y);
187 }
188
189 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
190 {
191 return ((wxDC *)this)->XDEV2LOGREL(x);
192 }
193
194 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
195 {
196 return ((wxDC *)this)->YDEV2LOGREL(y);
197 }
198
199 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
200 {
201 return ((wxDC *)this)->XLOG2DEV(x);
202 }
203
204 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
205 {
206 return ((wxDC *)this)->YLOG2DEV(y);
207 }
208
209 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
210 {
211 return ((wxDC *)this)->XLOG2DEVREL(x);
212 }
213
214 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
215 {
216 return ((wxDC *)this)->YLOG2DEVREL(y);
217 }
218