]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/fl/dyntbar.cpp
use full 32bit range for the process ids
[wxWidgets.git] / contrib / src / fl / dyntbar.cpp
index 138f5a0b95be3b46c90f2137aac6d4d27d5e50cd..fe526de12e05b3031c079d76f110769e97e3e935 100644 (file)
@@ -29,9 +29,9 @@
 #include "wx/fl/dyntbar.h"
 #include "wx/fl/newbmpbtn.h"
 
 #include "wx/fl/dyntbar.h"
 #include "wx/fl/newbmpbtn.h"
 
-IMPLEMENT_DYNAMIC_CLASS(wxDynamicToolBar, wxControl )
+IMPLEMENT_DYNAMIC_CLASS( wxDynamicToolBar, wxToolBarBase )
 
 
-BEGIN_EVENT_TABLE( wxDynamicToolBar, wxControl )
+BEGIN_EVENT_TABLE( wxDynamicToolBar, wxToolBarBase )
 
     EVT_SIZE ( wxDynamicToolBar::OnSize  )
     EVT_PAINT( wxDynamicToolBar::OnPaint )
 
     EVT_SIZE ( wxDynamicToolBar::OnSize  )
     EVT_PAINT( wxDynamicToolBar::OnPaint )
@@ -39,6 +39,11 @@ BEGIN_EVENT_TABLE( wxDynamicToolBar, wxControl )
 
 END_EVENT_TABLE()
 
 
 END_EVENT_TABLE()
 
+/***** Implementation for class wxToolLayoutItem *****/
+        
+IMPLEMENT_DYNAMIC_CLASS(wxToolLayoutItem, wxObject)
+
+
 /***** Implementation for class wxDynToolInfo *****/
         
 IMPLEMENT_DYNAMIC_CLASS(wxDynToolInfo, wxToolLayoutItem)
 /***** Implementation for class wxDynToolInfo *****/
         
 IMPLEMENT_DYNAMIC_CLASS(wxDynToolInfo, wxToolLayoutItem)
@@ -180,6 +185,10 @@ wxToolBarToolBase*
 
     pBmpBtn->Reshape();
 
 
     pBmpBtn->Reshape();
 
+#if wxUSE_TOOLTIPS
+    pBmpBtn->SetToolTip( helpString1 );
+#endif  // wxUSE_TOOLTIPS
+
     AddTool( toolIndex, pBmpBtn );
 
     return NULL;
     AddTool( toolIndex, pBmpBtn );
 
     return NULL;
@@ -229,11 +238,14 @@ void wxDynamicToolBar::AddSeparator( wxWindow* pSepartorWnd )
 
     pInfo->mpToolWnd    = pSepartorWnd;
     pInfo->mIndex       = -1;
 
     pInfo->mpToolWnd    = pSepartorWnd;
     pInfo->mIndex       = -1;
-    pInfo->mIsSeparator    = TRUE;
+    pInfo->mIsSeparator = TRUE;
 
 
+    // Do we draw a separator or is a other object?
     if ( pSepartorWnd )
     {
     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 );
 
         int x,y;
         pSepartorWnd->GetSize( &x, &y );
@@ -245,11 +257,13 @@ void wxDynamicToolBar::AddSeparator( wxWindow* pSepartorWnd )
     }
     else
     {
     }
     else
     {
-        pInfo->mRealSize.x = mSepartorSize;
+        // Init x and y to the default.
+        pInfo->mRealSize.x = 0;
         pInfo->mRealSize.y = 0;
 
         pInfo->mRealSize.y = 0;
 
+        // Init height and width to the normal size of a separator.
         pInfo->mRect.width  = mSepartorSize;
         pInfo->mRect.width  = mSepartorSize;
-        pInfo->mRect.height = 0;
+        pInfo->mRect.height = mSepartorSize;
     }
 
     mTools.Add( pInfo );
     }
 
     mTools.Add( pInfo );
@@ -299,21 +313,19 @@ void wxDynamicToolBar::DrawSeparator( wxDynToolInfo& info, wxDC& dc )
 void wxDynamicToolBar::OnPaint( wxPaintEvent& event )
 {
     // draw separators if any
 void wxDynamicToolBar::OnPaint( wxPaintEvent& event )
 {
     // draw separators if any
-
     wxPaintDC dc(this);
 
     size_t i;
     for( i = 0; i != mTools.Count(); ++i )
     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]->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 )
             if ( !mTools[i]->mpToolWnd )
-
                 DrawSeparator( *mTools[i], dc );
         }
                 DrawSeparator( *mTools[i], dc );
         }
+    }
 }
 
 // FOR NOW:: quick fix
 }
 
 // FOR NOW:: quick fix
@@ -321,6 +333,11 @@ void wxDynamicToolBar::OnPaint( wxPaintEvent& event )
 
 void wxDynamicToolBar::SizeToolWindows()
 {
 
 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 )
     {
     size_t i;
     for( i = 0; i != mTools.Count(); ++i )
     {
@@ -328,7 +345,6 @@ void wxDynamicToolBar::SizeToolWindows()
 
         if ( !info.mIsSeparator ) 
         {
 
         if ( !info.mIsSeparator ) 
         {
-
             // center real rectangle within the rectangle 
             // provided by the layout manager
 
             // center real rectangle within the rectangle 
             // provided by the layout manager
 
@@ -338,38 +354,114 @@ void wxDynamicToolBar::SizeToolWindows()
             // FOR NOW FOR NOW:: quick & dirty fix
             if ( info.mpToolWnd->IsKindOf( CLASSINFO( wxChoice ) ) )
             {
             // 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
             }
             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 = NULL;
+                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()
 {
     }
 }
 
 bool wxDynamicToolBar::Layout()
 {
-    if ( !mpLayoutMan )
-        mpLayoutMan = CreateDefaultLayout();
-
     int x,y;
     GetSize( &x, &y );
     wxSize wndDim(x,y);
     wxSize result;
     int x,y;
     GetSize( &x, &y );
     wxSize wndDim(x,y);
     wxSize result;
-
-    wxLayoutItemArrayT items;
-
-    // safe conversion
     size_t i;
     size_t i;
+    wxDynToolInfo *pInfo;
+
+    // Reset the size of separators...
     for( i = 0; i != mTools.Count(); ++i )
     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;
 
     SizeToolWindows();
     return TRUE;
@@ -387,7 +479,7 @@ void wxDynamicToolBar::GetPreferredDim( const wxSize& givenDim, wxSize& prefDim
     for( i = 0; i != mTools.Count(); ++i )
         items.Add( mTools[i] );
 
     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 )
 }
 
 void wxDynamicToolBar::SetLayout( LayoutManagerBase* pLayout )
@@ -419,7 +511,7 @@ void BagLayout::Layout(  const wxSize&       parentDim,
                          wxSize&             resultingDim,
                          wxLayoutItemArrayT& items,
                          int                 horizGap,
                          wxSize&             resultingDim,
                          wxLayoutItemArrayT& items,
                          int                 horizGap,
-                          int                 vertGap  
+                         int                 vertGap  
                       )
 {
     int maxWidth = 0;
                       )
 {
     int maxWidth = 0;
@@ -504,7 +596,7 @@ void wxDynamicToolBar::DoSetToggle( wxToolBarToolBase* tool, bool 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 id, const wxString& label, const wxBitmap& bmpNormal, const wxBitmap& bmpDisabled, wxItemKind kind, wxObject *clientData, const wxString& shortHelp, const wxString& longHelp)
 {
     return NULL;
 }
 {
     return NULL;
 }