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