]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/NSView.mm
test for __DARWIN__ with ifdef, not if
[wxWidgets.git] / src / cocoa / NSView.mm
CommitLineData
fb896a32
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: cocoa/NSView.mm
3// Purpose: wxCocoaNSView
4// Author: David Elliott
5// Modified by:
6// Created: 2003/02/15
ad3628fa 7// RCS-ID: $Id$
fb896a32 8// Copyright: (c) 2003 David Elliott
065e208e 9// Licence: wxWidgets licence
fb896a32
DE
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#include "wx/wxprec.h"
21#ifndef WX_PRECOMP
22 #include "wx/window.h"
23#endif // WX_PRECOMP
24
a24aa427 25#include "wx/cocoa/objc/objc_uniquifying.h"
fb896a32
DE
26#include "wx/cocoa/NSView.h"
27
fb896a32
DE
28#import <Foundation/NSNotification.h>
29#import <Foundation/NSString.h>
ad3628fa 30#include "wx/cocoa/objc/NSView.h"
fb896a32
DE
31
32// ----------------------------------------------------------------------------
33// globals
34// ----------------------------------------------------------------------------
35WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSView)
36
37void wxCocoaNSView::AssociateNSView(WX_NSView cocoaNSView)
38{
bac6f234
DE
39 if(cocoaNSView)
40 {
41 sm_cocoaHash.insert(wxCocoaNSViewHash::value_type(cocoaNSView,this));
42 [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(notificationFrameChanged:) name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
43 [cocoaNSView setPostsFrameChangedNotifications: YES];
44 }
fb896a32
DE
45}
46
47void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
48{
bac6f234
DE
49 if(cocoaNSView)
50 {
51 sm_cocoaHash.erase(cocoaNSView);
52 [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
53 }
fb896a32
DE
54}
55
56// ============================================================================
829a2e95 57// @class WXNSView
fb896a32 58// ============================================================================
829a2e95
DE
59
60@implementation WXNSView : NSView
fb896a32 61
c05e07cb
DE
62- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent
63{
64 bool acceptsFirstMouse = false;
65 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
66 if(!win || !win->Cocoa_acceptsFirstMouse(acceptsFirstMouse, theEvent))
67 acceptsFirstMouse = [super acceptsFirstMouse:theEvent];
68 return acceptsFirstMouse;
69}
70
8ea5271e
DE
71- (void)drawRect: (NSRect)rect
72{
73 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
74 if( !win || !win->Cocoa_drawRect(rect) )
75 [super drawRect:rect];
76}
77
fe802fc2
DE
78- (void)mouseDown:(NSEvent *)theEvent
79{
80 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
81 if( !win || !win->Cocoa_mouseDown(theEvent) )
82 [super mouseDown:theEvent];
83}
84
85- (void)mouseDragged:(NSEvent *)theEvent
86{
87 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
88 if( !win || !win->Cocoa_mouseDragged(theEvent) )
89 [super mouseDragged:theEvent];
90}
91
92- (void)mouseUp:(NSEvent *)theEvent
93{
94 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
95 if( !win || !win->Cocoa_mouseUp(theEvent) )
96 [super mouseUp:theEvent];
97}
98
99- (void)mouseMoved:(NSEvent *)theEvent
100{
101 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
102 if( !win || !win->Cocoa_mouseMoved(theEvent) )
103 [super mouseMoved:theEvent];
104}
105
106- (void)mouseEntered:(NSEvent *)theEvent
107{
108 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
109 if( !win || !win->Cocoa_mouseEntered(theEvent) )
110 [super mouseEntered:theEvent];
111}
112
113- (void)mouseExited:(NSEvent *)theEvent
114{
115 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
116 if( !win || !win->Cocoa_mouseExited(theEvent) )
117 [super mouseExited:theEvent];
118}
119
120- (void)rightMouseDown:(NSEvent *)theEvent
121{
122 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
123 if( !win || !win->Cocoa_rightMouseDown(theEvent) )
124 [super rightMouseDown:theEvent];
125}
126
127- (void)rightMouseDragged:(NSEvent *)theEvent
128{
129 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
130 if( !win || !win->Cocoa_rightMouseDragged(theEvent) )
131 [super rightMouseDragged:theEvent];
132}
133
134- (void)rightMouseUp:(NSEvent *)theEvent
135{
136 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
137 if( !win || !win->Cocoa_rightMouseUp(theEvent) )
138 [super rightMouseUp:theEvent];
139}
140
141- (void)otherMouseDown:(NSEvent *)theEvent
142{
143 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
144 if( !win || !win->Cocoa_otherMouseDown(theEvent) )
145 [super otherMouseDown:theEvent];
146}
147
148- (void)otherMouseDragged:(NSEvent *)theEvent
149{
150 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
151 if( !win || !win->Cocoa_otherMouseDragged(theEvent) )
152 [super otherMouseDragged:theEvent];
153}
154
155- (void)otherMouseUp:(NSEvent *)theEvent
156{
157 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
158 if( !win || !win->Cocoa_otherMouseUp(theEvent) )
159 [super otherMouseUp:theEvent];
160}
161
5558135c
RN
162- (void)resetCursorRects
163{
164 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
165 if( !win || !win->Cocoa_resetCursorRects() )
166 [super resetCursorRects];
167}
168
7c5a378f
DE
169- (void)viewDidMoveToWindow
170{
171 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
172 if( !win || !win->Cocoa_viewDidMoveToWindow() )
173 [super viewDidMoveToWindow];
174}
175
176- (void)viewWillMoveToWindow:(NSWindow *)newWindow
177{
178 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
179 if( !win || !win->Cocoa_viewWillMoveToWindow(newWindow) )
180 [super viewWillMoveToWindow:newWindow];
181}
182
829a2e95 183@end // implementation WXNSView
a24aa427
DE
184WX_IMPLEMENT_GET_OBJC_CLASS(WXNSView,NSView)
185
186// ============================================================================
187// @class wxNSViewNotificationObserver
188// ============================================================================
fb896a32
DE
189
190@interface wxNSViewNotificationObserver : NSObject
191{
192}
193
fb896a32 194- (void)notificationFrameChanged: (NSNotification *)notification;
7c5a378f 195- (void)synthesizeMouseMovedForView: (NSView *)theView;
fb896a32 196@end // interface wxNSViewNotificationObserver
a24aa427 197WX_DECLARE_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject)
fb896a32
DE
198
199@implementation wxNSViewNotificationObserver : NSObject
200
201- (void)notificationFrameChanged: (NSNotification *)notification;
202{
203 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([notification object]);
2b030203 204 wxCHECK_RET(win,wxT("notificationFrameChanged received but no wxWindow exists"));
fb896a32
DE
205 win->Cocoa_FrameChanged();
206}
207
7c5a378f
DE
208- (void)synthesizeMouseMovedForView: (NSView *)theView
209{
210 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(theView);
211 wxCHECK_RET(win,wxT("synthesizeMouseMovedForView received but no wxWindow exists"));
212 win->Cocoa_synthesizeMouseMoved();
213}
214
fb896a32 215@end // implementation wxNSViewNotificationObserver
a24aa427
DE
216WX_IMPLEMENT_GET_OBJC_CLASS(wxNSViewNotificationObserver,NSObject)
217
218void *wxCocoaNSView::sm_cocoaObserver = [[WX_GET_OBJC_CLASS(wxNSViewNotificationObserver) alloc] init];
fb896a32 219