]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/toolbar.mm
first attempt at adding the minimal set needed for dead-key support, see #15345
[wxWidgets.git] / src / osx / cocoa / toolbar.mm
index 429380132977a942e8d7bd9f275e8cba14c20dfb..ebca4f42e1d70c5ca499383c45e408a3cf6069f2 100644 (file)
@@ -4,7 +4,6 @@
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     04/01/98
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     04/01/98
-// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -305,8 +304,11 @@ private:
 
 @interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>)
 {
 
 @interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER(<NSToolbarDelegate>)
 {
+    bool m_isSelectable;
 }
 
 }
 
+- (void)setSelectable:(bool) value;
+
 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
 
 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
 
 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
@@ -363,6 +365,17 @@ private:
 
 @implementation wxNSToolbarDelegate
 
 
 @implementation wxNSToolbarDelegate
 
+- (id)init
+{
+    m_isSelectable = false;
+    return [super init];
+}
+
+- (void)setSelectable:(bool) value
+{
+    m_isSelectable = true;
+}
+
 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
 {
     wxUnusedVar(toolbar);
 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
 {
     wxUnusedVar(toolbar);
@@ -377,8 +390,10 @@ private:
 
 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
 {
 
 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
 {
-    wxUnusedVar(toolbar);
-    return nil;
+  if ( m_isSelectable )
+      return [[toolbar items] valueForKey:@"itemIdentifier"];
+  else
+      return nil;
 }
 
 - (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag
 }
 
 - (NSToolbarItem*) toolbar:(NSToolbar*) toolbar itemForItemIdentifier:(NSString*) itemIdentifier willBeInsertedIntoToolbar:(BOOL) flag
@@ -1228,9 +1243,6 @@ bool wxToolBar::Realize()
     SetInitialSize( wxSize(m_minWidth, m_minHeight));
 
     SendSizeEventToParent();
     SetInitialSize( wxSize(m_minWidth, m_minHeight));
 
     SendSizeEventToParent();
-    wxWindow * const parent = GetParent();
-    if ( parent && !parent->IsBeingDeleted() )
-        parent->MacOnInternalSize();
     
     return true;
 }
     
     return true;
 }
@@ -1449,7 +1461,8 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase)
 
 #endif // wxOSX_USE_NATIVE_TOOLBAR
                 tool->SetControlHandle( controlHandle );
 
 #endif // wxOSX_USE_NATIVE_TOOLBAR
                 tool->SetControlHandle( controlHandle );
-                tool->UpdateImages();
+                if ( !(style & wxTB_NOICONS) )
+                    tool->UpdateImages();
                 tool->UpdateLabel();
 
                 if ( style & wxTB_NOICONS )
                 tool->UpdateLabel();
 
                 if ( style & wxTB_NOICONS )
@@ -1609,4 +1622,23 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
     event.Skip();
 }
 
     event.Skip();
 }
 
+#if wxOSX_USE_NATIVE_TOOLBAR
+void wxToolBar::OSXSetSelectableTools(bool set)
+{
+    wxCHECK_RET( m_macToolbar, "toolbar must be non-NULL" );
+    [(wxNSToolbarDelegate*)[(NSToolbar*)m_macToolbar delegate] setSelectable:set];
+}
+
+void wxToolBar::OSXSelectTool(int toolId)
+{
+    wxToolBarToolBase *tool = FindById(toolId);
+    wxCHECK_RET( tool, "invalid tool ID" );
+    wxCHECK_RET( m_macToolbar, "toolbar must be non-NULL" );
+
+    wxString identifier = wxString::Format(wxT("%ld"), (long)tool);
+    wxCFStringRef cfidentifier(identifier, wxFont::GetDefaultEncoding());
+    [(NSToolbar*)m_macToolbar setSelectedItemIdentifier:cfidentifier.AsNSString()];
+}
+#endif // wxOSX_USE_NATIVE_TOOLBAR
+
 #endif // wxUSE_TOOLBAR
 #endif // wxUSE_TOOLBAR