]> git.saurik.com Git - wxWidgets.git/blame - src/x11/dc.cpp
Document osx hack
[wxWidgets.git] / src / x11 / dc.cpp
CommitLineData
83df96d6
JS
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
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
83df96d6
JS
13 #pragma implementation "dc.h"
14#endif
15
16#include "wx/dc.h"
17#include "wx/dcmemory.h"
18#include "wx/defs.h"
19
bc797f4c 20IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
83df96d6
JS
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
37wxDC::wxDC()
38{
39 m_ok = FALSE;
40
3cd0b8c5 41#if 1
83df96d6
JS
42 m_mm_to_pix_x = 1.0;
43 m_mm_to_pix_y = 1.0;
3cd0b8c5
RR
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
83df96d6 50
3cd0b8c5
RR
51 m_needComputeScaleX = FALSE; /* not used yet */
52 m_needComputeScaleY = FALSE; /* not used yet */
83df96d6 53
3cd0b8c5 54 m_logicalFunction = wxCOPY;
83df96d6 55
3cd0b8c5
RR
56 m_pen = *wxBLACK_PEN;
57 m_font = *wxNORMAL_FONT;
58 m_brush = *wxWHITE_BRUSH;
83df96d6 59
3cd0b8c5 60 m_backgroundMode = wxTRANSPARENT;
83df96d6 61
3cd0b8c5 62 m_isInteractive = FALSE; // ???
83df96d6
JS
63}
64
65void 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
83df96d6
JS
74void wxDC::DoGetSizeMM( int* width, int* height ) const
75{
76 int w, h;
77 GetSize( &w, &h );
78
79 if ( width )
80 *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) );
81 if ( height )
82 *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) );
83}
84
85// Resolution in pixels per logical inch
86wxSize wxDC::GetPPI() const
87{
88 // TODO (should probably be pure virtual)
89 return wxSize(0, 0);
90}
91
92void wxDC::SetMapMode( int mode )
93{
94 switch (mode)
95 {
96 case wxMM_TWIPS:
97 SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y );
98 break;
99 case wxMM_POINTS:
100 SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y );
101 break;
102 case wxMM_METRIC:
103 SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y );
104 break;
105 case wxMM_LOMETRIC:
106 SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 );
107 break;
108 default:
109 case wxMM_TEXT:
110 SetLogicalScale( 1.0, 1.0 );
111 break;
112 }
113 if (mode != wxMM_TEXT)
114 {
115 m_needComputeScaleX = TRUE;
116 m_needComputeScaleY = TRUE;
117 }
118}
119
120void wxDC::SetUserScale( double x, double y )
121{
122 // allow negative ? -> no
123 m_userScaleX = x;
124 m_userScaleY = y;
125 ComputeScaleAndOrigin();
126}
127
128void wxDC::SetLogicalScale( double x, double y )
129{
130 // allow negative ?
131 m_logicalScaleX = x;
132 m_logicalScaleY = y;
133 ComputeScaleAndOrigin();
134}
135
136void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
137{
138 m_logicalOriginX = x * m_signX; // is this still correct ?
139 m_logicalOriginY = y * m_signY;
140 ComputeScaleAndOrigin();
141}
142
143void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
144{
145 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
146 m_deviceOriginX = x;
147 m_deviceOriginY = y;
148 ComputeScaleAndOrigin();
149}
150
151void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
152{
153 m_signX = xLeftRight ? 1 : -1;
154 m_signY = yBottomUp ? -1 : 1;
155 ComputeScaleAndOrigin();
156}
157
158wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
159{
160 return ((wxDC *)this)->XDEV2LOG(x);
161}
162
163wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
164{
165 return ((wxDC *)this)->YDEV2LOG(y);
166}
167
168wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
169{
170 return ((wxDC *)this)->XDEV2LOGREL(x);
171}
172
173wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
174{
175 return ((wxDC *)this)->YDEV2LOGREL(y);
176}
177
178wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
179{
180 return ((wxDC *)this)->XLOG2DEV(x);
181}
182
183wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
184{
185 return ((wxDC *)this)->YLOG2DEV(y);
186}
187
188wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
189{
190 return ((wxDC *)this)->XLOG2DEVREL(x);
191}
192
193wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
194{
195 return ((wxDC *)this)->YLOG2DEVREL(y);
196}
197
198void wxDC::ComputeScaleAndOrigin()
199{
200 m_scaleX = m_logicalScaleX * m_userScaleX;
201 m_scaleY = m_logicalScaleY * m_userScaleY;
202}
203