]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/menu.mm
support native edit menu handling (cocoa enables menu items in built-in modal dialogs...
[wxWidgets.git] / src / osx / cocoa / menu.mm
index aff7a283e18e28b0a4334d5cb1d2e16bdc5c7365..053c1200520ef980c26e3d0905cc60b389446f32 100644 (file)
@@ -36,9 +36,9 @@
 
 @implementation wxNSMenu
 
-- (id) init
+- (id) initWithTitle:(NSString*) title
 {
-    [super init];
+    [super initWithTitle:title];
     impl = NULL;
     return self;
 }
@@ -55,7 +55,7 @@
 
 @end
 
-@interface wxNSMenuController : NSObject <NSMenuDelegate>
+@interface wxNSMenuController : NSObject wxOSX_10_6_AND_LATER(<NSMenuDelegate>)
 {
 }
 
@@ -143,10 +143,25 @@ public :
 
     virtual void InsertOrAppend(wxMenuItem *pItem, size_t pos)
     {
+        NSMenuItem* nsmenuitem = (NSMenuItem*) pItem->GetPeer()->GetHMenuItem();
+        // make sure a call of SetSubMenu is also reflected (occuring after Create)
+        // update the native menu item accordingly
+        
+        if ( pItem->IsSubMenu() )
+        {
+            wxMenu* wxsubmenu = pItem->GetSubMenu();
+            WXHMENU nssubmenu = wxsubmenu->GetHMenu();
+            if ( [nsmenuitem submenu] != nssubmenu )
+            {
+                wxsubmenu->GetPeer()->SetTitle( pItem->GetItemLabelText() );
+                [nsmenuitem setSubmenu:nssubmenu];
+            }
+        }
+        
         if ( pos == (size_t) -1 )
-            [m_osxMenu addItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem() ];
+            [m_osxMenu addItem:nsmenuitem ];
         else
-            [m_osxMenu insertItem:(NSMenuItem*) pItem->GetPeer()->GetHMenuItem() atIndex:pos];
+            [m_osxMenu insertItem:nsmenuitem atIndex:pos];
     }
 
     virtual void Remove( wxMenuItem *pItem )