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