+
+ int width = r.right - r.left;
+
+ if ( tool->IsControl() )
+ {
+ nButtonsToDelete = ((wxToolBarTool *)tool)->GetSeparatorsCount();
+
+ width *= nButtonsToDelete;
+ }
+
+ // do delete all buttons
+ m_nButtons -= nButtonsToDelete;
+ while ( nButtonsToDelete-- > 0 )
+ {
+ if ( !::SendMessage(GetHwnd(), TB_DELETEBUTTON, pos, 0) )
+ {
+ wxLogLastError(wxT("TB_DELETEBUTTON"));
+
+ return FALSE;
+ }
+ }
+
+ tool->Detach();
+
+ // 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() )
+ {
+ wxToolBarToolBase *tool2 = node->GetData();
+ if ( tool2->IsControl() )
+ {
+ int x;
+ wxControl *control = tool2->GetControl();
+ control->GetPosition(&x, NULL);
+ control->Move(x - width, -1);
+ }
+ }
+
+ return TRUE;
+}
+
+bool wxToolBar::Realize()
+{
+ size_t nTools = GetToolsCount();
+ if ( nTools == 0 )
+ {
+ // nothing to do
+ return TRUE;
+ }
+
+ bool isVertical = (GetWindowStyle() & wxTB_VERTICAL) != 0;
+
+ // First, add the bitmap: we use one bitmap for all toolbar buttons
+ // ----------------------------------------------------------------
+
+ // if we already have a bitmap, we'll replace the existing one - otherwise
+ // we'll install a new one
+ HBITMAP oldToolBarBitmap = (HBITMAP)m_hBitmap;
+
+ int totalBitmapWidth = (int)(m_defaultWidth * nTools);
+ int totalBitmapHeight = (int)m_defaultHeight;
+
+ // Create a bitmap and copy all the tool bitmaps to it
+#if USE_BITMAP_MASKS
+ wxMemoryDC dcAllButtons;
+ wxBitmap bitmap(totalBitmapWidth, totalBitmapHeight);
+ dcAllButtons.SelectObject(bitmap);
+ dcAllButtons.SetBackground(*wxLIGHT_GREY_BRUSH);
+ dcAllButtons.Clear();
+
+ m_hBitmap = bitmap.GetHBITMAP();
+ HBITMAP hBitmap = (HBITMAP)m_hBitmap;
+#else // !USE_BITMAP_MASKS
+ HBITMAP hBitmap = ::CreateCompatibleBitmap(ScreenHDC(),
+ totalBitmapWidth,
+ totalBitmapHeight);
+ if ( !hBitmap )
+ {
+ wxLogLastError(_T("CreateCompatibleBitmap"));
+
+ return FALSE;
+ }
+
+ m_hBitmap = (WXHBITMAP)hBitmap;
+
+ HDC memoryDC = ::CreateCompatibleDC(NULL);
+ HBITMAP oldBitmap = (HBITMAP) ::SelectObject(memoryDC, hBitmap);
+
+ HDC memoryDC2 = ::CreateCompatibleDC(NULL);
+#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
+
+ // the button position
+ wxCoord x = 0;
+
+ // the number of buttons (not separators)
+ int nButtons = 0;
+
+ wxToolBarToolsList::Node *node = m_tools.GetFirst();
+ while ( node )
+ {
+ wxToolBarToolBase *tool = node->GetData();
+ if ( tool->IsButton() )
+ {
+ const wxBitmap& bmp = tool->GetBitmap1();
+ if ( bmp.Ok() )
+ {
+#if USE_BITMAP_MASKS
+ // notice the last parameter: do use mask
+ dcAllButtons.DrawBitmap(tool->GetBitmap1(), x, 0, TRUE);
+#else // !USE_BITMAP_MASKS
+ HBITMAP hbmp = GetHbitmapOf(bmp);
+ HBITMAP oldBitmap2 = (HBITMAP)::SelectObject(memoryDC2, hbmp);
+ if ( !BitBlt(memoryDC, x, 0, m_defaultWidth, m_defaultHeight,
+ memoryDC2, 0, 0, SRCCOPY) )
+ {
+ wxLogLastError(wxT("BitBlt"));
+ }
+
+ ::SelectObject(memoryDC2, oldBitmap2);
+#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
+ }
+ 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++;
+ }
+
+ node = node->GetNext();
+ }
+
+#if USE_BITMAP_MASKS
+ dcAllButtons.SelectObject(wxNullBitmap);
+
+ // don't delete this HBITMAP!
+ bitmap.SetHBITMAP(0);
+#else // !USE_BITMAP_MASKS
+ ::SelectObject(memoryDC, oldBitmap);
+ ::DeleteDC(memoryDC);
+ ::DeleteDC(memoryDC2);
+#endif // USE_BITMAP_MASKS/!USE_BITMAP_MASKS
+
+ // Map to system colours
+ hBitmap = (HBITMAP)MapBitmap((WXHBITMAP) hBitmap,
+ totalBitmapWidth, totalBitmapHeight);
+
+ int bitmapId = 0;
+
+ bool addBitmap = TRUE;
+
+ if ( oldToolBarBitmap )