+ dcAllButtons.SelectObject(bitmap);
+ }
+#endif // wxREMAP_BUTTON_COLOURS
+
+ // the button position
+ wxCoord x = 0;
+
+ // the number of buttons (not separators)
+ int nButtons = 0;
+
+ CreateDisabledImageList();
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
+ {
+ wxToolBarToolBase *tool = node->GetData();
+ if ( tool->IsButton() )
+ {
+ const wxBitmap& bmp = tool->GetNormalBitmap();
+
+ const int w = bmp.GetWidth();
+ const int h = bmp.GetHeight();
+
+ if ( bmp.Ok() )
+ {
+ int xOffset = wxMax(0, (m_defaultWidth - w)/2);
+ int yOffset = wxMax(0, (m_defaultHeight - h)/2);
+
+ // notice the last parameter: do use mask
+ dcAllButtons.DrawBitmap(bmp, x + xOffset, yOffset, true);
+ }
+ else
+ {
+ wxFAIL_MSG( _T("invalid tool button bitmap") );
+ }
+
+ // also deal with disabled bitmap if we want to use them
+ if ( m_disabledImgList )
+ {
+ wxBitmap bmpDisabled = tool->GetDisabledBitmap();
+#if wxUSE_IMAGE && wxUSE_WXDIB
+ if ( !bmpDisabled.Ok() )
+ {
+ // no disabled bitmap specified but we still need to
+ // fill the space in the image list with something, so
+ // we grey out the normal bitmap
+ wxImage imgGreyed;
+ wxCreateGreyedImage(bmp.ConvertToImage(), imgGreyed);
+
+#ifdef wxREMAP_BUTTON_COLOURS
+ if ( remapValue == Remap_Buttons )
+ {
+ // we need to have light grey background colour for
+ // MapBitmap() to work correctly
+ for ( int y = 0; y < h; y++ )
+ {
+ for ( int x = 0; x < w; x++ )
+ {
+ if ( imgGreyed.IsTransparent(x, y) )
+ imgGreyed.SetRGB(x, y,
+ wxLIGHT_GREY->Red(),
+ wxLIGHT_GREY->Green(),
+ wxLIGHT_GREY->Blue());
+ }
+ }
+ }
+#endif // wxREMAP_BUTTON_COLOURS
+
+ bmpDisabled = wxBitmap(imgGreyed);
+ }
+#endif // wxUSE_IMAGE
+
+#ifdef wxREMAP_BUTTON_COLOURS
+ if ( remapValue == Remap_Buttons )
+ MapBitmap(bmpDisabled.GetHBITMAP(), w, h);
+#endif // wxREMAP_BUTTON_COLOURS
+
+ m_disabledImgList->Add(bmpDisabled);
+ }
+
+ // 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);
+
+#ifdef wxREMAP_BUTTON_COLOURS
+ if ( remapValue == Remap_Buttons )
+ {
+ // Map to system colours
+ hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
+ totalBitmapWidth, totalBitmapHeight);
+ }
+#endif // wxREMAP_BUTTON_COLOURS
+
+ bool addBitmap = true;
+
+ if ( oldToolBarBitmap )
+ {
+#ifdef TB_REPLACEBITMAP
+ if ( wxApp::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);
+
+ // already done
+ addBitmap = false;
+ }
+ else
+#endif // TB_REPLACEBITMAP
+ {
+ // we can't replace the old bitmap, so we will add another one
+ // (awfully inefficient, but what else to do?) and shift the bitmap
+ // indices accordingly
+ addBitmap = true;
+
+ bitmapId = m_nButtons;
+ }
+ }
+
+ if ( addBitmap ) // no old bitmap or we can't replace it
+ {
+ TBADDBITMAP addBitmap;
+ addBitmap.hInst = 0;
+ addBitmap.nID = (UINT) hBitmap;
+ if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
+ (WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
+ {
+ wxFAIL_MSG(wxT("Could not add bitmap to toolbar"));
+ }
+ }
+
+ if ( m_disabledImgList )
+ {
+ HIMAGELIST oldImageList = (HIMAGELIST)
+ ::SendMessage(GetHwnd(),
+ TB_SETDISABLEDIMAGELIST,
+ 0,
+ (LPARAM)GetHimagelistOf(m_disabledImgList));
+
+ // delete previous image list if any
+ if ( oldImageList )
+ ::DeleteObject( oldImageList );
+ }
+ }
+
+ // 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];
+
+ // this array will hold the indices of all controls in the toolbar
+ wxArrayInt controlIds;
+
+ bool lastWasRadio = false;
+ int i = 0;
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )