]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/NSView.mm
byte length for interim UniChar String corrected
[wxWidgets.git] / src / cocoa / NSView.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/NSView.mm
3 // Purpose: wxCocoaNSView
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/02/15
7 // RCS-ID: $Id:
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
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
25 #include "wx/cocoa/ObjcPose.h"
26 #include "wx/cocoa/NSView.h"
27
28 #import <AppKit/NSView.h>
29 #import <Foundation/NSNotification.h>
30 #import <Foundation/NSString.h>
31
32 // ----------------------------------------------------------------------------
33 // globals
34 // ----------------------------------------------------------------------------
35 WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSView)
36
37 void wxCocoaNSView::AssociateNSView(WX_NSView cocoaNSView)
38 {
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 }
45 }
46
47 void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
48 {
49 if(cocoaNSView)
50 {
51 sm_cocoaHash.erase(cocoaNSView);
52 [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
53 }
54 }
55
56 // ============================================================================
57 // @class wxPoserNSView
58 // ============================================================================
59 @interface wxPoserNSView : NSView
60 {
61 }
62
63 - (void)drawRect: (NSRect)rect;
64 - (void)mouseDown:(NSEvent *)theEvent;
65 - (void)mouseDragged:(NSEvent *)theEvent;
66 - (void)mouseUp:(NSEvent *)theEvent;
67 - (void)mouseMoved:(NSEvent *)theEvent;
68 - (void)mouseEntered:(NSEvent *)theEvent;
69 - (void)mouseExited:(NSEvent *)theEvent;
70 - (void)rightMouseDown:(NSEvent *)theEvent;
71 - (void)rightMouseDragged:(NSEvent *)theEvent;
72 - (void)rightMouseUp:(NSEvent *)theEvent;
73 - (void)otherMouseDown:(NSEvent *)theEvent;
74 - (void)otherMouseDragged:(NSEvent *)theEvent;
75 - (void)otherMouseUp:(NSEvent *)theEvent;
76 @end // wxPoserNSView
77
78 WX_IMPLEMENT_POSER(wxPoserNSView);
79 @implementation wxPoserNSView : NSView
80
81 - (void)drawRect: (NSRect)rect
82 {
83 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
84 if( !win || !win->Cocoa_drawRect(rect) )
85 [super drawRect:rect];
86 }
87
88 - (void)mouseDown:(NSEvent *)theEvent
89 {
90 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
91 if( !win || !win->Cocoa_mouseDown(theEvent) )
92 [super mouseDown:theEvent];
93 }
94
95 - (void)mouseDragged:(NSEvent *)theEvent
96 {
97 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
98 if( !win || !win->Cocoa_mouseDragged(theEvent) )
99 [super mouseDragged:theEvent];
100 }
101
102 - (void)mouseUp:(NSEvent *)theEvent
103 {
104 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
105 if( !win || !win->Cocoa_mouseUp(theEvent) )
106 [super mouseUp:theEvent];
107 }
108
109 - (void)mouseMoved:(NSEvent *)theEvent
110 {
111 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
112 if( !win || !win->Cocoa_mouseMoved(theEvent) )
113 [super mouseMoved:theEvent];
114 }
115
116 - (void)mouseEntered:(NSEvent *)theEvent
117 {
118 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
119 if( !win || !win->Cocoa_mouseEntered(theEvent) )
120 [super mouseEntered:theEvent];
121 }
122
123 - (void)mouseExited:(NSEvent *)theEvent
124 {
125 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
126 if( !win || !win->Cocoa_mouseExited(theEvent) )
127 [super mouseExited:theEvent];
128 }
129
130 - (void)rightMouseDown:(NSEvent *)theEvent
131 {
132 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
133 if( !win || !win->Cocoa_rightMouseDown(theEvent) )
134 [super rightMouseDown:theEvent];
135 }
136
137 - (void)rightMouseDragged:(NSEvent *)theEvent
138 {
139 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
140 if( !win || !win->Cocoa_rightMouseDragged(theEvent) )
141 [super rightMouseDragged:theEvent];
142 }
143
144 - (void)rightMouseUp:(NSEvent *)theEvent
145 {
146 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
147 if( !win || !win->Cocoa_rightMouseUp(theEvent) )
148 [super rightMouseUp:theEvent];
149 }
150
151 - (void)otherMouseDown:(NSEvent *)theEvent
152 {
153 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
154 if( !win || !win->Cocoa_otherMouseDown(theEvent) )
155 [super otherMouseDown:theEvent];
156 }
157
158 - (void)otherMouseDragged:(NSEvent *)theEvent
159 {
160 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
161 if( !win || !win->Cocoa_otherMouseDragged(theEvent) )
162 [super otherMouseDragged:theEvent];
163 }
164
165 - (void)otherMouseUp:(NSEvent *)theEvent
166 {
167 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
168 if( !win || !win->Cocoa_otherMouseUp(theEvent) )
169 [super otherMouseUp:theEvent];
170 }
171
172 @end // implementation wxPoserNSView
173
174 @interface wxNSViewNotificationObserver : NSObject
175 {
176 }
177
178 // FIXME: Initializing like this is a really bad idea. If for some reason
179 // we ever require posing as an NSObject we won't be able to since an instance
180 // will have already been created here. Of course, catching messages for
181 // NSObject seems like a LOT of overkill, so I doubt we ever will anyway!
182 void *wxCocoaNSView::sm_cocoaObserver = [[wxNSViewNotificationObserver alloc] init];
183
184 - (void)notificationFrameChanged: (NSNotification *)notification;
185 @end // interface wxNSViewNotificationObserver
186
187 @implementation wxNSViewNotificationObserver : NSObject
188
189 - (void)notificationFrameChanged: (NSNotification *)notification;
190 {
191 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([notification object]);
192 wxCHECK_RET(win,wxT("notificationFrameChanged received but no wxWindow exists"));
193 win->Cocoa_FrameChanged();
194 }
195
196 @end // implementation wxNSViewNotificationObserver
197