]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
3f2711d5 | 2 | // Name: msw/statbox.cpp |
2bda0e17 KB |
3 | // Purpose: wxStaticBox |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3f2711d5 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
3f2711d5 | 21 | #pragma implementation "statbox.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
3f2711d5 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_STATBOX |
32 | ||
2bda0e17 | 33 | #ifndef WX_PRECOMP |
3f2711d5 VZ |
34 | #include "wx/app.h" |
35 | #include "wx/dcclient.h" | |
2bda0e17 KB |
36 | #endif |
37 | ||
38 | #include "wx/statbox.h" | |
3ad70d31 | 39 | #include "wx/notebook.h" |
9dabade2 | 40 | #include "wx/sysopt.h" |
eba99da4 | 41 | #include "wx/image.h" |
a4c46c19 | 42 | #include "wx/dcmemory.h" |
2bda0e17 | 43 | |
3f2711d5 VZ |
44 | #include "wx/msw/private.h" |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | // wxWin macros | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
51741307 | 50 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
51 | WX_DEFINE_FLAGS( wxStaticBoxStyle ) |
52 | ||
3ff066a4 | 53 | wxBEGIN_FLAGS( wxStaticBoxStyle ) |
bc9fb572 JS |
54 | // new style border flags, we put them first to |
55 | // use them for streaming out | |
3ff066a4 SC |
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) | |
57f4f925 | 62 | |
bc9fb572 | 63 | // old style border flags |
3ff066a4 SC |
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) | |
cb0afb26 | 69 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
70 | |
71 | // standard window styles | |
3ff066a4 SC |
72 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
73 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
74 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
75 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 76 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
77 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
78 | wxFLAGS_MEMBER(wxVSCROLL) | |
79 | wxFLAGS_MEMBER(wxHSCROLL) | |
bc9fb572 | 80 | |
3ff066a4 | 81 | wxEND_FLAGS( wxStaticBoxStyle ) |
bc9fb572 | 82 | |
51741307 SC |
83 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox, wxControl,"wx/statbox.h") |
84 | ||
3ff066a4 | 85 | wxBEGIN_PROPERTIES_TABLE(wxStaticBox) |
57f4f925 | 86 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 | 87 | wxPROPERTY_FLAGS( WindowStyle , wxStaticBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
066f1b7a | 88 | /* |
57f4f925 WS |
89 | TODO PROPERTIES : |
90 | label | |
066f1b7a | 91 | */ |
3ff066a4 | 92 | wxEND_PROPERTIES_TABLE() |
51741307 | 93 | |
3ff066a4 SC |
94 | wxBEGIN_HANDLERS_TABLE(wxStaticBox) |
95 | wxEND_HANDLERS_TABLE() | |
51741307 | 96 | |
57f4f925 | 97 | wxCONSTRUCTOR_6( wxStaticBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
98 | #else |
99 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) | |
100 | #endif | |
2bda0e17 | 101 | |
3f2711d5 VZ |
102 | // ============================================================================ |
103 | // implementation | |
104 | // ============================================================================ | |
105 | ||
106 | // ---------------------------------------------------------------------------- | |
107 | // wxStaticBox | |
108 | // ---------------------------------------------------------------------------- | |
109 | ||
110 | bool wxStaticBox::Create(wxWindow *parent, | |
111 | wxWindowID id, | |
112 | const wxString& label, | |
113 | const wxPoint& pos, | |
114 | const wxSize& size, | |
115 | long style, | |
116 | const wxString& name) | |
2bda0e17 | 117 | { |
11b6a93b | 118 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) |
57f4f925 | 119 | return false; |
2bda0e17 | 120 | |
e31e6ea7 | 121 | if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) ) |
57f4f925 | 122 | return false; |
2bda0e17 | 123 | |
9f769708 | 124 | #ifndef __WXWINCE__ |
3b6e5fb3 | 125 | Connect(wxEVT_PAINT, wxPaintEventHandler(wxStaticBox::OnPaint)); |
9f769708 | 126 | #endif |
3b6e5fb3 | 127 | |
57f4f925 | 128 | return true; |
2bda0e17 KB |
129 | } |
130 | ||
9f769708 JS |
131 | wxBorder wxStaticBox::GetDefaultBorder() const |
132 | { | |
133 | return wxBORDER_NONE; | |
134 | } | |
135 | ||
e31e6ea7 VZ |
136 | WXDWORD wxStaticBox::MSWGetStyle(long style, WXDWORD *exstyle) const |
137 | { | |
138 | long styleWin = wxStaticBoxBase::MSWGetStyle(style, exstyle); | |
139 | ||
eba99da4 JS |
140 | // no need for it anymore, must be removed for wxRadioBox child |
141 | // buttons to be able to repaint themselves | |
142 | styleWin &= ~WS_CLIPCHILDREN; | |
143 | ||
e31e6ea7 | 144 | if ( exstyle ) |
eba99da4 | 145 | *exstyle = 0; |
e31e6ea7 VZ |
146 | |
147 | return styleWin | BS_GROUPBOX; | |
148 | } | |
149 | ||
f68586e5 | 150 | wxSize wxStaticBox::DoGetBestSize() const |
2bda0e17 | 151 | { |
4438caf4 | 152 | int cx, cy; |
7a5e53ab | 153 | wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); |
2bda0e17 | 154 | |
4438caf4 VZ |
155 | int wBox; |
156 | GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy); | |
2bda0e17 | 157 | |
4438caf4 VZ |
158 | wBox += 3*cx; |
159 | int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); | |
2bda0e17 | 160 | |
4438caf4 VZ |
161 | return wxSize(wBox, hBox); |
162 | } | |
2bda0e17 | 163 | |
6aa01033 JS |
164 | WXLRESULT wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
165 | { | |
abf912c5 | 166 | #ifndef __WXWINCE__ |
58385af0 | 167 | if ( nMsg == WM_NCHITTEST ) |
6aa01033 | 168 | { |
58385af0 VZ |
169 | // This code breaks some other processing such as enter/leave tracking |
170 | // so it's off by default. | |
171 | ||
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) | |
176 | { | |
177 | int xPos = LOWORD(lParam); // horizontal position of cursor | |
178 | int yPos = HIWORD(lParam); // vertical position of cursor | |
179 | ||
180 | ScreenToClient(&xPos, &yPos); | |
181 | ||
182 | // Make sure you can drag by the top of the groupbox, but let | |
183 | // other (enclosed) controls get mouse events also | |
184 | if ( yPos < 10 ) | |
185 | return (long)HTCLIENT; | |
186 | } | |
6aa01033 | 187 | } |
abf912c5 | 188 | #endif // !__WXWINCE__ |
6aa01033 JS |
189 | |
190 | return wxControl::MSWWindowProc(nMsg, wParam, lParam); | |
191 | } | |
192 | ||
58385af0 VZ |
193 | void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const |
194 | { | |
195 | wxStaticBoxBase::GetBordersForSizer(borderTop, borderOther); | |
196 | ||
9c2a1d53 | 197 | // need extra space, don't know how much but this seems to be enough |
8397b2f7 | 198 | *borderTop += GetCharHeight()/3; |
58385af0 VZ |
199 | } |
200 | ||
3b6e5fb3 VZ |
201 | // MSWGetRegionWithoutSelf helper: removes the given rectangle from region |
202 | static inline void | |
203 | SubtractRectFromRgn(HRGN hrgn, int left, int top, int right, int bottom) | |
204 | { | |
205 | AutoHRGN hrgnRect(::CreateRectRgn(left, top, right, bottom)); | |
206 | if ( !hrgnRect ) | |
207 | { | |
208 | wxLogLastError(_T("CreateRectRgn()")); | |
209 | return; | |
210 | } | |
211 | ||
212 | ::CombineRgn(hrgn, hrgn, hrgnRect, RGN_DIFF); | |
213 | } | |
214 | ||
215 | void wxStaticBox::MSWGetRegionWithoutSelf(WXHRGN hRgn, int w, int h) | |
eba99da4 | 216 | { |
3b6e5fb3 VZ |
217 | HRGN hrgn = (HRGN)hRgn; |
218 | ||
219 | // remove the area occupied by the static box borders from the region | |
220 | int borderTop, border; | |
221 | GetBordersForSizer(&borderTop, &border); | |
eba99da4 JS |
222 | |
223 | // top | |
3b6e5fb3 | 224 | SubtractRectFromRgn(hrgn, 0, 0, w, borderTop); |
eba99da4 JS |
225 | |
226 | // bottom | |
3b6e5fb3 | 227 | SubtractRectFromRgn(hrgn, 0, h - border, w, h); |
eba99da4 JS |
228 | |
229 | // left | |
3b6e5fb3 | 230 | SubtractRectFromRgn(hrgn, 0, 0, border, h); |
eba99da4 JS |
231 | |
232 | // right | |
3b6e5fb3 | 233 | SubtractRectFromRgn(hrgn, w - border, 0, w, h); |
eba99da4 JS |
234 | } |
235 | ||
3b6e5fb3 | 236 | WXHRGN wxStaticBox::MSWGetRegionWithoutChildren() |
eba99da4 JS |
237 | { |
238 | RECT rc; | |
239 | ::GetWindowRect(GetHwnd(), &rc); | |
240 | HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1); | |
3b6e5fb3 VZ |
241 | |
242 | // iterate over all child windows (not just wxWindows but all windows) | |
243 | for ( HWND child = ::GetWindow(GetHwndOf(GetParent()), GW_CHILD); | |
244 | child; | |
245 | child = ::GetWindow(child, GW_HWNDNEXT) ) | |
eba99da4 | 246 | { |
3b6e5fb3 | 247 | wxWindow *childWindow = wxGetWindowFromHWND((WXHWND) child); |
eba99da4 JS |
248 | |
249 | // can't just test for (this != child) here since if a wxStaticBox | |
250 | // overlaps another wxStaticBox then neither are drawn. The overlapping | |
251 | // region will flicker but we shouldn't have overlapping windows anyway. | |
3b6e5fb3 | 252 | if ( !childWindow || !wxDynamicCast(childWindow, wxStaticBox) ) |
eba99da4 | 253 | { |
54c5498d | 254 | ::GetWindowRect(child, &rc); |
3b6e5fb3 | 255 | if ( ::RectInRegion(hrgn, &rc) ) |
eba99da4 JS |
256 | { |
257 | // need to remove WS_CLIPSIBLINGS from all sibling windows | |
258 | // that are within this staticbox if set | |
54c5498d | 259 | LONG style = ::GetWindowLong(child, GWL_STYLE); |
eba99da4 JS |
260 | if ( style & WS_CLIPSIBLINGS ) |
261 | { | |
262 | style &= ~WS_CLIPSIBLINGS; | |
54c5498d | 263 | ::SetWindowLong(child, GWL_STYLE, style); |
eba99da4 JS |
264 | |
265 | // MSDN: "If you have changed certain window data using | |
266 | // SetWindowLong, you must call SetWindowPos to have the | |
267 | // changes take effect." | |
54c5498d | 268 | ::SetWindowPos(child, NULL, 0, 0, 0, 0, |
eba99da4 JS |
269 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | |
270 | SWP_FRAMECHANGED); | |
271 | } | |
272 | ||
3b6e5fb3 VZ |
273 | AutoHRGN hrgnChild(::CreateRectRgnIndirect(&rc)); |
274 | ::CombineRgn(hrgn, hrgn, hrgnChild, RGN_DIFF); | |
eba99da4 JS |
275 | } |
276 | } | |
eba99da4 | 277 | } |
eba99da4 | 278 | |
3b6e5fb3 VZ |
279 | return (WXHRGN)hrgn; |
280 | } | |
281 | ||
282 | // helper for OnPaint() | |
283 | void wxStaticBox::PaintBackground(wxDC& dc, const RECT& rc) | |
284 | { | |
f05f427f VZ |
285 | // note that static box should be transparent, so it should show its |
286 | // parents colour, not its own | |
287 | wxWindow * const parent = GetParent(); | |
288 | ||
289 | HBRUSH hbr = (HBRUSH)parent->MSWGetBgBrush(dc.GetHDC()); | |
3b6e5fb3 VZ |
290 | if ( !hbr ) |
291 | { | |
f05f427f VZ |
292 | wxBrush *brush = |
293 | wxTheBrushList->FindOrCreateBrush(parent->GetBackgroundColour()); | |
3b6e5fb3 VZ |
294 | if ( brush ) |
295 | hbr = GetHbrushOf(*brush); | |
296 | } | |
297 | ||
298 | if ( hbr ) | |
299 | ::FillRect(GetHdcOf(dc), &rc, hbr); | |
eba99da4 JS |
300 | } |
301 | ||
302 | void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event)) | |
303 | { | |
304 | wxPaintDC dc(this); | |
305 | RECT rc; | |
306 | ::GetClientRect(GetHwnd(), &rc); | |
307 | ||
3b6e5fb3 VZ |
308 | // draw the entire box in a memory DC, but only blit the bits not redrawn |
309 | // either by our children windows nor by FillRect() painting the background | |
310 | // below | |
eba99da4 JS |
311 | wxMemoryDC memdc; |
312 | wxBitmap bitmap(rc.right, rc.bottom); | |
313 | memdc.SelectObject(bitmap); | |
314 | ||
3b6e5fb3 | 315 | PaintBackground(memdc, rc); |
eba99da4 JS |
316 | MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(memdc), 0); |
317 | ||
3b6e5fb3 VZ |
318 | int borderTop, border; |
319 | GetBordersForSizer(&borderTop, &border); | |
320 | ||
eba99da4 | 321 | // top |
3b6e5fb3 VZ |
322 | dc.Blit(border, 0, rc.right - border, borderTop, |
323 | &memdc, border, 0); | |
eba99da4 | 324 | // bottom |
3b6e5fb3 VZ |
325 | dc.Blit(border, rc.bottom - border, rc.right - border, rc.bottom, |
326 | &memdc, border, rc.bottom - border); | |
eba99da4 | 327 | // left |
3b6e5fb3 VZ |
328 | dc.Blit(0, 0, border, rc.bottom, |
329 | &memdc, 0, 0); | |
eba99da4 | 330 | // right |
3b6e5fb3 VZ |
331 | dc.Blit(rc.right - border, 0, rc.right, rc.bottom, |
332 | &memdc, rc.right - border, 0); | |
eba99da4 | 333 | |
3b6e5fb3 VZ |
334 | AutoHRGN hrgn((HRGN)MSWGetRegionWithoutChildren()); |
335 | RECT rcWin; | |
336 | ::GetWindowRect(GetHwnd(), &rcWin); | |
337 | ::OffsetRgn(hrgn, -rcWin.left, -rcWin.top); | |
eba99da4 | 338 | |
eba99da4 | 339 | |
3b6e5fb3 VZ |
340 | // now remove the box itself |
341 | MSWGetRegionWithoutSelf((WXHRGN) hrgn, rc.right, rc.bottom); | |
342 | ||
343 | // and paint the inside of the box (excluding child controls) | |
eba99da4 | 344 | ::SelectClipRgn(GetHdcOf(dc), hrgn); |
3b6e5fb3 | 345 | PaintBackground(dc, rc); |
eba99da4 | 346 | ::SelectClipRgn(GetHdcOf(dc), NULL); |
eba99da4 JS |
347 | } |
348 | ||
1e6feb95 | 349 | #endif // wxUSE_STATBOX |
6aa01033 | 350 |