]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbox.cpp
Removed rarely-used cursor; replaced other cursors
[wxWidgets.git] / src / msw / statbox.cpp
CommitLineData
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"
5bf4788a 43#include "wx/sysopt.h"
2bda0e17 44
3f2711d5 45#include "wx/msw/private.h"
72093cd8 46#include "wx/msw/missing.h"
3f2711d5
VZ
47
48// ----------------------------------------------------------------------------
49// wxWin macros
50// ----------------------------------------------------------------------------
51
51741307 52#if wxUSE_EXTENDED_RTTI
bc9fb572
JS
53WX_DEFINE_FLAGS( wxStaticBoxStyle )
54
3ff066a4 55wxBEGIN_FLAGS( wxStaticBoxStyle )
bc9fb572
JS
56 // new style border flags, we put them first to
57 // use them for streaming out
3ff066a4
SC
58 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
59 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
60 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
61 wxFLAGS_MEMBER(wxBORDER_RAISED)
62 wxFLAGS_MEMBER(wxBORDER_STATIC)
63 wxFLAGS_MEMBER(wxBORDER_NONE)
57f4f925 64
bc9fb572 65 // old style border flags
3ff066a4
SC
66 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
67 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
68 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
69 wxFLAGS_MEMBER(wxRAISED_BORDER)
70 wxFLAGS_MEMBER(wxSTATIC_BORDER)
cb0afb26 71 wxFLAGS_MEMBER(wxBORDER)
bc9fb572
JS
72
73 // standard window styles
3ff066a4
SC
74 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
75 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
76 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
77 wxFLAGS_MEMBER(wxWANTS_CHARS)
cb0afb26 78 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
3ff066a4
SC
79 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
80 wxFLAGS_MEMBER(wxVSCROLL)
81 wxFLAGS_MEMBER(wxHSCROLL)
bc9fb572 82
3ff066a4 83wxEND_FLAGS( wxStaticBoxStyle )
bc9fb572 84
51741307
SC
85IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox, wxControl,"wx/statbox.h")
86
3ff066a4 87wxBEGIN_PROPERTIES_TABLE(wxStaticBox)
57f4f925 88 wxPROPERTY( Label,wxString, SetLabel, GetLabel, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
af498247 89 wxPROPERTY_FLAGS( WindowStyle , wxStaticBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
066f1b7a 90/*
57f4f925
WS
91 TODO PROPERTIES :
92 label
066f1b7a 93*/
3ff066a4 94wxEND_PROPERTIES_TABLE()
51741307 95
3ff066a4
SC
96wxBEGIN_HANDLERS_TABLE(wxStaticBox)
97wxEND_HANDLERS_TABLE()
51741307 98
57f4f925 99wxCONSTRUCTOR_6( wxStaticBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
51741307
SC
100#else
101IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
102#endif
2bda0e17 103
3f2711d5
VZ
104// ============================================================================
105// implementation
106// ============================================================================
107
108// ----------------------------------------------------------------------------
109// wxStaticBox
110// ----------------------------------------------------------------------------
111
112bool wxStaticBox::Create(wxWindow *parent,
113 wxWindowID id,
114 const wxString& label,
115 const wxPoint& pos,
116 const wxSize& size,
117 long style,
118 const wxString& name)
2bda0e17 119{
11b6a93b 120 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
57f4f925 121 return false;
2bda0e17 122
e31e6ea7 123 if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) )
57f4f925 124 return false;
2bda0e17 125
9f769708 126#ifndef __WXWINCE__
5bf4788a
JS
127 if (!wxSystemOptions::IsFalse(wxT("msw.staticbox.optimized-paint")))
128 Connect(wxEVT_PAINT, wxPaintEventHandler(wxStaticBox::OnPaint));
c3732409 129#endif // !__WXWINCE__
3b6e5fb3 130
57f4f925 131 return true;
2bda0e17
KB
132}
133
9f769708
JS
134wxBorder wxStaticBox::GetDefaultBorder() const
135{
136 return wxBORDER_NONE;
137}
138
e31e6ea7
VZ
139WXDWORD wxStaticBox::MSWGetStyle(long style, WXDWORD *exstyle) const
140{
141 long styleWin = wxStaticBoxBase::MSWGetStyle(style, exstyle);
142
eba99da4
JS
143 // no need for it anymore, must be removed for wxRadioBox child
144 // buttons to be able to repaint themselves
145 styleWin &= ~WS_CLIPCHILDREN;
146
e31e6ea7 147 if ( exstyle )
5bf4788a 148 {
a92e7f30 149#ifndef __WXWINCE__
5bf4788a
JS
150 if (wxSystemOptions::IsFalse(wxT("msw.staticbox.optimized-paint")))
151 *exstyle = WS_EX_TRANSPARENT;
152 else
a92e7f30 153#endif
5bf4788a
JS
154 *exstyle = 0;
155 }
a83b5b74 156
e31e6ea7
VZ
157 return styleWin | BS_GROUPBOX;
158}
159
f68586e5 160wxSize wxStaticBox::DoGetBestSize() const
2bda0e17 161{
4438caf4 162 int cx, cy;
7a5e53ab 163 wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
2bda0e17 164
4438caf4
VZ
165 int wBox;
166 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
2bda0e17 167
4438caf4
VZ
168 wBox += 3*cx;
169 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17 170
4438caf4
VZ
171 return wxSize(wBox, hBox);
172}
2bda0e17 173
c3732409 174void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
6aa01033 175{
c3732409
VZ
176 wxStaticBoxBase::GetBordersForSizer(borderTop, borderOther);
177
178 // need extra space, don't know how much but this seems to be enough
179 *borderTop += GetCharHeight()/3;
180}
181
182// all the hacks below are not necessary for WinCE
abf912c5 183#ifndef __WXWINCE__
c3732409
VZ
184
185WXLRESULT wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
186{
58385af0 187 if ( nMsg == WM_NCHITTEST )
6aa01033 188 {
58385af0
VZ
189 // This code breaks some other processing such as enter/leave tracking
190 // so it's off by default.
191
192 static int s_useHTClient = -1;
193 if (s_useHTClient == -1)
194 s_useHTClient = wxSystemOptions::GetOptionInt(wxT("msw.staticbox.htclient"));
195 if (s_useHTClient == 1)
196 {
c3732409
VZ
197 int xPos = GET_X_LPARAM(lParam);
198 int yPos = GET_Y_LPARAM(lParam);
58385af0
VZ
199
200 ScreenToClient(&xPos, &yPos);
201
202 // Make sure you can drag by the top of the groupbox, but let
203 // other (enclosed) controls get mouse events also
204 if ( yPos < 10 )
205 return (long)HTCLIENT;
206 }
6aa01033
JS
207 }
208
209 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
210}
211
c3732409
VZ
212// ----------------------------------------------------------------------------
213// static box drawing
214// ----------------------------------------------------------------------------
58385af0 215
c3732409
VZ
216/*
217 We draw the static box ourselves because it's the only way to prevent it
218 from flickering horribly on resize (because everything inside the box is
219 erased twice: once when the box itself is repainted and second time when
220 the control inside it is repainted) without using WS_EX_TRANSPARENT style as
221 we used to do and which resulted in other problems.
222 */
58385af0 223
3b6e5fb3
VZ
224// MSWGetRegionWithoutSelf helper: removes the given rectangle from region
225static inline void
226SubtractRectFromRgn(HRGN hrgn, int left, int top, int right, int bottom)
227{
228 AutoHRGN hrgnRect(::CreateRectRgn(left, top, right, bottom));
229 if ( !hrgnRect )
230 {
231 wxLogLastError(_T("CreateRectRgn()"));
232 return;
233 }
234
235 ::CombineRgn(hrgn, hrgn, hrgnRect, RGN_DIFF);
236}
237
238void wxStaticBox::MSWGetRegionWithoutSelf(WXHRGN hRgn, int w, int h)
eba99da4 239{
3b6e5fb3
VZ
240 HRGN hrgn = (HRGN)hRgn;
241
242 // remove the area occupied by the static box borders from the region
243 int borderTop, border;
244 GetBordersForSizer(&borderTop, &border);
eba99da4
JS
245
246 // top
3b6e5fb3 247 SubtractRectFromRgn(hrgn, 0, 0, w, borderTop);
eba99da4
JS
248
249 // bottom
3b6e5fb3 250 SubtractRectFromRgn(hrgn, 0, h - border, w, h);
eba99da4
JS
251
252 // left
3b6e5fb3 253 SubtractRectFromRgn(hrgn, 0, 0, border, h);
eba99da4
JS
254
255 // right
3b6e5fb3 256 SubtractRectFromRgn(hrgn, w - border, 0, w, h);
eba99da4
JS
257}
258
3b6e5fb3 259WXHRGN wxStaticBox::MSWGetRegionWithoutChildren()
eba99da4
JS
260{
261 RECT rc;
262 ::GetWindowRect(GetHwnd(), &rc);
263 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
3b6e5fb3
VZ
264
265 // iterate over all child windows (not just wxWindows but all windows)
266 for ( HWND child = ::GetWindow(GetHwndOf(GetParent()), GW_CHILD);
267 child;
268 child = ::GetWindow(child, GW_HWNDNEXT) )
eba99da4 269 {
4249e334
RD
270 if ( ! ::IsWindowVisible(child) )
271 {
272 // if the window isn't visible then it doesn't need clipped
273 continue;
274 }
275
276 LONG style = ::GetWindowLong(child, GWL_STYLE);
277 wxString str(wxGetWindowClass(child));
278 str.UpperCase();
5c17f6d3 279 if ( str == wxT("BUTTON") && (style & BS_GROUPBOX) == BS_GROUPBOX )
eba99da4 280 {
4249e334
RD
281 // Don't clip any static boxes, not just this one. This will
282 // result in flicker in overlapping static boxes, but at least
283 // they will all be drawn correctly and we shouldn't have
284 // overlapping windows anyway.
285 continue;
286 }
287
288 ::GetWindowRect(child, &rc);
289 if ( ::RectInRegion(hrgn, &rc) )
290 {
291 // need to remove WS_CLIPSIBLINGS from all sibling windows
292 // that are within this staticbox if set
293 if ( style & WS_CLIPSIBLINGS )
eba99da4 294 {
4249e334
RD
295 style &= ~WS_CLIPSIBLINGS;
296 ::SetWindowLong(child, GWL_STYLE, style);
297
298 // MSDN: "If you have changed certain window data using
299 // SetWindowLong, you must call SetWindowPos to have the
300 // changes take effect."
301 ::SetWindowPos(child, NULL, 0, 0, 0, 0,
302 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
303 SWP_FRAMECHANGED);
eba99da4 304 }
4249e334
RD
305
306 AutoHRGN hrgnChild(::CreateRectRgnIndirect(&rc));
307 ::CombineRgn(hrgn, hrgn, hrgnChild, RGN_DIFF);
eba99da4 308 }
eba99da4 309 }
eba99da4 310
3b6e5fb3
VZ
311 return (WXHRGN)hrgn;
312}
313
c3732409
VZ
314// helper for OnPaint(): really erase the background, i.e. do it even if we
315// don't have any non default brush for doing it (DoEraseBackground() doesn't
316// do anything in such case)
3b6e5fb3
VZ
317void wxStaticBox::PaintBackground(wxDC& dc, const RECT& rc)
318{
c3732409
VZ
319 // note that we do not use the box background colour here, it shouldn't
320 // apply to its interior for several reasons:
321 // 1. wxGTK doesn't do it
322 // 2. controls inside the box don't get correct bg colour because they
323 // are not our children so we'd have some really ugly colour mix if
324 // we did it
325 // 3. this is backwards compatible behaviour and some people rely on it,
326 // see http://groups.google.com/groups?selm=4252E932.3080801%40able.es
327 wxWindow *parent = GetParent();
bcb8ba61 328 HBRUSH hbr = (HBRUSH)parent->MSWGetBgBrush(dc.GetHDC(), GetHWND());
c3732409
VZ
329
330 // if there is no special brush for painting this control, just use the
331 // solid background colour
332 wxBrush brush;
3b6e5fb3
VZ
333 if ( !hbr )
334 {
c3732409
VZ
335 brush = wxBrush(parent->GetBackgroundColour());
336 hbr = GetHbrushOf(brush);
3b6e5fb3
VZ
337 }
338
c3732409 339 ::FillRect(GetHdcOf(dc), &rc, hbr);
eba99da4
JS
340}
341
21c6080d
JS
342void wxStaticBox::PaintForeground(wxDC& dc, const RECT& WXUNUSED(rc))
343{
344 // NB: neither setting the text colour nor transparent background mode
345 // doesn't change anything: the static box def window proc still
346 // draws the label in its own colours, so if we want to have control
347 // over this we really have to draw everything ourselves
348 MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(dc), 0);
349}
350
eba99da4
JS
351void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event))
352{
eba99da4
JS
353 RECT rc;
354 ::GetClientRect(GetHwnd(), &rc);
355
c3732409 356 // draw the entire box in a memory DC
eba99da4
JS
357 wxMemoryDC memdc;
358 wxBitmap bitmap(rc.right, rc.bottom);
359 memdc.SelectObject(bitmap);
360
3b6e5fb3 361 PaintBackground(memdc, rc);
21c6080d 362 PaintForeground(memdc, rc);
c3732409
VZ
363
364 // now only blit the static box border itself, not the interior, to avoid
365 // flicker when background is drawn below
366 //
367 // note that it seems to be faster to do 4 small blits here and then paint
368 // directly into wxPaintDC than painting background in wxMemoryDC and then
369 // blitting everything at once to wxPaintDC, this is why we do it like this
370 wxPaintDC dc(this);
3b6e5fb3
VZ
371 int borderTop, border;
372 GetBordersForSizer(&borderTop, &border);
373
eba99da4 374 // top
3b6e5fb3
VZ
375 dc.Blit(border, 0, rc.right - border, borderTop,
376 &memdc, border, 0);
eba99da4 377 // bottom
3b6e5fb3
VZ
378 dc.Blit(border, rc.bottom - border, rc.right - border, rc.bottom,
379 &memdc, border, rc.bottom - border);
eba99da4 380 // left
3b6e5fb3
VZ
381 dc.Blit(0, 0, border, rc.bottom,
382 &memdc, 0, 0);
eba99da4 383 // right
3b6e5fb3
VZ
384 dc.Blit(rc.right - border, 0, rc.right, rc.bottom,
385 &memdc, rc.right - border, 0);
eba99da4 386
c3732409
VZ
387
388 // create the region excluding box children
3b6e5fb3
VZ
389 AutoHRGN hrgn((HRGN)MSWGetRegionWithoutChildren());
390 RECT rcWin;
391 ::GetWindowRect(GetHwnd(), &rcWin);
392 ::OffsetRgn(hrgn, -rcWin.left, -rcWin.top);
eba99da4 393
c3732409 394 // and also the box itself
3b6e5fb3 395 MSWGetRegionWithoutSelf((WXHRGN) hrgn, rc.right, rc.bottom);
c3732409 396 HDCClipper clipToBg(GetHdcOf(dc), hrgn);
3b6e5fb3 397
c3732409 398 // paint the inside of the box (excluding box itself and child controls)
3b6e5fb3 399 PaintBackground(dc, rc);
eba99da4
JS
400}
401
c3732409
VZ
402#endif // !__WXWINCE__
403
1e6feb95 404#endif // wxUSE_STATBOX
6aa01033 405