]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
Applied patch [ 649157 ] wxDisplay for Unix
[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
89bool 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
0cf6acbf 98, const wxValidator& rValidator
0cf6acbf
DW
99, const wxString& rsName
100)
0e320a79 101{
cfcebdb1 102 m_isShown = FALSE;
0cf6acbf 103
b9b1d6c8 104 if (!CreateControl( pParent
0cf6acbf
DW
105 ,vId
106 ,rPos
107 ,rSize
108 ,lStyle
0cf6acbf 109 ,rValidator
0cf6acbf
DW
110 ,rsName
111 ))
112 return FALSE;
113
114 //
115 // Get the right style
116 //
117 long lSstyle = 0L;
118
119 lSstyle = WS_TABSTOP |
120 WS_VISIBLE;
121
122 if (lStyle & wxCLIP_SIBLINGS )
123 lSstyle |= WS_CLIPSIBLINGS;
124 if (lStyle & wxCB_READONLY)
125 lSstyle |= CBS_DROPDOWNLIST;
126 else if (lStyle & wxCB_SIMPLE)
127 lSstyle |= CBS_SIMPLE; // A list (shown always) and edit control
128 else
129 lSstyle |= CBS_DROPDOWN;
130
131
132 if (!OS2CreateControl( "COMBOBOX"
133 ,lSstyle
134 ))
135 return FALSE;
136
137 //
138 // A choice/combobox normally has a white background (or other, depending
139 // on global settings) rather than inheriting the parent's background colour.
140 //
a756f210 141 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
0cf6acbf 142
cfcebdb1 143 SetFont(*wxSMALL_FONT);
0cf6acbf
DW
144
145 int i;
0cf6acbf
DW
146 for (i = 0; i < n; i++)
147 {
148 Append(asChoices[i]);
149 }
150
151 SetSize( rPos.x
152 ,rPos.y
153 ,rSize.x
154 ,rSize.y
155 );
156 if (!rsValue.IsEmpty())
157 {
158 SetValue(rsValue);
159 }
160 gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd()
161 ,(PFNWP)wxComboEditWndProc
162 );
5d44b24e 163 ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
cfcebdb1 164 Show(TRUE);
0cf6acbf
DW
165 return TRUE;
166} // end of wxComboBox::Create
167
168void wxComboBox::SetValue(
169 const wxString& rsValue
170)
0e320a79 171{
2b5f62a0
VZ
172 if ( HasFlag(wxCB_READONLY) )
173 SetStringSelection(rsValue);
0cf6acbf
DW
174 else
175 ::WinSetWindowText(GetHwnd(), rsValue.c_str());
176} // end of wxComboBox::SetValue
0e320a79 177
0cf6acbf 178//
0e320a79 179// Clipboard operations
0cf6acbf 180//
0e320a79
DW
181void wxComboBox::Copy()
182{
0cf6acbf
DW
183 HWND hWnd = GetHwnd();
184
185 ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0);
186} // end of wxComboBox::Copy
0e320a79
DW
187
188void wxComboBox::Cut()
189{
0cf6acbf
DW
190 HWND hWnd = GetHwnd();
191
192 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
193} // end of wxComboBox::Cut
0e320a79
DW
194
195void wxComboBox::Paste()
196{
0cf6acbf 197 HWND hWnd = GetHwnd();
0e320a79 198
0cf6acbf
DW
199 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
200} // end of wxComboBox::Paste
201
202void wxComboBox::SetEditable(
203 bool bEditable
204)
0e320a79 205{
0cf6acbf
DW
206 HWND hWnd = GetHwnd();
207
208 ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L);
209} // end of wxComboBox::SetEditable
0e320a79 210
0cf6acbf
DW
211void wxComboBox::SetInsertionPoint(
212 long lPos
213)
0e320a79 214{
0cf6acbf
DW
215 HWND hWnd = GetHwnd();
216
217 ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0);
218} // end of wxComboBox::SetInsertionPoint
0e320a79
DW
219
220void wxComboBox::SetInsertionPointEnd()
221{
0cf6acbf
DW
222 long lPos = GetLastPosition();
223
224 SetInsertionPoint(lPos);
225} // end of wxComboBox::SetInsertionPointEnd
0e320a79
DW
226
227long wxComboBox::GetInsertionPoint() const
228{
0cf6acbf
DW
229 long lPos = LONGFROMMR(::WinSendMsg( GetHwnd()
230 ,LM_QUERYSELECTION
231 ,(MPARAM)0
232 ,(MPARAM)0
233 ));
234 if (lPos == LIT_NONE)
235 return wxNOT_FOUND;
236 return lPos;
237} // end of wxComboBox::GetInsertionPoint
0e320a79
DW
238
239long wxComboBox::GetLastPosition() const
240{
0cf6acbf
DW
241 HWND hEditWnd = GetHwnd();
242 long lLineLength = 0L;
243 WNDPARAMS vParams;
0e320a79 244
0cf6acbf
DW
245 //
246 // Get number of characters in the last (only) line. We'll add this to the character
37f214d5 247 // index for the last line, 1st position.
0cf6acbf 248 //
0e320a79 249
0e320a79 250
0cf6acbf
DW
251 vParams.fsStatus = WPM_CCHTEXT;
252 if (::WinSendMsg( GetHwnd()
253 ,WM_QUERYWINDOWPARAMS
254 ,&vParams
255 ,0
256 ))
257 {
258 lLineLength = (long)vParams.cchText;
259 }
260 else
261 lLineLength = 0L;
262 return lLineLength;
263} // end of wxComboBox::GetLastPosition
264
265void wxComboBox::Replace(
266 long lFrom
267, long lTo
268, const wxString& rsValue
269)
0e320a79 270{
37f214d5 271#if wxUSE_CLIPBOARD
0cf6acbf
DW
272 HWND hWnd = GetHwnd();
273 long lFromChar = lFrom;
274 long lToChar = lTo;
0e320a79 275
0cf6acbf 276 //
37f214d5 277 // Set selection and remove it
0cf6acbf
DW
278 //
279 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
280 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
0e320a79 281
0cf6acbf 282 //
37f214d5 283 // Now replace with 'value', by pasting.
0cf6acbf
DW
284 //
285 wxSetClipboardData( wxDF_TEXT
286 ,(wxObject *)rsValue.c_str()
287 ,0
288 ,0
289 );
290
291 //
37f214d5 292 // Paste into edit control
0cf6acbf
DW
293 //
294 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
37f214d5 295#endif
0cf6acbf 296} // end of wxComboBox::Replace
0e320a79 297
0cf6acbf
DW
298void wxComboBox::Remove(
299 long lFrom
300, long lTo
301)
0e320a79 302{
0cf6acbf
DW
303#if wxUSE_CLIPBOARD
304 HWND hWnd = GetHwnd();
305 long lFromChar = lFrom;
306 long lToChar = lTo;
0e320a79 307
0cf6acbf
DW
308 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
309 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
310#endif
311} // end of wxComboBox::Remove
0e320a79 312
0cf6acbf
DW
313void wxComboBox::SetSelection(
314 long lFrom
315, long lTo
316)
0e320a79 317{
0cf6acbf
DW
318 HWND hWnd = GetHwnd();
319 long lFromChar = lFrom;
320 long lToChar = lTo;
321
322 //
323 // If from and to are both -1, it means
37f214d5
DW
324 // (in wxWindows) that all text should be selected.
325 // This translates into Windows convention
0cf6acbf
DW
326 //
327 if ((lFrom == -1L) && (lTo == -1L))
37f214d5 328 {
0cf6acbf
DW
329 lFromChar = 0;
330 lToChar = -1;
37f214d5
DW
331 }
332
0cf6acbf
DW
333 ::WinSendMsg( hWnd
334 ,EM_SETSEL
335 ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar)
336 ,(MPARAM)0
337 );
338} // end of wxComboBox::SetSelection
339
340void wxComboBox::DoSetSize(
341 int nX
342, int nY
343, int nWidth
344, int nHeight
345, int nSizeFlags
346)
347{
348 wxControl::DoSetSize( nX
349 ,nY
350 ,nWidth
351 ,nHeight
352 ,nSizeFlags
353 );
354} // end of wxComboBox::DoSetSize
355
356bool wxComboBox::ProcessEditMsg(
357 WXUINT uMsg
358, WXWPARAM wParam
359, WXLPARAM lParam)
0e320a79 360{
0cf6acbf
DW
361 SHORT vFlag;
362 switch (uMsg)
363 {
364 case WM_CHAR:
365 vFlag = SHORT1FROMMP(wParam);
366 switch(vFlag)
367 {
368 case KC_CHAR:
598d8cac 369 return (HandleChar( wParam
0cf6acbf
DW
370 ,lParam
371 ,TRUE /* isASCII */
372 ));
373
374 case KC_PREVDOWN:
a086de98 375 return (HandleKeyDown( wParam
0cf6acbf
DW
376 ,lParam
377 ));
378
379 case KC_KEYUP:
a086de98 380 return (HandleKeyUp( wParam
0cf6acbf
DW
381 ,lParam
382 ));
383 }
384 break;
598d8cac
DW
385
386 case WM_SETFOCUS:
387 if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
388 return(HandleSetFocus((WXHWND)(HWND)wParam));
389 else
390 return(HandleKillFocus((WXHWND)(HWND)wParam));
391 break;
0cf6acbf
DW
392 }
393 return FALSE;
394} // end of WinGuiBase_CComboBox::ProcessEditMsg
395
396MRESULT EXPENTRY wxComboEditWndProc(
397 HWND hWnd
398, UINT uMessage
399, MPARAM wParam
400, MPARAM lParam
401)
402{
403 HWND hWndCombo;
404 wxWindow* pWin = NULL;
405
406 hWndCombo = ::WinQueryWindow(hWnd, QW_PARENT);
407 pWin = (wxWindow*)wxFindWinFromHandle((WXHWND)hWndCombo);
408 switch (uMessage)
409 {
410 //
411 // Forward some messages to the combobox
412 //
598d8cac 413 case WM_SETFOCUS:
0cf6acbf
DW
414 case WM_CHAR:
415 {
416 wxComboBox* pCombo = wxDynamicCast( pWin
417 ,wxComboBox
418 );
419
420 if (pCombo->ProcessEditMsg( uMessage
421 ,wParam
422 ,lParam
423 ))
424 return ((MRESULT)0);
425 }
426 break;
427
428 //
429 // TODO: Deal with tooltips here
430 //
431 }
432 return (gfnWndprocEdit(hWnd, (ULONG)uMessage, (MPARAM)wParam, (MPARAM)lParam));
433} // end of wxComboEditWndProc
37f214d5
DW
434
435#endif
436 // wxUSE_COMBOBOX
437