less code, but a delegate will be required for future functionality.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23294
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
virtual void CocoaNotification_DidBecomeKey(void) { }
virtual void CocoaNotification_DidResignKey(void) { }
protected:
virtual void CocoaNotification_DidBecomeKey(void) { }
virtual void CocoaNotification_DidResignKey(void) { }
protected:
- static void *sm_cocoaObserver;
+ static struct objc_object *sm_cocoaDelegate;
};
#endif // _WX_COCOA_NSWINDOW_H_
};
#endif // _WX_COCOA_NSWINDOW_H_
#import <Foundation/NSString.h>
// ============================================================================
#import <Foundation/NSString.h>
// ============================================================================
-// @class wxNSWindowNotificationObserver
+// @class wxNSWindowDelegate
// ============================================================================
// ============================================================================
-@interface wxNSWindowNotificationObserver : NSObject
+@interface wxNSWindowDelegate : NSObject
-- (void)notificationDidBecomeKey: (NSNotification *)notification;
-- (void)notificationDidResignKey: (NSNotification *)notification;
-@end //interface wxNSWindowNotificationObserver
+- (void)windowDidBecomeKey: (NSNotification *)notification;
+- (void)windowDidResignKey: (NSNotification *)notification;
+@end //interface wxNSWindowDelegate
-@implementation wxNSWindowNotificationObserver : NSObject
+@implementation wxNSWindowDelegate : NSObject
-- (void)notificationDidBecomeKey: (NSNotification *)notification
+- (void)windowDidBecomeKey: (NSNotification *)notification
{
wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
win->CocoaNotification_DidBecomeKey();
}
{
wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
wxCHECK_RET(win,"notificationDidBecomeKey received but no wxWindow exists");
win->CocoaNotification_DidBecomeKey();
}
-- (void)notificationDidResignKey: (NSNotification *)notification
+- (void)windowDidResignKey: (NSNotification *)notification
{
wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
win->CocoaNotification_DidResignKey();
}
{
wxCocoaNSWindow *win = wxCocoaNSWindow::GetFromCocoa([notification object]);
wxCHECK_RET(win,"notificationDidResignKey received but no wxWindow exists");
win->CocoaNotification_DidResignKey();
}
-@end //implementation wxNSWindowNotificationObserver
+@end //implementation wxNSWindowDelegate
// ============================================================================
// class wxCocoaNSWindow
// ============================================================================
// class wxCocoaNSWindow
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSWindow)
-void *wxCocoaNSWindow::sm_cocoaObserver = [[wxNSWindowNotificationObserver alloc] init];
+struct objc_object *wxCocoaNSWindow::sm_cocoaDelegate = [[wxNSWindowDelegate alloc] init];
void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
{
void wxCocoaNSWindow::AssociateNSWindow(WX_NSWindow cocoaNSWindow)
{
{
[cocoaNSWindow setReleasedWhenClosed: NO];
sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
{
[cocoaNSWindow setReleasedWhenClosed: NO];
sm_cocoaHash.insert(wxCocoaNSWindowHash::value_type(cocoaNSWindow,this));
- [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(notificationDidBecomeKey:) name:@"NSWindowDidBecomeKeyNotification" object:cocoaNSWindow];
- [[NSNotificationCenter defaultCenter] addObserver:(id)sm_cocoaObserver selector:@selector(notificationDidResignKey:) name:@"NSWindowDidResignKeyNotification" object:cocoaNSWindow];
+ [cocoaNSWindow setDelegate: sm_cocoaDelegate];
- [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSWindowDidBecomeKeyNotification" object:cocoaNSWindow];
- [[NSNotificationCenter defaultCenter] removeObserver:(id)sm_cocoaObserver name:@"NSWindowDidResignKeyNotification" object:cocoaNSWindow];
+ [cocoaNSWindow setDelegate: nil];
sm_cocoaHash.erase(cocoaNSWindow);
}
}
sm_cocoaHash.erase(cocoaNSWindow);
}
}