]> git.saurik.com Git - wxWidgets.git/blobdiff - src/cocoa/NSMenu.mm
Use the data scheme to load resources in the WebKitGTK+ implementation, rather than...
[wxWidgets.git] / src / cocoa / NSMenu.mm
index ca226efa44f6b8c65cd0d1bf97ec10776547a1d3..4060f544a5d62a037e4225286a66779112f14557 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        cocoa/NSMenu.mm
+// Name:        src/cocoa/NSMenu.mm
 // Purpose:     wxCocoaNSMenu implementation
 // Author:      David Elliott
 // Modified by:
     #include "wx/log.h"
 #endif // WX_PRECOMP
 
+#include "wx/cocoa/ObjcRef.h"
 #include "wx/cocoa/NSMenu.h"
-//#include "wx/cocoa/ObjcPose.h"
 
 #import <Foundation/NSNotification.h>
-#import <AppKit/NSMenu.h>
+#include "wx/cocoa/objc/NSMenu.h"
 
-#if 0 // There is no reason to pose for NSMenu at this time.
 // ============================================================================
-// @class wxPoserNSMenu
+// @class WXNSMenu
 // ============================================================================
-@interface wxPoserNSMenu : NSMenu
-{
-}
 
-@end // wxPoserNSMenu
+@implementation WXNSMenu : NSMenu
 
-WX_IMPLEMENT_POSER(wxPoserNSMenu);
-@implementation wxPoserNSMenu : NSMenu
+- (void)dealloc
+{
+    wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa(self);
+    if(menu)
+        menu->Cocoa_dealloc();
+    [super dealloc];
+}
 
-@end // wxPoserNSMenu
-#endif // 0
+@end // WXNSMenu
+WX_IMPLEMENT_GET_OBJC_CLASS(WXNSMenu,NSMenu)
 
 // ============================================================================
 // @class wxNSMenuNotificationObserver
@@ -44,57 +45,64 @@ WX_IMPLEMENT_POSER(wxPoserNSMenu);
 {
 }
 
-struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = [[wxNSMenuNotificationObserver alloc] init];
-
 - (void)menuDidAddItem: (NSNotification *)notification;
 - (void)menuDidChangeItem: (NSNotification *)notification;
 - (void)menuDidRemoveItem: (NSNotification *)notification;
 - (void)menuDidSendAction: (NSNotification *)notification;
 - (void)menuWillSendAction: (NSNotification *)notification;
 @end // interface wxNSMenuNotificationObserver
+WX_DECLARE_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject)
 
 @implementation wxNSMenuNotificationObserver : NSObject
 
 - (void)menuDidAddItem: (NSNotification *)notification
 {
     wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]);
-    wxCHECK_RET(menu,"menuDidAddItem received but no wxMenu exists");
+    wxCHECK_RET(menu,wxT("menuDidAddItem received but no wxMenu exists"));
     menu->CocoaNotification_menuDidAddItem(notification);
 }
 
 - (void)menuDidChangeItem: (NSNotification *)notification
 {
     wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]);
-    wxCHECK_RET(menu,"menuDidChangeItem received but no wxMenu exists");
+    wxCHECK_RET(menu,wxT("menuDidChangeItem received but no wxMenu exists"));
     menu->CocoaNotification_menuDidChangeItem(notification);
 }
 
 - (void)menuDidRemoveItem: (NSNotification *)notification
 {
     wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]);
-    wxCHECK_RET(menu,"menuDidRemoveItem received but no wxMenu exists");
+    wxCHECK_RET(menu,wxT("menuDidRemoveItem received but no wxMenu exists"));
     menu->CocoaNotification_menuDidRemoveItem(notification);
 }
 
 - (void)menuDidSendAction: (NSNotification *)notification
 {
     wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]);
-    wxCHECK_RET(menu,"menuDidSendAction received but no wxMenu exists");
+    wxCHECK_RET(menu,wxT("menuDidSendAction received but no wxMenu exists"));
     menu->CocoaNotification_menuDidSendAction(notification);
 }
 
 - (void)menuWillSendAction: (NSNotification *)notification
 {
     wxCocoaNSMenu *menu = wxCocoaNSMenu::GetFromCocoa([notification object]);
-    wxCHECK_RET(menu,"menuWillSendAction received but no wxMenu exists");
+    wxCHECK_RET(menu,wxT("menuWillSendAction received but no wxMenu exists"));
     menu->CocoaNotification_menuWillSendAction(notification);
 }
 
 @end // implementation wxNSMenuNotificationObserver
+WX_IMPLEMENT_GET_OBJC_CLASS(wxNSMenuNotificationObserver,NSObject)
 
 // ========================================================================
 // wxCocoaNSMenu
 // ========================================================================
+WX_IMPLEMENT_OBJC_INTERFACE_HASHMAP(NSMenu)
+
+// New CF-retained observer (this should have been using wxObjcAutoRefFromAlloc to begin with)
+static wxObjcAutoRefFromAlloc<wxNSMenuNotificationObserver*> s_cocoaNSMenuObserver([[WX_GET_OBJC_CLASS(wxNSMenuNotificationObserver) alloc] init]);
+// For compatibility with old code
+struct objc_object *wxCocoaNSMenu::sm_cocoaObserver = s_cocoaNSMenuObserver;
+
 void wxCocoaNSMenu::AssociateNSMenu(WX_NSMenu cocoaNSMenu, unsigned int flags)
 {
     if(cocoaNSMenu)