]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbox.cpp
adding correct handling of uncovering or covering controls via tlw-resizes (in which...
[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"
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
51WX_DEFINE_FLAGS( wxStaticBoxStyle )
52
3ff066a4 53wxBEGIN_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 81wxEND_FLAGS( wxStaticBoxStyle )
bc9fb572 82
51741307
SC
83IMPLEMENT_DYNAMIC_CLASS_XTI(wxStaticBox, wxControl,"wx/statbox.h")
84
3ff066a4 85wxBEGIN_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 92wxEND_PROPERTIES_TABLE()
51741307 93
3ff066a4
SC
94wxBEGIN_HANDLERS_TABLE(wxStaticBox)
95wxEND_HANDLERS_TABLE()
51741307 96
57f4f925 97wxCONSTRUCTOR_6( wxStaticBox , wxWindow* , Parent , wxWindowID , Id , wxString , Label , wxPoint , Position , wxSize , Size , long , WindowStyle )
51741307
SC
98#else
99IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
100#endif
2bda0e17 101
eba99da4
JS
102BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
103 EVT_PAINT(wxStaticBox::OnPaint)
104END_EVENT_TABLE()
105
3f2711d5
VZ
106// ============================================================================
107// implementation
108// ============================================================================
109
110// ----------------------------------------------------------------------------
111// wxStaticBox
112// ----------------------------------------------------------------------------
113
114bool wxStaticBox::Create(wxWindow *parent,
115 wxWindowID id,
116 const wxString& label,
117 const wxPoint& pos,
118 const wxSize& size,
119 long style,
120 const wxString& name)
2bda0e17 121{
11b6a93b 122 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
57f4f925 123 return false;
2bda0e17 124
e31e6ea7 125 if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) )
57f4f925 126 return false;
2bda0e17 127
57f4f925 128 return true;
2bda0e17
KB
129}
130
e31e6ea7
VZ
131WXDWORD wxStaticBox::MSWGetStyle(long style, WXDWORD *exstyle) const
132{
133 long styleWin = wxStaticBoxBase::MSWGetStyle(style, exstyle);
134
eba99da4
JS
135 // no need for it anymore, must be removed for wxRadioBox child
136 // buttons to be able to repaint themselves
137 styleWin &= ~WS_CLIPCHILDREN;
138
e31e6ea7 139 if ( exstyle )
eba99da4 140 *exstyle = 0;
e31e6ea7
VZ
141
142 return styleWin | BS_GROUPBOX;
143}
144
f68586e5 145wxSize wxStaticBox::DoGetBestSize() const
2bda0e17 146{
4438caf4 147 int cx, cy;
7a5e53ab 148 wxGetCharSize(GetHWND(), &cx, &cy, GetFont());
2bda0e17 149
4438caf4
VZ
150 int wBox;
151 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
2bda0e17 152
4438caf4
VZ
153 wBox += 3*cx;
154 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17 155
4438caf4
VZ
156 return wxSize(wBox, hBox);
157}
2bda0e17 158
6aa01033
JS
159WXLRESULT wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
160{
abf912c5 161#ifndef __WXWINCE__
58385af0 162 if ( nMsg == WM_NCHITTEST )
6aa01033 163 {
58385af0
VZ
164 // This code breaks some other processing such as enter/leave tracking
165 // so it's off by default.
166
167 static int s_useHTClient = -1;
168 if (s_useHTClient == -1)
169 s_useHTClient = wxSystemOptions::GetOptionInt(wxT("msw.staticbox.htclient"));
170 if (s_useHTClient == 1)
171 {
172 int xPos = LOWORD(lParam); // horizontal position of cursor
173 int yPos = HIWORD(lParam); // vertical position of cursor
174
175 ScreenToClient(&xPos, &yPos);
176
177 // Make sure you can drag by the top of the groupbox, but let
178 // other (enclosed) controls get mouse events also
179 if ( yPos < 10 )
180 return (long)HTCLIENT;
181 }
6aa01033 182 }
abf912c5 183#endif // !__WXWINCE__
6aa01033
JS
184
185 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
186}
187
58385af0
VZ
188void wxStaticBox::GetBordersForSizer(int *borderTop, int *borderOther) const
189{
190 wxStaticBoxBase::GetBordersForSizer(borderTop, borderOther);
191
192 // if not using correct (but backwards cojmpatible) text metrics
193 // calculations, we need to add some extra margin or otherwise static box
194 // title is clipped
195#if !wxDIALOG_UNIT_COMPATIBILITY
196 if ( !GetLabel().empty() )
197 *borderTop += GetCharHeight()/3;
198#endif // !wxDIALOG_UNIT_COMPATIBILITY
199}
200
eba99da4 201// rc must be in client coords!
2f059e30 202void wxStaticBox::MSWClipBoxRegion(WXHRGN hrgn, const WXRECTPTR rc)
eba99da4
JS
203{
204 HRGN hrgnchild;
205
206 // top
2f059e30
JS
207 hrgnchild = ::CreateRectRgn(0, 0, ((const RECT*) rc)->right, 14);
208 ::CombineRgn((HRGN) hrgn, (HRGN) hrgn, hrgnchild, RGN_DIFF);
eba99da4
JS
209 ::DeleteObject(hrgnchild);
210
211 // bottom
2f059e30
JS
212 hrgnchild = ::CreateRectRgn(0, ((const RECT*) rc)->bottom - 7, ((const RECT*) rc)->right, ((const RECT*) rc)->bottom);
213 ::CombineRgn((HRGN) hrgn, (HRGN) hrgn, hrgnchild, RGN_DIFF);
eba99da4
JS
214 ::DeleteObject(hrgnchild);
215
216 // left
2f059e30
JS
217 hrgnchild = ::CreateRectRgn(0, 0, 7, ((const RECT*) rc)->bottom);
218 ::CombineRgn((HRGN) hrgn, (HRGN) hrgn, hrgnchild, RGN_DIFF);
eba99da4
JS
219 ::DeleteObject(hrgnchild);
220
221 // right
2f059e30
JS
222 hrgnchild = ::CreateRectRgn(((const RECT*) rc)->right - 7, 0, ((const RECT*) rc)->right, ((const RECT*) rc)->bottom);
223 ::CombineRgn((HRGN) hrgn, (HRGN) hrgn, hrgnchild, RGN_DIFF);
eba99da4
JS
224 ::DeleteObject(hrgnchild);
225}
226
227WXHRGN wxStaticBox::MSWCalculateClippingRegion()
228{
229 RECT rc;
230 ::GetWindowRect(GetHwnd(), &rc);
231 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
232
233 wxWindowList::compatibility_iterator node = GetParent()->GetChildren().GetFirst();
234 while ( node )
235 {
236 wxWindow *child = node->GetData();
237
238 // can't just test for (this != child) here since if a wxStaticBox
239 // overlaps another wxStaticBox then neither are drawn. The overlapping
240 // region will flicker but we shouldn't have overlapping windows anyway.
241 if ( !child->IsKindOf(CLASSINFO(wxStaticBox)) )
242 {
243 ::GetWindowRect(GetHwndOf(child), &rc);
244 if ( RectInRegion(hrgn, &rc) )
245 {
246 // need to remove WS_CLIPSIBLINGS from all sibling windows
247 // that are within this staticbox if set
248 LONG style = ::GetWindowLong(GetHwndOf(child), GWL_STYLE);
249 if ( style & WS_CLIPSIBLINGS )
250 {
251 style &= ~WS_CLIPSIBLINGS;
252 ::SetWindowLong(GetHwndOf(child), GWL_STYLE, style);
253
254 // MSDN: "If you have changed certain window data using
255 // SetWindowLong, you must call SetWindowPos to have the
256 // changes take effect."
257 ::SetWindowPos(GetHwndOf(child), NULL, 0, 0, 0, 0,
258 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
259 SWP_FRAMECHANGED);
260 }
261
262 HRGN hrgnchild = ::CreateRectRgnIndirect(&rc);
263 ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
264 ::DeleteObject(hrgnchild);
265 }
266 }
267
268 node = node->GetNext();
269 }
270 ::GetWindowRect(GetHwnd(), &rc);
271 ::OffsetRgn(hrgn, -rc.left, -rc.top);
272
273 return hrgn;
274}
275
276void wxStaticBox::OnPaint(wxPaintEvent& WXUNUSED(event))
277{
278 wxPaintDC dc(this);
279 RECT rc;
280 ::GetClientRect(GetHwnd(), &rc);
281
282 // paint the actual box
283 wxMemoryDC memdc;
284 wxBitmap bitmap(rc.right, rc.bottom);
285 memdc.SelectObject(bitmap);
286
287 // get bg brush
288 WXHBRUSH hbr = DoMSWControlColor(GetHdcOf(memdc), wxNullColour);
289 if ( !hbr )
290 {
291 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
292 hbr = (WXHBRUSH)brush->GetResourceHandle();
293 }
294
295 // draw solid box, but only blit the good bits
296 ::FillRect(GetHdcOf(memdc), &rc, (HBRUSH)hbr);
297 MSWDefWindowProc(WM_PAINT, (WPARAM)GetHdcOf(memdc), 0);
298
299 // top
300 dc.Blit(7, 0, rc.right - 7, 14, &memdc, 7, 0);
301 // bottom
302 dc.Blit(7, rc.bottom - 7, rc.right - 7, rc.bottom, &memdc, 7, rc.bottom - 7);
303 // left
304 dc.Blit(0, 0, 7, rc.bottom, &memdc, 0, 0);
305 // right
306 dc.Blit(rc.right - 7, 0, rc.right, rc.bottom, &memdc, rc.right - 7, 0);
307
308 // paint the inner
309 HRGN hrgn = (HRGN)MSWCalculateClippingRegion();
310 // now remove the box itself
2f059e30 311 MSWClipBoxRegion((WXHRGN) hrgn, (const WXRECTPTR) &rc);
eba99da4
JS
312
313 hbr = DoMSWControlColor(GetHdcOf(dc), wxNullColour);
314 if ( !hbr )
315 {
316 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
317 hbr = (WXHBRUSH)brush->GetResourceHandle();
318 }
319
320 ::SelectClipRgn(GetHdcOf(dc), hrgn);
321 ::FillRect(GetHdcOf(dc), &rc, (HBRUSH)hbr);
322 ::SelectClipRgn(GetHdcOf(dc), NULL);
323 ::DeleteObject(hrgn);
324}
325
1e6feb95 326#endif // wxUSE_STATBOX
6aa01033 327