]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/statbox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/statbox.cpp
3 // Purpose: wxStaticBox
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "statbox.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
35 #include "wx/dcclient.h"
38 #include "wx/statbox.h"
39 #include "wx/notebook.h"
40 #include "wx/sysopt.h"
42 #include "wx/dcmemory.h"
44 #include "wx/msw/private.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 #if wxUSE_EXTENDED_RTTI
51 WX_DEFINE_FLAGS( wxStaticBoxStyle
)
53 wxBEGIN_FLAGS( wxStaticBoxStyle
)
54 // new style border flags, we put them first to
55 // use them for streaming out
56 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
57 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
58 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
59 wxFLAGS_MEMBER(wxBORDER_RAISED
)
60 wxFLAGS_MEMBER(wxBORDER_STATIC
)
61 wxFLAGS_MEMBER(wxBORDER_NONE
)
63 // old style border flags
64 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
65 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
66 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
67 wxFLAGS_MEMBER(wxRAISED_BORDER
)
68 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
69 wxFLAGS_MEMBER(wxBORDER
)
71 // standard window styles
72 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
73 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
74 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
75 wxFLAGS_MEMBER(wxWANTS_CHARS
)
76 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
77 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
78 wxFLAGS_MEMBER(wxVSCROLL
)
79 wxFLAGS_MEMBER(wxHSCROLL
)
81 wxEND_FLAGS( wxStaticBoxStyle
)
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox
, wxControl
,"wx/statbox.h")
85 wxBEGIN_PROPERTIES_TABLE(wxStaticBox
)
86 wxPROPERTY( Label
,wxString
, SetLabel
, GetLabel
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
87 wxPROPERTY_FLAGS( WindowStyle
, wxStaticBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
92 wxEND_PROPERTIES_TABLE()
94 wxBEGIN_HANDLERS_TABLE(wxStaticBox
)
95 wxEND_HANDLERS_TABLE()
97 wxCONSTRUCTOR_6( wxStaticBox
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Label
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
99 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox
, wxControl
)
102 // ============================================================================
104 // ============================================================================
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 bool wxStaticBox::Create(wxWindow
*parent
,
112 const wxString
& label
,
116 const wxString
& name
)
118 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
121 if ( !MSWCreateControl(wxT("BUTTON"), label
, pos
, size
) )
125 Connect(wxEVT_PAINT
, wxPaintEventHandler(wxStaticBox::OnPaint
));
131 wxBorder
wxStaticBox::GetDefaultBorder() const
133 return wxBORDER_NONE
;
136 WXDWORD
wxStaticBox::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
138 long styleWin
= wxStaticBoxBase::MSWGetStyle(style
, exstyle
);
140 // no need for it anymore, must be removed for wxRadioBox child
141 // buttons to be able to repaint themselves
142 styleWin
&= ~WS_CLIPCHILDREN
;
147 return styleWin
| BS_GROUPBOX
;
150 wxSize
wxStaticBox::DoGetBestSize() const
153 wxGetCharSize(GetHWND(), &cx
, &cy
, GetFont());
156 GetTextExtent(wxGetWindowText(m_hWnd
), &wBox
, &cy
);
159 int hBox
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy
);
161 return wxSize(wBox
, hBox
);
164 WXLRESULT
wxStaticBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
167 if ( nMsg
== WM_NCHITTEST
)
169 // This code breaks some other processing such as enter/leave tracking
170 // so it's off by default.
172 static int s_useHTClient
= -1;
173 if (s_useHTClient
== -1)
174 s_useHTClient
= wxSystemOptions::GetOptionInt(wxT("msw.staticbox.htclient"));
175 if (s_useHTClient
== 1)
177 int xPos
= LOWORD(lParam
); // horizontal position of cursor
178 int yPos
= HIWORD(lParam
); // vertical position of cursor
180 ScreenToClient(&xPos
, &yPos
);
182 // Make sure you can drag by the top of the groupbox, but let
183 // other (enclosed) controls get mouse events also
185 return (long)HTCLIENT
;
188 #endif // !__WXWINCE__
190 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
193 void wxStaticBox::GetBordersForSizer(int *borderTop
, int *borderOther
) const
195 wxStaticBoxBase::GetBordersForSizer(borderTop
, borderOther
);
197 // if not using correct (but backwards cojmpatible) text metrics
198 // calculations, we need to add some extra margin or otherwise static box
200 #if !wxDIALOG_UNIT_COMPATIBILITY
201 if ( !GetLabel().empty() )
202 *borderTop
+= GetCharHeight()/3;
203 #endif // !wxDIALOG_UNIT_COMPATIBILITY
206 // MSWGetRegionWithoutSelf helper: removes the given rectangle from region
208 SubtractRectFromRgn(HRGN hrgn
, int left
, int top
, int right
, int bottom
)
210 AutoHRGN
hrgnRect(::CreateRectRgn(left
, top
, right
, bottom
));
213 wxLogLastError(_T("CreateRectRgn()"));
217 ::CombineRgn(hrgn
, hrgn
, hrgnRect
, RGN_DIFF
);
220 void wxStaticBox::MSWGetRegionWithoutSelf(WXHRGN hRgn
, int w
, int h
)
222 HRGN hrgn
= (HRGN
)hRgn
;
224 // remove the area occupied by the static box borders from the region
225 int borderTop
, border
;
226 GetBordersForSizer(&borderTop
, &border
);
229 SubtractRectFromRgn(hrgn
, 0, 0, w
, borderTop
);
232 SubtractRectFromRgn(hrgn
, 0, h
- border
, w
, h
);
235 SubtractRectFromRgn(hrgn
, 0, 0, border
, h
);
238 SubtractRectFromRgn(hrgn
, w
- border
, 0, w
, h
);
241 WXHRGN
wxStaticBox::MSWGetRegionWithoutChildren()
244 ::GetWindowRect(GetHwnd(), &rc
);
245 HRGN hrgn
= ::CreateRectRgn(rc
.left
, rc
.top
, rc
.right
+ 1, rc
.bottom
+ 1);
247 // iterate over all child windows (not just wxWindows but all windows)
248 for ( HWND child
= ::GetWindow(GetHwndOf(GetParent()), GW_CHILD
);
250 child
= ::GetWindow(child
, GW_HWNDNEXT
) )
252 wxWindow
*childWindow
= wxGetWindowFromHWND((WXHWND
) child
);
254 // can't just test for (this != child) here since if a wxStaticBox
255 // overlaps another wxStaticBox then neither are drawn. The overlapping
256 // region will flicker but we shouldn't have overlapping windows anyway.
257 if ( !childWindow
|| !wxDynamicCast(childWindow
, wxStaticBox
) )
259 ::GetWindowRect(child
, &rc
);
260 if ( ::RectInRegion(hrgn
, &rc
) )
262 // need to remove WS_CLIPSIBLINGS from all sibling windows
263 // that are within this staticbox if set
264 LONG style
= ::GetWindowLong(child
, GWL_STYLE
);
265 if ( style
& WS_CLIPSIBLINGS
)
267 style
&= ~WS_CLIPSIBLINGS
;
268 ::SetWindowLong(child
, GWL_STYLE
, style
);
270 // MSDN: "If you have changed certain window data using
271 // SetWindowLong, you must call SetWindowPos to have the
272 // changes take effect."
273 ::SetWindowPos(child
, NULL
, 0, 0, 0, 0,
274 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
278 AutoHRGN
hrgnChild(::CreateRectRgnIndirect(&rc
));
279 ::CombineRgn(hrgn
, hrgn
, hrgnChild
, RGN_DIFF
);
287 // helper for OnPaint()
288 void wxStaticBox::PaintBackground(wxDC
& dc
, const RECT
& rc
)
290 HBRUSH hbr
= (HBRUSH
)DoMSWControlColor(GetHdcOf(dc
), wxNullColour
);
294 brush
= wxTheBrushList
->FindOrCreateBrush(GetBackgroundColour());
296 hbr
= GetHbrushOf(*brush
);
300 ::FillRect(GetHdcOf(dc
), &rc
, hbr
);
303 void wxStaticBox::OnPaint(wxPaintEvent
& WXUNUSED(event
))
307 ::GetClientRect(GetHwnd(), &rc
);
309 // draw the entire box in a memory DC, but only blit the bits not redrawn
310 // either by our children windows nor by FillRect() painting the background
313 wxBitmap
bitmap(rc
.right
, rc
.bottom
);
314 memdc
.SelectObject(bitmap
);
316 PaintBackground(memdc
, rc
);
317 MSWDefWindowProc(WM_PAINT
, (WPARAM
)GetHdcOf(memdc
), 0);
319 int borderTop
, border
;
320 GetBordersForSizer(&borderTop
, &border
);
323 dc
.Blit(border
, 0, rc
.right
- border
, borderTop
,
326 dc
.Blit(border
, rc
.bottom
- border
, rc
.right
- border
, rc
.bottom
,
327 &memdc
, border
, rc
.bottom
- border
);
329 dc
.Blit(0, 0, border
, rc
.bottom
,
332 dc
.Blit(rc
.right
- border
, 0, rc
.right
, rc
.bottom
,
333 &memdc
, rc
.right
- border
, 0);
335 AutoHRGN
hrgn((HRGN
)MSWGetRegionWithoutChildren());
337 ::GetWindowRect(GetHwnd(), &rcWin
);
338 ::OffsetRgn(hrgn
, -rcWin
.left
, -rcWin
.top
);
341 // now remove the box itself
342 MSWGetRegionWithoutSelf((WXHRGN
) hrgn
, rc
.right
, rc
.bottom
);
344 // and paint the inside of the box (excluding child controls)
345 ::SelectClipRgn(GetHdcOf(dc
), hrgn
);
346 PaintBackground(dc
, rc
);
347 ::SelectClipRgn(GetHdcOf(dc
), NULL
);
350 #endif // wxUSE_STATBOX