]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/control.cpp
Inexplicable removal of wxRadioBox::MSWWindowProc reversed, so wxRadioBox
[wxWidgets.git] / src / msw / control.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.cpp
3// Purpose: wxControl class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "control.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/event.h"
25#include "wx/app.h"
26#include "wx/dcclient.h"
27#endif
28
29#include "wx/control.h"
30
31#include "wx/msw/private.h"
32
33#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
34#include <commctrl.h>
35#endif
36
37#if !USE_SHARED_LIBRARY
38IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
39
40BEGIN_EVENT_TABLE(wxControl, wxWindow)
41 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
42END_EVENT_TABLE()
43#endif
44
45// Item members
46wxControl::wxControl()
47{
48 m_backgroundColour = *wxWHITE;
49 m_foregroundColour = *wxBLACK;
50
51#if WXWIN_COMPATIBILITY
52 m_callback = 0;
53#endif // WXWIN_COMPATIBILITY
54}
55
56wxControl::~wxControl()
57{
58 m_isBeingDeleted = TRUE;
59}
60
61bool wxControl::MSWCreateControl(const wxChar *classname,
62 WXDWORD style,
63 const wxPoint& pos,
64 const wxSize& size,
65 const wxString& label,
66 WXDWORD exstyle)
67{
68 // VZ: if someone could put a comment here explaining what exactly this is
69 // needed for, it would be nice...
70 bool want3D;
71
72 // if no extended style given, determine it ourselves
73 if ( exstyle == (WXDWORD)-1 )
74 {
75 exstyle = GetExStyle(style, &want3D);
76 }
77
78 // all controls have these childs (wxWindows creates all controls visible
79 // by default)
80 style |= WS_CHILD | WS_VISIBLE;
81
82 m_hWnd = (WXHWND)::CreateWindowEx
83 (
84 exstyle, // extended style
85 classname, // the kind of control to create
86 label, // the window name
87 style, // the window style
88 pos.x, pos.y, // the window position
89 size.x, size.y, // and size
90 GetHwndOf(GetParent()), // parent
91 (HMENU)GetId(), // child id
92 wxGetInstance(), // app instance
93 NULL // creation parameters
94 );
95
96 if ( !m_hWnd )
97 {
98#ifdef __WXDEBUG__
99 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
100#endif // DEBUG
101
102 return FALSE;
103 }
104
105#if wxUSE_CTL3D
106 if ( want3D )
107 {
108 Ctl3dSubclassCtl(GetHwnd());
109 m_useCtl3D = TRUE;
110 }
111#endif // wxUSE_CTL3D
112
113 // subclass again for purposes of dialog editing mode
114 SubclassWin(m_hWnd);
115
116 // controls use the same font and colours as their parent dialog by default
117 InheritAttributes();
118
119 return TRUE;
120}
121
122wxSize wxControl::DoGetBestSize() const
123{
124 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
125}
126
127bool wxControl::ProcessCommand(wxCommandEvent& event)
128{
129#if WXWIN_COMPATIBILITY
130 if ( m_callback )
131 {
132 (void)(*m_callback)(this, event);
133
134 return TRUE;
135 }
136 else
137#endif // WXWIN_COMPATIBILITY
138
139 return GetEventHandler()->ProcessEvent(event);
140}
141
142#ifdef __WIN95__
143bool wxControl::MSWOnNotify(int idCtrl,
144 WXLPARAM lParam,
145 WXLPARAM* result)
146{
147 wxCommandEvent event(wxEVT_NULL, m_windowId);
148 wxEventType eventType = wxEVT_NULL;
149 NMHDR *hdr1 = (NMHDR*) lParam;
150 switch ( hdr1->code )
151 {
152 case NM_CLICK:
153 eventType = wxEVT_COMMAND_LEFT_CLICK;
154 break;
155
156 case NM_DBLCLK:
157 eventType = wxEVT_COMMAND_LEFT_DCLICK;
158 break;
159
160 case NM_RCLICK:
161 eventType = wxEVT_COMMAND_RIGHT_CLICK;
162 break;
163
164 case NM_RDBLCLK:
165 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
166 break;
167
168 case NM_SETFOCUS:
169 eventType = wxEVT_COMMAND_SET_FOCUS;
170 break;
171
172 case NM_KILLFOCUS:
173 eventType = wxEVT_COMMAND_KILL_FOCUS;
174 break;
175
176 case NM_RETURN:
177 eventType = wxEVT_COMMAND_ENTER;
178 break;
179
180 default:
181 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
182 }
183
184 event.SetEventType(eventType);
185 event.SetEventObject(this);
186
187 return GetEventHandler()->ProcessEvent(event);
188}
189#endif // Win95
190
191void wxControl::OnEraseBackground(wxEraseEvent& event)
192{
193 // In general, you don't want to erase the background of a control,
194 // or you'll get a flicker.
195 // TODO: move this 'null' function into each control that
196 // might flicker.
197
198 RECT rect;
199 ::GetClientRect(GetHwnd(), &rect);
200
201 HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
202
203 HDC hdc = GetHdcOf((*event.GetDC()));
204 int mode = ::SetMapMode(hdc, MM_TEXT);
205
206 ::FillRect(hdc, &rect, hBrush);
207 ::DeleteObject(hBrush);
208 ::SetMapMode(hdc, mode);
209}
210
211WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
212 WXUINT message,
213 WXWPARAM wParam,
214 WXLPARAM lParam)
215{
216#if wxUSE_CTL3D
217 if ( m_useCtl3D )
218 {
219 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
220 return (WXHBRUSH) hbrush;
221 }
222#endif // wxUSE_CTL3D
223
224 HDC hdc = (HDC)pDC;
225 if (GetParent()->GetTransparentBackground())
226 SetBkMode(hdc, TRANSPARENT);
227 else
228 SetBkMode(hdc, OPAQUE);
229
230 const wxColour& colBack = GetBackgroundColour();
231 ::SetBkColor(hdc, wxColourToRGB(colBack));
232 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
233
234 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
235
236 return (WXHBRUSH)brush->GetResourceHandle();
237}
238
239WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const
240{
241 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D);
242
243 // Even with extended styles, need to combine with WS_BORDER for them to
244 // look right.
245 if ( *want3D || wxStyleHasBorder(m_windowStyle) )
246 style |= WS_BORDER;
247
248 return exStyle;
249}
250
251// ---------------------------------------------------------------------------
252// global functions
253// ---------------------------------------------------------------------------
254
255// Call this repeatedly for several wnds to find the overall size
256// of the widget.
257// Call it initially with -1 for all values in rect.
258// Keep calling for other widgets, and rect will be modified
259// to calculate largest bounding rectangle.
260void wxFindMaxSize(WXHWND wnd, RECT *rect)
261{
262 int left = rect->left;
263 int right = rect->right;
264 int top = rect->top;
265 int bottom = rect->bottom;
266
267 GetWindowRect((HWND) wnd, rect);
268
269 if (left < 0)
270 return;
271
272 if (left < rect->left)
273 rect->left = left;
274
275 if (right > rect->right)
276 rect->right = right;
277
278 if (top < rect->top)
279 rect->top = top;
280
281 if (bottom > rect->bottom)
282 rect->bottom = bottom;
283}
284