]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/toolbar.cpp
compilation fix for new event types (this shouldn't be necessary but do it to tempora...
[wxWidgets.git] / src / msw / toolbar.cpp
index 13d07891169ba434c8d657022c6a7a6053f003e8..140831106f7a9ec6dcaf16a79b5ede90b65bd057 100644 (file)
@@ -46,6 +46,7 @@
 #include "wx/artprov.h"
 #include "wx/sysopt.h"
 #include "wx/dcclient.h"
+#include "wx/ptr_scpd.h"
 
 #include "wx/msw/private.h"
 #include "wx/msw/dc.h"
@@ -629,6 +630,31 @@ void wxToolBar::CreateDisabledImageList()
     }
 }
 
+void wxToolBar::MSWSetBitmapSize(const wxSize& size)
+{
+    ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
+}
+
+void wxToolBar::AdjustToolBitmapSize()
+{
+    // this is the default bitmap size, we only need to call TB_SETBITMAPSIZE
+    // if we use something different
+    static const wxSize sizeStd(16, 15);
+
+    wxSize s(m_defaultWidth, m_defaultHeight);
+
+    for ( wxToolBarToolsList::const_iterator i = m_tools.begin();
+          i != m_tools.end();
+          ++i )
+    {
+        const wxBitmap& bmp = (*i)->GetNormalBitmap();
+        s.IncTo(bmp.GetSize());
+    }
+
+    if ( s != sizeStd )
+        MSWSetBitmapSize(s);
+}
+
 bool wxToolBar::Realize()
 {
     const size_t nTools = GetToolsCount();
@@ -636,6 +662,10 @@ bool wxToolBar::Realize()
         // nothing to do
         return true;
 
+    // make sure tool size is larger enough for all all bitmaps to fit in
+    // (this is consistent with what other ports do):
+    AdjustToolBitmapSize();
+
 #ifdef wxREMAP_BUTTON_COLOURS
     // don't change the values of these constants, they can be set from the
     // user code via wxSystemOptions
@@ -673,22 +703,12 @@ bool wxToolBar::Realize()
     wxToolBarToolsList::compatibility_iterator node;
     int bitmapId = 0;
 
-    wxSize sizeBmp;
-    if ( HasFlag(wxTB_NOICONS) )
-    {
-        // no icons, don't leave space for them
-        sizeBmp.x =
-        sizeBmp.y = 0;
-    }
-    else // do show icons
+    if ( !HasFlag(wxTB_NOICONS) )
     {
         // if we already have a bitmap, we'll replace the existing one --
         // otherwise we'll install a new one
         HBITMAP oldToolBarBitmap = (HBITMAP)m_hBitmap;
 
-        sizeBmp.x = m_defaultWidth;
-        sizeBmp.y = m_defaultHeight;
-
         const wxCoord totalBitmapWidth  = m_defaultWidth *
                                           wx_truncate_cast(wxCoord, nTools),
                       totalBitmapHeight = m_defaultHeight;
@@ -892,18 +912,11 @@ bool wxToolBar::Realize()
         }
     }
 
-    // don't call SetToolBitmapSize() as we don't want to change the values of
-    // m_defaultWidth/Height
-    if ( !::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0,
-                        MAKELONG(sizeBmp.x, sizeBmp.y)) )
-    {
-        wxLogLastError(_T("TB_SETBITMAPSIZE"));
-    }
 
     // Next add the buttons and separators
     // -----------------------------------
 
-    TBBUTTON *buttons = new TBBUTTON[nTools];
+    wxScopedArray<TBBUTTON> buttons(new TBBUTTON[nTools]);
 
     // this array will hold the indices of all controls in the toolbar
     wxArrayInt controlIds;
@@ -1023,12 +1036,11 @@ bool wxToolBar::Realize()
         i++;
     }
 
-    if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS, (WPARAM)i, (LPARAM)buttons) )
+    if ( !::SendMessage(GetHwnd(), TB_ADDBUTTONS, i, (LPARAM)buttons.get()) )
     {
         wxLogLastError(wxT("TB_ADDBUTTONS"));
     }
 
-    delete [] buttons;
 
     // Deal with the controls finally
     // ------------------------------
@@ -1342,7 +1354,7 @@ void wxToolBar::SetToolBitmapSize(const wxSize& size)
 {
     wxToolBarBase::SetToolBitmapSize(size);
 
-    ::SendMessage(GetHwnd(), TB_SETBITMAPSIZE, 0, MAKELONG(size.x, size.y));
+    MSWSetBitmapSize(size);
 }
 
 void wxToolBar::SetRows(int nRows)