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