diff --git a/docs/changes.txt b/docs/changes.txt index 3ccc2e61a8..670f2d047c 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -99,6 +99,7 @@ All: - Made wxTextFile work with unseekable files again (David Hart) - Added wxCONFIG_USE_SUBDIR flag to wxFileConfig (Giuseppe Bilotta) - Added wxSearchCtrl::[Get|Set]DescriptiveText +- Added wxToolBar::SetTool[Normal|Disabled]Bitmap for wxMSW, wxGTK and wxMac wxMSW diff --git a/include/wx/gtk/tbargtk.h b/include/wx/gtk/tbargtk.h index 28fc7ee00b..ea4c9e223b 100644 --- a/include/wx/gtk/tbargtk.h +++ b/include/wx/gtk/tbargtk.h @@ -52,6 +52,12 @@ public: virtual void SetWindowStyleFlag( long style ); +#if wxABI_VERSION >= 20802 + // TODO: In 2.9 these should probably be virtual, and declared in the base class... + void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); +#endif + 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..cc17b485d9 100644 --- a/include/wx/mac/carbon/toolbar.h +++ b/include/wx/mac/carbon/toolbar.h @@ -57,7 +57,13 @@ class WXDLLEXPORT wxToolBar: public wxToolBarBase virtual void SetRows(int nRows); - // Add all the buttons +#if wxABI_VERSION >= 20802 + // TODO: In 2.9 these should probably be virtual, and declared in the base class... + void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); +#endif + + // 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..44f52610e9 100644 --- a/include/wx/msw/tbar95.h +++ b/include/wx/msw/tbar95.h @@ -54,6 +54,12 @@ public: virtual void SetRows(int nRows); +#if wxABI_VERSION >= 20802 + // TODO: In 2.9 these should probably be virtual, and declared in the base class... + void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); +#endif + // implementation only from now on // ------------------------------- 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 // ---------------------------------------------------------------------------- diff --git a/version-script.in b/version-script.in index 231bb6a082..1319e789f1 100644 --- a/version-script.in +++ b/version-script.in @@ -29,10 +29,12 @@ global: # wxFileHistory::Set/GetBaseId() *wxFileHistory*etBaseId*; + *wxSearchCtrl*SetDescriptiveText*; + *wxSearchCtrl*GetDescriptiveText*; *wxSizerFlags*Shaped*; *wxSizerFlags*FixedMinSize*; - *wxSearchCtrl*SetDescriptiveText*; - *wxSearchCtrl*GetDescriptiveText*; + *wxToolBar*SetToolNormalBitmap; + *wxToolBar*SetToolDisabledBitmap; }; # public symbols added in 2.8.1 (please keep in alphabetical order): @@ -43,10 +45,10 @@ *wxDirDialog*etStyle*; # Mac OS X only, but it still must go in IIUC *wxListCtrl*SetFocus*; - *wxListCtrl*OnChar*; - *wxListCtrl*OnRightDown*; - *wxListCtrl*OnMiddleDown*; - *wxListCtrl*FireMouseEvent*; + *wxListCtrl*OnChar*; + *wxListCtrl*OnRightDown*; + *wxListCtrl*OnMiddleDown*; + *wxListCtrl*FireMouseEvent*; # wxTreeCtrl::CollapseAll[Children]() and IsEmpty *wxTreeCtrl*CollapseAll*; *wxTreeCtrl*IsEmpty*; diff --git a/wxPython/docs/CHANGES.txt b/wxPython/docs/CHANGES.txt index c8d6e5e859..ba5402e073 100644 --- a/wxPython/docs/CHANGES.txt +++ b/wxPython/docs/CHANGES.txt @@ -5,6 +5,12 @@ Recent Changes for wxPython ------- * +Added wx.ToolBar.SetToolNormalBitmap and SetToolDisabledBitmap +methods. (Keep in mind however that the disabled bitmap is currently +generated on the fly by most native toolbar widgets, so this +SetToolDisabledBitmap method won't have any affect on them...) + + 2.8.1.1 diff --git a/wxPython/src/_toolbar.i b/wxPython/src/_toolbar.i index f7e886494e..3180b8e515 100644 --- a/wxPython/src/_toolbar.i +++ b/wxPython/src/_toolbar.i @@ -442,6 +442,10 @@ public: long style = wxNO_BORDER | wxTB_HORIZONTAL, const wxString& name = wxPyToolBarNameStr); + // TODO: In 2.9 move these to the base class... + void SetToolNormalBitmap(int id, const wxBitmap& bitmap); + void SetToolDisabledBitmap(int id, const wxBitmap& bitmap); + static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); };