]> git.saurik.com Git - wxWidgets.git/blame - src/msw/statbox.cpp
compilation 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
4438caf4 102wxSize wxStaticBox::DoGetBestSize()
2bda0e17 103{
4438caf4
VZ
104 int cx, cy;
105 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
2bda0e17 106
4438caf4
VZ
107 int wBox;
108 GetTextExtent(wxGetWindowText(m_hWnd), &wBox, &cy);
2bda0e17 109
4438caf4
VZ
110 wBox += 3*cx;
111 int hBox = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
2bda0e17 112
4438caf4
VZ
113 return wxSize(wBox, hBox);
114}
2bda0e17 115
4438caf4
VZ
116void wxStaticBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
117{
118 wxControl::DoSetSize(x, y, width, height, sizeFlags);
1c4a764c 119
094637f6
VZ
120 return;
121
4438caf4
VZ
122 // the static box should always be on the bottom of the Z-order, otherwise
123 // it may hide controls which are positioned inside it
124 if ( !::SetWindowPos(GetHwnd(), HWND_TOP, 0, 0, 0, 0,
125 SWP_NOMOVE | SWP_NOSIZE) )
126 {
127 wxLogLastError(_T("SetWindowPos"));
128 }
2bda0e17
KB
129}
130
debe6624 131WXHBRUSH wxStaticBox::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
42e69d6b 132 WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
2bda0e17 133{
1f112209 134#if wxUSE_CTL3D
2bda0e17
KB
135 if ( m_useCtl3D )
136 {
137 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
138 return (WXHBRUSH) hbrush;
139 }
140#endif
141
142 if (GetParent()->GetTransparentBackground())
143 SetBkMode((HDC) pDC, TRANSPARENT);
144 else
145 SetBkMode((HDC) pDC, OPAQUE);
146
147 ::SetBkColor((HDC) pDC, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
148 ::SetTextColor((HDC) pDC, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
149
150 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
151
152 // Note that this will be cleaned up in wxApp::OnIdle, if backgroundBrush
153 // has a zero usage count.
154// backgroundBrush->RealizeResource();
155 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
156}
157
158// Shouldn't erase the whole window, since the static box must only paint its
159// outline.
160void wxStaticBox::OnEraseBackground(wxEraseEvent& event)
161{
1c089c47
JS
162 // If we don't have this (call Default()), we don't paint the background properly.
163 // If we do have this, we seem to overwrite enclosed controls.
164 // Is it the WS_CLIPCHILDREN style that's causing the problems?
165 // Probably - without this style, the background of the window will show through,
166 // so the control doesn't have to paint it. The window background will always be
167 // painted before all other controls, therefore there are no problems with
168 // controls being hidden by the static box.
169 // So, if we could specify wxCLIP_CHILDREN in window, or not, we could optimise painting better.
170 // We would assume wxCLIP_CHILDREN in a frame and a scrolled window, but not in a panel.
171 // Is this too platform-specific?? What else can we do? Not a lot, since we have to pass
172 // this information from arbitrary wxWindow derivatives, and it depends on what you wish to
173 // do with the windows.
174 // Alternatively, just make sure that wxStaticBox is always at the back! There are probably
175 // few other circumstances where it matters about child clipping. But what about painting onto
176 // to panel, inside a groupbox? Doesn't appear, because the box wipes it out.
094637f6 177 wxWindow *parent = 0; //GetParent();
2bda0e17
KB
178 if ( parent && parent->GetHWND() && (::GetWindowLong((HWND) parent->GetHWND(), GWL_STYLE) & WS_CLIPCHILDREN) )
179 {
180 // TODO: May in fact need to generate a paint event for inside this
181 // control's rectangle, otherwise all controls are going to be clipped -
182 // ugh.
183 HBRUSH hBrush = ::CreateSolidBrush(PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
184 int mode = ::SetMapMode((HDC) event.GetDC()->GetHDC(), MM_TEXT);
185
186 RECT rect;
187
4438caf4 188 ::GetClientRect(GetHwnd(), &rect);
2bda0e17
KB
189 ::FillRect ((HDC) event.GetDC()->GetHDC(), &rect, hBrush);
190 ::DeleteObject(hBrush);
191 ::SetMapMode((HDC) event.GetDC()->GetHDC(), mode);
192 }
193 else
42e69d6b
VZ
194 {
195 event.Skip();
196 }
2bda0e17
KB
197}
198
199long wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
200{
094637f6 201 if ( nMsg == WM_NCHITTEST)
1c089c47
JS
202 {
203 int xPos = LOWORD(lParam); // horizontal position of cursor
204 int yPos = HIWORD(lParam); // vertical position of cursor
205
206 ScreenToClient(&xPos, &yPos);
207
208 // Make sure you can drag by the top of the groupbox, but let
209 // other (enclosed) controls get mouse events also
210 if (yPos < 10)
211 return (long)HTCLIENT;
212 }
2bda0e17 213
42e69d6b 214 return wxControl::MSWWindowProc(nMsg, wParam, lParam);
2bda0e17
KB
215}
216