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