+ wxUxThemeHandle hTheme(this, L"REBAR");
+
+ RECT r;
+ wxRect rect = GetClientRect();
+ wxCopyRectToRECT(rect, r);
+
+ HRESULT hr = theme->DrawThemeBackground(hTheme, hdc, 0, 0, & r, NULL);
+ if ( hr == S_OK )
+ return;
+
+ // it can also return S_FALSE which seems to simply say that it
+ // didn't draw anything but no error really occurred
+ if ( FAILED(hr) )
+ wxLogApiError(_T("DrawThemeParentBackground(toolbar)"), hr);
+ }
+ }
+
+#endif // wxUSE_UXTHEME
+
+ // we need to always draw our background under XP, as otherwise it doesn't
+ // appear correctly with some themes (e.g. Zune one)
+ if ( majorVersion == 5 ||
+ UseBgCol() || (GetMSWToolbarStyle() & TBSTYLE_TRANSPARENT) )
+ {
+ // do draw our background
+ //
+ // notice that this 'dumb' implementation may cause flicker for some of
+ // the controls in which case they should intercept wxEraseEvent and
+ // process it themselves somehow
+ AutoHBRUSH hBrush(wxColourToRGB(GetBackgroundColour()));
+
+ wxCHANGE_HDC_MAP_MODE(hdc, MM_TEXT);
+ ::FillRect(hdc, &rect, hBrush);
+ }
+ else // we have no non default background colour
+ {
+ // let the system do it for us
+ event.Skip();
+ }
+}
+
+bool wxToolBar::HandleSize(WXWPARAM WXUNUSED(wParam), WXLPARAM lParam)
+{
+ // calculate our minor dimension ourselves - we're confusing the standard
+ // logic (TB_AUTOSIZE) with our horizontal toolbars and other hacks
+ RECT r;
+ if ( ::SendMessage(GetHwnd(), TB_GETITEMRECT, 0, (LPARAM)&r) )
+ {
+ int w, h;
+
+ if ( IsVertical() )
+ {
+ w = r.right - r.left;
+ if ( m_maxRows )
+ {
+ w *= (m_nButtons + m_maxRows - 1)/m_maxRows;
+ }
+ h = HIWORD(lParam);
+ }
+ else
+ {
+ w = LOWORD(lParam);
+ if (HasFlag( wxTB_FLAT ))
+ h = r.bottom - r.top - 3;
+ else
+ h = r.bottom - r.top;
+ if ( m_maxRows )
+ {
+ // FIXME: hardcoded separator line height...
+ h += HasFlag(wxTB_NODIVIDER) ? 4 : 6;
+ h *= m_maxRows;
+ }
+ }
+
+ if ( MAKELPARAM(w, h) != lParam )
+ {
+ // size really changed
+ SetSize(w, h);
+ }
+
+ // message processed
+ return true;
+ }
+
+ return false;
+}
+
+bool wxToolBar::HandlePaint(WXWPARAM wParam, WXLPARAM lParam)
+{
+ // erase any dummy separators which were used
+ // for aligning the controls if any here
+
+ // first of all, are there any controls at all?
+ wxToolBarToolsList::compatibility_iterator node;
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
+ {
+ if ( node->GetData()->IsControl() )
+ break;
+ }
+
+ if ( !node )
+ // no controls, nothing to erase
+ return false;
+
+ wxSize clientSize = GetClientSize();
+ int majorVersion, minorVersion;
+ wxGetOsVersion(& majorVersion, & minorVersion);
+
+ // prepare the DC on which we'll be drawing
+ wxClientDC dc(this);
+ dc.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID));
+ dc.SetPen(*wxTRANSPARENT_PEN);
+
+ RECT r;
+ if ( !::GetUpdateRect(GetHwnd(), &r, FALSE) )
+ // nothing to redraw anyhow
+ return false;
+
+ wxRect rectUpdate;
+ wxCopyRECTToRect(r, rectUpdate);
+
+ dc.SetClippingRegion(rectUpdate);
+
+ // draw the toolbar tools, separators &c normally
+ wxControl::MSWWindowProc(WM_PAINT, wParam, lParam);
+
+ // for each control in the toolbar find all the separators intersecting it
+ // and erase them
+ //
+ // NB: this is really the only way to do it as we don't know if a separator
+ // corresponds to a control (i.e. is a dummy one) or a real one
+ // otherwise
+ for ( node = m_tools.GetFirst(); node; node = node->GetNext() )
+ {
+ wxToolBarTool *tool = (wxToolBarTool*)node->GetData();
+ if ( tool->IsControl() )
+ {
+ // get the control rect in our client coords
+ wxControl *control = tool->GetControl();
+ wxStaticText *staticText = tool->GetStaticText();
+ wxRect rectCtrl = control->GetRect();
+ wxRect rectStaticText(0,0,0,0);
+ if ( staticText )
+ {
+ rectStaticText = staticText->GetRect();
+ }