]> git.saurik.com Git - wxWidgets.git/blame - src/msw/control.cpp
Distrib changes.
[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
65fd5cb0 33#if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
2bda0e17
KB
34#include <commctrl.h>
35#endif
36
2bda0e17
KB
37#if !USE_SHARED_LIBRARY
38IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
39
40BEGIN_EVENT_TABLE(wxControl, wxWindow)
a23fd0e1 41 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
2bda0e17
KB
42END_EVENT_TABLE()
43#endif
44
45// Item members
42e69d6b 46wxControl::wxControl()
2bda0e17 47{
3f2711d5
VZ
48 m_backgroundColour = *wxWHITE;
49 m_foregroundColour = *wxBLACK;
42e69d6b
VZ
50
51#if WXWIN_COMPATIBILITY
3f2711d5 52 m_callback = 0;
42e69d6b 53#endif // WXWIN_COMPATIBILITY
2bda0e17
KB
54}
55
42e69d6b 56wxControl::~wxControl()
2bda0e17 57{
42e69d6b 58 m_isBeingDeleted = TRUE;
2bda0e17
KB
59}
60
8d99be5f
VZ
61bool wxControl::MSWCreateControl(const wxChar *classname, WXDWORD style)
62{
3f2711d5
VZ
63 // VZ: if someone could put a comment here explaining what exactly this is
64 // needed for, it would be nice...
65 bool want3D;
66
67 // all controls have these childs (wxWindows creates all controls visible
68 // by default)
69 style |= WS_CHILD | WS_VISIBLE;
70
8d99be5f
VZ
71 m_hWnd = (WXHWND)::CreateWindowEx
72 (
3f2711d5 73 GetExStyle(style, &want3D), // extended style
8d99be5f
VZ
74 classname, // the kind of control to create
75 NULL, // the window name
76 style, // the window style
77 0, 0, 0, 0, // the window position and size
78 GetHwndOf(GetParent()), // parent
79 (HMENU)GetId(), // child id
80 wxGetInstance(), // app instance
81 NULL // creation parameters
82 );
83
84 if ( !m_hWnd )
85 {
86#ifdef __WXDEBUG__
223d09f6 87 wxLogError(wxT("Failed to create a control of class '%s'"), classname);
8d99be5f
VZ
88#endif // DEBUG
89
90 return FALSE;
91 }
92
3f2711d5
VZ
93#if wxUSE_CTL3D
94 if ( want3D )
95 {
96 Ctl3dSubclassCtl(GetHwnd());
97 m_useCtl3D = TRUE;
98 }
99#endif // wxUSE_CTL3D
100
8d99be5f
VZ
101 // subclass again for purposes of dialog editing mode
102 SubclassWin(m_hWnd);
103
104 // controls use the same font and colours as their parent dialog by default
105 InheritAttributes();
106
107 return TRUE;
108}
109
4438caf4
VZ
110wxSize wxControl::DoGetBestSize()
111{
112 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
113}
114
42e69d6b 115bool wxControl::ProcessCommand(wxCommandEvent& event)
2bda0e17 116{
42e69d6b
VZ
117#if WXWIN_COMPATIBILITY
118 if ( m_callback )
119 {
120 (void)(*m_callback)(this, event);
2bda0e17 121
42e69d6b
VZ
122 return TRUE;
123 }
124 else
125#endif // WXWIN_COMPATIBILITY
2bda0e17 126
42e69d6b 127 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
128}
129
a23fd0e1
VZ
130#ifdef __WIN95__
131bool wxControl::MSWOnNotify(int idCtrl,
132 WXLPARAM lParam,
133 WXLPARAM* result)
2bda0e17 134{
a23fd0e1
VZ
135 wxCommandEvent event(wxEVT_NULL, m_windowId);
136 wxEventType eventType = wxEVT_NULL;
137 NMHDR *hdr1 = (NMHDR*) lParam;
138 switch ( hdr1->code )
139 {
140 case NM_CLICK:
141 eventType = wxEVT_COMMAND_LEFT_CLICK;
142 break;
2bda0e17 143
a23fd0e1
VZ
144 case NM_DBLCLK:
145 eventType = wxEVT_COMMAND_LEFT_DCLICK;
146 break;
2bda0e17 147
a23fd0e1
VZ
148 case NM_RCLICK:
149 eventType = wxEVT_COMMAND_RIGHT_CLICK;
150 break;
2bda0e17 151
a23fd0e1
VZ
152 case NM_RDBLCLK:
153 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
154 break;
2bda0e17 155
a23fd0e1
VZ
156 case NM_SETFOCUS:
157 eventType = wxEVT_COMMAND_SET_FOCUS;
158 break;
debe6624 159
a23fd0e1
VZ
160 case NM_KILLFOCUS:
161 eventType = wxEVT_COMMAND_KILL_FOCUS;
162 break;
2bda0e17 163
a23fd0e1
VZ
164 case NM_RETURN:
165 eventType = wxEVT_COMMAND_ENTER;
166 break;
167
168 default:
169 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
170 }
fd3f686c 171
2bda0e17 172 event.SetEventType(eventType);
a23fd0e1 173 event.SetEventObject(this);
2bda0e17 174
a23fd0e1 175 return GetEventHandler()->ProcessEvent(event);
2bda0e17 176}
a23fd0e1 177#endif // Win95
2bda0e17 178
2bda0e17
KB
179void wxControl::OnEraseBackground(wxEraseEvent& event)
180{
42e69d6b
VZ
181 // In general, you don't want to erase the background of a control,
182 // or you'll get a flicker.
183 // TODO: move this 'null' function into each control that
184 // might flicker.
185
186 RECT rect;
3f2711d5 187 ::GetClientRect(GetHwnd(), &rect);
42e69d6b 188
3f2711d5 189 HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
42e69d6b 190
3f2711d5
VZ
191 HDC hdc = GetHdcOf((*event.GetDC()));
192 int mode = ::SetMapMode(hdc, MM_TEXT);
193
194 ::FillRect(hdc, &rect, hBrush);
42e69d6b 195 ::DeleteObject(hBrush);
3f2711d5 196 ::SetMapMode(hdc, mode);
2bda0e17
KB
197}
198
3f2711d5 199WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const
8d99be5f 200{
3f2711d5 201 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D);
8d99be5f 202
3f2711d5
VZ
203 // Even with extended styles, need to combine with WS_BORDER for them to
204 // look right.
205 if ( *want3D || wxStyleHasBorder(m_windowStyle) )
8d99be5f
VZ
206 style |= WS_BORDER;
207
208 return exStyle;
209}
210
42e69d6b
VZ
211// ---------------------------------------------------------------------------
212// global functions
213// ---------------------------------------------------------------------------
2bda0e17 214
42e69d6b
VZ
215// Call this repeatedly for several wnds to find the overall size
216// of the widget.
217// Call it initially with -1 for all values in rect.
218// Keep calling for other widgets, and rect will be modified
219// to calculate largest bounding rectangle.
220void wxFindMaxSize(WXHWND wnd, RECT *rect)
2bda0e17 221{
42e69d6b
VZ
222 int left = rect->left;
223 int right = rect->right;
224 int top = rect->top;
225 int bottom = rect->bottom;
2bda0e17 226
42e69d6b 227 GetWindowRect((HWND) wnd, rect);
2bda0e17 228
42e69d6b
VZ
229 if (left < 0)
230 return;
2bda0e17 231
42e69d6b
VZ
232 if (left < rect->left)
233 rect->left = left;
2bda0e17 234
42e69d6b
VZ
235 if (right > rect->right)
236 rect->right = right;
2bda0e17 237
42e69d6b
VZ
238 if (top < rect->top)
239 rect->top = top;
2bda0e17 240
42e69d6b
VZ
241 if (bottom > rect->bottom)
242 rect->bottom = bottom;
2bda0e17
KB
243}
244