]> git.saurik.com Git - wxWidgets.git/blob - src/os2/combobox.cpp
Turn off UseAntiAliasing by default on wxMac
[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 HWND hEditWnd = GetHwnd();
260 long lLineLength = 0L;
261 WNDPARAMS vParams;
262
263 //
264 // Get number of characters in the last (only) line. We'll add this to the character
265 // index for the last line, 1st position.
266 //
267
268
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
283 void wxComboBox::Replace(
284 long lFrom
285 , long lTo
286 , const wxString& rsValue
287 )
288 {
289 #if wxUSE_CLIPBOARD
290 HWND hWnd = GetHwnd();
291 long lFromChar = lFrom;
292 long lToChar = lTo;
293
294 //
295 // Set selection and remove it
296 //
297 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
298 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
299
300 //
301 // Now replace with 'value', by pasting.
302 //
303 wxSetClipboardData( wxDF_TEXT
304 ,(wxObject *)rsValue.c_str()
305 ,0
306 ,0
307 );
308
309 //
310 // Paste into edit control
311 //
312 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
313 #endif
314 } // end of wxComboBox::Replace
315
316 void wxComboBox::Remove(
317 long lFrom
318 , long lTo
319 )
320 {
321 #if wxUSE_CLIPBOARD
322 HWND hWnd = GetHwnd();
323 long lFromChar = lFrom;
324 long lToChar = lTo;
325
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
330
331 void wxComboBox::SetSelection(
332 long lFrom
333 , long lTo
334 )
335 {
336 HWND hWnd = GetHwnd();
337 long lFromChar = lFrom;
338 long lToChar = lTo;
339
340 //
341 // If from and to are both -1, it means
342 // (in wxWindows) that all text should be selected.
343 // This translates into Windows convention
344 //
345 if ((lFrom == -1L) && (lTo == -1L))
346 {
347 lFromChar = 0;
348 lToChar = -1;
349 }
350
351 ::WinSendMsg( hWnd
352 ,EM_SETSEL
353 ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar)
354 ,(MPARAM)0
355 );
356 } // end of wxComboBox::SetSelection
357
358 void 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
374 bool wxComboBox::ProcessEditMsg(
375 WXUINT uMsg
376 , WXWPARAM wParam
377 , WXLPARAM lParam)
378 {
379 SHORT vFlag;
380 switch (uMsg)
381 {
382 case WM_CHAR:
383 vFlag = SHORT1FROMMP(wParam);
384 switch(vFlag)
385 {
386 case KC_CHAR:
387 return (HandleChar( wParam
388 ,lParam
389 ,TRUE /* isASCII */
390 ));
391
392 case KC_PREVDOWN:
393 return (HandleKeyDown( wParam
394 ,lParam
395 ));
396
397 case KC_KEYUP:
398 return (HandleKeyUp( wParam
399 ,lParam
400 ));
401 }
402 break;
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;
410 }
411 return FALSE;
412 } // end of WinGuiBase_CComboBox::ProcessEditMsg
413
414 MRESULT 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 //
431 case WM_SETFOCUS:
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
452
453 #endif
454 // wxUSE_COMBOBOX
455