]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/dcclient.mm
fixed all the other ports broken by controls labels in wxToolBar patch commit
[wxWidgets.git] / src / cocoa / dcclient.mm
CommitLineData
891d0563
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/cocoa/dcclient.mm
3// Purpose: wxWindowDC, wxPaintDC, and wxClientDC classes
4// Author: David Elliott
5// Modified by:
6// Created: 2003/04/01
7// RCS-ID: $Id$
8// Copyright: (c) 2003 David Elliott
065e208e 9// Licence: wxWidgets licence
891d0563
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673
DE
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/log.h"
15 #include "wx/window.h"
16 #include "wx/dcclient.h"
17#endif //WX_PRECOMP
891d0563
DE
18
19#import <AppKit/NSView.h>
20#import <AppKit/NSAffineTransform.h>
9d180f3a
DE
21#import <AppKit/NSColor.h>
22#import <AppKit/NSGraphicsContext.h>
23#import <AppKit/NSBezierPath.h>
fe8f7943 24#import <AppKit/NSWindow.h>
891d0563
DE
25
26/*
27 * wxWindowDC
28 */
29IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
30
31wxWindowDC::wxWindowDC(void)
fcc9de54 32: m_window(NULL)
b66e9853 33, m_lockedNSView(NULL)
891d0563
DE
34{
35};
36
37wxWindowDC::wxWindowDC( wxWindow *window )
fcc9de54 38: m_window(window)
b66e9853 39, m_lockedNSView(NULL)
891d0563 40{
2b030203 41 wxLogDebug(wxT("non-client window DC's are not supported, oh well"));
891d0563
DE
42};
43
44wxWindowDC::~wxWindowDC(void)
45{
b66e9853 46 CocoaUnwindStackAndLoseFocus();
891d0563
DE
47};
48
b66e9853
DE
49bool wxWindowDC::CocoaLockFocusOnNSView(WX_NSView nsview)
50{
51 if([nsview lockFocusIfCanDraw])
52 {
53 sm_cocoaDCStack.Insert(this);
b66e9853
DE
54 CocoaApplyTransformations();
55 m_lockedNSView = nsview;
56 return true;
57 }
2b030203 58 wxLogDebug(wxT("focus lock failed!"));
b66e9853
DE
59 return false;
60}
61
62bool wxWindowDC::CocoaUnlockFocusOnNSView()
63{
64 [[m_lockedNSView window] flushWindow];
65 [m_lockedNSView unlockFocus];
66 m_lockedNSView = NULL;
67 return true;
68}
69
70bool wxWindowDC::CocoaLockFocus()
71{
48580976 72 wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView());
1a1e9ff1
DE
73 NSAffineTransform *newTransform = CocoaGetWxToBoundsTransform([m_window->GetNonClientNSView() isFlipped], [m_window->GetNonClientNSView() bounds].size.height);
74 [newTransform retain];
75 [m_cocoaWxToBoundsTransform release];
76 m_cocoaWxToBoundsTransform = newTransform;
b66e9853
DE
77 return CocoaLockFocusOnNSView(m_window->GetNonClientNSView());
78}
79
80bool wxWindowDC::CocoaUnlockFocus()
81{
48580976 82 wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView());
b66e9853
DE
83 return CocoaUnlockFocusOnNSView();
84}
85
3e21fc05 86bool wxWindowDC::CocoaGetBounds(void *rectData)
9d180f3a 87{
3e21fc05
DE
88 if(!rectData)
89 return false;
90 if(!m_lockedNSView)
91 return false;
92 NSRect *pRect = (NSRect*)rectData;
93 *pRect = [m_lockedNSView bounds];
94 return true;
9d180f3a
DE
95}
96
891d0563
DE
97/*
98 * wxClientDC
99 */
100IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
101
102wxClientDC::wxClientDC(void)
103{
104};
105
106wxClientDC::wxClientDC( wxWindow *window )
107{
d630f41d 108 m_window = window;
891d0563
DE
109};
110
111wxClientDC::~wxClientDC(void)
112{
fe8f7943 113 CocoaUnwindStackAndLoseFocus();
891d0563
DE
114};
115
fe8f7943
DE
116bool wxClientDC::CocoaLockFocus()
117{
48580976 118 wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxClientDC=%p, NSView=%p"),this, m_window->GetNSView());
1a1e9ff1
DE
119 NSAffineTransform *newTransform = m_window->CocoaGetWxToBoundsTransform();
120 [newTransform retain];
121 [m_cocoaWxToBoundsTransform release];
122 m_cocoaWxToBoundsTransform = newTransform;
b66e9853 123 return CocoaLockFocusOnNSView(m_window->GetNSView());
fe8f7943
DE
124}
125
126bool wxClientDC::CocoaUnlockFocus()
127{
48580976 128 wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxClientDC=%p, NSView=%p"),this, m_window->GetNSView());
b66e9853 129 return CocoaUnlockFocusOnNSView();
fe8f7943
DE
130}
131
891d0563
DE
132/*
133 * wxPaintDC
134 */
135IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
136
137wxPaintDC::wxPaintDC(void)
138{
139};
140
141wxPaintDC::wxPaintDC( wxWindow *window )
142{
d630f41d 143 m_window = window;
2b030203 144 wxASSERT_MSG([NSView focusView]==window->GetNSView(), wxT("PaintDC's NSView does not have focus. Please use wxPaintDC only as the first DC created in a paint handler"));
fe8f7943 145 sm_cocoaDCStack.Insert(this);
b66e9853 146 m_lockedNSView = window->GetNSView();
1a1e9ff1
DE
147 NSAffineTransform *newTransform = window->CocoaGetWxToBoundsTransform();
148 [newTransform retain];
149 [m_cocoaWxToBoundsTransform release];
150 m_cocoaWxToBoundsTransform = newTransform;
fe8f7943 151 CocoaApplyTransformations();
891d0563
DE
152};
153
154wxPaintDC::~wxPaintDC(void)
155{
fe8f7943 156 CocoaUnwindStackAndLoseFocus();
891d0563
DE
157};
158
fe8f7943
DE
159bool wxPaintDC::CocoaLockFocus()
160{
2b030203 161 wxFAIL_MSG(wxT("wxPaintDC cannot be asked to lock focus!"));
fe8f7943
DE
162 return false;
163}
164
165bool wxPaintDC::CocoaUnlockFocus()
166{
167 // wxPaintDC focus can never be unlocked.
168 return false;
169}
170