+ // delete all old buttons, if any
+ for ( size_t pos = 0; pos < m_nButtons; pos++ )
+ {
+ if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, 0, 0) )
+ {
+ wxLogDebug(wxT("TB_DELETEBUTTON failed"));
+ }
+ }
+
+ // First, add the bitmap: we use one bitmap for all toolbar buttons
+ // ----------------------------------------------------------------
+
+ 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 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 * nTools,
+ totalBitmapHeight = m_defaultHeight;
+
+ // Create a bitmap and copy all the tool bitmaps to it
+ wxMemoryDC dcAllButtons;
+ wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight);
+ dcAllButtons.SelectObject(bitmap);
+ if (doTransparent)
+ dcAllButtons.SetBackground(*wxTRANSPARENT_BRUSH);
+ else
+ dcAllButtons.SetBackground(*wxLIGHT_GREY_BRUSH);
+ dcAllButtons.Clear();
+
+ m_hBitmap = bitmap.GetHBITMAP();
+ HBITMAP hBitmap = (HBITMAP)m_hBitmap;
+
+ if (doRemapBg)
+ {
+ dcAllButtons.SelectObject(wxNullBitmap);
+
+ // Even if we're not remapping the bitmap
+ // content, we still have to remap the background.
+ hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
+ totalBitmapWidth, totalBitmapHeight);
+
+ dcAllButtons.SelectObject(bitmap);
+ }
+
+ // the button position
+ wxCoord x = 0;
+
+ // the number of buttons (not separators)
+ int nButtons = 0;
+
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
+ {
+ wxToolBarToolBase *tool = node->GetData();
+ if ( tool->IsButton() )
+ {
+ const wxBitmap& bmp = tool->GetNormalBitmap();
+ if ( bmp.Ok() )
+ {
+ int xOffset = wxMax(0, (m_defaultWidth - bmp.GetWidth())/2);
+ int yOffset = wxMax(0, (m_defaultHeight - bmp.GetHeight())/2);
+ // notice the last parameter: do use mask
+ dcAllButtons.DrawBitmap(bmp, x+xOffset, yOffset, true);
+ }
+ else
+ {
+ wxFAIL_MSG( _T("invalid tool button bitmap") );
+ }
+
+ // still inc width and number of buttons because otherwise the
+ // subsequent buttons will all be shifted which is rather confusing
+ // (and like this you'd see immediately which bitmap was bad)
+ x += m_defaultWidth;
+ nButtons++;
+ }
+ }
+
+ dcAllButtons.SelectObject(wxNullBitmap);
+
+ // don't delete this HBITMAP!
+ bitmap.SetHBITMAP(0);
+
+ if (doRemap)
+ {
+ // Map to system colours
+ hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
+ totalBitmapWidth, totalBitmapHeight);
+ }
+
+ bool addBitmap = true;
+
+ if ( oldToolBarBitmap )
+ {
+#ifdef TB_REPLACEBITMAP
+ if ( wxTheApp->GetComCtl32Version() >= 400 )
+ {
+ TBREPLACEBITMAP replaceBitmap;
+ replaceBitmap.hInstOld = NULL;
+ replaceBitmap.hInstNew = NULL;
+ replaceBitmap.nIDOld = (UINT) oldToolBarBitmap;
+ replaceBitmap.nIDNew = (UINT) hBitmap;
+ replaceBitmap.nButtons = nButtons;
+ if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
+ 0, (LPARAM) &replaceBitmap) )
+ {
+ wxFAIL_MSG(wxT("Could not replace the old bitmap"));
+ }
+
+ ::DeleteObject(oldToolBarBitmap);