adjust the toolbar tools bitmap size to fit the biggest bitmap used under wxOSX too, not only under MSW (and moved the code doing it to the common base class to avoid duplicating it)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61174 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-06-23 10:21:18 +00:00
parent 12a124ddc9
commit bb2212e6c4
5 changed files with 56 additions and 44 deletions

View File

@@ -361,6 +361,9 @@ public:
// must be called after all buttons have been created to finish toolbar // must be called after all buttons have been created to finish toolbar
// initialisation // initialisation
//
// derived class versions should call the base one first, before doing
// platform-specific stuff
virtual bool Realize(); virtual bool Realize();
// tools state // tools state
@@ -602,6 +605,10 @@ protected:
// un-toggle all buttons in the same radio group // un-toggle all buttons in the same radio group
void UnToggleRadioGroup(wxToolBarToolBase *tool); void UnToggleRadioGroup(wxToolBarToolBase *tool);
// make the size of the buttons big enough to fit the largest bitmap size
void AdjustToolBitmapSize();
// the list of all our tools // the list of all our tools
wxToolBarToolsList m_tools; wxToolBarToolsList m_tools;

View File

@@ -446,8 +446,35 @@ void wxToolBarBase::ClearTools()
} }
} }
void wxToolBarBase::AdjustToolBitmapSize()
{
const wxSize sizeOrig(m_defaultWidth, m_defaultHeight);
wxSize sizeActual(sizeOrig);
for ( wxToolBarToolsList::const_iterator i = m_tools.begin();
i != m_tools.end();
++i )
{
const wxBitmap& bmp = (*i)->GetNormalBitmap();
if ( bmp.IsOk() )
sizeActual.IncTo(bmp.GetSize());
}
if ( sizeActual != sizeOrig )
SetToolBitmapSize(sizeActual);
}
bool wxToolBarBase::Realize() bool wxToolBarBase::Realize()
{ {
// check if we have anything to do
if ( m_tools.empty() )
return false;
// make sure tool size is larger enough for all all bitmaps to fit in
// (this is consistent with what other ports do):
AdjustToolBitmapSize();
return true; return true;
} }

View File

@@ -286,7 +286,7 @@ void wxToolBar::Init()
// 32*32) size for their bitmaps, the native control itself still uses the // 32*32) size for their bitmaps, the native control itself still uses the
// old 16*15 default size (see TB_SETBITMAPSIZE documentation in MSDN), so // old 16*15 default size (see TB_SETBITMAPSIZE documentation in MSDN), so
// default to it so that we don't call SetToolBitmapSize() unnecessarily in // default to it so that we don't call SetToolBitmapSize() unnecessarily in
// AdjustToolBitmapSize() // wxToolBarBase::AdjustToolBitmapSize()
m_defaultWidth = 16; m_defaultWidth = 16;
m_defaultHeight = 15; m_defaultHeight = 15;
@@ -634,34 +634,12 @@ void wxToolBar::CreateDisabledImageList()
} }
} }
void wxToolBar::AdjustToolBitmapSize()
{
const wxSize sizeOrig(m_defaultWidth, m_defaultHeight);
wxSize sizeActual(sizeOrig);
for ( wxToolBarToolsList::const_iterator i = m_tools.begin();
i != m_tools.end();
++i )
{
const wxBitmap& bmp = (*i)->GetNormalBitmap();
sizeActual.IncTo(bmp.GetSize());
}
if ( sizeActual != sizeOrig )
SetToolBitmapSize(sizeActual);
}
bool wxToolBar::Realize() bool wxToolBar::Realize()
{ {
const size_t nTools = GetToolsCount(); if ( !wxToolBarBase::Realize() )
if ( nTools == 0 ) return false;
// nothing to do
return true;
// make sure tool size is larger enough for all all bitmaps to fit in const size_t nTools = GetToolsCount();
// (this is consistent with what other ports do):
AdjustToolBitmapSize();
#ifdef wxREMAP_BUTTON_COLOURS #ifdef wxREMAP_BUTTON_COLOURS
// don't change the values of these constants, they can be set from the // don't change the values of these constants, they can be set from the

View File

@@ -167,14 +167,14 @@ public:
{ {
if ( wxToolBarToolBase::Toggle( toggle ) == false ) if ( wxToolBarToolBase::Toggle( toggle ) == false )
return false; return false;
UpdateToggleImage(toggle); UpdateToggleImage(toggle);
return true; return true;
} }
void UpdateHelpStrings() void UpdateHelpStrings()
{ {
#if wxOSX_USE_NATIVE_TOOLBAR #if wxOSX_USE_NATIVE_TOOLBAR
if ( m_toolbarItemRef ) if ( m_toolbarItemRef )
{ {
wxFontEncoding enc = GetToolBarFontEncoding(); wxFontEncoding enc = GetToolBarFontEncoding();
@@ -186,16 +186,16 @@ public:
} }
#endif #endif
} }
virtual bool SetShortHelp(const wxString& help) virtual bool SetShortHelp(const wxString& help)
{ {
if ( wxToolBarToolBase::SetShortHelp( help ) == false ) if ( wxToolBarToolBase::SetShortHelp( help ) == false )
return false; return false;
UpdateHelpStrings(); UpdateHelpStrings();
return true; return true;
} }
virtual bool SetLongHelp(const wxString& help) virtual bool SetLongHelp(const wxString& help)
{ {
if ( wxToolBarToolBase::SetLongHelp( help ) == false ) if ( wxToolBarToolBase::SetLongHelp( help ) == false )
@@ -205,12 +205,12 @@ public:
return true; return true;
} }
virtual void SetNormalBitmap(const wxBitmap& bmp) virtual void SetNormalBitmap(const wxBitmap& bmp)
{ {
wxToolBarToolBase::SetNormalBitmap(bmp); wxToolBarToolBase::SetNormalBitmap(bmp);
UpdateToggleImage(CanBeToggled() && IsToggled()); UpdateToggleImage(CanBeToggled() && IsToggled());
} }
virtual void SetLabel(const wxString& label) virtual void SetLabel(const wxString& label)
{ {
wxToolBarToolBase::SetLabel(label); wxToolBarToolBase::SetLabel(label);
@@ -429,7 +429,7 @@ bool wxToolBarTool::Enable( bool enable )
{ {
if ( wxToolBarToolBase::Enable( enable ) == false ) if ( wxToolBarToolBase::Enable( enable ) == false )
return false; return false;
if ( IsControl() ) if ( IsControl() )
{ {
GetControl()->Enable( enable ); GetControl()->Enable( enable );
@@ -1108,18 +1108,18 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
bResult = true; bResult = true;
SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar ); SetWindowToolbar( tlw, (HIToolbarRef) m_macToolbar );
// ShowHideWindowToolbar will make the wxFrame grow // ShowHideWindowToolbar will make the wxFrame grow
// which we don't want in this case // which we don't want in this case
wxSize sz = GetParent()->GetSize(); wxSize sz = GetParent()->GetSize();
ShowHideWindowToolbar( tlw, true, false ); ShowHideWindowToolbar( tlw, true, false );
// Restore the orginal size // Restore the orginal size
GetParent()->SetSize( sz ); GetParent()->SetSize( sz );
ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 ); ChangeWindowAttributes( tlw, kWindowToolbarButtonAttribute, 0 );
SetAutomaticControlDragTrackingEnabledForWindow( tlw, true ); SetAutomaticControlDragTrackingEnabledForWindow( tlw, true );
m_peer->Move(0,0,0,0 ); m_peer->Move(0,0,0,0 );
SetSize( wxSIZE_AUTO_WIDTH, 0 ); SetSize( wxSIZE_AUTO_WIDTH, 0 );
m_peer->SetVisibility( false ); m_peer->SetVisibility( false );
@@ -1151,9 +1151,9 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
bool wxToolBar::Realize() bool wxToolBar::Realize()
{ {
if (m_tools.GetCount() == 0) if ( !wxToolBarBase::Realize() )
return false; return false;
wxSize tlw_sz = GetParent()->GetSize(); wxSize tlw_sz = GetParent()->GetSize();
int maxWidth = 0; int maxWidth = 0;
@@ -1365,7 +1365,7 @@ bool wxToolBar::Realize()
if (m_macUsesNativeToolbar) if (m_macUsesNativeToolbar)
GetParent()->SetSize( tlw_sz ); GetParent()->SetSize( tlw_sz );
if ( GetWindowStyleFlag() & (wxTB_TOP|wxTB_BOTTOM) ) if ( GetWindowStyleFlag() & (wxTB_TOP|wxTB_BOTTOM) )
{ {
// if not set yet, only one row // if not set yet, only one row

View File

@@ -839,7 +839,7 @@ bool wxToolBar::MacInstallNativeToolbar(bool usesNative)
bool wxToolBar::Realize() bool wxToolBar::Realize()
{ {
if (m_tools.GetCount() == 0) if ( !wxToolBarBase::Realize() )
return false; return false;
int maxWidth = 0; int maxWidth = 0;