1/////////////////////////////////////////////////////////////////////////////
2// Name:        dc.cpp
3// Purpose:
4// Author:      Robert Roebling
5// RCS-ID:      $Id: dc.cpp 40682 2006-08-19 21:30:06Z PC $
6// Copyright:   (c) 1998 Robert Roebling
7// Licence:     wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#include "wx/dc.h"
14
15//-----------------------------------------------------------------------------
16// wxDC
17//-----------------------------------------------------------------------------
18
19IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
20
21wxDC::wxDC()
22{
23    m_ok = FALSE;
24
25    m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
26                    (double)wxGetDisplaySizeMM().GetWidth();
27    m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
28                    (double)wxGetDisplaySizeMM().GetHeight();
29
30    m_needComputeScaleX = FALSE; /* not used yet */
31    m_needComputeScaleY = FALSE; /* not used yet */
32
33    m_logicalFunction = wxCOPY;
34
35    m_pen = *wxBLACK_PEN;
36    m_font = *wxNORMAL_FONT;
37    m_brush = *wxWHITE_BRUSH;
38}
39
40void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
41{
42    m_clipping = TRUE;
43    m_clipX1 = x;
44    m_clipY1 = y;
45    m_clipX2 = x + width;
46    m_clipY2 = y + height;
47}
48
49// ---------------------------------------------------------------------------
50// get DC capabilities
51// ---------------------------------------------------------------------------
52
53void wxDC::DoGetSizeMM( int* width, int* height ) const
54{
55    int w = 0;
56    int h = 0;
57    GetSize( &w, &h );
58    if (width) *width = int( double(w) / (m_userScaleX*m_mm_to_pix_x) );
59    if (height) *height = int( double(h) / (m_userScaleY*m_mm_to_pix_y) );
60}
61
62// Resolution in pixels per logical inch
63wxSize wxDC::GetPPI() const
64{
65    // TODO (should probably be pure virtual)
66    return wxSize(0, 0);
67}
68
69// ---------------------------------------------------------------------------
70// set various DC parameters
71// ---------------------------------------------------------------------------
72
73void wxDC::ComputeScaleAndOrigin()
74{
75    m_scaleX = m_logicalScaleX * m_userScaleX;
76    m_scaleY = m_logicalScaleY * m_userScaleY;
77}
78
79void 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    m_mappingMode = mode;
101
102/*  we don't do this mega optimisation
103    if (mode != wxMM_TEXT)
104    {
105        m_needComputeScaleX = TRUE;
106        m_needComputeScaleY = TRUE;
107    }
108*/
109}
110
111void wxDC::SetUserScale( double x, double y )
112{
113    // allow negative ? -> no
114    m_userScaleX = x;
115    m_userScaleY = y;
116    ComputeScaleAndOrigin();
117}
118
119void wxDC::SetLogicalScale( double x, double y )
120{
121    // allow negative ?
122    m_logicalScaleX = x;
123    m_logicalScaleY = y;
124    ComputeScaleAndOrigin();
125}
126
127void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
128{
129    m_logicalOriginX = x * m_signX;   // is this still correct ?
130    m_logicalOriginY = y * m_signY;
131    ComputeScaleAndOrigin();
132}
133
134void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
135{
136    // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
137    m_deviceOriginX = x;
138    m_deviceOriginY = y;
139    ComputeScaleAndOrigin();
140}
141
142void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
143{
144    // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
145    m_signX = (xLeftRight ?  1 : -1);
146    m_signY = (yBottomUp  ? -1 :  1);
147    ComputeScaleAndOrigin();
148}
149