From 2bed17c862db626a40bfb981cb8d2bfed17b2737 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 12 Sep 2008 19:38:27 +0000 Subject: [PATCH] implementing changes in toolbartool directly git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/carbon/toolbar.cpp | 113 ++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/src/osx/carbon/toolbar.cpp b/src/osx/carbon/toolbar.cpp index d2e2b5cccb..f1ff79cd4c 100644 --- a/src/osx/carbon/toolbar.cpp +++ b/src/osx/carbon/toolbar.cpp @@ -159,10 +159,75 @@ public: return wxPoint( m_x, m_y ); } - bool DoEnable( bool enable ); + virtual bool Enable( bool enable ); void UpdateToggleImage( bool toggle ); + virtual bool Toggle(bool toggle) + { + if ( wxToolBarToolBase::Toggle( toggle ) == false ) + return false; + + UpdateToggleImage(toggle); + return true; + } + + void UpdateHelpStrings() + { +#if wxOSX_USE_NATIVE_TOOLBAR + if ( m_toolbarItemRef ) + { + wxFontEncoding enc = GetToolBarFontEncoding(); + + HIToolbarItemSetHelpText( + m_toolbarItemRef, + wxCFStringRef( GetShortHelp(), enc ), + wxCFStringRef( GetLongHelp(), enc ) ); + } +#endif + } + + virtual bool SetShortHelp(const wxString& help) + { + if ( wxToolBarToolBase::SetShortHelp( help ) == false ) + return false; + + UpdateHelpStrings(); + return true; + } + + virtual bool SetLongHelp(const wxString& help) + { + if ( wxToolBarToolBase::SetLongHelp( help ) == false ) + return false; + + UpdateHelpStrings(); + return true; + } + + virtual void SetNormalBitmap(const wxBitmap& bmp) + { + wxToolBarToolBase::SetNormalBitmap(bmp); + UpdateToggleImage(CanBeToggled() && IsToggled()); + } + + virtual void SetLabel(const wxString& label) + { + wxToolBarToolBase::SetLabel(label); +#if wxOSX_USE_NATIVE_TOOLBAR + if ( m_toolbarItemRef ) + { + // strip mnemonics from the label for compatibility with the usual + // labels in wxStaticText sense + wxString labelStr = wxStripMenuCodes(label); + + HIToolbarItemSetLabel( + m_toolbarItemRef, + wxCFStringRef(labelStr, GetToolBarFontEncoding()) ); + } +#endif + } + #if wxOSX_USE_NATIVE_TOOLBAR void SetToolbarItemRef( HIToolbarItemRef ref ) { @@ -172,15 +237,7 @@ public: CFRelease( m_toolbarItemRef ); m_toolbarItemRef = ref; - if ( m_toolbarItemRef ) - { - wxFontEncoding enc = GetToolBarFontEncoding(); - - HIToolbarItemSetHelpText( - m_toolbarItemRef, - wxCFStringRef( GetShortHelp(), enc ), - wxCFStringRef( GetLongHelp(), enc ) ); - } + UpdateHelpStrings(); } HIToolbarItemRef GetToolbarItemRef() const @@ -197,22 +254,6 @@ public: { return m_index; } - - virtual void SetLabel(const wxString& label) - { - wxToolBarToolBase::SetLabel(label); - - if ( m_toolbarItemRef ) - { - // strip mnemonics from the label for compatibility with the usual - // labels in wxStaticText sense - wxString labelStr = wxStripMenuCodes(label); - - HIToolbarItemSetLabel( - m_toolbarItemRef, - wxCFStringRef(labelStr, GetToolBarFontEncoding()) ); - } - } #endif // wxOSX_USE_NATIVE_TOOLBAR private: @@ -384,8 +425,11 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacToolBarEventHandler ) #endif -bool wxToolBarTool::DoEnable( bool enable ) +bool wxToolBarTool::Enable( bool enable ) { + if ( wxToolBarToolBase::Enable( enable ) == false ) + return false; + if ( IsControl() ) { GetControl()->Enable( enable ); @@ -1190,10 +1234,6 @@ bool wxToolBar::Realize() { // since setting the help texts is non-virtual we have to update // the strings now - HIToolbarItemSetHelpText( hiItemRef, - wxCFStringRef( tool->GetShortHelp(), enc ), - wxCFStringRef( tool->GetLongHelp(), enc ) ); - if ( insertAll || (tool->GetIndex() != currentPosition) ) { OSStatus err = noErr; @@ -1461,17 +1501,14 @@ 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 implementation } void wxToolBar::DoToggleTool(wxToolBarToolBase *t, bool toggle) { - wxToolBarTool *tool = (wxToolBarTool *)t; - if ( ( tool != NULL ) && tool->IsButton() ) - tool->UpdateToggleImage( toggle ); + // everything already done in the tool's implementation } bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) @@ -1655,7 +1692,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(toggle)) { - wxFAIL_MSG( wxT("not implemented") ); + // nothing to do } bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolbase)