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