]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
Unused warning fix.
[wxWidgets.git] / src / os2 / combobox.cpp
CommitLineData
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#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
30MRESULT EXPENTRY wxComboEditWndProc( HWND hWnd
31 ,UINT uMessage
32 ,MPARAM wParam
33 ,MPARAM lParam
34 );
35//
36// The pointer to standard wnd proc
37//
38static WXFARPROC gfnWndprocEdit = (WXFARPROC)NULL;
39
0e320a79 40IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
0e320a79 41
0cf6acbf
DW
42bool 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
584ad2a3
MB
89bool wxComboBox::Create(
90 wxWindow* pParent
91, wxWindowID vId
92, const wxString& rsValue
93, const wxPoint& rPos
94, const wxSize& rSize
95, const wxArrayString& asChoices
96, long lStyle
97, const wxValidator& rValidator
98, const wxString& rsName
99)
100{
101 wxCArrayString chs(asChoices);
102
103 return Create(pParent, vId, rsValue, rPos, rSize, chs.GetCount(),
104 chs.GetStrings(), lStyle, rValidator, rsName);
105}
106
0cf6acbf
DW
107bool wxComboBox::Create(
108 wxWindow* pParent
109, wxWindowID vId
110, const wxString& rsValue
111, const wxPoint& rPos
112, const wxSize& rSize
113, int n
114, const wxString asChoices[]
115, long lStyle
0cf6acbf 116, const wxValidator& rValidator
0cf6acbf
DW
117, const wxString& rsName
118)
0e320a79 119{
cfcebdb1 120 m_isShown = FALSE;
0cf6acbf 121
b9b1d6c8 122 if (!CreateControl( pParent
0cf6acbf
DW
123 ,vId
124 ,rPos
125 ,rSize
126 ,lStyle
0cf6acbf 127 ,rValidator
0cf6acbf
DW
128 ,rsName
129 ))
130 return FALSE;
131
132 //
133 // Get the right style
134 //
135 long lSstyle = 0L;
136
137 lSstyle = WS_TABSTOP |
138 WS_VISIBLE;
139
140 if (lStyle & wxCLIP_SIBLINGS )
141 lSstyle |= WS_CLIPSIBLINGS;
142 if (lStyle & wxCB_READONLY)
143 lSstyle |= CBS_DROPDOWNLIST;
144 else if (lStyle & wxCB_SIMPLE)
145 lSstyle |= CBS_SIMPLE; // A list (shown always) and edit control
146 else
147 lSstyle |= CBS_DROPDOWN;
148
149
150 if (!OS2CreateControl( "COMBOBOX"
151 ,lSstyle
152 ))
153 return FALSE;
154
155 //
156 // A choice/combobox normally has a white background (or other, depending
157 // on global settings) rather than inheriting the parent's background colour.
158 //
a756f210 159 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
0cf6acbf 160
cfcebdb1 161 SetFont(*wxSMALL_FONT);
0cf6acbf
DW
162
163 int i;
0cf6acbf
DW
164 for (i = 0; i < n; i++)
165 {
166 Append(asChoices[i]);
167 }
168
169 SetSize( rPos.x
170 ,rPos.y
171 ,rSize.x
172 ,rSize.y
173 );
174 if (!rsValue.IsEmpty())
175 {
176 SetValue(rsValue);
177 }
178 gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd()
179 ,(PFNWP)wxComboEditWndProc
180 );
5d44b24e 181 ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
cfcebdb1 182 Show(TRUE);
0cf6acbf
DW
183 return TRUE;
184} // end of wxComboBox::Create
185
186void wxComboBox::SetValue(
187 const wxString& rsValue
188)
0e320a79 189{
2b5f62a0
VZ
190 if ( HasFlag(wxCB_READONLY) )
191 SetStringSelection(rsValue);
0cf6acbf
DW
192 else
193 ::WinSetWindowText(GetHwnd(), rsValue.c_str());
194} // end of wxComboBox::SetValue
0e320a79 195
0cf6acbf 196//
0e320a79 197// Clipboard operations
0cf6acbf 198//
0e320a79
DW
199void wxComboBox::Copy()
200{
0cf6acbf
DW
201 HWND hWnd = GetHwnd();
202
203 ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0);
204} // end of wxComboBox::Copy
0e320a79
DW
205
206void wxComboBox::Cut()
207{
0cf6acbf
DW
208 HWND hWnd = GetHwnd();
209
210 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
211} // end of wxComboBox::Cut
0e320a79
DW
212
213void wxComboBox::Paste()
214{
0cf6acbf 215 HWND hWnd = GetHwnd();
0e320a79 216
0cf6acbf
DW
217 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
218} // end of wxComboBox::Paste
219
220void wxComboBox::SetEditable(
221 bool bEditable
222)
0e320a79 223{
0cf6acbf
DW
224 HWND hWnd = GetHwnd();
225
226 ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L);
227} // end of wxComboBox::SetEditable
0e320a79 228
0cf6acbf
DW
229void wxComboBox::SetInsertionPoint(
230 long lPos
231)
0e320a79 232{
0cf6acbf
DW
233 HWND hWnd = GetHwnd();
234
235 ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0);
236} // end of wxComboBox::SetInsertionPoint
0e320a79
DW
237
238void wxComboBox::SetInsertionPointEnd()
239{
0cf6acbf
DW
240 long lPos = GetLastPosition();
241
242 SetInsertionPoint(lPos);
243} // end of wxComboBox::SetInsertionPointEnd
0e320a79
DW
244
245long wxComboBox::GetInsertionPoint() const
246{
0cf6acbf
DW
247 long lPos = LONGFROMMR(::WinSendMsg( GetHwnd()
248 ,LM_QUERYSELECTION
249 ,(MPARAM)0
250 ,(MPARAM)0
251 ));
252 if (lPos == LIT_NONE)
253 return wxNOT_FOUND;
254 return lPos;
255} // end of wxComboBox::GetInsertionPoint
0e320a79
DW
256
257long wxComboBox::GetLastPosition() const
258{
0cf6acbf
DW
259 long lLineLength = 0L;
260 WNDPARAMS vParams;
0e320a79 261
0cf6acbf
DW
262 //
263 // Get number of characters in the last (only) line. We'll add this to the character
37f214d5 264 // index for the last line, 1st position.
0cf6acbf 265 //
0e320a79 266
0e320a79 267
0cf6acbf
DW
268 vParams.fsStatus = WPM_CCHTEXT;
269 if (::WinSendMsg( GetHwnd()
270 ,WM_QUERYWINDOWPARAMS
271 ,&vParams
272 ,0
273 ))
274 {
275 lLineLength = (long)vParams.cchText;
276 }
277 else
278 lLineLength = 0L;
279 return lLineLength;
280} // end of wxComboBox::GetLastPosition
281
282void wxComboBox::Replace(
283 long lFrom
284, long lTo
285, const wxString& rsValue
286)
0e320a79 287{
37f214d5 288#if wxUSE_CLIPBOARD
0cf6acbf 289 HWND hWnd = GetHwnd();
0e320a79 290
0cf6acbf 291 //
37f214d5 292 // Set selection and remove it
0cf6acbf
DW
293 //
294 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
295 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
0e320a79 296
0cf6acbf 297 //
37f214d5 298 // Now replace with 'value', by pasting.
0cf6acbf
DW
299 //
300 wxSetClipboardData( wxDF_TEXT
301 ,(wxObject *)rsValue.c_str()
302 ,0
303 ,0
304 );
305
306 //
37f214d5 307 // Paste into edit control
0cf6acbf
DW
308 //
309 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
37f214d5 310#endif
0cf6acbf 311} // end of wxComboBox::Replace
0e320a79 312
0cf6acbf
DW
313void wxComboBox::Remove(
314 long lFrom
315, long lTo
316)
0e320a79 317{
0cf6acbf
DW
318#if wxUSE_CLIPBOARD
319 HWND hWnd = GetHwnd();
0e320a79 320
0cf6acbf
DW
321 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
322 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
323#endif
324} // end of wxComboBox::Remove
0e320a79 325
0cf6acbf
DW
326void 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
353void 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
369bool 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
DW
383 ,lParam
384 ,TRUE /* isASCII */
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));
404 break;
0cf6acbf
DW
405 }
406 return FALSE;
407} // end of WinGuiBase_CComboBox::ProcessEditMsg
408
409MRESULT EXPENTRY wxComboEditWndProc(
410 HWND hWnd
411, UINT uMessage
412, MPARAM wParam
413, MPARAM lParam
414)
415{
0cf6acbf
DW
416 switch (uMessage)
417 {
418 //
419 // Forward some messages to the combobox
420 //
598d8cac 421 case WM_SETFOCUS:
0cf6acbf
DW
422 case WM_CHAR:
423 {
d804ec69
SN
424 wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd
425 ,QWL_USER
426 );
0cf6acbf
DW
427
428 if (pCombo->ProcessEditMsg( uMessage
429 ,wParam
430 ,lParam
431 ))
432 return ((MRESULT)0);
433 }
434 break;
435
436 //
437 // TODO: Deal with tooltips here
438 //
439 }
440 return (gfnWndprocEdit(hWnd, (ULONG)uMessage, (MPARAM)wParam, (MPARAM)lParam));
441} // end of wxComboEditWndProc
37f214d5
DW
442
443#endif
444 // wxUSE_COMBOBOX
445