]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbox.cpp
Committing in .
[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$
8// Copyright: (c) Julian Smart and Markus Holzem
c49245f8 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
3f2711d5
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
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
31#ifndef WX_PRECOMP
3f2711d5
VZ
32 #include "wx/app.h"
33 #include "wx/dcclient.h"
2bda0e17
KB
34#endif
35
36#include "wx/statbox.h"
2bda0e17 37
3f2711d5
VZ
38#include "wx/msw/private.h"
39
40// ----------------------------------------------------------------------------
41// wxWin macros
42// ----------------------------------------------------------------------------
43
2bda0e17
KB
44#if !USE_SHARED_LIBRARY
45IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
46
47BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
42e69d6b 48 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
2bda0e17
KB
49END_EVENT_TABLE()
50
51#endif
52
3f2711d5
VZ
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// wxStaticBox
59// ----------------------------------------------------------------------------
60
61bool wxStaticBox::Create(wxWindow *parent,
62 wxWindowID id,
63 const wxString& label,
64 const wxPoint& pos,
65 const wxSize& size,
66 long style,
67 const wxString& name)
2bda0e17 68{
3f2711d5
VZ
69 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
70 return FALSE;
2bda0e17 71
3f2711d5
VZ
72 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX) )
73 return FALSE;
2bda0e17 74
3f2711d5 75 SetSize(pos.x, pos.y, size.x, size.y);
2bda0e17 76
3f2711d5 77 return TRUE;
2bda0e17
KB
78}
79
4438caf4 80wxSize wxStaticBox::DoGetBestSize()
2bda0e17 81{
4438caf4
VZ
82 int cx, cy;
83 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
2bda0e17 84
4438caf4
VZ
85 int wBox;
86 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
2bda0e17 87
4438caf4
VZ
88 wBox += 3*cx;
89 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17 90
4438caf4
VZ
91 return wxSize(wBox, hBox);
92}
2bda0e17 93
debe6624 94WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
c49245f8
VZ
95 WXUINT message,
96 WXWPARAM wParam,
97 WXLPARAM lParam)
2bda0e17 98{
1f112209 99#if wxUSE_CTL3D
3f2711d5
VZ
100 if ( m_useCtl3D )
101 {
102 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
103 return (WXHBRUSH) hbrush;
104 }
105#endif // wxUSE_CTL3D
2bda0e17 106
3f2711d5
VZ
107 HDC hdc = (HDC)pDC;
108 if (GetParent()->GetTransparentBackground())
109 SetBkMode(hdc, TRANSPARENT);
110 else
111 SetBkMode(hdc, OPAQUE);
2bda0e17 112
3f2711d5
VZ
113 const wxColour& colBack = GetBackgroundColour();
114 ::SetBkColor(hdc, wxColourToRGB(colBack));
115 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
2bda0e17 116
3f2711d5 117 wxBrush *brush= wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
2bda0e17 118
3f2711d5 119 return (WXHBRUSH)brush->GetResourceHandle();
2bda0e17
KB
120}
121
3f2711d5
VZ
122// VZ: this is probably the most commented function in wxWindows, but I still
123// don't understand what it does and why. Wouldn't it be better to _never_
124// erase the background here? What would we lose if we didn't do it?
125// (FIXME)
126
2bda0e17
KB
127// Shouldn't erase the whole window, since the static box must only paint its
128// outline.
129void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
130{
1c089c47
JS
131 // If we don't have this (call Default()), we don't paint the background properly.
132 // If we do have this, we seem to overwrite enclosed controls.
133 // Is it the WS_CLIPCHILDREN style that's causing the problems?
134 // Probably - without this style, the background of the window will show through,
135 // so the control doesn't have to paint it. The window background will always be
136 // painted before all other controls, therefore there are no problems with
137 // controls being hidden by the static box.
138 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
139 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
140 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
141 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
142 // do with the windows.
143 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
144 // few other circumstances where it matters about child clipping. But what about painting onto
145 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
c49245f8 146 wxWindow *parent = GetParent();
3f2711d5
VZ
147 if ( parent && parent->GetHWND() &&
148 (::GetWindowLong(GetHwndOf(parent), GWL_STYLE) & WS_CLIPCHILDREN) )
c49245f8 149 {
2bda0e17
KB
150 // TODO: May in fact need to generate a paint event for inside this
151 // control's rectangle, otherwise all controls are going to be clipped -
152 // ugh.
2bda0e17 153
3f2711d5 154 // let wxControl::OnEraseBackground() do the job
c49245f8
VZ
155 event.Skip();
156 }
3f2711d5 157 //else: do *not* call event.Skip() or wxControl will erase the background
2bda0e17
KB
158}
159
160long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
161{
094637f6 162 if ( nMsg == WM_NCHITTEST)
1c089c47
JS
163 {
164 int xPos = LOWORD(lParam); // horizontal position of cursor
165 int yPos = HIWORD(lParam); // vertical position of cursor
166
167 ScreenToClient(&xPos, &yPos);
168
169 // Make sure you can drag by the top of the groupbox, but let
170 // other (enclosed) controls get mouse events also
171 if (yPos < 10)
172 return (long)HTCLIENT;
173 }
2bda0e17 174
42e69d6b 175 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
2bda0e17
KB
176}
177