]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/cocoa/NSView.mm
Applied bug fix [ 684949 ] Dialup Sample With Borland C++ 5.5.1 Free Compiler
[wxWidgets.git] / src / cocoa / NSView.mm
... / ...
CommitLineData
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// ----------------------------------------------------------------------------
35WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSView)
36
37void wxCocoaNSView::AssociateNSView(WX_NSView cocoaNSView)
38{
39 sm_cocoaHash.insert(wxCocoaNSViewHash::value_type(cocoaNSView,this));
40 [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(notificationFrameChanged:) name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
41 [cocoaNSView setPostsFrameChangedNotifications: YES];
42}
43
44void wxCocoaNSView::DisassociateNSView(WX_NSView cocoaNSView)
45{
46 sm_cocoaHash.erase(cocoaNSView);
47 [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSViewFrameDidChangeNotification" object:cocoaNSView];
48}
49
50// ============================================================================
51// @class wxPoserNSView
52// ============================================================================
53@interface wxPoserNSView : NSView
54{
55}
56
57- (void)drawRect: (NSRect)rect;
58- (void)mouseDown:(NSEvent *)theEvent;
59- (void)mouseDragged:(NSEvent *)theEvent;
60- (void)mouseUp:(NSEvent *)theEvent;
61- (void)mouseMoved:(NSEvent *)theEvent;
62- (void)mouseEntered:(NSEvent *)theEvent;
63- (void)mouseExited:(NSEvent *)theEvent;
64- (void)rightMouseDown:(NSEvent *)theEvent;
65- (void)rightMouseDragged:(NSEvent *)theEvent;
66- (void)rightMouseUp:(NSEvent *)theEvent;
67- (void)otherMouseDown:(NSEvent *)theEvent;
68- (void)otherMouseDragged:(NSEvent *)theEvent;
69- (void)otherMouseUp:(NSEvent *)theEvent;
70@end // wxPoserNSView
71
72WX_IMPLEMENT_POSER(wxPoserNSView);
73@implementation wxPoserNSView : NSView
74
75- (void)drawRect: (NSRect)rect
76{
77 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
78 if( !win || !win->Cocoa_drawRect(rect) )
79 [super drawRect:rect];
80}
81
82- (void)mouseDown:(NSEvent *)theEvent
83{
84 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
85 if( !win || !win->Cocoa_mouseDown(theEvent) )
86 [super mouseDown:theEvent];
87}
88
89- (void)mouseDragged:(NSEvent *)theEvent
90{
91 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
92 if( !win || !win->Cocoa_mouseDragged(theEvent) )
93 [super mouseDragged:theEvent];
94}
95
96- (void)mouseUp:(NSEvent *)theEvent
97{
98 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
99 if( !win || !win->Cocoa_mouseUp(theEvent) )
100 [super mouseUp:theEvent];
101}
102
103- (void)mouseMoved:(NSEvent *)theEvent
104{
105 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
106 if( !win || !win->Cocoa_mouseMoved(theEvent) )
107 [super mouseMoved:theEvent];
108}
109
110- (void)mouseEntered:(NSEvent *)theEvent
111{
112 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
113 if( !win || !win->Cocoa_mouseEntered(theEvent) )
114 [super mouseEntered:theEvent];
115}
116
117- (void)mouseExited:(NSEvent *)theEvent
118{
119 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
120 if( !win || !win->Cocoa_mouseExited(theEvent) )
121 [super mouseExited:theEvent];
122}
123
124- (void)rightMouseDown:(NSEvent *)theEvent
125{
126 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
127 if( !win || !win->Cocoa_rightMouseDown(theEvent) )
128 [super rightMouseDown:theEvent];
129}
130
131- (void)rightMouseDragged:(NSEvent *)theEvent
132{
133 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
134 if( !win || !win->Cocoa_rightMouseDragged(theEvent) )
135 [super rightMouseDragged:theEvent];
136}
137
138- (void)rightMouseUp:(NSEvent *)theEvent
139{
140 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
141 if( !win || !win->Cocoa_rightMouseUp(theEvent) )
142 [super rightMouseUp:theEvent];
143}
144
145- (void)otherMouseDown:(NSEvent *)theEvent
146{
147 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
148 if( !win || !win->Cocoa_otherMouseDown(theEvent) )
149 [super otherMouseDown:theEvent];
150}
151
152- (void)otherMouseDragged:(NSEvent *)theEvent
153{
154 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
155 if( !win || !win->Cocoa_otherMouseDragged(theEvent) )
156 [super otherMouseDragged:theEvent];
157}
158
159- (void)otherMouseUp:(NSEvent *)theEvent
160{
161 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa(self);
162 if( !win || !win->Cocoa_otherMouseUp(theEvent) )
163 [super otherMouseUp:theEvent];
164}
165
166@end // implementation wxPoserNSView
167
168@interface wxNSViewNotificationObserver : NSObject
169{
170}
171
172// FIXME: Initializing like this is a really bad idea. If for some reason
173// we ever require posing as an NSObject we won't be able to since an instance
174// will have already been created here. Of course, catching messages for
175// NSObject seems like a LOT of overkill, so I doubt we ever will anyway!
176void *wxCocoaNSView::sm_cocoaObserver = [[wxNSViewNotificationObserver alloc] init];
177
178- (void)notificationFrameChanged: (NSNotification *)notification;
179@end // interface wxNSViewNotificationObserver
180
181@implementation wxNSViewNotificationObserver : NSObject
182
183- (void)notificationFrameChanged: (NSNotification *)notification;
184{
185 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([notification object]);
186 wxCHECK_RET(win,"notificationFrameChanged received but no wxWindow exists");
187 win->Cocoa_FrameChanged();
188}
189
190@end // implementation wxNSViewNotificationObserver
191