]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbox.cpp
Changed [] parameters to be unsigned.
[wxWidgets.git] / src / msw / statbox.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: statbox.cpp
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
42e69d6b 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "statbox.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24#include "wx/dcclient.h"
25#include "wx/app.h"
26#endif
27
28#include "wx/statbox.h"
29#include "wx/msw/private.h"
30
31#if !USE_SHARED_LIBRARY
32IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
33
34BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
42e69d6b 35 EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
2bda0e17
KB
36END_EVENT_TABLE()
37
38#endif
39
40/*
41 * Group box
42 */
43
debe6624 44bool wxStaticBox::Create(wxWindow *parent, wxWindowID id,
2bda0e17
KB
45 const wxString& label,
46 const wxPoint& pos,
47 const wxSize& size,
debe6624 48 long style,
2bda0e17
KB
49 const wxString& name)
50{
51 SetName(name);
52
53 if (parent) parent->AddChild(this);
54
fd71308f
JS
55 SetBackgroundColour(parent->GetBackgroundColour()) ;
56 SetForegroundColour(parent->GetForegroundColour()) ;
2bda0e17
KB
57
58 if ( id == -1 )
42e69d6b 59 m_windowId = (int)NewControlId();
2bda0e17 60 else
42e69d6b 61 m_windowId = id;
2bda0e17
KB
62
63 int x = pos.x;
64 int y = pos.y;
65 int width = size.x;
66 int height = size.y;
67
68 m_windowStyle = style;
69
70 long msStyle = BS_GROUPBOX | WS_CHILD | WS_VISIBLE ; // GROUP_FLAGS;
71
72 bool want3D;
73 WXDWORD exStyle = Determine3DEffects(0, &want3D) ;
74
75 HWND wx_button =
76 CreateWindowEx(exStyle, "BUTTON", (const char *)label, msStyle,
77 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
78 wxGetInstance(), NULL);
1f112209 79#if wxUSE_CTL3D
2bda0e17
KB
80 if (want3D)
81 {
82 Ctl3dSubclassCtl(wx_button);
42e69d6b 83 m_useCtl3D = TRUE;
2bda0e17
KB
84 }
85#endif
86
87 m_hWnd = (WXHWND)wx_button;
88
89 // Subclass again for purposes of dialog editing mode
90 SubclassWin(GetHWND());
91
c0ed460c 92 SetFont(parent->GetFont());
2bda0e17
KB
93
94 SetSize(x, y, width, height);
95 ShowWindow(wx_button, SW_SHOW);
96
97 return TRUE;
98}
99
100void wxStaticBox::SetLabel(const wxString& label)
101{
102 SetWindowText((HWND)m_hWnd, (const char *)label);
103}
104
bfc6fde4 105void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
2bda0e17
KB
106{
107 int currentX, currentY;
108 GetPosition(&currentX, &currentY);
109
110 int x1 = x;
111 int y1 = y;
112 int w1 = width;
113 int h1 = height;
114
115 if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
116 x1 = currentX;
117 if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
118 y1 = currentY;
119
81d66cf3
JS
120 AdjustForParentClientOrigin(x1, y1, sizeFlags);
121
2bda0e17
KB
122 // If we're prepared to use the existing size, then...
123 if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO))
124 {
125 GetSize(&w1, &h1);
126 }
127
debe6624 128 int current_width;
2bda0e17
KB
129
130 int cx;
131 int cy;
debe6624 132 int cyf;
2bda0e17 133
ce3ed50d 134 wxGetCharSize(GetHWND(), &cx, &cy, & this->GetFont());
2bda0e17 135
1c4a764c 136 GetTextExtent(wxGetWindowText(m_hWnd), &current_width, &cyf,
ce3ed50d 137 NULL,NULL, & this->GetFont());
1c4a764c
VZ
138 if ( w1 < 0 )
139 w1 = current_width + 3*cx;
140 if ( h1 < 0 )
141 h1 = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cyf);
142
143 MoveWindow((HWND)m_hWnd, x1, y1, w1, h1, TRUE);
2bda0e17
KB
144}
145
debe6624 146WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
42e69d6b 147 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 148{
1f112209 149#if wxUSE_CTL3D
2bda0e17
KB
150 if ( m_useCtl3D )
151 {
152 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
153 return (WXHBRUSH) hbrush;
154 }
155#endif
156
157 if (GetParent()->GetTransparentBackground())
158 SetBkMode((HDC) pDC, TRANSPARENT);
159 else
160 SetBkMode((HDC) pDC, OPAQUE);
161
162 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
163 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
164
165 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
166
167 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
168 // has a zero usage count.
169// backgroundBrush->RealizeResource();
170 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
171}
172
173// Shouldn't erase the whole window, since the static box must only paint its
174// outline.
175void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
176{
1c089c47
JS
177 // If we don't have this (call Default()), we don't paint the background properly.
178 // If we do have this, we seem to overwrite enclosed controls.
179 // Is it the WS_CLIPCHILDREN style that's causing the problems?
180 // Probably - without this style, the background of the window will show through,
181 // so the control doesn't have to paint it. The window background will always be
182 // painted before all other controls, therefore there are no problems with
183 // controls being hidden by the static box.
184 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
185 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
186 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
187 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
188 // do with the windows.
189 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
190 // few other circumstances where it matters about child clipping. But what about painting onto
191 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
2bda0e17
KB
192 wxWindow *parent = GetParent();
193 if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) )
194 {
195 // TODO: May in fact need to generate a paint event for inside this
196 // control's rectangle, otherwise all controls are going to be clipped -
197 // ugh.
198 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
199 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
200
201 RECT rect;
202
203 ::GetClientRect((HWND) GetHWND(), &rect);
204 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
205 ::DeleteObject(hBrush);
206 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
207 }
208 else
42e69d6b
VZ
209 {
210 event.Skip();
211 }
2bda0e17
KB
212}
213
214long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
215{
42e69d6b 216 if (nMsg == WM_NCHITTEST)
1c089c47
JS
217 {
218 int xPos = LOWORD(lParam); // horizontal position of cursor
219 int yPos = HIWORD(lParam); // vertical position of cursor
220
221 ScreenToClient(&xPos, &yPos);
222
223 // Make sure you can drag by the top of the groupbox, but let
224 // other (enclosed) controls get mouse events also
225 if (yPos < 10)
226 return (long)HTCLIENT;
227 }
2bda0e17 228
42e69d6b 229 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
2bda0e17
KB
230}
231