]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
don't call SelectObject() twice in SetBrush() nor SetFont() neither
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dcclient.cpp
3// Purpose: wxClientDC class
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dcclient.h"
14#endif
15
16#include "wx/dcclient.h"
17#include "wx/dcmemory.h"
18#include "wx/region.h"
03e11df5 19#include "wx/window.h"
456c94e1 20#include "wx/toplevel.h"
e9576ca5 21#include <math.h>
76a5e5d2 22#include "wx/mac/private.h"
e9576ca5
SC
23
24//-----------------------------------------------------------------------------
25// constants
26//-----------------------------------------------------------------------------
27
28#define RAD2DEG 57.2957795131
29
30//-----------------------------------------------------------------------------
31// wxPaintDC
32//-----------------------------------------------------------------------------
33
2f1ae414 34#if !USE_SHARED_LIBRARY
e9576ca5
SC
35IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
36IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
37IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
2f1ae414 38#endif
e9576ca5
SC
39
40/*
41 * wxWindowDC
42 */
43
d497dca4 44#include "wx/mac/uma.h"
519cb848 45
2f1ae414 46wxWindowDC::wxWindowDC()
e9576ca5 47{
1be0560e 48 m_window = NULL ;
519cb848 49}
e9576ca5 50
1be0560e 51wxWindowDC::wxWindowDC(wxWindow *window)
519cb848 52{
1be0560e
SC
53 m_window = window ;
54 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
e40298d5
JS
55 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
56
57 int x , y ;
58 x = y = 0 ;
1be0560e 59 window->MacWindowToRootWindow( &x , &y ) ;
e40298d5
JS
60 m_macLocalOrigin.x = x ;
61 m_macLocalOrigin.y = y ;
1be0560e 62 CopyRgn( (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
e40298d5
JS
63 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
64 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
65 m_macPort = UMAGetWindowPort( windowref ) ;
1be0560e
SC
66 m_ok = TRUE ;
67 SetBackground(window->MacGetBackgroundBrush());
519cb848 68}
e9576ca5 69
2f1ae414 70wxWindowDC::~wxWindowDC()
e9576ca5 71{
519cb848 72}
e9576ca5 73
1be0560e
SC
74void wxWindowDC::DoGetSize( int* width, int* height ) const
75{
76 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
77
78 m_window->GetSize(width, height);
79}
80
519cb848
SC
81/*
82 * wxClientDC
83 */
e9576ca5 84
2f1ae414 85wxClientDC::wxClientDC()
e9576ca5 86{
1be0560e 87 m_window = NULL ;
e9576ca5
SC
88}
89
519cb848 90wxClientDC::wxClientDC(wxWindow *window)
e9576ca5 91{
1be0560e 92 m_window = window ;
e40298d5
JS
93 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
94 if (!rootwindow)
95 return;
96 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
97 wxPoint origin = window->GetClientAreaOrigin() ;
98 wxSize size = window->GetClientSize() ;
99 int x , y ;
100 x = origin.x ;
101 y = origin.y ;
102 window->MacWindowToRootWindow( &x , &y ) ;
103 m_macLocalOrigin.x = x ;
104 m_macLocalOrigin.y = y ;
105 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
106 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
107 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
108 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
109 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
110 m_macPort = UMAGetWindowPort( windowref ) ;
1be0560e 111
e40298d5
JS
112 m_ok = TRUE ;
113 SetBackground(window->MacGetBackgroundBrush());
114 SetFont( window->GetFont() ) ;
e9576ca5
SC
115}
116
2f1ae414 117wxClientDC::~wxClientDC()
e9576ca5 118{
e9576ca5
SC
119}
120
1be0560e
SC
121void wxClientDC::DoGetSize(int *width, int *height) const
122{
123 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
124
125 m_window->GetClientSize( width, height );
126}
127
128
519cb848
SC
129/*
130 * wxPaintDC
131 */
e9576ca5 132
2f1ae414 133wxPaintDC::wxPaintDC()
e9576ca5 134{
1be0560e 135 m_window = NULL ;
e9576ca5
SC
136}
137
519cb848 138wxPaintDC::wxPaintDC(wxWindow *window)
e9576ca5 139{
1be0560e 140 m_window = window ;
e40298d5
JS
141 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
142 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
143 wxPoint origin = window->GetClientAreaOrigin() ;
144 wxSize size = window->GetClientSize() ;
145 int x , y ;
146 x = origin.x ;
147 y = origin.y ;
148 window->MacWindowToRootWindow( &x , &y ) ;
149 m_macLocalOrigin.x = x ;
150 m_macLocalOrigin.y = y ;
151 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
152 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
153 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
154 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
155 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
156 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
157 m_macPort = UMAGetWindowPort( windowref ) ;
1be0560e 158
e40298d5
JS
159 m_ok = TRUE ;
160 SetBackground(window->MacGetBackgroundBrush());
161 SetFont( window->GetFont() ) ;
e9576ca5
SC
162}
163
519cb848 164wxPaintDC::~wxPaintDC()
e9576ca5 165{
519cb848 166}
1be0560e
SC
167
168void wxPaintDC::DoGetSize(int *width, int *height) const
169{
170 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
171
172 m_window->GetClientSize( width, height );
173}
174
175