]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/toolbar.mm
guarding open combo box against AppDefined NSEvents issued by wxEventLoop::WakeUp...
[wxWidgets.git] / src / osx / cocoa / toolbar.mm
index 5fa4bb5c5a4a65c221b09f56864506fdb525b585..ed713512c8bc25a58e1ce1769e4f2cfa2e576979 100644 (file)
@@ -305,8 +305,11 @@ private:
 
 @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;
@@ -363,6 +366,17 @@ private:
 
 @implementation wxNSToolbarDelegate
 
+- (id)init
+{
+    m_isSelectable = false;
+    return [super init];
+}
+
+- (void)setSelectable:(bool) value
+{
+    m_isSelectable = true;
+}
+
 - (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
 {
     wxUnusedVar(toolbar);
@@ -377,8 +391,10 @@ private:
 
 - (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
@@ -1228,9 +1244,6 @@ bool wxToolBar::Realize()
     SetInitialSize( wxSize(m_minWidth, m_minHeight));
 
     SendSizeEventToParent();
-    wxWindow * const parent = GetParent();
-    if ( parent && !parent->IsBeingDeleted() )
-        parent->MacOnInternalSize();
     
     return true;
 }
@@ -1591,45 +1604,41 @@ void wxToolBar::OnPaint(wxPaintEvent& event)
         int w, h;
         GetSize( &w, &h );
 
-        bool drawMetalTheme = MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL;
-
-        if ( UMAGetSystemVersion() < 0x1050 )
-        {
-            if ( !drawMetalTheme )
-            {
-                HIThemePlacardDrawInfo info;
-                memset( &info, 0, sizeof(info) );
-                info.version = 0;
-                info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive;
-
-                CGContextRef cgContext = (CGContextRef) MacGetCGContextRef();
-                HIRect rect = CGRectMake( 0, 0, w, h );
-                HIThemeDrawPlacard( &rect, &info, cgContext, kHIThemeOrientationNormal );
-            }
-            else
-            {
-                // leave the background as it is (striped or metal)
-            }
-        }
-        else
-        {
-            wxPaintDC dc(this);
-            
-            wxRect rect(0,0,w,h);
-            
-            dc.GradientFillLinear( rect , wxColour( 0xCC,0xCC,0xCC ), wxColour( 0xA8,0xA8,0xA8 ) , wxSOUTH );
-            dc.SetPen( wxPen( wxColour( 0x51,0x51,0x51 ) ) );
-            if ( HasFlag(wxTB_LEFT) )
-                dc.DrawLine(w-1, 0, w-1, h);
-            else if ( HasFlag(wxTB_RIGHT) )
-                dc.DrawLine(0, 0, 0, h);
-            else if ( HasFlag(wxTB_BOTTOM) )
-                dc.DrawLine(0, 0, w, 0);
-            else if ( HasFlag(wxTB_TOP) )
-                dc.DrawLine(0, h-1, w, h-1);
-        }
+        wxPaintDC dc(this);
+        
+        wxRect rect(0,0,w,h);
+        
+        dc.GradientFillLinear( rect , wxColour( 0xCC,0xCC,0xCC ), wxColour( 0xA8,0xA8,0xA8 ) , wxSOUTH );
+        dc.SetPen( wxPen( wxColour( 0x51,0x51,0x51 ) ) );
+        if ( HasFlag(wxTB_LEFT) )
+            dc.DrawLine(w-1, 0, w-1, h);
+        else if ( HasFlag(wxTB_RIGHT) )
+            dc.DrawLine(0, 0, 0, h);
+        else if ( HasFlag(wxTB_BOTTOM) )
+            dc.DrawLine(0, 0, w, 0);
+        else if ( HasFlag(wxTB_TOP) )
+            dc.DrawLine(0, h-1, w, h-1);
     }
     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