]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/toolbar.cpp
Don't scale 16x15 to 16x16 - fixes corruption of bookmark icons in help window
[wxWidgets.git] / src / msw / toolbar.cpp
index 44f08bffb811235d869af5df9eea84860fba4238..4866b30c54c0c2b7f0e65010a8f7428915f91608 100644 (file)
@@ -568,14 +568,18 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
     // get the size of the button we're going to delete
     const RECT r = wxGetTBItemRect(GetHwnd(), pos);
 
-    int width = r.right - r.left;
+    int delta = IsVertical() ? r.bottom - r.top : r.right - r.left;
 
     if ( tool->IsControl() )
     {
         nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount();
-        width *= nButtonsToDelete;
+
+        if ( !IsVertical() )
+            delta *= nButtonsToDelete;
     }
 
+    m_totalFixedSize -= delta;
+
     // do delete all buttons
     m_nButtons -= nButtonsToDelete;
     while ( nButtonsToDelete-- > 0 )
@@ -588,14 +592,45 @@ bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
         }
     }
 
-    // and finally reposition all the controls after this button (the toolbar
-    // takes care of all normal items)
-    for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
+    // and finally rearrange the tools
+
+    // search for any stretch spacers before the removed tool
+    bool hasPrecedingStrechables = false;
+    for ( wxToolBarToolsList::compatibility_iterator nodeStch = m_tools.GetFirst();
+                                 nodeStch != node; nodeStch = nodeStch->GetNext() )
     {
-        wxToolBarTool *tool2 = (wxToolBarTool*)node->GetData();
-        if ( tool2->IsControl() )
+        if ( ((wxToolBarTool*)nodeStch->GetData())->IsStretchable() )
         {
-            tool2->MoveBy(-width);
+            hasPrecedingStrechables = true;
+            break;
+        }
+    }
+
+    if ( hasPrecedingStrechables )
+    {
+        // if the removed tool is preceded by stretch spacers
+        // just redistribute the space
+        UpdateStretchableSpacersSize();
+    }
+    else
+    {
+        // reposition all the controls after this button but before any
+        // stretch spacer (the toolbar takes care of all normal items)
+        for ( /* node -> first after deleted */ ; node; node = node->GetNext() )
+        {
+            wxToolBarTool *tool2 = (wxToolBarTool*)node->GetData();
+
+            if ( tool2->IsControl() )
+            {
+                tool2->MoveBy(-delta);
+            }
+
+            // if a stretch spacer is found just redistribute the available space
+            else if ( tool2->IsStretchable() )
+            {
+                UpdateStretchableSpacersSize();
+                break;
+            }
         }
     }
 
@@ -618,12 +653,13 @@ void wxToolBar::CreateDisabledImageList()
         {
             wxToolBarToolBase *tool = node->GetData();
             wxBitmap bmpDisabled = tool->GetDisabledBitmap();
-            if ( bmpDisabled.Ok() )
+            if ( bmpDisabled.IsOk() )
             {
+                const wxSize sizeBitmap = bmpDisabled.GetSize();
                 m_disabledImgList = new wxImageList
                                         (
-                                            m_defaultWidth,
-                                            m_defaultHeight,
+                                            sizeBitmap.x,
+                                            sizeBitmap.y,
                                             bmpDisabled.GetMask() != NULL,
                                             GetToolsCount()
                                         );
@@ -743,7 +779,7 @@ bool wxToolBar::Realize()
                 const int w = bmp.GetWidth();
                 const int h = bmp.GetHeight();
 
-                if ( bmp.Ok() )
+                if ( bmp.IsOk() )
                 {
                     int xOffset = wxMax(0, (m_defaultWidth - w)/2);
                     int yOffset = wxMax(0, (m_defaultHeight - h)/2);
@@ -761,7 +797,7 @@ bool wxToolBar::Realize()
                 {
                     wxBitmap bmpDisabled = tool->GetDisabledBitmap();
 #if wxUSE_IMAGE && wxUSE_WXDIB
-                    if ( !bmpDisabled.Ok() )
+                    if ( !bmpDisabled.IsOk() )
                     {
                         // no disabled bitmap specified but we still need to
                         // fill the space in the image list with something, so
@@ -1295,7 +1331,7 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_)
     // Without the two lines of code below, if the toolbar was repainted during
     // OnLeftClick(), then it could end up without the tool bitmap temporarily
     // (see http://lists.nongnu.org/archive/html/lmi/2008-10/msg00014.html).
-    // The Update() call bellow ensures that this won't happen, by repainting
+    // The Update() call below ensures that this won't happen, by repainting
     // invalidated areas of the toolbar immediately.
     //
     // To complicate matters, the tool would be drawn in depressed state (this
@@ -1322,7 +1358,7 @@ bool wxToolBar::MSWCommand(WXUINT WXUNUSED(cmd), WXWORD id_)
     ::SendMessage(GetHwnd(), TB_SETSTATE, id, MAKELONG(state, 0));
 
     // OnLeftClick() can veto the button state change - for buttons which
-    // may be toggled only, of couse
+    // may be toggled only, of course.
     if ( !allowLeftClick && tool->CanBeToggled() )
     {
         // revert back
@@ -1721,10 +1757,18 @@ bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
             {
                 // for some reason TB_GETITEMRECT returns a rectangle 1 pixel
                 // shorter than the full window size (at least under Windows 7)
-                // but we need to erase the full height below
+                // but we need to erase the full width/height below
                 RECT rcItem = wxGetTBItemRect(GetHwnd(), toolIndex);
-                rcItem.top = 0;
-                rcItem.bottom = rectTotal.height;
+                if ( IsVertical() )
+                {
+                    rcItem.left = 0;
+                    rcItem.right = rectTotal.width;
+                }
+                else
+                {
+                    rcItem.top = 0;
+                    rcItem.bottom = rectTotal.height;
+                }
 
                 rgnDummySeps.Union(wxRectFromRECT(rcItem));
             }