Added wxToolBar::SetTool[Normal|Disabled]Bitmap for wxMSW, wxGTK and wxMac

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@44317 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2007-01-25 23:35:07 +00:00
parent a34d58f775
commit 69d4bbb974
10 changed files with 125 additions and 10 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -57,6 +57,12 @@ class WXDLLEXPORT wxToolBar: public wxToolBarBase
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
// Add all the buttons
virtual wxString MacGetToolTipString( wxPoint &where ) ;

View File

@@ -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
// -------------------------------

View File

@@ -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
// ----------------------------------------------------------------------------

View File

@@ -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

View File

@@ -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
// ----------------------------------------------------------------------------

View File

@@ -29,10 +29,12 @@
global:
# wxFileHistory::Set/GetBaseId()
*wxFileHistory*etBaseId*;
*wxSizerFlags*Shaped*;
*wxSizerFlags*FixedMinSize*;
*wxSearchCtrl*SetDescriptiveText*;
*wxSearchCtrl*GetDescriptiveText*;
*wxSizerFlags*Shaped*;
*wxSizerFlags*FixedMinSize*;
*wxToolBar*SetToolNormalBitmap;
*wxToolBar*SetToolDisabledBitmap;
};
# public symbols added in 2.8.1 (please keep in alphabetical order):

View File

@@ -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

View File

@@ -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);
};