]> git.saurik.com Git - wxWidgets.git/blame - src/msw/control.cpp
OS/2 updates for statusbar processing
[wxWidgets.git] / src / msw / control.cpp
CommitLineData
2bda0e17
KB
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
a23fd0e1 9// Licence: wxWindows licence
2bda0e17
KB
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
2432b92d 24#include "wx/event.h"
2bda0e17
KB
25#include "wx/app.h"
26#include "wx/dcclient.h"
27#endif
28
2432b92d
JS
29#include "wx/control.h"
30
2bda0e17
KB
31#include "wx/msw/private.h"
32
c42404a5
VZ
33#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) || defined(__TWIN32__))
34 #include <commctrl.h>
2bda0e17
KB
35#endif
36
2bda0e17
KB
37IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
38
39BEGIN_EVENT_TABLE(wxControl, wxWindow)
a23fd0e1 40 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
2bda0e17 41END_EVENT_TABLE()
2bda0e17
KB
42
43// Item members
42e69d6b 44wxControl::wxControl()
2bda0e17 45{
3f2711d5
VZ
46 m_backgroundColour = *wxWHITE;
47 m_foregroundColour = *wxBLACK;
42e69d6b
VZ
48
49#if WXWIN_COMPATIBILITY
3f2711d5 50 m_callback = 0;
42e69d6b 51#endif // WXWIN_COMPATIBILITY
2bda0e17
KB
52}
53
42e69d6b 54wxControl::~wxControl()
2bda0e17 55{
42e69d6b 56 m_isBeingDeleted = TRUE;
2bda0e17
KB
57}
58
8d772832
RD
59
60bool wxControl::Create(wxWindow *parent, wxWindowID id,
61 const wxPoint& pos,
62 const wxSize& size, long style,
8d772832 63 const wxValidator& validator,
8d772832
RD
64 const wxString& name)
65{
66 bool rval = wxWindow::Create(parent, id, pos, size, style, name);
67 if (rval) {
68#if wxUSE_VALIDATORS
69 SetValidator(validator);
70#endif
71 }
72 return rval;
73}
74
222594ea
VZ
75bool wxControl::MSWCreateControl(const wxChar *classname,
76 WXDWORD style,
77 const wxPoint& pos,
78 const wxSize& size,
79 const wxString& label,
80 WXDWORD exstyle)
8d99be5f 81{
f6bcfd97
BP
82 // want3D tells us whether or not the style specified a 3D border.
83 // If so, under WIN16 we can use Ctl3D to give it an appropriate style.
84 // Sometimes want3D is used to indicate that the non-extended style should have
85 // WS_BORDER.
86 bool want3D = TRUE;
3f2711d5 87
222594ea
VZ
88 // if no extended style given, determine it ourselves
89 if ( exstyle == (WXDWORD)-1 )
90 {
91 exstyle = GetExStyle(style, &want3D);
92 }
93
f6bcfd97 94 // all controls have these styles (wxWindows creates all controls visible
3f2711d5
VZ
95 // by default)
96 style |= WS_CHILD | WS_VISIBLE;
97
8d99be5f
VZ
98 m_hWnd = (WXHWND)::CreateWindowEx
99 (
222594ea 100 exstyle, // extended style
8d99be5f 101 classname, // the kind of control to create
222594ea 102 label, // the window name
8d99be5f 103 style, // the window style
222594ea
VZ
104 pos.x, pos.y, // the window position
105 size.x, size.y, // and size
8d99be5f
VZ
106 GetHwndOf(GetParent()), // parent
107 (HMENU)GetId(), // child id
108 wxGetInstance(), // app instance
109 NULL // creation parameters
110 );
111
112 if ( !m_hWnd )
113 {
f6bcfd97
BP
114 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname);
115 wxFAIL_MSG(_T("something is very wrong"));
8d99be5f
VZ
116
117 return FALSE;
118 }
119
3f2711d5
VZ
120#if wxUSE_CTL3D
121 if ( want3D )
122 {
123 Ctl3dSubclassCtl(GetHwnd());
124 m_useCtl3D = TRUE;
125 }
126#endif // wxUSE_CTL3D
127
8d99be5f
VZ
128 // subclass again for purposes of dialog editing mode
129 SubclassWin(m_hWnd);
130
131 // controls use the same font and colours as their parent dialog by default
132 InheritAttributes();
133
134 return TRUE;
135}
136
f68586e5 137wxSize wxControl::DoGetBestSize() const
4438caf4
VZ
138{
139 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
140}
141
42e69d6b 142bool wxControl::ProcessCommand(wxCommandEvent& event)
2bda0e17 143{
42e69d6b
VZ
144#if WXWIN_COMPATIBILITY
145 if ( m_callback )
146 {
d8ecfb85 147 (void)(*m_callback)(*this, event);
2bda0e17 148
42e69d6b
VZ
149 return TRUE;
150 }
151 else
152#endif // WXWIN_COMPATIBILITY
2bda0e17 153
42e69d6b 154 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
155}
156
a23fd0e1
VZ
157#ifdef __WIN95__
158bool wxControl::MSWOnNotify(int idCtrl,
159 WXLPARAM lParam,
160 WXLPARAM* result)
2bda0e17 161{
a23fd0e1
VZ
162 wxCommandEvent event(wxEVT_NULL, m_windowId);
163 wxEventType eventType = wxEVT_NULL;
164 NMHDR *hdr1 = (NMHDR*) lParam;
165 switch ( hdr1->code )
166 {
167 case NM_CLICK:
168 eventType = wxEVT_COMMAND_LEFT_CLICK;
169 break;
2bda0e17 170
a23fd0e1
VZ
171 case NM_DBLCLK:
172 eventType = wxEVT_COMMAND_LEFT_DCLICK;
173 break;
2bda0e17 174
a23fd0e1
VZ
175 case NM_RCLICK:
176 eventType = wxEVT_COMMAND_RIGHT_CLICK;
177 break;
2bda0e17 178
a23fd0e1
VZ
179 case NM_RDBLCLK:
180 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
181 break;
2bda0e17 182
a23fd0e1
VZ
183 case NM_SETFOCUS:
184 eventType = wxEVT_COMMAND_SET_FOCUS;
185 break;
debe6624 186
a23fd0e1
VZ
187 case NM_KILLFOCUS:
188 eventType = wxEVT_COMMAND_KILL_FOCUS;
189 break;
2bda0e17 190
a23fd0e1
VZ
191 case NM_RETURN:
192 eventType = wxEVT_COMMAND_ENTER;
193 break;
194
195 default:
196 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
197 }
fd3f686c 198
2bda0e17 199 event.SetEventType(eventType);
a23fd0e1 200 event.SetEventObject(this);
2bda0e17 201
a23fd0e1 202 return GetEventHandler()->ProcessEvent(event);
2bda0e17 203}
a23fd0e1 204#endif // Win95
2bda0e17 205
2bda0e17
KB
206void wxControl::OnEraseBackground(wxEraseEvent& event)
207{
5bd3a2da
VZ
208 // notice that this 'dumb' implementation may cause flicker for some of the
209 // controls in which case they should intercept wxEraseEvent and process it
210 // themselves somehow
42e69d6b
VZ
211
212 RECT rect;
3f2711d5 213 ::GetClientRect(GetHwnd(), &rect);
42e69d6b 214
3f2711d5 215 HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
42e69d6b 216
3f2711d5
VZ
217 HDC hdc = GetHdcOf((*event.GetDC()));
218 int mode = ::SetMapMode(hdc, MM_TEXT);
219
220 ::FillRect(hdc, &rect, hBrush);
42e69d6b 221 ::DeleteObject(hBrush);
3f2711d5 222 ::SetMapMode(hdc, mode);
2bda0e17
KB
223}
224
f048e32f
VZ
225WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
226 WXUINT message,
227 WXWPARAM wParam,
228 WXLPARAM lParam)
229{
230#if wxUSE_CTL3D
231 if ( m_useCtl3D )
232 {
233 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
234 return (WXHBRUSH) hbrush;
235 }
236#endif // wxUSE_CTL3D
237
238 HDC hdc = (HDC)pDC;
239 if (GetParent()->GetTransparentBackground())
240 SetBkMode(hdc, TRANSPARENT);
241 else
242 SetBkMode(hdc, OPAQUE);
243
f6bcfd97
BP
244 wxColour colBack = GetBackgroundColour();
245
f048e32f
VZ
246 ::SetBkColor(hdc, wxColourToRGB(colBack));
247 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
248
249 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
250
251 return (WXHBRUSH)brush->GetResourceHandle();
252}
253
3f2711d5 254WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const
8d99be5f 255{
3f2711d5 256 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D);
8d99be5f 257
3f2711d5
VZ
258 // Even with extended styles, need to combine with WS_BORDER for them to
259 // look right.
260 if ( *want3D || wxStyleHasBorder(m_windowStyle) )
8d99be5f
VZ
261 style |= WS_BORDER;
262
263 return exStyle;
264}
265
42e69d6b
VZ
266// ---------------------------------------------------------------------------
267// global functions
268// ---------------------------------------------------------------------------
2bda0e17 269
42e69d6b
VZ
270// Call this repeatedly for several wnds to find the overall size
271// of the widget.
272// Call it initially with -1 for all values in rect.
273// Keep calling for other widgets, and rect will be modified
274// to calculate largest bounding rectangle.
275void wxFindMaxSize(WXHWND wnd, RECT *rect)
2bda0e17 276{
42e69d6b
VZ
277 int left = rect->left;
278 int right = rect->right;
279 int top = rect->top;
280 int bottom = rect->bottom;
2bda0e17 281
42e69d6b 282 GetWindowRect((HWND) wnd, rect);
2bda0e17 283
42e69d6b
VZ
284 if (left < 0)
285 return;
2bda0e17 286
42e69d6b
VZ
287 if (left < rect->left)
288 rect->left = left;
2bda0e17 289
42e69d6b
VZ
290 if (right > rect->right)
291 rect->right = right;
2bda0e17 292
42e69d6b
VZ
293 if (top < rect->top)
294 rect->top = top;
2bda0e17 295
42e69d6b
VZ
296 if (bottom > rect->bottom)
297 rect->bottom = bottom;
2bda0e17
KB
298}
299