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