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