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