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