]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dcclient.cpp
reSWIGged
[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
65571936 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"
be346c26
SC
45#include "wx/notebook.h"
46#include "wx/tabctrl.h"
47
48
49static wxBrush MacGetBackgroundBrush( wxWindow* window )
50{
51 wxBrush bkdBrush = window->MacGetBackgroundBrush() ;
52#if !TARGET_API_MAC_OSX
53 // transparency cannot be handled by the OS when not using composited windows
54 wxWindow* parent = window->GetParent() ;
55 // if we have some 'pseudo' transparency
56 if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
57 {
58 // walk up until we find something
59 while( parent != NULL )
60 {
61 if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) )
62 {
63 // if we have any other colours in the hierarchy
64 bkdBrush.SetColour( parent->GetBackgroundColour() ) ;
65 break ;
66 }
67 if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) )
68 {
69 bkdBrush = parent->MacGetBackgroundBrush() ;
70 break ;
71 }
72 if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) )
73 {
74 Rect extent = { 0 , 0 , 0 , 0 } ;
75 int x , y ;
76 x = y = 0 ;
77 wxSize size = parent->GetSize() ;
78 parent->MacClientToRootWindow( &x , &y ) ;
79 extent.left = x ;
80 extent.top = y ;
81 extent.top-- ;
82 extent.right = x + size.x ;
83 extent.bottom = y + size.y ;
84 bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ;
85 break ;
86 }
87
88 parent = parent->GetParent() ;
89 }
90 }
91 if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT )
92 {
93 // if we did not find something, use a default
94 bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
95 }
96#endif
97 return bkdBrush ;
98}
99
519cb848 100
2f1ae414 101wxWindowDC::wxWindowDC()
e9576ca5 102{
1be0560e 103 m_window = NULL ;
519cb848 104}
e9576ca5 105
1be0560e 106wxWindowDC::wxWindowDC(wxWindow *window)
519cb848 107{
1be0560e
SC
108 m_window = window ;
109 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
e40298d5
JS
110 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
111
112 int x , y ;
113 x = y = 0 ;
1be0560e 114 window->MacWindowToRootWindow( &x , &y ) ;
e40298d5
JS
115 m_macLocalOrigin.x = x ;
116 m_macLocalOrigin.y = y ;
1be0560e 117 CopyRgn( (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
e40298d5
JS
118 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
119 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
120 m_macPort = UMAGetWindowPort( windowref ) ;
1be0560e 121 m_ok = TRUE ;
be346c26 122 SetBackground(MacGetBackgroundBrush(window));
519cb848 123}
e9576ca5 124
2f1ae414 125wxWindowDC::~wxWindowDC()
e9576ca5 126{
519cb848 127}
e9576ca5 128
1be0560e
SC
129void wxWindowDC::DoGetSize( int* width, int* height ) const
130{
131 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
132
133 m_window->GetSize(width, height);
134}
135
519cb848
SC
136/*
137 * wxClientDC
138 */
e9576ca5 139
2f1ae414 140wxClientDC::wxClientDC()
e9576ca5 141{
1be0560e 142 m_window = NULL ;
e9576ca5
SC
143}
144
519cb848 145wxClientDC::wxClientDC(wxWindow *window)
e9576ca5 146{
1be0560e 147 m_window = window ;
e40298d5
JS
148 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
149 if (!rootwindow)
150 return;
151 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
152 wxPoint origin = window->GetClientAreaOrigin() ;
153 wxSize size = window->GetClientSize() ;
154 int x , y ;
155 x = origin.x ;
156 y = origin.y ;
157 window->MacWindowToRootWindow( &x , &y ) ;
158 m_macLocalOrigin.x = x ;
159 m_macLocalOrigin.y = y ;
160 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
161 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
162 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
163 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
164 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
165 m_macPort = UMAGetWindowPort( windowref ) ;
1be0560e 166
e40298d5 167 m_ok = TRUE ;
be346c26 168 SetBackground(MacGetBackgroundBrush(window));
e40298d5 169 SetFont( window->GetFont() ) ;
e9576ca5
SC
170}
171
2f1ae414 172wxClientDC::~wxClientDC()
e9576ca5 173{
e9576ca5
SC
174}
175
1be0560e
SC
176void wxClientDC::DoGetSize(int *width, int *height) const
177{
178 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
179
180 m_window->GetClientSize( width, height );
181}
182
183
519cb848
SC
184/*
185 * wxPaintDC
186 */
e9576ca5 187
2f1ae414 188wxPaintDC::wxPaintDC()
e9576ca5 189{
1be0560e 190 m_window = NULL ;
e9576ca5
SC
191}
192
519cb848 193wxPaintDC::wxPaintDC(wxWindow *window)
e9576ca5 194{
1be0560e 195 m_window = window ;
e40298d5
JS
196 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
197 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
198 wxPoint origin = window->GetClientAreaOrigin() ;
199 wxSize size = window->GetClientSize() ;
200 int x , y ;
201 x = origin.x ;
202 y = origin.y ;
203 window->MacWindowToRootWindow( &x , &y ) ;
204 m_macLocalOrigin.x = x ;
205 m_macLocalOrigin.y = y ;
206 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
207 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
208 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
209 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
210 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
211 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
212 m_macPort = UMAGetWindowPort( windowref ) ;
1be0560e 213
e40298d5 214 m_ok = TRUE ;
be346c26 215 SetBackground(MacGetBackgroundBrush(window));
e40298d5 216 SetFont( window->GetFont() ) ;
e9576ca5
SC
217}
218
519cb848 219wxPaintDC::~wxPaintDC()
e9576ca5 220{
519cb848 221}
1be0560e
SC
222
223void wxPaintDC::DoGetSize(int *width, int *height) const
224{
225 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
226
227 m_window->GetClientSize( width, height );
228}
229
230