]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/toolbar.mm
fixing coordinate conversions for captured windows
[wxWidgets.git] / src / osx / cocoa / toolbar.mm
index 3d24514ef0b25430a38770d56c64dfd8e9532b48..0add59ad0093a5f5dab02216f9db051ef4e29bfd 100644 (file)
@@ -269,7 +269,7 @@ private:
 @end
 
 
-@interface wxNSToolbarDelegate : NSObject
+@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>)
 {
 }
 
@@ -631,19 +631,10 @@ bool wxToolBar::Create(
 }
 
 wxToolBar::~wxToolBar()
-{
-#if wxOSX_USE_NATIVE_TOOLBAR
-    if (m_macToolbar != NULL)
-    {
-        // if this is the installed toolbar, then deinstall it
-        if (m_macUsesNativeToolbar)
-            MacInstallNativeToolbar( false );
-
-        [(NSToolbar*)m_macToolbar setDelegate:nil];
-        [(NSToolbar*)m_macToolbar release];
-        m_macToolbar = NULL;
-    }
-#endif
+{  
+    [(NSToolbar*)m_macToolbar setDelegate:nil];
+    [(NSToolbar*)m_macToolbar release];
+    m_macToolbar = NULL;
 }
 
 bool wxToolBar::Show( bool show )
@@ -824,7 +815,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
         {
             bResult = true;
             [(NSToolbar*) m_macToolbar setVisible:NO];
-            [tlw setToolbar:nil];
+            MacUninstallNativeToolbar();
             m_peer->SetVisibility( true );
         }
     }
@@ -835,6 +826,16 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
 // wxLogDebug( wxT("    --> [%lx] - result [%s]"), (long)this, bResult ? wxT("T") : wxT("F") );
     return bResult;
 }
+
+void wxToolBar::MacUninstallNativeToolbar()
+{
+    if (!m_macToolbar)
+        return;
+        
+    WXWindow tlw = MacGetTopLevelWindowRef();
+    if (tlw)
+        [tlw setToolbar:nil];
+}
 #endif
 
 bool wxToolBar::Realize()
@@ -960,10 +961,21 @@ bool wxToolBar::Realize()
                             }
                         }
                     }
-                    wxString identifier = wxString::Format( wxT("%ld"), (long) tool );
-                    wxCFStringRef cfidentifier(identifier);
 
-                    [refTB insertItemWithItemIdentifier:cfidentifier.AsNSString() atIndex:currentPosition];
+                    wxCFStringRef cfidentifier;
+                    const NSString *nsItemId;
+                    if (tool->GetStyle() == wxTOOL_STYLE_SEPARATOR)
+                    {
+                        nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
+                                                         : NSToolbarSeparatorItemIdentifier;
+                    }
+                    else
+                    {
+                        cfidentifier = wxCFStringRef(wxString::Format("%ld", (long)tool));
+                        nsItemId = cfidentifier.AsNSString();
+                    }
+
+                    [refTB insertItemWithItemIdentifier:nsItemId atIndex:currentPosition];
                     tool->SetIndex( currentPosition );
                 }
 
@@ -1214,7 +1226,10 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
 #if wxOSX_USE_NATIVE_TOOLBAR
                 if (m_macToolbar != NULL)
                 {
-                    NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:NSToolbarSeparatorItemIdentifier];
+                    const NSString * const
+                        nsItemId = tool->IsStretchable() ? NSToolbarFlexibleSpaceItemIdentifier
+                                                         : NSToolbarSeparatorItemIdentifier;
+                    NSToolbarItem* item = [[NSToolbarItem alloc] initWithItemIdentifier:nsItemId];
                     tool->SetToolbarItemRef( item );
                 }
 #endif // wxOSX_USE_NATIVE_TOOLBAR