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