]> git.saurik.com Git - wxWidgets.git/blob - src/os2/combobox.cpp
fixed bug with lower-case colours in wxColourDatabase::AddColour() (patch 1074865)
[wxWidgets.git] / src / os2 / combobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #include "wx/combobox.h"
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/setup.h"
19 #include "wx/settings.h"
20 #endif
21
22 #if wxUSE_COMBOBOX
23
24 #include "wx/combobox.h"
25 #include "wx/clipbrd.h"
26 #include "wx/os2/private.h"
27
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
40 IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
41
42 bool wxComboBox::OS2Command(
43 WXUINT uParam
44 , WXWORD WXUNUSED(wId)
45 )
46 {
47 long lSel = -1L;
48 wxString sValue;
49
50 switch (uParam)
51 {
52 case CBN_LBSELECT:
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
66 case CBN_EFCHANGE:
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 , 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
107 bool 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
116 , const wxValidator& rValidator
117 , const wxString& rsName
118 )
119 {
120 m_isShown = FALSE;
121
122 if (!CreateControl( pParent
123 ,vId
124 ,rPos
125 ,rSize
126 ,lStyle
127 ,rValidator
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 //
159 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
160
161 SetFont(*wxSMALL_FONT);
162
163 int i;
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 );
181 ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
182 Show(TRUE);
183 return TRUE;
184 } // end of wxComboBox::Create
185
186 void wxComboBox::SetValue(
187 const wxString& rsValue
188 )
189 {
190 if ( HasFlag(wxCB_READONLY) )
191 SetStringSelection(rsValue);
192 else
193 ::WinSetWindowText(GetHwnd(), rsValue.c_str());
194 } // end of wxComboBox::SetValue
195
196 //
197 // Clipboard operations
198 //
199 void wxComboBox::Copy()
200 {
201 HWND hWnd = GetHwnd();
202
203 ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0);
204 } // end of wxComboBox::Copy
205
206 void wxComboBox::Cut()
207 {
208 HWND hWnd = GetHwnd();
209
210 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
211 } // end of wxComboBox::Cut
212
213 void wxComboBox::Paste()
214 {
215 HWND hWnd = GetHwnd();
216
217 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
218 } // end of wxComboBox::Paste
219
220 void wxComboBox::SetEditable(
221 bool bEditable
222 )
223 {
224 HWND hWnd = GetHwnd();
225
226 ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L);
227 } // end of wxComboBox::SetEditable
228
229 void wxComboBox::SetInsertionPoint(
230 long lPos
231 )
232 {
233 HWND hWnd = GetHwnd();
234
235 ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0);
236 } // end of wxComboBox::SetInsertionPoint
237
238 void wxComboBox::SetInsertionPointEnd()
239 {
240 long lPos = GetLastPosition();
241
242 SetInsertionPoint(lPos);
243 } // end of wxComboBox::SetInsertionPointEnd
244
245 long wxComboBox::GetInsertionPoint() const
246 {
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
256
257 long wxComboBox::GetLastPosition() const
258 {
259 long lLineLength = 0L;
260 WNDPARAMS vParams;
261
262 //
263 // Get number of characters in the last (only) line. We'll add this to the character
264 // index for the last line, 1st position.
265 //
266
267
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
282 void wxComboBox::Replace(
283 long lFrom
284 , long lTo
285 , const wxString& rsValue
286 )
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 #endif
311 } // end of wxComboBox::Replace
312
313 void wxComboBox::Remove(
314 long lFrom
315 , long lTo
316 )
317 {
318 #if wxUSE_CLIPBOARD
319 HWND hWnd = GetHwnd();
320
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
325
326 void wxComboBox::SetSelection(
327 long lFrom
328 , long lTo
329 )
330 {
331 HWND hWnd = GetHwnd();
332 long lFromChar = 0;
333 long lToChar = 0;
334
335 //
336 // If from and to are both -1, it means
337 // (in wxWidgets) that all text should be selected.
338 // This translates into Windows convention
339 //
340 if ((lFrom == -1L) && (lTo == -1L))
341 {
342 lFromChar = 0;
343 lToChar = -1;
344 }
345
346 ::WinSendMsg( hWnd
347 ,EM_SETSEL
348 ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar)
349 ,(MPARAM)0
350 );
351 } // end of wxComboBox::SetSelection
352
353 void 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
369 bool wxComboBox::ProcessEditMsg(
370 WXUINT uMsg
371 , WXWPARAM wParam
372 , WXLPARAM lParam)
373 {
374 SHORT vFlag;
375 switch (uMsg)
376 {
377 case WM_CHAR:
378 vFlag = SHORT1FROMMP(wParam);
379 switch(vFlag)
380 {
381 case KC_CHAR:
382 return (HandleChar( wParam
383 ,lParam
384 ,TRUE /* isASCII */
385 ));
386
387 case KC_PREVDOWN:
388 return (HandleKeyDown( wParam
389 ,lParam
390 ));
391
392 case KC_KEYUP:
393 return (HandleKeyUp( wParam
394 ,lParam
395 ));
396 }
397 break;
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;
405 }
406 return FALSE;
407 } // end of WinGuiBase_CComboBox::ProcessEditMsg
408
409 MRESULT EXPENTRY wxComboEditWndProc(
410 HWND hWnd
411 , UINT uMessage
412 , MPARAM wParam
413 , MPARAM lParam
414 )
415 {
416 switch (uMessage)
417 {
418 //
419 // Forward some messages to the combobox
420 //
421 case WM_SETFOCUS:
422 case WM_CHAR:
423 {
424 wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd
425 ,QWL_USER
426 );
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
442
443 #endif
444 // wxUSE_COMBOBOX
445