]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
check for NULL pointer returned by wxFontEnumerator::GetFacenames() (it actually...
[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
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
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 HWND hEditWnd = GetHwnd();
260 long lLineLength = 0L;
261 WNDPARAMS vParams;
0e320a79 262
0cf6acbf
DW
263 //
264 // Get number of characters in the last (only) line. We'll add this to the character
37f214d5 265 // index for the last line, 1st position.
0cf6acbf 266 //
0e320a79 267
0e320a79 268
0cf6acbf
DW
269 vParams.fsStatus = WPM_CCHTEXT;
270 if (::WinSendMsg( GetHwnd()
271 ,WM_QUERYWINDOWPARAMS
272 ,&vParams
273 ,0
274 ))
275 {
276 lLineLength = (long)vParams.cchText;
277 }
278 else
279 lLineLength = 0L;
280 return lLineLength;
281} // end of wxComboBox::GetLastPosition
282
283void wxComboBox::Replace(
284 long lFrom
285, long lTo
286, const wxString& rsValue
287)
0e320a79 288{
37f214d5 289#if wxUSE_CLIPBOARD
0cf6acbf
DW
290 HWND hWnd = GetHwnd();
291 long lFromChar = lFrom;
292 long lToChar = lTo;
0e320a79 293
0cf6acbf 294 //
37f214d5 295 // Set selection and remove it
0cf6acbf
DW
296 //
297 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
298 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
0e320a79 299
0cf6acbf 300 //
37f214d5 301 // Now replace with 'value', by pasting.
0cf6acbf
DW
302 //
303 wxSetClipboardData( wxDF_TEXT
304 ,(wxObject *)rsValue.c_str()
305 ,0
306 ,0
307 );
308
309 //
37f214d5 310 // Paste into edit control
0cf6acbf
DW
311 //
312 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
37f214d5 313#endif
0cf6acbf 314} // end of wxComboBox::Replace
0e320a79 315
0cf6acbf
DW
316void wxComboBox::Remove(
317 long lFrom
318, long lTo
319)
0e320a79 320{
0cf6acbf
DW
321#if wxUSE_CLIPBOARD
322 HWND hWnd = GetHwnd();
323 long lFromChar = lFrom;
324 long lToChar = lTo;
0e320a79 325
0cf6acbf
DW
326 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
327 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
328#endif
329} // end of wxComboBox::Remove
0e320a79 330
0cf6acbf
DW
331void wxComboBox::SetSelection(
332 long lFrom
333, long lTo
334)
0e320a79 335{
0cf6acbf
DW
336 HWND hWnd = GetHwnd();
337 long lFromChar = lFrom;
338 long lToChar = lTo;
339
340 //
341 // If from and to are both -1, it means
37f214d5
DW
342 // (in wxWindows) that all text should be selected.
343 // This translates into Windows convention
0cf6acbf
DW
344 //
345 if ((lFrom == -1L) && (lTo == -1L))
37f214d5 346 {
0cf6acbf
DW
347 lFromChar = 0;
348 lToChar = -1;
37f214d5
DW
349 }
350
0cf6acbf
DW
351 ::WinSendMsg( hWnd
352 ,EM_SETSEL
353 ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar)
354 ,(MPARAM)0
355 );
356} // end of wxComboBox::SetSelection
357
358void wxComboBox::DoSetSize(
359 int nX
360, int nY
361, int nWidth
362, int nHeight
363, int nSizeFlags
364)
365{
366 wxControl::DoSetSize( nX
367 ,nY
368 ,nWidth
369 ,nHeight
370 ,nSizeFlags
371 );
372} // end of wxComboBox::DoSetSize
373
374bool wxComboBox::ProcessEditMsg(
375 WXUINT uMsg
376, WXWPARAM wParam
377, WXLPARAM lParam)
0e320a79 378{
0cf6acbf
DW
379 SHORT vFlag;
380 switch (uMsg)
381 {
382 case WM_CHAR:
383 vFlag = SHORT1FROMMP(wParam);
384 switch(vFlag)
385 {
386 case KC_CHAR:
598d8cac 387 return (HandleChar( wParam
0cf6acbf
DW
388 ,lParam
389 ,TRUE /* isASCII */
390 ));
391
392 case KC_PREVDOWN:
a086de98 393 return (HandleKeyDown( wParam
0cf6acbf
DW
394 ,lParam
395 ));
396
397 case KC_KEYUP:
a086de98 398 return (HandleKeyUp( wParam
0cf6acbf
DW
399 ,lParam
400 ));
401 }
402 break;
598d8cac
DW
403
404 case WM_SETFOCUS:
405 if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
406 return(HandleSetFocus((WXHWND)(HWND)wParam));
407 else
408 return(HandleKillFocus((WXHWND)(HWND)wParam));
409 break;
0cf6acbf
DW
410 }
411 return FALSE;
412} // end of WinGuiBase_CComboBox::ProcessEditMsg
413
414MRESULT EXPENTRY wxComboEditWndProc(
415 HWND hWnd
416, UINT uMessage
417, MPARAM wParam
418, MPARAM lParam
419)
420{
421 HWND hWndCombo;
422 wxWindow* pWin = NULL;
423
424 hWndCombo = ::WinQueryWindow(hWnd, QW_PARENT);
425 pWin = (wxWindow*)wxFindWinFromHandle((WXHWND)hWndCombo);
426 switch (uMessage)
427 {
428 //
429 // Forward some messages to the combobox
430 //
598d8cac 431 case WM_SETFOCUS:
0cf6acbf
DW
432 case WM_CHAR:
433 {
434 wxComboBox* pCombo = wxDynamicCast( pWin
435 ,wxComboBox
436 );
437
438 if (pCombo->ProcessEditMsg( uMessage
439 ,wParam
440 ,lParam
441 ))
442 return ((MRESULT)0);
443 }
444 break;
445
446 //
447 // TODO: Deal with tooltips here
448 //
449 }
450 return (gfnWndprocEdit(hWnd, (ULONG)uMessage, (MPARAM)wParam, (MPARAM)lParam));
451} // end of wxComboEditWndProc
37f214d5
DW
452
453#endif
454 // wxUSE_COMBOBOX
455