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