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