]>
Commit | Line | Data |
---|---|---|
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 |
38 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
39 | ||
40 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
a23fd0e1 | 41 | EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) |
2bda0e17 KB |
42 | END_EVENT_TABLE() |
43 | #endif | |
44 | ||
45 | // Item members | |
42e69d6b | 46 | wxControl::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 | 56 | wxControl::~wxControl() |
2bda0e17 | 57 | { |
42e69d6b | 58 | m_isBeingDeleted = TRUE; |
2bda0e17 KB |
59 | } |
60 | ||
222594ea VZ |
61 | bool wxControl::MSWCreateControl(const wxChar *classname, |
62 | WXDWORD style, | |
63 | const wxPoint& pos, | |
64 | const wxSize& size, | |
65 | const wxString& label, | |
66 | WXDWORD exstyle) | |
8d99be5f | 67 | { |
3f2711d5 VZ |
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 | ||
222594ea VZ |
72 | // if no extended style given, determine it ourselves |
73 | if ( exstyle == (WXDWORD)-1 ) | |
74 | { | |
75 | exstyle = GetExStyle(style, &want3D); | |
76 | } | |
77 | ||
3f2711d5 VZ |
78 | // all controls have these childs (wxWindows creates all controls visible |
79 | // by default) | |
80 | style |= WS_CHILD | WS_VISIBLE; | |
81 | ||
8d99be5f VZ |
82 | m_hWnd = (WXHWND)::CreateWindowEx |
83 | ( | |
222594ea | 84 | exstyle, // extended style |
8d99be5f | 85 | classname, // the kind of control to create |
222594ea | 86 | label, // the window name |
8d99be5f | 87 | style, // the window style |
222594ea VZ |
88 | pos.x, pos.y, // the window position |
89 | size.x, size.y, // and size | |
8d99be5f VZ |
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__ | |
223d09f6 | 99 | wxLogError(wxT("Failed to create a control of class '%s'"), classname); |
8d99be5f VZ |
100 | #endif // DEBUG |
101 | ||
102 | return FALSE; | |
103 | } | |
104 | ||
3f2711d5 VZ |
105 | #if wxUSE_CTL3D |
106 | if ( want3D ) | |
107 | { | |
108 | Ctl3dSubclassCtl(GetHwnd()); | |
109 | m_useCtl3D = TRUE; | |
110 | } | |
111 | #endif // wxUSE_CTL3D | |
112 | ||
8d99be5f VZ |
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 | ||
f68586e5 | 122 | wxSize wxControl::DoGetBestSize() const |
4438caf4 VZ |
123 | { |
124 | return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); | |
125 | } | |
126 | ||
42e69d6b | 127 | bool wxControl::ProcessCommand(wxCommandEvent& event) |
2bda0e17 | 128 | { |
42e69d6b VZ |
129 | #if WXWIN_COMPATIBILITY |
130 | if ( m_callback ) | |
131 | { | |
132 | (void)(*m_callback)(this, event); | |
2bda0e17 | 133 | |
42e69d6b VZ |
134 | return TRUE; |
135 | } | |
136 | else | |
137 | #endif // WXWIN_COMPATIBILITY | |
2bda0e17 | 138 | |
42e69d6b | 139 | return GetEventHandler()->ProcessEvent(event); |
2bda0e17 KB |
140 | } |
141 | ||
a23fd0e1 VZ |
142 | #ifdef __WIN95__ |
143 | bool wxControl::MSWOnNotify(int idCtrl, | |
144 | WXLPARAM lParam, | |
145 | WXLPARAM* result) | |
2bda0e17 | 146 | { |
a23fd0e1 VZ |
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; | |
2bda0e17 | 155 | |
a23fd0e1 VZ |
156 | case NM_DBLCLK: |
157 | eventType = wxEVT_COMMAND_LEFT_DCLICK; | |
158 | break; | |
2bda0e17 | 159 | |
a23fd0e1 VZ |
160 | case NM_RCLICK: |
161 | eventType = wxEVT_COMMAND_RIGHT_CLICK; | |
162 | break; | |
2bda0e17 | 163 | |
a23fd0e1 VZ |
164 | case NM_RDBLCLK: |
165 | eventType = wxEVT_COMMAND_RIGHT_DCLICK; | |
166 | break; | |
2bda0e17 | 167 | |
a23fd0e1 VZ |
168 | case NM_SETFOCUS: |
169 | eventType = wxEVT_COMMAND_SET_FOCUS; | |
170 | break; | |
debe6624 | 171 | |
a23fd0e1 VZ |
172 | case NM_KILLFOCUS: |
173 | eventType = wxEVT_COMMAND_KILL_FOCUS; | |
174 | break; | |
2bda0e17 | 175 | |
a23fd0e1 VZ |
176 | case NM_RETURN: |
177 | eventType = wxEVT_COMMAND_ENTER; | |
178 | break; | |
179 | ||
180 | default: | |
181 | return wxWindow::MSWOnNotify(idCtrl, lParam, result); | |
182 | } | |
fd3f686c | 183 | |
2bda0e17 | 184 | event.SetEventType(eventType); |
a23fd0e1 | 185 | event.SetEventObject(this); |
2bda0e17 | 186 | |
a23fd0e1 | 187 | return GetEventHandler()->ProcessEvent(event); |
2bda0e17 | 188 | } |
a23fd0e1 | 189 | #endif // Win95 |
2bda0e17 | 190 | |
2bda0e17 KB |
191 | void wxControl::OnEraseBackground(wxEraseEvent& event) |
192 | { | |
42e69d6b VZ |
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; | |
3f2711d5 | 199 | ::GetClientRect(GetHwnd(), &rect); |
42e69d6b | 200 | |
3f2711d5 | 201 | HBRUSH hBrush = ::CreateSolidBrush(wxColourToRGB(GetBackgroundColour())); |
42e69d6b | 202 | |
3f2711d5 VZ |
203 | HDC hdc = GetHdcOf((*event.GetDC())); |
204 | int mode = ::SetMapMode(hdc, MM_TEXT); | |
205 | ||
206 | ::FillRect(hdc, &rect, hBrush); | |
42e69d6b | 207 | ::DeleteObject(hBrush); |
3f2711d5 | 208 | ::SetMapMode(hdc, mode); |
2bda0e17 KB |
209 | } |
210 | ||
3f2711d5 | 211 | WXDWORD wxControl::GetExStyle(WXDWORD& style, bool *want3D) const |
8d99be5f | 212 | { |
3f2711d5 | 213 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, want3D); |
8d99be5f | 214 | |
3f2711d5 VZ |
215 | // Even with extended styles, need to combine with WS_BORDER for them to |
216 | // look right. | |
217 | if ( *want3D || wxStyleHasBorder(m_windowStyle) ) | |
8d99be5f VZ |
218 | style |= WS_BORDER; |
219 | ||
220 | return exStyle; | |
221 | } | |
222 | ||
42e69d6b VZ |
223 | // --------------------------------------------------------------------------- |
224 | // global functions | |
225 | // --------------------------------------------------------------------------- | |
2bda0e17 | 226 | |
42e69d6b VZ |
227 | // Call this repeatedly for several wnds to find the overall size |
228 | // of the widget. | |
229 | // Call it initially with -1 for all values in rect. | |
230 | // Keep calling for other widgets, and rect will be modified | |
231 | // to calculate largest bounding rectangle. | |
232 | void wxFindMaxSize(WXHWND wnd, RECT *rect) | |
2bda0e17 | 233 | { |
42e69d6b VZ |
234 | int left = rect->left; |
235 | int right = rect->right; | |
236 | int top = rect->top; | |
237 | int bottom = rect->bottom; | |
2bda0e17 | 238 | |
42e69d6b | 239 | GetWindowRect((HWND) wnd, rect); |
2bda0e17 | 240 | |
42e69d6b VZ |
241 | if (left < 0) |
242 | return; | |
2bda0e17 | 243 | |
42e69d6b VZ |
244 | if (left < rect->left) |
245 | rect->left = left; | |
2bda0e17 | 246 | |
42e69d6b VZ |
247 | if (right > rect->right) |
248 | rect->right = right; | |
2bda0e17 | 249 | |
42e69d6b VZ |
250 | if (top < rect->top) |
251 | rect->top = top; | |
2bda0e17 | 252 | |
42e69d6b VZ |
253 | if (bottom > rect->bottom) |
254 | rect->bottom = bottom; | |
2bda0e17 KB |
255 | } |
256 |