X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4cbc57f086cee690f397ac5622d3f1d7153b300e..1721a8c028d3b6a553634c632117fbfac102a30e:/contrib/src/fl/dyntbar.cpp?ds=sidebyside diff --git a/contrib/src/fl/dyntbar.cpp b/contrib/src/fl/dyntbar.cpp index 138f5a0b95..f68882a5c5 100644 --- a/contrib/src/fl/dyntbar.cpp +++ b/contrib/src/fl/dyntbar.cpp @@ -6,7 +6,7 @@ // Created: ??/10/98 // RCS-ID: $Id$ // Copyright: (c) Aleksandras Gluchovas -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -29,9 +29,9 @@ #include "wx/fl/dyntbar.h" #include "wx/fl/newbmpbtn.h" -IMPLEMENT_DYNAMIC_CLASS(wxDynamicToolBar, wxControl ) +IMPLEMENT_DYNAMIC_CLASS( wxDynamicToolBar, wxObject ) -BEGIN_EVENT_TABLE( wxDynamicToolBar, wxControl ) +BEGIN_EVENT_TABLE( wxDynamicToolBar, wxToolBarBase ) EVT_SIZE ( wxDynamicToolBar::OnSize ) EVT_PAINT( wxDynamicToolBar::OnPaint ) @@ -39,6 +39,11 @@ BEGIN_EVENT_TABLE( wxDynamicToolBar, wxControl ) END_EVENT_TABLE() +/***** Implementation for class wxToolLayoutItem *****/ + +IMPLEMENT_DYNAMIC_CLASS(wxToolLayoutItem, wxObject) + + /***** Implementation for class wxDynToolInfo *****/ IMPLEMENT_DYNAMIC_CLASS(wxDynToolInfo, wxToolLayoutItem) @@ -71,23 +76,23 @@ bool wxDynamicToolBar::Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, const long style, - const int orientation, const int RowsOrColumns, + const int WXUNUSED(orientation), const int WXUNUSED(RowsOrColumns), const wxString& name) { // cut&pasted from wxtbatsmpl.h if ( ! wxWindow::Create(parent, id, pos, size, style, name) ) - return FALSE; + return false; SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE )); - return TRUE; + return true; } bool wxDynamicToolBar::Realize(void) { // FOR NOW:: nothing - return TRUE; + return true; } wxDynamicToolBar::~wxDynamicToolBar(void) @@ -104,14 +109,14 @@ wxDynamicToolBar::~wxDynamicToolBar(void) void wxDynamicToolBar::AddTool( int toolIndex, wxWindow* pToolWindow, - const wxSize& size + const wxSize& WXUNUSED(size) ) { wxDynToolInfo* pInfo = new wxDynToolInfo(); pInfo->mpToolWnd = pToolWindow; pInfo->mIndex = toolIndex; - pInfo->mIsSeparator = FALSE; + pInfo->mIsSeparator = false; int x,y; pToolWindow->GetSize( &x, &y ); @@ -169,10 +174,10 @@ void wxDynamicToolBar::AddTool( int toolIndex, wxBitmap labelBmp, wxToolBarToolBase* wxDynamicToolBar::AddTool(const int toolIndex, const wxBitmap& bitmap, - const wxBitmap& pushedBitmap, - const bool toggle, const long xPos, - const long yPos, wxObject *clientData, - const wxString& helpString1, const wxString& helpString2) + const wxBitmap& WXUNUSED(pushedBitmap), + const bool WXUNUSED(toggle), const long WXUNUSED(xPos), + const long WXUNUSED(yPos), wxObject *WXUNUSED(clientData), + const wxString& helpString1, const wxString& WXUNUSED(helpString2)) { wxNewBitmapButton* pBmpBtn = new wxNewBitmapButton( bitmap ); @@ -180,6 +185,10 @@ wxToolBarToolBase* pBmpBtn->Reshape(); +#if wxUSE_TOOLTIPS + pBmpBtn->SetToolTip( helpString1 ); +#endif // wxUSE_TOOLTIPS + AddTool( toolIndex, pBmpBtn ); return NULL; @@ -229,11 +238,14 @@ void wxDynamicToolBar::AddSeparator( wxWindow* pSepartorWnd ) pInfo->mpToolWnd = pSepartorWnd; pInfo->mIndex = -1; - pInfo->mIsSeparator = TRUE; + pInfo->mIsSeparator = true; + // Do we draw a separator or is a other object? if ( pSepartorWnd ) { - pSepartorWnd->Create( this, -1 ); + // hvl => Is there a way to know if it was already created? + // hvl => shouldn't the pSepartorWnd be created? (like one should expect?) + // pSepartorWnd->Create( this, -1 ); int x,y; pSepartorWnd->GetSize( &x, &y ); @@ -245,22 +257,24 @@ void wxDynamicToolBar::AddSeparator( wxWindow* pSepartorWnd ) } else { - pInfo->mRealSize.x = mSepartorSize; + // Init x and y to the default. + pInfo->mRealSize.x = 0; pInfo->mRealSize.y = 0; + // Init height and width to the normal size of a separator. pInfo->mRect.width = mSepartorSize; - pInfo->mRect.height = 0; + pInfo->mRect.height = mSepartorSize; } mTools.Add( pInfo ); } -void wxDynamicToolBar::OnEraseBackground( wxEraseEvent& event ) +void wxDynamicToolBar::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) { // FOR NOW:: nothing } -void wxDynamicToolBar::OnSize( wxSizeEvent& event ) +void wxDynamicToolBar::OnSize( wxSizeEvent& WXUNUSED(event) ) { //SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) ); @@ -296,24 +310,22 @@ void wxDynamicToolBar::DrawSeparator( wxDynToolInfo& info, wxDC& dc ) } } -void wxDynamicToolBar::OnPaint( wxPaintEvent& event ) +void wxDynamicToolBar::OnPaint( wxPaintEvent& WXUNUSED(event) ) { // draw separators if any - wxPaintDC dc(this); size_t i; for( i = 0; i != mTools.Count(); ++i ) - + { if ( mTools[i]->mIsSeparator ) { // check if separator doesn't have it's own window // if so, then draw it using built-in drawing method - if ( !mTools[i]->mpToolWnd ) - DrawSeparator( *mTools[i], dc ); } + } } // FOR NOW:: quick fix @@ -321,6 +333,11 @@ void wxDynamicToolBar::OnPaint( wxPaintEvent& event ) void wxDynamicToolBar::SizeToolWindows() { + bool bStateCheckDone = false; + bool bHorzSeparator = false; + int maxWidth = 0; + int maxHeight = 0; + size_t i; for( i = 0; i != mTools.Count(); ++i ) { @@ -328,7 +345,6 @@ void wxDynamicToolBar::SizeToolWindows() if ( !info.mIsSeparator ) { - // center real rectangle within the rectangle // provided by the layout manager @@ -338,41 +354,117 @@ void wxDynamicToolBar::SizeToolWindows() // FOR NOW FOR NOW:: quick & dirty fix if ( info.mpToolWnd->IsKindOf( CLASSINFO( wxChoice ) ) ) { - info.mpToolWnd->SetSize( x,y, - info.mRealSize.x - 3, - info.mRealSize.y); + info.mpToolWnd->SetSize( x, y, + info.mRealSize.x - 3, + info.mRealSize.y); } else - info.mpToolWnd->SetSize( x,y, - info.mRealSize.x, - info.mRealSize.y ); + { + info.mpToolWnd->SetSize( x, y, + info.mRealSize.x, + info.mRealSize.y ); + } } + else + { + // We performer this code here, so we only execute it when we have + // separators and we do it only once (all to do with performance...) + if (!bStateCheckDone) + { + bStateCheckDone = true; + + size_t j; + wxDynToolInfo *pInfo; + wxDynToolInfo *pPrevInfo = NULL; + int nVertSeparators = 0; + + for( j = 0; j != mTools.Count(); ++j ) + { + pInfo = mTools[j]; + + // Count all Vert Separators. + if ( pInfo->mIsSeparator ) + nVertSeparators++; + + // Check if the new row starts with a Separator. + if ( pPrevInfo && pInfo->mIsSeparator && + // pPrevInfo->mRect.x >= pInfo->mRect.x && + pPrevInfo->mRect.y < pInfo->mRect.y) + { + // If the Separator is shown on the next row and it's + // the only object on the row it would mean that the + // Separator should be shown as Horizontal one. + if (j+1 != mTools.Count()) + { + if (pInfo->mRect.y < mTools[j+1]->mRect.y) + nVertSeparators--; + } + else + { + nVertSeparators--; + } + } + + pPrevInfo = pInfo; + + maxWidth = wxMax(pInfo->mRect.width, maxWidth); + maxHeight = wxMax(pInfo->mRect.height, maxHeight); + } + + bHorzSeparator = nVertSeparators == 0; + } + + // Check if we should draw Horz or Vert... + if ( !bHorzSeparator ) + { + info.mRect.width = mSepartorSize; + info.mRect.height = maxHeight; + } + else + { + info.mRect.width = maxWidth; + info.mRect.height = mSepartorSize; + } + + // Do we need to set a new size to a seperator object? + if ( info.mpToolWnd ) + { + info.mpToolWnd->SetSize( info.mRect.x, + info.mRect.y, + info.mRect.width, + info.mRect.height); + } - // TBD:: size separator window if present + } } } bool wxDynamicToolBar::Layout() { - if ( !mpLayoutMan ) - mpLayoutMan = CreateDefaultLayout(); - int x,y; GetSize( &x, &y ); wxSize wndDim(x,y); wxSize result; - - wxLayoutItemArrayT items; - - // safe conversion size_t i; + wxDynToolInfo *pInfo; + + // Reset the size of separators... for( i = 0; i != mTools.Count(); ++i ) - items.Add( mTools[i] ); + { + pInfo = mTools[i]; + + if ( pInfo->mIsSeparator ) + { + pInfo->mRect.width = mSepartorSize; + pInfo->mRect.height = mSepartorSize; + } + } - mpLayoutMan->Layout( wndDim, result, items, mVertGap, mHorizGap );; + // Calc and set the best layout + GetPreferredDim( wndDim, result ); SizeToolWindows(); - return TRUE; + return true; } void wxDynamicToolBar::GetPreferredDim( const wxSize& givenDim, wxSize& prefDim ) @@ -387,7 +479,7 @@ void wxDynamicToolBar::GetPreferredDim( const wxSize& givenDim, wxSize& prefDim for( i = 0; i != mTools.Count(); ++i ) items.Add( mTools[i] ); - mpLayoutMan->Layout( givenDim, prefDim, items, mVertGap, mHorizGap );; + mpLayoutMan->Layout( givenDim, prefDim, items, mVertGap, mHorizGap ); } void wxDynamicToolBar::SetLayout( LayoutManagerBase* pLayout ) @@ -400,7 +492,7 @@ void wxDynamicToolBar::SetLayout( LayoutManagerBase* pLayout ) Layout(); } -void wxDynamicToolBar::EnableTool(const int toolIndex, const bool enable ) +void wxDynamicToolBar::EnableTool(int toolIndex, bool enable ) { wxDynToolInfo* pInfo = GetToolInfo( toolIndex ); @@ -419,7 +511,7 @@ void BagLayout::Layout( const wxSize& parentDim, wxSize& resultingDim, wxLayoutItemArrayT& items, int horizGap, - int vertGap + int vertGap ) { int maxWidth = 0; @@ -477,39 +569,47 @@ void BagLayout::Layout( const wxSize& parentDim, //////// stuff from 2.1.15 /////////// -wxToolBarToolBase* wxDynamicToolBar::FindToolForPosition( wxCoord x, wxCoord y ) const +wxToolBarToolBase* wxDynamicToolBar::FindToolForPosition( wxCoord WXUNUSED(x), wxCoord WXUNUSED(y) ) const { return NULL; } -bool wxDynamicToolBar::DoInsertTool( size_t pos, wxToolBarToolBase* tool ) +bool wxDynamicToolBar::DoInsertTool( size_t WXUNUSED(pos), wxToolBarToolBase* WXUNUSED(tool) ) { - return TRUE; + return true; } -bool wxDynamicToolBar::DoDeleteTool( size_t pos, wxToolBarToolBase* tool ) +bool wxDynamicToolBar::DoDeleteTool( size_t WXUNUSED(pos), wxToolBarToolBase* WXUNUSED(tool) ) { - return TRUE; + return true; } -void wxDynamicToolBar::DoEnableTool( wxToolBarToolBase* tool, bool enable ) +void wxDynamicToolBar::DoEnableTool( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(enable) ) { } -void wxDynamicToolBar::DoToggleTool( wxToolBarToolBase* tool, bool toggle ) +void wxDynamicToolBar::DoToggleTool( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(toggle) ) { } -void wxDynamicToolBar::DoSetToggle( wxToolBarToolBase* tool, bool toggle ) +void wxDynamicToolBar::DoSetToggle( wxToolBarToolBase* WXUNUSED(tool), bool WXUNUSED(toggle) ) { } -wxToolBarToolBase* wxDynamicToolBar::CreateTool( int id, const wxBitmap& bitmap1, const wxBitmap& bitmap2, bool toggle, wxObject* clientData, const wxString& shortHelpString, const wxString& longHelpString ) +wxToolBarToolBase* wxDynamicToolBar::CreateTool( int WXUNUSED(id), + const wxString& WXUNUSED(label), + const wxBitmap& WXUNUSED(bmpNormal), + const wxBitmap& WXUNUSED(bmpDisabled), + wxItemKind WXUNUSED(kind), + wxObject *WXUNUSED(clientData), + const wxString& WXUNUSED(shortHelp), + const wxString& WXUNUSED(longHelp) + ) { return NULL; } -wxToolBarToolBase* wxDynamicToolBar::CreateTool( wxControl* control ) +wxToolBarToolBase* wxDynamicToolBar::CreateTool( wxControl* WXUNUSED(control) ) { return NULL; }