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