]> git.saurik.com Git - wxWidgets.git/blame - src/msw/control.cpp
fixes for page positioning for notebooks with wxNB_MULTILINE style (closes bugs 70909...
[wxWidgets.git] / src / msw / control.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: msw/control.cpp
2bda0e17
KB
3// Purpose: wxControl class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
a23fd0e1 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1e6feb95 13 #pragma implementation "control.h"
2bda0e17
KB
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
1e6feb95 20 #pragma hdrstop
2bda0e17
KB
21#endif
22
1e6feb95
VZ
23#if wxUSE_CONTROLS
24
2bda0e17 25#ifndef WX_PRECOMP
1e6feb95
VZ
26 #include "wx/event.h"
27 #include "wx/app.h"
28 #include "wx/dcclient.h"
29 #include "wx/log.h"
2bda0e17
KB
30#endif
31
2432b92d
JS
32#include "wx/control.h"
33
2bda0e17
KB
34#include "wx/msw/private.h"
35
b39dbf34 36#if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
c42404a5 37 #include <commctrl.h>
2bda0e17
KB
38#endif
39
2bda0e17
KB
40IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
41
42BEGIN_EVENT_TABLE(wxControl, wxWindow)
a23fd0e1 43 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
2bda0e17 44END_EVENT_TABLE()
2bda0e17
KB
45
46// Item members
42e69d6b 47wxControl::wxControl()
2bda0e17 48{
2bda0e17
KB
49}
50
42e69d6b 51wxControl::~wxControl()
2bda0e17 52{
42e69d6b 53 m_isBeingDeleted = TRUE;
2bda0e17
KB
54}
55
8d772832 56
5b2f31eb
VZ
57bool wxControl::Create(wxWindow *parent,
58 wxWindowID id,
8d772832 59 const wxPoint& pos,
5b2f31eb
VZ
60 const wxSize& size,
61 long style,
ac8d0c11 62 const wxValidator& wxVALIDATOR_PARAM(validator),
8d772832
RD
63 const wxString& name)
64{
5b2f31eb
VZ
65 if ( !wxWindow::Create(parent, id, pos, size, style, name) )
66 return FALSE;
67
8d772832 68#if wxUSE_VALIDATORS
5b2f31eb 69 SetValidator(validator);
8d772832 70#endif
5b2f31eb
VZ
71
72 return TRUE;
73}
74
75bool wxControl::MSWCreateControl(const wxChar *classname,
76 const wxString& label,
77 const wxPoint& pos,
6dd16e4f 78 const wxSize& size)
5b2f31eb
VZ
79{
80 WXDWORD exstyle;
6dd16e4f 81 WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), &exstyle);
5b2f31eb 82
2eb4c3aa 83 return MSWCreateControl(classname, msStyle, pos, size, label, exstyle);
8d772832
RD
84}
85
222594ea
VZ
86bool wxControl::MSWCreateControl(const wxChar *classname,
87 WXDWORD style,
88 const wxPoint& pos,
89 const wxSize& size,
90 const wxString& label,
2eb4c3aa 91 WXDWORD exstyle)
8d99be5f 92{
222594ea
VZ
93 // if no extended style given, determine it ourselves
94 if ( exstyle == (WXDWORD)-1 )
95 {
fe3d9123 96 exstyle = 0;
65bc172c 97 (void) MSWGetStyle(GetWindowStyle(), &exstyle);
222594ea
VZ
98 }
99
bdf5c30d
VZ
100 // all controls should have this style
101 style |= WS_CHILD;
102
103 // create the control visible if it's currently shown for wxWindows
104 if ( m_isShown )
105 {
106 style |= WS_VISIBLE;
107 }
3f2711d5 108
4e9d23cd 109 // choose the position for the control
a63cbfa3
VZ
110 int x = pos.x == -1 ? 0 : pos.x,
111 y = pos.y == -1 ? 0 : pos.y,
112 w = size.x == -1 ? 0 : size.x,
113 h = size.y == -1 ? 0 : size.y;
114
4e9d23cd
VZ
115 // ... and adjust it to account for ap ossible parent frames toolbar
116 AdjustForParentClientOrigin(x, y);
117
8d99be5f
VZ
118 m_hWnd = (WXHWND)::CreateWindowEx
119 (
222594ea 120 exstyle, // extended style
8d99be5f 121 classname, // the kind of control to create
222594ea 122 label, // the window name
8d99be5f 123 style, // the window style
a63cbfa3 124 x, y, w, h, // the window position and size
8d99be5f
VZ
125 GetHwndOf(GetParent()), // parent
126 (HMENU)GetId(), // child id
127 wxGetInstance(), // app instance
128 NULL // creation parameters
129 );
130
131 if ( !m_hWnd )
132 {
f6bcfd97
BP
133 wxLogDebug(wxT("Failed to create a control of class '%s'"), classname);
134 wxFAIL_MSG(_T("something is very wrong"));
8d99be5f
VZ
135
136 return FALSE;
137 }
138
3f2711d5
VZ
139#if wxUSE_CTL3D
140 if ( want3D )
141 {
142 Ctl3dSubclassCtl(GetHwnd());
143 m_useCtl3D = TRUE;
144 }
145#endif // wxUSE_CTL3D
146
b225f659 147 // install wxWindows window proc for this window
8d99be5f
VZ
148 SubclassWin(m_hWnd);
149
150 // controls use the same font and colours as their parent dialog by default
151 InheritAttributes();
152
a63cbfa3 153 // set the size now if no initial size specified
d45720c5 154 if ( w <= 0 || h <= 0 )
a63cbfa3
VZ
155 {
156 SetBestSize(size);
157 }
158
8d99be5f
VZ
159 return TRUE;
160}
161
65bc172c
VZ
162wxBorder wxControl::GetDefaultBorder() const
163{
164 // we want to automatically give controls a sunken style (confusingly,
165 // it may not really mean sunken at all as we map it to WS_EX_CLIENTEDGE
166 // which is not sunken at all under Windows XP -- rather, just the default)
167 return wxBORDER_SUNKEN;
168}
169
f68586e5 170wxSize wxControl::DoGetBestSize() const
4438caf4
VZ
171{
172 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
173}
174
42e69d6b 175bool wxControl::ProcessCommand(wxCommandEvent& event)
2bda0e17 176{
42e69d6b 177 return GetEventHandler()->ProcessEvent(event);
2bda0e17
KB
178}
179
a23fd0e1
VZ
180#ifdef __WIN95__
181bool wxControl::MSWOnNotify(int idCtrl,
182 WXLPARAM lParam,
183 WXLPARAM* result)
2bda0e17 184{
a23fd0e1 185 wxEventType eventType = wxEVT_NULL;
b6e5eaa5
VZ
186
187 NMHDR *hdr = (NMHDR*) lParam;
188 switch ( hdr->code )
a23fd0e1
VZ
189 {
190 case NM_CLICK:
191 eventType = wxEVT_COMMAND_LEFT_CLICK;
192 break;
2bda0e17 193
a23fd0e1
VZ
194 case NM_DBLCLK:
195 eventType = wxEVT_COMMAND_LEFT_DCLICK;
196 break;
2bda0e17 197
a23fd0e1
VZ
198 case NM_RCLICK:
199 eventType = wxEVT_COMMAND_RIGHT_CLICK;
200 break;
2bda0e17 201
a23fd0e1
VZ
202 case NM_RDBLCLK:
203 eventType = wxEVT_COMMAND_RIGHT_DCLICK;
204 break;
2bda0e17 205
a23fd0e1
VZ
206 case NM_SETFOCUS:
207 eventType = wxEVT_COMMAND_SET_FOCUS;
208 break;
debe6624 209
a23fd0e1
VZ
210 case NM_KILLFOCUS:
211 eventType = wxEVT_COMMAND_KILL_FOCUS;
212 break;
2bda0e17 213
a23fd0e1
VZ
214 case NM_RETURN:
215 eventType = wxEVT_COMMAND_ENTER;
216 break;
217
218 default:
219 return wxWindow::MSWOnNotify(idCtrl, lParam, result);
220 }
fd3f686c 221
b6e5eaa5 222 wxCommandEvent event(wxEVT_NULL, m_windowId);
2bda0e17 223 event.SetEventType(eventType);
a23fd0e1 224 event.SetEventObject(this);
2bda0e17 225
a23fd0e1 226 return GetEventHandler()->ProcessEvent(event);
2bda0e17 227}
a23fd0e1 228#endif // Win95
2bda0e17 229
2bda0e17
KB
230void wxControl::OnEraseBackground(wxEraseEvent& event)
231{
5bd3a2da
VZ
232 // notice that this 'dumb' implementation may cause flicker for some of the
233 // controls in which case they should intercept wxEraseEvent and process it
234 // themselves somehow
42e69d6b
VZ
235
236 RECT rect;
3f2711d5 237 ::GetClientRect(GetHwnd(), &rect);
42e69d6b 238
3f2711d5 239 HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour()));
42e69d6b 240
3f2711d5 241 HDC hdc = GetHdcOf((*event.GetDC()));
4676948b
JS
242
243#ifndef __WXWINCE__
3f2711d5 244 int mode = ::SetMapMode(hdc, MM_TEXT);
4676948b 245#endif
3f2711d5
VZ
246
247 ::FillRect(hdc, &rect, hBrush);
42e69d6b 248 ::DeleteObject(hBrush);
4676948b
JS
249
250#ifndef __WXWINCE__
3f2711d5 251 ::SetMapMode(hdc, mode);
4676948b 252#endif
2bda0e17
KB
253}
254
33ac7e6f 255WXHBRUSH wxControl::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
788722ac
JS
256#if wxUSE_CTL3D
257 WXUINT message,
258 WXWPARAM wParam,
259 WXLPARAM lParam
260#else
33ac7e6f
KB
261 WXUINT WXUNUSED(message),
262 WXWPARAM WXUNUSED(wParam),
788722ac
JS
263 WXLPARAM WXUNUSED(lParam)
264#endif
265 )
f048e32f
VZ
266{
267#if wxUSE_CTL3D
268 if ( m_useCtl3D )
269 {
270 HBRUSH hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
271 return (WXHBRUSH) hbrush;
272 }
273#endif // wxUSE_CTL3D
274
275 HDC hdc = (HDC)pDC;
f6bcfd97
BP
276 wxColour colBack = GetBackgroundColour();
277
f048e32f
VZ
278 ::SetBkColor(hdc, wxColourToRGB(colBack));
279 ::SetTextColor(hdc, wxColourToRGB(GetForegroundColour()));
280
281 wxBrush *brush = wxTheBrushList->FindOrCreateBrush(colBack, wxSOLID);
282
283 return (WXHBRUSH)brush->GetResourceHandle();
284}
285
5b2f31eb 286WXDWORD wxControl::MSWGetStyle(long style, WXDWORD *exstyle) const
8d99be5f 287{
5b2f31eb 288 long msStyle = wxWindow::MSWGetStyle(style, exstyle);
8d99be5f 289
5b2f31eb
VZ
290 if ( AcceptsFocus() )
291 {
292 msStyle |= WS_TABSTOP;
293 }
8d99be5f 294
5b2f31eb 295 return msStyle;
8d99be5f
VZ
296}
297
42e69d6b
VZ
298// ---------------------------------------------------------------------------
299// global functions
300// ---------------------------------------------------------------------------
2bda0e17 301
42e69d6b
VZ
302// Call this repeatedly for several wnds to find the overall size
303// of the widget.
304// Call it initially with -1 for all values in rect.
305// Keep calling for other widgets, and rect will be modified
306// to calculate largest bounding rectangle.
307void wxFindMaxSize(WXHWND wnd, RECT *rect)
2bda0e17 308{
42e69d6b
VZ
309 int left = rect->left;
310 int right = rect->right;
311 int top = rect->top;
312 int bottom = rect->bottom;
2bda0e17 313
42e69d6b 314 GetWindowRect((HWND) wnd, rect);
2bda0e17 315
42e69d6b
VZ
316 if (left < 0)
317 return;
2bda0e17 318
42e69d6b
VZ
319 if (left < rect->left)
320 rect->left = left;
2bda0e17 321
42e69d6b
VZ
322 if (right > rect->right)
323 rect->right = right;
2bda0e17 324
42e69d6b
VZ
325 if (top < rect->top)
326 rect->top = top;
2bda0e17 327
42e69d6b
VZ
328 if (bottom > rect->bottom)
329 rect->bottom = bottom;
2bda0e17
KB
330}
331
1e6feb95 332#endif // wxUSE_CONTROLS