+ HRGN hrgn = (HRGN)hRgn;
+
+ // remove the area occupied by the static box borders from the region
+ int borderTop, border;
+ GetBordersForSizer(&borderTop, &border);
+
+ // top
+ SubtractRectFromRgn(hrgn, 0, 0, w, borderTop);
+
+ // bottom
+ SubtractRectFromRgn(hrgn, 0, h - border, w, h);
+
+ // left
+ SubtractRectFromRgn(hrgn, 0, 0, border, h);
+
+ // right
+ SubtractRectFromRgn(hrgn, w - border, 0, w, h);
+}
+
+WXHRGN wxStaticBox::MSWGetRegionWithoutChildren()
+{
+ RECT rc;
+ ::GetWindowRect(GetHwnd(), &rc);
+ HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
+
+ // iterate over all child windows (not just wxWindows but all windows)
+ for ( HWND child = ::GetWindow(GetHwndOf(GetParent()), GW_CHILD);
+ child;
+ child = ::GetWindow(child, GW_HWNDNEXT) )
+ {
+ if ( ! ::IsWindowVisible(child) )
+ {
+ // if the window isn't visible then it doesn't need clipped
+ continue;
+ }
+
+ LONG style = ::GetWindowLong(child, GWL_STYLE);
+ wxString str(wxGetWindowClass(child));
+ str.UpperCase();
+ if ( str == wxT("BUTTON") && (style & BS_GROUPBOX) == BS_GROUPBOX )
+ {
+ // Don't clip any static boxes, not just this one. This will
+ // result in flicker in overlapping static boxes, but at least
+ // they will all be drawn correctly and we shouldn't have
+ // overlapping windows anyway.
+ continue;
+ }
+
+ ::GetWindowRect(child, &rc);
+ if ( ::RectInRegion(hrgn, &rc) )
+ {
+ // need to remove WS_CLIPSIBLINGS from all sibling windows
+ // that are within this staticbox if set
+ if ( style & WS_CLIPSIBLINGS )
+ {
+ style &= ~WS_CLIPSIBLINGS;
+ ::SetWindowLong(child, GWL_STYLE, style);
+
+ // MSDN: "If you have changed certain window data using
+ // SetWindowLong, you must call SetWindowPos to have the
+ // changes take effect."
+ ::SetWindowPos(child, NULL, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
+ SWP_FRAMECHANGED);
+ }
+
+ AutoHRGN hrgnChild(::CreateRectRgnIndirect(&rc));
+ ::CombineRgn(hrgn, hrgn, hrgnChild, RGN_DIFF);
+ }
+ }
+
+ return (WXHRGN)hrgn;
+}
+
+// helper for OnPaint(): really erase the background, i.e. do it even if we
+// don't have any non default brush for doing it (DoEraseBackground() doesn't
+// do anything in such case)
+void wxStaticBox::PaintBackground(wxDC& dc, const RECT& rc)
+{
+ // note that we do not use the box background colour here, it shouldn't
+ // apply to its interior for several reasons:
+ // 1. wxGTK doesn't do it
+ // 2. controls inside the box don't get correct bg colour because they
+ // are not our children so we'd have some really ugly colour mix if
+ // we did it
+ // 3. this is backwards compatible behaviour and some people rely on it,
+ // see http://groups.google.com/groups?selm=4252E932.3080801%40able.es
+ wxWindow *parent = GetParent();
+ HBRUSH hbr = (HBRUSH)parent->MSWGetBgBrush(dc.GetHDC(), GetHWND());
+
+ // if there is no special brush for painting this control, just use the
+ // solid background colour
+ wxBrush brush;
+ if ( !hbr )
+ {
+ brush = wxBrush(parent->GetBackgroundColour());
+ hbr = GetHbrushOf(brush);
+ }
+
+ ::FillRect(GetHdcOf(dc), &rc, hbr);
+}
+
+void wxStaticBox::PaintForeground(wxDC& dc, const RECT& WXUNUSED(rc))
+{
+ // NB: neither setting the text colour nor transparent background mode
+ // doesn't change anything: the static box def window proc still
+ // draws the label in its own colours, so if we want to have control
+ // over this we really have to draw everything ourselves
+ MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(dc), 0);
+}
+
+void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event))
+{
+ RECT rc;
+ ::GetClientRect(GetHwnd(), &rc);
+
+ // draw the entire box in a memory DC
+ wxMemoryDC memdc;
+ wxBitmap bitmap(rc.right, rc.bottom);
+ memdc.SelectObject(bitmap);
+
+ PaintBackground(memdc, rc);
+ PaintForeground(memdc, rc);
+
+ // now only blit the static box border itself, not the interior, to avoid
+ // flicker when background is drawn below