]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f38924e8 | 2 | // Name: src/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 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
3f2711d5 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
1e6feb95 VZ |
27 | #if wxUSE_STATBOX |
28 | ||
f38924e8 WS |
29 | #include "wx/statbox.h" |
30 | ||
2bda0e17 | 31 | #ifndef WX_PRECOMP |
3f2711d5 VZ |
32 | #include "wx/app.h" |
33 | #include "wx/dcclient.h" | |
f38924e8 | 34 | #include "wx/dcmemory.h" |
155ecd4c | 35 | #include "wx/image.h" |
2bda0e17 KB |
36 | #endif |
37 | ||
3ad70d31 | 38 | #include "wx/notebook.h" |
9dabade2 | 39 | #include "wx/sysopt.h" |
2bda0e17 | 40 | |
72a55896 | 41 | #include "wx/msw/uxtheme.h" |
3f2711d5 | 42 | #include "wx/msw/private.h" |
7212d155 | 43 | #include "wx/msw/missing.h" |
74052fe8 | 44 | #include "wx/msw/dc.h" |
3f2711d5 | 45 | |
95fab76b VZ |
46 | // the values coincide with those in tmschema.h |
47 | #define BP_GROUPBOX 4 | |
48 | ||
49 | #define GBS_NORMAL 1 | |
50 | ||
51 | #define TMT_FONT 210 | |
52 | ||
3f2711d5 VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // wxWin macros | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
51741307 | 57 | #if wxUSE_EXTENDED_RTTI |
bc9fb572 JS |
58 | WX_DEFINE_FLAGS( wxStaticBoxStyle ) |
59 | ||
3ff066a4 | 60 | wxBEGIN_FLAGS( wxStaticBoxStyle ) |
bc9fb572 JS |
61 | // new style border flags, we put them first to |
62 | // use them for streaming out | |
3ff066a4 SC |
63 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
64 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
65 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
66 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
67 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
68 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
57f4f925 | 69 | |
bc9fb572 | 70 | // old style border flags |
3ff066a4 SC |
71 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
72 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
73 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
74 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
75 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 76 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
77 | |
78 | // standard window styles | |
3ff066a4 SC |
79 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
80 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
81 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
82 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 83 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
84 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
85 | wxFLAGS_MEMBER(wxVSCROLL) | |
86 | wxFLAGS_MEMBER(wxHSCROLL) | |
bc9fb572 | 87 | |
3ff066a4 | 88 | wxEND_FLAGS( wxStaticBoxStyle ) |
bc9fb572 | 89 | |
51741307 SC |
90 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox, wxControl,"wx/statbox.h") |
91 | ||
3ff066a4 | 92 | wxBEGIN_PROPERTIES_TABLE(wxStaticBox) |
57f4f925 | 93 | wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
af498247 | 94 | wxPROPERTY_FLAGS( WindowStyle , wxStaticBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style |
066f1b7a | 95 | /* |
57f4f925 WS |
96 | TODO PROPERTIES : |
97 | label | |
066f1b7a | 98 | */ |
3ff066a4 | 99 | wxEND_PROPERTIES_TABLE() |
51741307 | 100 | |
3ff066a4 SC |
101 | wxBEGIN_HANDLERS_TABLE(wxStaticBox) |
102 | wxEND_HANDLERS_TABLE() | |
51741307 | 103 | |
57f4f925 | 104 | wxCONSTRUCTOR_6( wxStaticBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle ) |
51741307 SC |
105 | #else |
106 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl) | |
107 | #endif | |
2bda0e17 | 108 | |
3f2711d5 VZ |
109 | // ============================================================================ |
110 | // implementation | |
111 | // ============================================================================ | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
114 | // wxStaticBox | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
117 | bool wxStaticBox::Create(wxWindow *parent, | |
118 | wxWindowID id, | |
119 | const wxString& label, | |
120 | const wxPoint& pos, | |
121 | const wxSize& size, | |
122 | long style, | |
123 | const wxString& name) | |
2bda0e17 | 124 | { |
11b6a93b | 125 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) |
57f4f925 | 126 | return false; |
2bda0e17 | 127 | |
e31e6ea7 | 128 | if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) ) |
57f4f925 | 129 | return false; |
2bda0e17 | 130 | |
cf072997 VZ |
131 | // Always use LTR layout. Otherwise, the label would be mirrored. |
132 | SetLayoutDirection(wxLayout_LeftToRight); | |
133 | ||
9f769708 | 134 | #ifndef __WXWINCE__ |
5bf4788a JS |
135 | if (!wxSystemOptions::IsFalse(wxT("msw.staticbox.optimized-paint"))) |
136 | Connect(wxEVT_PAINT, wxPaintEventHandler(wxStaticBox::OnPaint)); | |
c3732409 | 137 | #endif // !__WXWINCE__ |
3b6e5fb3 | 138 | |
57f4f925 | 139 | return true; |
2bda0e17 KB |
140 | } |
141 | ||
e31e6ea7 VZ |
142 | WXDWORD wxStaticBox::MSWGetStyle(long style, WXDWORD *exstyle) const |
143 | { | |
144 | long styleWin = wxStaticBoxBase::MSWGetStyle(style, exstyle); | |
145 | ||
eba99da4 JS |
146 | // no need for it anymore, must be removed for wxRadioBox child |
147 | // buttons to be able to repaint themselves | |
148 | styleWin &= ~WS_CLIPCHILDREN; | |
149 | ||
e31e6ea7 | 150 | if ( exstyle ) |
5bf4788a | 151 | { |
a92e7f30 | 152 | #ifndef __WXWINCE__ |
5bf4788a JS |
153 | if (wxSystemOptions::IsFalse(wxT("msw.staticbox.optimized-paint"))) |
154 | *exstyle = WS_EX_TRANSPARENT; | |
155 | else | |
a92e7f30 | 156 | #endif |
5bf4788a JS |
157 | *exstyle = 0; |
158 | } | |
a83b5b74 | 159 | |
cf072997 VZ |
160 | styleWin |= BS_GROUPBOX; |
161 | ||
162 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) | |
163 | { | |
164 | // Make sure label is on the right | |
165 | styleWin |= BS_RIGHT; | |
166 | } | |
167 | ||
168 | return styleWin; | |
e31e6ea7 VZ |
169 | } |
170 | ||
f68586e5 | 171 | wxSize wxStaticBox::DoGetBestSize() const |
2bda0e17 | 172 | { |
4438caf4 | 173 | int cx, cy; |
7a5e53ab | 174 | wxGetCharSize(GetHWND(), &cx, &cy, GetFont()); |
2bda0e17 | 175 | |
4438caf4 | 176 | int wBox; |
32cd189d | 177 | GetTextExtent(GetLabelText(wxGetWindowText(m_hWnd)), &wBox, &cy); |
2bda0e17 | 178 | |
4438caf4 VZ |
179 | wBox += 3*cx; |
180 | int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); | |
2bda0e17 | 181 | |
31582e4e RD |
182 | wxSize best(wBox, hBox); |
183 | CacheBestSize(best); | |
184 | return best; | |
4438caf4 | 185 | } |
2bda0e17 | 186 | |
c3732409 | 187 | void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const |
6aa01033 | 188 | { |
c3732409 VZ |
189 | wxStaticBoxBase::GetBordersForSizer(borderTop, borderOther); |
190 | ||
191 | // need extra space, don't know how much but this seems to be enough | |
192 | *borderTop += GetCharHeight()/3; | |
193 | } | |
194 | ||
195 | // all the hacks below are not necessary for WinCE | |
abf912c5 | 196 | #ifndef __WXWINCE__ |
c3732409 VZ |
197 | |
198 | WXLRESULT wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
199 | { | |
58385af0 | 200 | if ( nMsg == WM_NCHITTEST ) |
6aa01033 | 201 | { |
58385af0 VZ |
202 | // This code breaks some other processing such as enter/leave tracking |
203 | // so it's off by default. | |
204 | ||
205 | static int s_useHTClient = -1; | |
206 | if (s_useHTClient == -1) | |
207 | s_useHTClient = wxSystemOptions::GetOptionInt(wxT("msw.staticbox.htclient")); | |
208 | if (s_useHTClient == 1) | |
209 | { | |
c3732409 VZ |
210 | int xPos = GET_X_LPARAM(lParam); |
211 | int yPos = GET_Y_LPARAM(lParam); | |
58385af0 VZ |
212 | |
213 | ScreenToClient(&xPos, &yPos); | |
214 | ||
215 | // Make sure you can drag by the top of the groupbox, but let | |
216 | // other (enclosed) controls get mouse events also | |
217 | if ( yPos < 10 ) | |
218 | return (long)HTCLIENT; | |
219 | } | |
6aa01033 JS |
220 | } |
221 | ||
9705fbe9 VZ |
222 | if ( nMsg == WM_PRINTCLIENT ) |
223 | { | |
224 | // we have to process WM_PRINTCLIENT ourselves as otherwise child | |
225 | // windows' background (eg buttons in radio box) would never be drawn | |
226 | // unless we have a parent with non default background | |
227 | ||
228 | // so check first if we have one | |
229 | if ( !HandlePrintClient((WXHDC)wParam) ) | |
230 | { | |
231 | // no, we don't, erase the background ourselves | |
232 | // (don't use our own) - see PaintBackground for explanation | |
233 | wxBrush brush(GetParent()->GetBackgroundColour()); | |
234 | wxFillRect(GetHwnd(), (HDC)wParam, GetHbrushOf(brush)); | |
235 | } | |
236 | ||
237 | return 0; | |
238 | } | |
239 | ||
6aa01033 JS |
240 | return wxControl::MSWWindowProc(nMsg, wParam, lParam); |
241 | } | |
242 | ||
c3732409 VZ |
243 | // ---------------------------------------------------------------------------- |
244 | // static box drawing | |
245 | // ---------------------------------------------------------------------------- | |
58385af0 | 246 | |
c3732409 VZ |
247 | /* |
248 | We draw the static box ourselves because it's the only way to prevent it | |
249 | from flickering horribly on resize (because everything inside the box is | |
250 | erased twice: once when the box itself is repainted and second time when | |
251 | the control inside it is repainted) without using WS_EX_TRANSPARENT style as | |
252 | we used to do and which resulted in other problems. | |
253 | */ | |
58385af0 | 254 | |
3b6e5fb3 VZ |
255 | // MSWGetRegionWithoutSelf helper: removes the given rectangle from region |
256 | static inline void | |
257 | SubtractRectFromRgn(HRGN hrgn, int left, int top, int right, int bottom) | |
258 | { | |
259 | AutoHRGN hrgnRect(::CreateRectRgn(left, top, right, bottom)); | |
260 | if ( !hrgnRect ) | |
261 | { | |
9a83f860 | 262 | wxLogLastError(wxT("CreateRectRgn()")); |
3b6e5fb3 VZ |
263 | return; |
264 | } | |
265 | ||
266 | ::CombineRgn(hrgn, hrgn, hrgnRect, RGN_DIFF); | |
267 | } | |
268 | ||
269 | void wxStaticBox::MSWGetRegionWithoutSelf(WXHRGN hRgn, int w, int h) | |
eba99da4 | 270 | { |
3b6e5fb3 VZ |
271 | HRGN hrgn = (HRGN)hRgn; |
272 | ||
273 | // remove the area occupied by the static box borders from the region | |
274 | int borderTop, border; | |
275 | GetBordersForSizer(&borderTop, &border); | |
eba99da4 JS |
276 | |
277 | // top | |
3b6e5fb3 | 278 | SubtractRectFromRgn(hrgn, 0, 0, w, borderTop); |
eba99da4 JS |
279 | |
280 | // bottom | |
3b6e5fb3 | 281 | SubtractRectFromRgn(hrgn, 0, h - border, w, h); |
eba99da4 JS |
282 | |
283 | // left | |
3b6e5fb3 | 284 | SubtractRectFromRgn(hrgn, 0, 0, border, h); |
eba99da4 JS |
285 | |
286 | // right | |
3b6e5fb3 | 287 | SubtractRectFromRgn(hrgn, w - border, 0, w, h); |
eba99da4 JS |
288 | } |
289 | ||
3b6e5fb3 | 290 | WXHRGN wxStaticBox::MSWGetRegionWithoutChildren() |
eba99da4 JS |
291 | { |
292 | RECT rc; | |
293 | ::GetWindowRect(GetHwnd(), &rc); | |
294 | HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1); | |
cec46079 | 295 | bool foundThis = false; |
3b6e5fb3 VZ |
296 | |
297 | // iterate over all child windows (not just wxWindows but all windows) | |
298 | for ( HWND child = ::GetWindow(GetHwndOf(GetParent()), GW_CHILD); | |
299 | child; | |
300 | child = ::GetWindow(child, GW_HWNDNEXT) ) | |
eba99da4 | 301 | { |
4249e334 RD |
302 | if ( ! ::IsWindowVisible(child) ) |
303 | { | |
304 | // if the window isn't visible then it doesn't need clipped | |
305 | continue; | |
306 | } | |
9705fbe9 | 307 | |
4249e334 RD |
308 | LONG style = ::GetWindowLong(child, GWL_STYLE); |
309 | wxString str(wxGetWindowClass(child)); | |
310 | str.UpperCase(); | |
5c17f6d3 | 311 | if ( str == wxT("BUTTON") && (style & BS_GROUPBOX) == BS_GROUPBOX ) |
eba99da4 | 312 | { |
cec46079 JS |
313 | if ( child == GetHwnd() ) |
314 | foundThis = true; | |
315 | ||
316 | // Any static boxes below this one in the Z-order can't be clipped | |
317 | // since if we have the case where a static box with a low Z-order | |
318 | // is nested inside another static box with a high Z-order then the | |
319 | // nested static box would be painted over. Doing it this way | |
320 | // unfortunately results in flicker if the Z-order of nested static | |
321 | // boxes is not inside (lowest) to outside (highest) but at least | |
322 | // they are still shown. | |
323 | if ( foundThis ) | |
324 | continue; | |
4249e334 | 325 | } |
9705fbe9 | 326 | |
4249e334 RD |
327 | ::GetWindowRect(child, &rc); |
328 | if ( ::RectInRegion(hrgn, &rc) ) | |
329 | { | |
330 | // need to remove WS_CLIPSIBLINGS from all sibling windows | |
331 | // that are within this staticbox if set | |
332 | if ( style & WS_CLIPSIBLINGS ) | |
eba99da4 | 333 | { |
4249e334 RD |
334 | style &= ~WS_CLIPSIBLINGS; |
335 | ::SetWindowLong(child, GWL_STYLE, style); | |
9705fbe9 | 336 | |
4249e334 RD |
337 | // MSDN: "If you have changed certain window data using |
338 | // SetWindowLong, you must call SetWindowPos to have the | |
339 | // changes take effect." | |
340 | ::SetWindowPos(child, NULL, 0, 0, 0, 0, | |
341 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | | |
342 | SWP_FRAMECHANGED); | |
eba99da4 | 343 | } |
4249e334 RD |
344 | |
345 | AutoHRGN hrgnChild(::CreateRectRgnIndirect(&rc)); | |
346 | ::CombineRgn(hrgn, hrgn, hrgnChild, RGN_DIFF); | |
eba99da4 | 347 | } |
eba99da4 | 348 | } |
eba99da4 | 349 | |
3b6e5fb3 VZ |
350 | return (WXHRGN)hrgn; |
351 | } | |
352 | ||
c3732409 VZ |
353 | // helper for OnPaint(): really erase the background, i.e. do it even if we |
354 | // don't have any non default brush for doing it (DoEraseBackground() doesn't | |
355 | // do anything in such case) | |
3b6e5fb3 VZ |
356 | void wxStaticBox::PaintBackground(wxDC& dc, const RECT& rc) |
357 | { | |
c3732409 VZ |
358 | // note that we do not use the box background colour here, it shouldn't |
359 | // apply to its interior for several reasons: | |
360 | // 1. wxGTK doesn't do it | |
361 | // 2. controls inside the box don't get correct bg colour because they | |
362 | // are not our children so we'd have some really ugly colour mix if | |
363 | // we did it | |
364 | // 3. this is backwards compatible behaviour and some people rely on it, | |
365 | // see http://groups.google.com/groups?selm=4252E932.3080801%40able.es | |
366 | wxWindow *parent = GetParent(); | |
888dde65 | 367 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
b8797d96 | 368 | HBRUSH hbr = (HBRUSH)parent->MSWGetBgBrush(impl->GetHDC(), this); |
c3732409 VZ |
369 | |
370 | // if there is no special brush for painting this control, just use the | |
371 | // solid background colour | |
372 | wxBrush brush; | |
3b6e5fb3 VZ |
373 | if ( !hbr ) |
374 | { | |
c3732409 VZ |
375 | brush = wxBrush(parent->GetBackgroundColour()); |
376 | hbr = GetHbrushOf(brush); | |
3b6e5fb3 VZ |
377 | } |
378 | ||
888dde65 | 379 | ::FillRect(GetHdcOf(*impl), &rc, hbr); |
eba99da4 JS |
380 | } |
381 | ||
cf072997 | 382 | void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc) |
21c6080d | 383 | { |
888dde65 RR |
384 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
385 | MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(*impl), 0); | |
72a55896 VZ |
386 | |
387 | // when using XP themes, neither setting the text colour nor transparent | |
388 | // background mode doesn't change anything: the static box def window proc | |
389 | // still draws the label in its own colours, so we need to redraw the text | |
390 | // ourselves if we have a non default fg colour | |
95fab76b | 391 | if ( m_hasFgCol && wxUxThemeEngine::GetIfActive() ) |
72a55896 VZ |
392 | { |
393 | // draw over the text in default colour in our colour | |
888dde65 | 394 | HDC hdc = GetHdcOf(*impl); |
95fab76b | 395 | ::SetTextColor(hdc, GetForegroundColour().GetPixel()); |
cf072997 VZ |
396 | |
397 | const bool rtl = wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft; | |
398 | if ( rtl ) | |
399 | ::SetTextAlign(hdc, TA_RTLREADING | TA_RIGHT); | |
400 | ||
401 | // Get dimensions of the label | |
24e35cf8 | 402 | const wxString label = GetLabel(); |
24e35cf8 | 403 | |
95fab76b VZ |
404 | // choose the correct font |
405 | AutoHFONT font; | |
406 | SelectInHDC selFont; | |
407 | if ( m_hasFont ) | |
408 | { | |
409 | selFont.Init(hdc, GetHfontOf(GetFont())); | |
410 | } | |
411 | else // no font set, use the one set by the theme | |
412 | { | |
413 | wxUxThemeHandle hTheme(this, L"BUTTON"); | |
414 | if ( hTheme ) | |
415 | { | |
416 | // GetThemeFont() expects its parameter to be LOGFONTW and not | |
417 | // LOGFONTA even in ANSI programs and will happily corrupt | |
418 | // memory after the struct end if we pass a LOGFONTA (which is | |
419 | // smaller) to it! | |
420 | LOGFONTW lfw; | |
421 | if ( wxUxThemeEngine::Get()->GetThemeFont | |
422 | ( | |
423 | hTheme, | |
424 | hdc, | |
425 | BP_GROUPBOX, | |
426 | GBS_NORMAL, | |
427 | TMT_FONT, | |
428 | (LOGFONT *)&lfw | |
429 | ) == S_OK ) | |
430 | { | |
431 | #if wxUSE_UNICODE | |
432 | // ok, no conversion necessary | |
433 | const LOGFONT& lf = lfw; | |
434 | #else // !wxUSE_UNICODE | |
435 | // most of the fields are the same in LOGFONTA and LOGFONTW | |
436 | LOGFONT lf; | |
437 | memcpy(&lf, &lfw, sizeof(lf)); | |
438 | ||
439 | // but the face name must be converted | |
440 | WideCharToMultiByte(CP_ACP, 0, lfw.lfFaceName, -1, | |
441 | lf.lfFaceName, sizeof(lf.lfFaceName), | |
442 | NULL, NULL); | |
443 | #endif // wxUSE_UNICODE/!wxUSE_UNICODE | |
444 | ||
445 | font.Init(lf); | |
446 | if ( font ) | |
447 | selFont.Init(hdc, font); | |
448 | } | |
449 | } | |
450 | } | |
451 | ||
441dfa1d VZ |
452 | // Get the font extent |
453 | int width, height; | |
454 | dc.GetTextExtent(wxStripMenuCodes(label, wxStrip_Mnemonics), | |
455 | &width, &height); | |
456 | ||
457 | int x; | |
458 | int y = height; | |
459 | ||
460 | // first we need to correctly paint the background of the label | |
461 | // as Windows ignores the brush offset when doing it | |
462 | // | |
463 | // FIXME: value of x is hardcoded as this is what it is on my system, | |
464 | // no idea if it's true everywhere | |
465 | RECT dimensions = {0, 0, 0, y}; | |
466 | if ( !rtl ) | |
467 | { | |
468 | x = 9; | |
469 | dimensions.left = x; | |
470 | dimensions.right = x + width; | |
471 | } | |
472 | else | |
473 | { | |
474 | x = rc.right - 7; | |
475 | dimensions.left = x - width; | |
476 | dimensions.right = x; | |
477 | } | |
478 | ||
479 | // need to adjust the rectangle to cover all the label background | |
480 | dimensions.left -= 2; | |
481 | dimensions.right += 2; | |
482 | dimensions.bottom += 2; | |
483 | ||
b8ec69e8 VZ |
484 | if ( UseBgCol() ) |
485 | { | |
486 | // our own background colour should be used for the background of | |
487 | // the label: this is consistent with the behaviour under pre-XP | |
488 | // systems (i.e. without visual themes) and generally makes sense | |
489 | wxBrush brush = wxBrush(GetBackgroundColour()); | |
888dde65 RR |
490 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
491 | ::FillRect(GetHdcOf(*impl), &dimensions, GetHbrushOf(brush)); | |
b8ec69e8 VZ |
492 | } |
493 | else // paint parent background | |
494 | { | |
495 | PaintBackground(dc, dimensions); | |
496 | } | |
441dfa1d | 497 | |
24e35cf8 | 498 | // now draw the text |
cf072997 VZ |
499 | if ( !rtl ) |
500 | { | |
ffabb347 | 501 | RECT rc2 = { x, 0, x + width, y }; |
e0a050e3 | 502 | ::DrawText(hdc, label.wx_str(), label.length(), &rc2, |
cf072997 VZ |
503 | DT_SINGLELINE | DT_VCENTER); |
504 | } | |
505 | else // RTL | |
506 | { | |
507 | RECT rc2 = { x, 0, x - width, y }; | |
e0a050e3 | 508 | ::DrawText(hdc, label.wx_str(), label.length(), &rc2, |
cf072997 VZ |
509 | DT_SINGLELINE | DT_VCENTER | DT_RTLREADING); |
510 | } | |
72a55896 | 511 | } |
21c6080d JS |
512 | } |
513 | ||
eba99da4 JS |
514 | void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event)) |
515 | { | |
eba99da4 JS |
516 | RECT rc; |
517 | ::GetClientRect(GetHwnd(), &rc); | |
518 | ||
c3732409 | 519 | // draw the entire box in a memory DC |
eba99da4 JS |
520 | wxMemoryDC memdc; |
521 | wxBitmap bitmap(rc.right, rc.bottom); | |
522 | memdc.SelectObject(bitmap); | |
523 | ||
3b6e5fb3 | 524 | PaintBackground(memdc, rc); |
21c6080d | 525 | PaintForeground(memdc, rc); |
c3732409 VZ |
526 | |
527 | // now only blit the static box border itself, not the interior, to avoid | |
528 | // flicker when background is drawn below | |
529 | // | |
530 | // note that it seems to be faster to do 4 small blits here and then paint | |
531 | // directly into wxPaintDC than painting background in wxMemoryDC and then | |
532 | // blitting everything at once to wxPaintDC, this is why we do it like this | |
533 | wxPaintDC dc(this); | |
3b6e5fb3 VZ |
534 | int borderTop, border; |
535 | GetBordersForSizer(&borderTop, &border); | |
536 | ||
eba99da4 | 537 | // top |
3b6e5fb3 VZ |
538 | dc.Blit(border, 0, rc.right - border, borderTop, |
539 | &memdc, border, 0); | |
eba99da4 | 540 | // bottom |
1d1b4862 | 541 | dc.Blit(border, rc.bottom - border, rc.right - border, border, |
3b6e5fb3 | 542 | &memdc, border, rc.bottom - border); |
eba99da4 | 543 | // left |
3b6e5fb3 VZ |
544 | dc.Blit(0, 0, border, rc.bottom, |
545 | &memdc, 0, 0); | |
1d1b4862 VZ |
546 | // right (note that upper and bottom right corners were already part of the |
547 | // first two blits so we shouldn't overwrite them here to avoi flicker) | |
548 | dc.Blit(rc.right - border, borderTop, | |
549 | border, rc.bottom - borderTop - border, | |
550 | &memdc, rc.right - border, borderTop); | |
eba99da4 | 551 | |
c3732409 VZ |
552 | |
553 | // create the region excluding box children | |
3b6e5fb3 VZ |
554 | AutoHRGN hrgn((HRGN)MSWGetRegionWithoutChildren()); |
555 | RECT rcWin; | |
556 | ::GetWindowRect(GetHwnd(), &rcWin); | |
557 | ::OffsetRgn(hrgn, -rcWin.left, -rcWin.top); | |
eba99da4 | 558 | |
c3732409 | 559 | // and also the box itself |
3b6e5fb3 | 560 | MSWGetRegionWithoutSelf((WXHRGN) hrgn, rc.right, rc.bottom); |
888dde65 RR |
561 | wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl(); |
562 | HDCClipper clipToBg(GetHdcOf(*impl), hrgn); | |
3b6e5fb3 | 563 | |
c3732409 | 564 | // paint the inside of the box (excluding box itself and child controls) |
3b6e5fb3 | 565 | PaintBackground(dc, rc); |
eba99da4 JS |
566 | } |
567 | ||
c3732409 VZ |
568 | #endif // !__WXWINCE__ |
569 | ||
1e6feb95 | 570 | #endif // wxUSE_STATBOX |