]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: combobox.cpp | |
3 | // Purpose: wxComboBox class | |
37f214d5 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
37f214d5 | 6 | // Created: 10/13/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
37f214d5 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
37f214d5 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
6670f564 | 16 | #include "wx/defs.h" |
a4a16252 | 17 | #include "wx/settings.h" |
0e320a79 DW |
18 | #endif |
19 | ||
37f214d5 DW |
20 | #if wxUSE_COMBOBOX |
21 | ||
0e320a79 | 22 | #include "wx/combobox.h" |
37f214d5 DW |
23 | #include "wx/clipbrd.h" |
24 | #include "wx/os2/private.h" | |
0e320a79 | 25 | |
0cf6acbf DW |
26 | #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1) |
27 | ||
28 | MRESULT EXPENTRY wxComboEditWndProc( HWND hWnd | |
29 | ,UINT uMessage | |
30 | ,MPARAM wParam | |
31 | ,MPARAM lParam | |
32 | ); | |
33 | // | |
34 | // The pointer to standard wnd proc | |
35 | // | |
36 | static WXFARPROC gfnWndprocEdit = (WXFARPROC)NULL; | |
37 | ||
0e320a79 | 38 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) |
0e320a79 | 39 | |
0cf6acbf DW |
40 | bool wxComboBox::OS2Command( |
41 | WXUINT uParam | |
42 | , WXWORD WXUNUSED(wId) | |
43 | ) | |
0e320a79 | 44 | { |
0cf6acbf DW |
45 | long lSel = -1L; |
46 | wxString sValue; | |
0e320a79 | 47 | |
0cf6acbf DW |
48 | switch (uParam) |
49 | { | |
1de4baa3 | 50 | case CBN_LBSELECT: |
0cf6acbf DW |
51 | if (GetSelection() > -1) |
52 | { | |
53 | wxCommandEvent vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED | |
54 | ,GetId() | |
55 | ); | |
56 | ||
57 | vEvent.SetInt(GetSelection()); | |
58 | vEvent.SetEventObject(this); | |
0fba44b4 | 59 | vEvent.SetString(GetStringSelection()); |
0cf6acbf DW |
60 | ProcessCommand(vEvent); |
61 | } | |
62 | break; | |
63 | ||
1de4baa3 | 64 | case CBN_EFCHANGE: |
0cf6acbf DW |
65 | { |
66 | wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED | |
67 | ,GetId() | |
68 | ); | |
69 | ||
70 | if (lSel == -1L) | |
71 | sValue = GetValue(); | |
72 | else | |
73 | SetValue(sValue); | |
0fba44b4 | 74 | vEvent.SetString(GetValue()); |
0cf6acbf DW |
75 | vEvent.SetEventObject(this); |
76 | ProcessCommand(vEvent); | |
77 | } | |
78 | break; | |
79 | } | |
80 | // | |
81 | // There is no return value for the CBN_ notifications, so always return | |
7d8268a1 | 82 | // false from here to pass the message to DefWindowProc() |
0cf6acbf | 83 | // |
7d8268a1 | 84 | return false; |
0cf6acbf DW |
85 | } // end of wxComboBox::OS2Command |
86 | ||
584ad2a3 MB |
87 | bool wxComboBox::Create( |
88 | wxWindow* pParent | |
89 | , wxWindowID vId | |
90 | , const wxString& rsValue | |
91 | , const wxPoint& rPos | |
92 | , const wxSize& rSize | |
93 | , const wxArrayString& asChoices | |
94 | , long lStyle | |
95 | , const wxValidator& rValidator | |
96 | , const wxString& rsName | |
97 | ) | |
98 | { | |
99 | wxCArrayString chs(asChoices); | |
100 | ||
101 | return Create(pParent, vId, rsValue, rPos, rSize, chs.GetCount(), | |
102 | chs.GetStrings(), lStyle, rValidator, rsName); | |
103 | } | |
104 | ||
0cf6acbf DW |
105 | bool wxComboBox::Create( |
106 | wxWindow* pParent | |
107 | , wxWindowID vId | |
108 | , const wxString& rsValue | |
109 | , const wxPoint& rPos | |
110 | , const wxSize& rSize | |
111 | , int n | |
112 | , const wxString asChoices[] | |
113 | , long lStyle | |
0cf6acbf | 114 | , const wxValidator& rValidator |
0cf6acbf DW |
115 | , const wxString& rsName |
116 | ) | |
0e320a79 | 117 | { |
7d8268a1 | 118 | m_isShown = false; |
0cf6acbf | 119 | |
b9b1d6c8 | 120 | if (!CreateControl( pParent |
0cf6acbf DW |
121 | ,vId |
122 | ,rPos | |
123 | ,rSize | |
124 | ,lStyle | |
0cf6acbf | 125 | ,rValidator |
0cf6acbf DW |
126 | ,rsName |
127 | )) | |
7d8268a1 | 128 | return false; |
0cf6acbf DW |
129 | |
130 | // | |
131 | // Get the right style | |
132 | // | |
133 | long lSstyle = 0L; | |
134 | ||
135 | lSstyle = WS_TABSTOP | | |
136 | WS_VISIBLE; | |
137 | ||
138 | if (lStyle & wxCLIP_SIBLINGS ) | |
139 | lSstyle |= WS_CLIPSIBLINGS; | |
140 | if (lStyle & wxCB_READONLY) | |
141 | lSstyle |= CBS_DROPDOWNLIST; | |
142 | else if (lStyle & wxCB_SIMPLE) | |
143 | lSstyle |= CBS_SIMPLE; // A list (shown always) and edit control | |
144 | else | |
145 | lSstyle |= CBS_DROPDOWN; | |
146 | ||
147 | ||
0fba44b4 | 148 | if (!OS2CreateControl( _T("COMBOBOX") |
0cf6acbf DW |
149 | ,lSstyle |
150 | )) | |
7d8268a1 | 151 | return false; |
0cf6acbf DW |
152 | |
153 | // | |
154 | // A choice/combobox normally has a white background (or other, depending | |
155 | // on global settings) rather than inheriting the parent's background colour. | |
156 | // | |
a756f210 | 157 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); |
0cf6acbf | 158 | |
cfcebdb1 | 159 | SetFont(*wxSMALL_FONT); |
0cf6acbf DW |
160 | |
161 | int i; | |
0cf6acbf DW |
162 | for (i = 0; i < n; i++) |
163 | { | |
164 | Append(asChoices[i]); | |
165 | } | |
166 | ||
167 | SetSize( rPos.x | |
168 | ,rPos.y | |
169 | ,rSize.x | |
170 | ,rSize.y | |
171 | ); | |
7d8268a1 | 172 | if (!rsValue.empty()) |
0cf6acbf DW |
173 | { |
174 | SetValue(rsValue); | |
175 | } | |
176 | gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd() | |
177 | ,(PFNWP)wxComboEditWndProc | |
178 | ); | |
5d44b24e | 179 | ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this); |
7d8268a1 WS |
180 | Show(true); |
181 | return true; | |
0cf6acbf DW |
182 | } // end of wxComboBox::Create |
183 | ||
184 | void wxComboBox::SetValue( | |
185 | const wxString& rsValue | |
186 | ) | |
0e320a79 | 187 | { |
2b5f62a0 VZ |
188 | if ( HasFlag(wxCB_READONLY) ) |
189 | SetStringSelection(rsValue); | |
0cf6acbf | 190 | else |
0fba44b4 | 191 | ::WinSetWindowText(GetHwnd(), (PSZ)rsValue.c_str()); |
0cf6acbf | 192 | } // end of wxComboBox::SetValue |
0e320a79 | 193 | |
0cf6acbf | 194 | // |
0e320a79 | 195 | // Clipboard operations |
0cf6acbf | 196 | // |
0e320a79 DW |
197 | void wxComboBox::Copy() |
198 | { | |
0cf6acbf DW |
199 | HWND hWnd = GetHwnd(); |
200 | ||
201 | ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0); | |
202 | } // end of wxComboBox::Copy | |
0e320a79 DW |
203 | |
204 | void wxComboBox::Cut() | |
205 | { | |
0cf6acbf DW |
206 | HWND hWnd = GetHwnd(); |
207 | ||
208 | ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0); | |
209 | } // end of wxComboBox::Cut | |
0e320a79 DW |
210 | |
211 | void wxComboBox::Paste() | |
212 | { | |
0cf6acbf | 213 | HWND hWnd = GetHwnd(); |
0e320a79 | 214 | |
0cf6acbf DW |
215 | ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0); |
216 | } // end of wxComboBox::Paste | |
217 | ||
218 | void wxComboBox::SetEditable( | |
219 | bool bEditable | |
220 | ) | |
0e320a79 | 221 | { |
0cf6acbf DW |
222 | HWND hWnd = GetHwnd(); |
223 | ||
224 | ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L); | |
225 | } // end of wxComboBox::SetEditable | |
0e320a79 | 226 | |
0cf6acbf DW |
227 | void wxComboBox::SetInsertionPoint( |
228 | long lPos | |
229 | ) | |
0e320a79 | 230 | { |
0cf6acbf DW |
231 | HWND hWnd = GetHwnd(); |
232 | ||
233 | ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0); | |
234 | } // end of wxComboBox::SetInsertionPoint | |
0e320a79 DW |
235 | |
236 | void wxComboBox::SetInsertionPointEnd() | |
237 | { | |
7d8268a1 | 238 | wxTextPos lPos = GetLastPosition(); |
0cf6acbf DW |
239 | |
240 | SetInsertionPoint(lPos); | |
241 | } // end of wxComboBox::SetInsertionPointEnd | |
0e320a79 DW |
242 | |
243 | long wxComboBox::GetInsertionPoint() const | |
244 | { | |
0cf6acbf DW |
245 | long lPos = LONGFROMMR(::WinSendMsg( GetHwnd() |
246 | ,LM_QUERYSELECTION | |
247 | ,(MPARAM)0 | |
248 | ,(MPARAM)0 | |
249 | )); | |
250 | if (lPos == LIT_NONE) | |
251 | return wxNOT_FOUND; | |
252 | return lPos; | |
253 | } // end of wxComboBox::GetInsertionPoint | |
0e320a79 | 254 | |
7d8268a1 | 255 | wxTextPos wxComboBox::GetLastPosition() const |
0e320a79 | 256 | { |
0cf6acbf DW |
257 | long lLineLength = 0L; |
258 | WNDPARAMS vParams; | |
0e320a79 | 259 | |
0cf6acbf DW |
260 | // |
261 | // Get number of characters in the last (only) line. We'll add this to the character | |
37f214d5 | 262 | // index for the last line, 1st position. |
0cf6acbf | 263 | // |
0e320a79 | 264 | |
0e320a79 | 265 | |
0cf6acbf DW |
266 | vParams.fsStatus = WPM_CCHTEXT; |
267 | if (::WinSendMsg( GetHwnd() | |
268 | ,WM_QUERYWINDOWPARAMS | |
269 | ,&vParams | |
270 | ,0 | |
271 | )) | |
272 | { | |
273 | lLineLength = (long)vParams.cchText; | |
274 | } | |
275 | else | |
276 | lLineLength = 0L; | |
277 | return lLineLength; | |
278 | } // end of wxComboBox::GetLastPosition | |
279 | ||
6670f564 WS |
280 | void wxComboBox::Replace( long lFrom, |
281 | long lTo, | |
282 | const wxString& rsValue ) | |
0e320a79 | 283 | { |
37f214d5 | 284 | #if wxUSE_CLIPBOARD |
0cf6acbf | 285 | HWND hWnd = GetHwnd(); |
0e320a79 | 286 | |
0cf6acbf | 287 | // |
37f214d5 | 288 | // Set selection and remove it |
0cf6acbf DW |
289 | // |
290 | ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0); | |
291 | ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0); | |
0e320a79 | 292 | |
0cf6acbf | 293 | // |
37f214d5 | 294 | // Now replace with 'value', by pasting. |
0cf6acbf DW |
295 | // |
296 | wxSetClipboardData( wxDF_TEXT | |
297 | ,(wxObject *)rsValue.c_str() | |
298 | ,0 | |
299 | ,0 | |
300 | ); | |
301 | ||
302 | // | |
37f214d5 | 303 | // Paste into edit control |
0cf6acbf DW |
304 | // |
305 | ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L); | |
6670f564 WS |
306 | #else |
307 | wxUnusedVar(lFrom); | |
308 | wxUnusedVar(lTo); | |
309 | wxUnusedVar(rsValue); | |
37f214d5 | 310 | #endif |
0cf6acbf | 311 | } // end of wxComboBox::Replace |
0e320a79 | 312 | |
6670f564 | 313 | void wxComboBox::Remove( long lFrom, long lTo) |
0e320a79 | 314 | { |
0cf6acbf DW |
315 | #if wxUSE_CLIPBOARD |
316 | HWND hWnd = GetHwnd(); | |
0e320a79 | 317 | |
0cf6acbf DW |
318 | ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0); |
319 | ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0); | |
6670f564 WS |
320 | #else |
321 | wxUnusedVar(lFrom); | |
322 | wxUnusedVar(lTo); | |
0cf6acbf DW |
323 | #endif |
324 | } // end of wxComboBox::Remove | |
0e320a79 | 325 | |
0cf6acbf DW |
326 | void wxComboBox::SetSelection( |
327 | long lFrom | |
328 | , long lTo | |
329 | ) | |
0e320a79 | 330 | { |
0cf6acbf | 331 | HWND hWnd = GetHwnd(); |
9923c37d DW |
332 | long lFromChar = 0; |
333 | long lToChar = 0; | |
0cf6acbf DW |
334 | |
335 | // | |
336 | // If from and to are both -1, it means | |
77ffb593 | 337 | // (in wxWidgets) that all text should be selected. |
37f214d5 | 338 | // This translates into Windows convention |
0cf6acbf DW |
339 | // |
340 | if ((lFrom == -1L) && (lTo == -1L)) | |
37f214d5 | 341 | { |
0cf6acbf DW |
342 | lFromChar = 0; |
343 | lToChar = -1; | |
37f214d5 DW |
344 | } |
345 | ||
0cf6acbf DW |
346 | ::WinSendMsg( hWnd |
347 | ,EM_SETSEL | |
348 | ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar) | |
349 | ,(MPARAM)0 | |
350 | ); | |
351 | } // end of wxComboBox::SetSelection | |
352 | ||
353 | void wxComboBox::DoSetSize( | |
354 | int nX | |
355 | , int nY | |
356 | , int nWidth | |
357 | , int nHeight | |
358 | , int nSizeFlags | |
359 | ) | |
360 | { | |
361 | wxControl::DoSetSize( nX | |
362 | ,nY | |
363 | ,nWidth | |
364 | ,nHeight | |
365 | ,nSizeFlags | |
366 | ); | |
367 | } // end of wxComboBox::DoSetSize | |
368 | ||
369 | bool wxComboBox::ProcessEditMsg( | |
370 | WXUINT uMsg | |
371 | , WXWPARAM wParam | |
372 | , WXLPARAM lParam) | |
0e320a79 | 373 | { |
0cf6acbf DW |
374 | SHORT vFlag; |
375 | switch (uMsg) | |
376 | { | |
377 | case WM_CHAR: | |
378 | vFlag = SHORT1FROMMP(wParam); | |
379 | switch(vFlag) | |
380 | { | |
381 | case KC_CHAR: | |
598d8cac | 382 | return (HandleChar( wParam |
0cf6acbf | 383 | ,lParam |
7d8268a1 | 384 | ,true /* isASCII */ |
0cf6acbf DW |
385 | )); |
386 | ||
387 | case KC_PREVDOWN: | |
a086de98 | 388 | return (HandleKeyDown( wParam |
0cf6acbf DW |
389 | ,lParam |
390 | )); | |
391 | ||
392 | case KC_KEYUP: | |
a086de98 | 393 | return (HandleKeyUp( wParam |
0cf6acbf DW |
394 | ,lParam |
395 | )); | |
396 | } | |
397 | break; | |
598d8cac DW |
398 | |
399 | case WM_SETFOCUS: | |
400 | if (SHORT1FROMMP((MPARAM)lParam) == TRUE) | |
401 | return(HandleSetFocus((WXHWND)(HWND)wParam)); | |
402 | else | |
403 | return(HandleKillFocus((WXHWND)(HWND)wParam)); | |
0cf6acbf | 404 | } |
7d8268a1 | 405 | return false; |
0cf6acbf DW |
406 | } // end of WinGuiBase_CComboBox::ProcessEditMsg |
407 | ||
408 | MRESULT EXPENTRY wxComboEditWndProc( | |
409 | HWND hWnd | |
410 | , UINT uMessage | |
411 | , MPARAM wParam | |
412 | , MPARAM lParam | |
413 | ) | |
414 | { | |
0cf6acbf DW |
415 | switch (uMessage) |
416 | { | |
417 | // | |
418 | // Forward some messages to the combobox | |
419 | // | |
598d8cac | 420 | case WM_SETFOCUS: |
0cf6acbf DW |
421 | case WM_CHAR: |
422 | { | |
d804ec69 SN |
423 | wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd |
424 | ,QWL_USER | |
425 | ); | |
0cf6acbf DW |
426 | |
427 | if (pCombo->ProcessEditMsg( uMessage | |
428 | ,wParam | |
429 | ,lParam | |
430 | )) | |
431 | return ((MRESULT)0); | |
432 | } | |
433 | break; | |
434 | ||
435 | // | |
436 | // TODO: Deal with tooltips here | |
437 | // | |
438 | } | |
439 | return (gfnWndprocEdit(hWnd, (ULONG)uMessage, (MPARAM)wParam, (MPARAM)lParam)); | |
440 | } // end of wxComboEditWndProc | |
37f214d5 DW |
441 | |
442 | #endif | |
443 | // wxUSE_COMBOBOX |