From bbd321ffc2d4e7f9e45c72af9e3f824fa9ccda51 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 6 Feb 2007 21:13:03 +0000 Subject: [PATCH] Added SetToolNormalBitmap and SetToolDisabledBitmap (ported from 2.8 branch) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44388 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/toolbar.tex | 20 ++++++++++++++++ include/wx/gtk/tbargtk.h | 3 +++ include/wx/mac/carbon/toolbar.h | 5 +++- include/wx/msw/tbar95.h | 3 +++ include/wx/tbarbase.h | 3 +++ src/gtk/tbargtk.cpp | 24 +++++++++++++++++++ src/mac/carbon/toolbar.cpp | 42 ++++++++++++++++++++++++++++++--- src/msw/tbar95.cpp | 24 +++++++++++++++++++ 8 files changed, 120 insertions(+), 4 deletions(-) diff --git a/docs/latex/wx/toolbar.tex b/docs/latex/wx/toolbar.tex index 122767fb79..400dd86252 100644 --- a/docs/latex/wx/toolbar.tex +++ b/docs/latex/wx/toolbar.tex @@ -761,6 +761,17 @@ and not the eventual size of the tool button. Sets the client data associated with the tool. +\membersection{wxToolBar::SetToolDisabledBitmap}\label{wxtoolbarsettooldisabledbitmap} + +\func{void}{SetToolDisabledBitmap}{\param{int }{id}, \param{const wxBitmap\& }{bitmap}} + +Sets the bitmap to be used by the tool with the given ID when the tool +is in a disabled state. This can only be used on Button tools, not +controls. NOTE: The native toolbar classes on the main platforms all +synthesize the disabled bitmap from the normal bitmap, so this +function will have no effect on those platforms. + + \membersection{wxToolBar::SetToolLongHelp}\label{wxtoolbarsettoollonghelp} \func{void}{SetToolLongHelp}{\param{int }{toolId}, \param{const wxString\& }{helpString}} @@ -824,6 +835,15 @@ An application might use short help for identifying the tool purpose in a toolti \helpref{wxToolBar::GetToolShortHelp}{wxtoolbargettoolshorthelp}, \helpref{wxToolBar::SetToolLongHelp}{wxtoolbarsettoollonghelp} +\membersection{wxToolBar::SetToolNormalBitmap}\label{wxtoolbarsettoolnormalbitmap} + +\func{void}{SetToolNormalBitmap}{\param{int }{id}, \param{const wxBitmap\& }{bitmap}} + +Sets the bitmap to be used by the tool with the given ID. This can +only be used on Button tools, not controls. + + + \membersection{wxToolBar::SetToolSeparation}\label{wxtoolbarsettoolseparation} \func{void}{SetToolSeparation}{\param{int}{ separation}} diff --git a/include/wx/gtk/tbargtk.h b/include/wx/gtk/tbargtk.h index 28fc7ee00b..bcf5da4a0d 100644 --- a/include/wx/gtk/tbargtk.h +++ b/include/wx/gtk/tbargtk.h @@ -52,6 +52,9 @@ public: virtual void SetWindowStyleFlag( long style ); + virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); + static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); diff --git a/include/wx/mac/carbon/toolbar.h b/include/wx/mac/carbon/toolbar.h index 62c91785e1..7673d04a43 100644 --- a/include/wx/mac/carbon/toolbar.h +++ b/include/wx/mac/carbon/toolbar.h @@ -57,7 +57,10 @@ class WXDLLEXPORT wxToolBar: public wxToolBarBase virtual void SetRows(int nRows); - // Add all the buttons + virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); + + // Add all the buttons virtual wxString MacGetToolTipString( wxPoint &where ) ; void OnPaint(wxPaintEvent& event) ; diff --git a/include/wx/msw/tbar95.h b/include/wx/msw/tbar95.h index daa168e3d6..4a3be73333 100644 --- a/include/wx/msw/tbar95.h +++ b/include/wx/msw/tbar95.h @@ -54,6 +54,9 @@ public: virtual void SetRows(int nRows); + virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); + // implementation only from now on // ------------------------------- diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index 3aa70ce99d..7872e6670b 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -372,6 +372,9 @@ public: virtual void SetToolLongHelp(int toolid, const wxString& helpString); virtual wxString GetToolLongHelp(int toolid) const; + virtual void SetToolNormalBitmap(int id, const wxBitmap& bitmap) {} + virtual void SetToolDisabledBitmap(int id, const wxBitmap& bitmap) {} + // margins/packing/separation // -------------------------- diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index 3ce3d74f7d..f1e0bcc9ad 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -597,6 +597,30 @@ void wxToolBar::SetToolShortHelp( int id, const wxString& helpString ) } } +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetNormalBitmap(bitmap); + tool->SetImage(tool->GetBitmap()); + } +} + +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetDisabledBitmap(bitmap); + tool->SetImage(tool->GetBitmap()); + } +} + // ---------------------------------------------------------------------------- // wxToolBar idle handling // ---------------------------------------------------------------------------- diff --git a/src/mac/carbon/toolbar.cpp b/src/mac/carbon/toolbar.cpp index 60e0a5cf9f..f65ba6d135 100644 --- a/src/mac/carbon/toolbar.cpp +++ b/src/mac/carbon/toolbar.cpp @@ -168,10 +168,19 @@ public: m_toolbarItemRef = ref; if ( m_toolbarItemRef ) { + wxFont f; + wxFontEncoding enc; + if ( GetToolBar() ) + f = GetToolBar()->GetFont(); + if ( f.IsOk() ) + enc = f.GetEncoding(); + else + enc = wxFont::GetDefaultEncoding(); + HIToolbarItemSetHelpText( m_toolbarItemRef, - wxMacCFStringHolder( GetShortHelp(), GetToolBar()->GetFont().GetEncoding() ), - wxMacCFStringHolder( GetLongHelp(), GetToolBar()->GetFont().GetEncoding() ) ); + wxMacCFStringHolder( GetShortHelp(), enc ), + wxMacCFStringHolder( GetLongHelp(), enc ) ); } } @@ -1312,6 +1321,33 @@ void wxToolBar::MacSuperChangedPosition() #endif } +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetNormalBitmap(bitmap); + + // a side-effect of the UpdateToggleImage function is that it always changes the bitmap used on the button. + tool->UpdateToggleImage( tool->CanBeToggled() && tool->IsToggled() ); + } +} + +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetDisabledBitmap(bitmap); + + // TODO: what to do for this one? + } +} + wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord x, wxCoord y) const { wxToolBarTool *tool; @@ -1365,6 +1401,7 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) Rect toolrect = { 0, 0, toolSize.y, toolSize.x }; ControlRef controlHandle = NULL; OSStatus err = 0; + tool->Attach( this ); switch (tool->GetStyle()) { @@ -1494,7 +1531,6 @@ bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *toolBase) tool->UpdateToggleImage( true ); // nothing special to do here - we relayout in Realize() later - tool->Attach( this ); InvalidateBestSize(); } else diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index 8d5ad8a0c7..5e4d811bf0 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -1331,6 +1331,30 @@ void wxToolBar::DoSetToggle(wxToolBarToolBase *WXUNUSED(tool), bool WXUNUSED(tog wxFAIL_MSG( _T("not implemented") ); } +void wxToolBar::SetToolNormalBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetNormalBitmap(bitmap); + Realize(); + } +} + +void wxToolBar::SetToolDisabledBitmap( int id, const wxBitmap& bitmap ) +{ + wxToolBarTool* tool = wx_static_cast(wxToolBarTool*, FindById(id)); + if ( tool ) + { + wxCHECK_RET( tool->IsButton(), wxT("Can only set bitmap on button tools.")); + + tool->SetDisabledBitmap(bitmap); + Realize(); + } +} + // ---------------------------------------------------------------------------- // event handlers // ---------------------------------------------------------------------------- -- 2.47.2