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