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