X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cc26010927f5bb12825a32487949d063e6c605fc..98f8e6666b4622a7dc96292f9dfb215af81573d7:/src/osx/cocoa/toolbar.mm diff --git a/src/osx/cocoa/toolbar.mm b/src/osx/cocoa/toolbar.mm index b6362a6e53..57c8989ccd 100644 --- a/src/osx/cocoa/toolbar.mm +++ b/src/osx/cocoa/toolbar.mm @@ -150,7 +150,7 @@ public: return wxPoint( m_x, m_y ); } - bool DoEnable( bool enable ); + bool Enable( bool enable ); void UpdateImages(); @@ -218,7 +218,17 @@ public: { wxToolBarToolBase::SetLabel(label); UpdateLabel(); - } + } + + virtual bool SetShortHelp(const wxString& help) + { + if ( !wxToolBarToolBase::SetShortHelp(help) ) + return false; + + UpdateLabel(); + + return true; + } #endif // wxOSX_USE_NATIVE_TOOLBAR private: @@ -265,11 +275,12 @@ private: - (void)setImplementation: (wxToolBarTool *) theImplementation; - (wxToolBarTool*) implementation; - (void) clickedAction: (id) sender; +- (BOOL) validateToolbarItem:(NSToolbarItem *)theItem; @end -@interface wxNSToolbarDelegate : NSObject +@interface wxNSToolbarDelegate : NSObject wxOSX_10_6_AND_LATER() { } @@ -332,6 +343,12 @@ private: return impl; } +- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem +{ + wxUnusedVar(theItem); + return impl->IsEnabled() ? YES:NO; +} + @end @implementation wxNSToolbarDelegate @@ -422,8 +439,11 @@ private: @end -bool wxToolBarTool::DoEnable( bool enable ) +bool wxToolBarTool::Enable( bool enable ) { + if ( wxToolBarToolBase::Enable( enable ) == false ) + return false; + if ( IsControl() ) { GetControl()->Enable( enable ); @@ -496,7 +516,7 @@ void wxToolBarTool::UpdateImages() dc.SelectObject( m_alternateBitmap ); dc.SetPen( wxPen(*wxBLACK) ); dc.SetBrush( wxBrush( *wxLIGHT_GREY )); - dc.DrawRectangle( 0, 0, w, h ); + dc.DrawRoundedRectangle( 0, 0, w, h, 2 ); dc.DrawBitmap( m_bmpNormal, 0, 0, true ); dc.SelectObject( wxNullBitmap ); @@ -517,7 +537,11 @@ void wxToolBarTool::UpdateToggleImage( bool toggle ) else [m_toolbarItem setImage:m_bmpNormal.GetNSImage()]; } + else #endif + { + [(NSButton*)m_controlHandle setState:(toggle ? NSOnState : NSOffState)]; + } } wxToolBarTool::wxToolBarTool( @@ -631,19 +655,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 +839,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative) { bResult = true; [(NSToolbar*) m_macToolbar setVisible:NO]; - [tlw setToolbar:nil]; + MacUninstallNativeToolbar(); m_peer->SetVisibility( true ); } } @@ -835,6 +850,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() @@ -1176,10 +1201,9 @@ wxString wxToolBar::MacGetToolTipString( wxPoint &pt ) return wxEmptyString; } -void wxToolBar::DoEnableTool(wxToolBarToolBase *t, bool enable) +void wxToolBar::DoEnableTool(wxToolBarToolBase * WXUNUSED(t), bool WXUNUSED(enable)) { - if ( t != NULL ) - ((wxToolBarTool*)t)->DoEnable( enable ); + // everything already done in the tool's Enable implementation } void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) @@ -1248,7 +1272,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) [v setBezelStyle:NSRegularSquareBezelStyle]; [v setBordered:NO]; - [v setButtonType: ( tool->CanBeToggled() ? NSOnOffButton : NSMomentaryPushInButton )]; + [v setButtonType: ( tool->CanBeToggled() ? NSToggleButton : NSMomentaryPushInButton )]; [v setImplementation:tool]; controlHandle = v;