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