]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
wxAUI: maintain minimum size of panes across dock/undock.
[wxWidgets.git] / src / os2 / combobox.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/os2/combobox.cpp
0e320a79 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 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
37f214d5
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
7520f3da
WS
15#if wxUSE_COMBOBOX
16
a5bbd1cc
WS
17#include "wx/combobox.h"
18
37f214d5 19#ifndef WX_PRECOMP
a4a16252 20 #include "wx/settings.h"
0e320a79
DW
21#endif
22
37f214d5
DW
23#include "wx/clipbrd.h"
24#include "wx/os2/private.h"
0e320a79 25
0cf6acbf
DW
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
0e320a79 38IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
0e320a79 39
a5bbd1cc 40bool wxComboBox::OS2Command( WXUINT uParam, WXWORD WXUNUSED(wId) )
0e320a79 41{
331f1e07 42 long lSel = GetSelection();
a5bbd1cc 43 wxString sValue;
0e320a79 44
0cf6acbf
DW
45 switch (uParam)
46 {
1de4baa3 47 case CBN_LBSELECT:
331f1e07 48 if (lSel > -1)
0cf6acbf 49 {
a5bbd1cc 50 wxCommandEvent vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED, GetId() );
0cf6acbf 51
331f1e07 52 vEvent.SetInt(lSel);
0cf6acbf 53 vEvent.SetEventObject(this);
0fba44b4 54 vEvent.SetString(GetStringSelection());
a5bbd1cc 55
0cf6acbf
DW
56 ProcessCommand(vEvent);
57 }
58 break;
59
1de4baa3 60 case CBN_EFCHANGE:
0cf6acbf 61 {
a5bbd1cc 62 wxCommandEvent vEvent( wxEVT_COMMAND_TEXT_UPDATED, GetId() );
0cf6acbf
DW
63
64 if (lSel == -1L)
65 sValue = GetValue();
66 else
331f1e07
SN
67 sValue = GetStringSelection();
68 vEvent.SetString(sValue);
0cf6acbf
DW
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
7d8268a1 76 // false from here to pass the message to DefWindowProc()
0cf6acbf 77 //
7d8268a1 78 return false;
0cf6acbf
DW
79} // end of wxComboBox::OS2Command
80
584ad2a3
MB
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
0cf6acbf
DW
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
0cf6acbf 108, const wxValidator& rValidator
0cf6acbf
DW
109, const wxString& rsName
110)
0e320a79 111{
7d8268a1 112 m_isShown = false;
0cf6acbf 113
b9b1d6c8 114 if (!CreateControl( pParent
0cf6acbf
DW
115 ,vId
116 ,rPos
117 ,rSize
118 ,lStyle
0cf6acbf 119 ,rValidator
0cf6acbf
DW
120 ,rsName
121 ))
7d8268a1 122 return false;
0cf6acbf
DW
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
0fba44b4 142 if (!OS2CreateControl( _T("COMBOBOX")
0cf6acbf
DW
143 ,lSstyle
144 ))
7d8268a1 145 return false;
0cf6acbf
DW
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 //
a756f210 151 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
0cf6acbf 152
154daa94 153 for (int i = 0; i < n; i++)
0cf6acbf
DW
154 {
155 Append(asChoices[i]);
156 }
157
158 SetSize( rPos.x
159 ,rPos.y
160 ,rSize.x
161 ,rSize.y
162 );
331f1e07
SN
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
7d8268a1 171 if (!rsValue.empty())
0cf6acbf
DW
172 {
173 SetValue(rsValue);
174 }
175 gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd()
176 ,(PFNWP)wxComboEditWndProc
177 );
5d44b24e 178 ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
7d8268a1
WS
179 Show(true);
180 return true;
0cf6acbf
DW
181} // end of wxComboBox::Create
182
331f1e07
SN
183wxString wxComboBox::GetValue() const
184{
185 return wxGetWindowText(GetHwnd());
186}
187
0cf6acbf
DW
188void wxComboBox::SetValue(
189 const wxString& rsValue
190)
0e320a79 191{
2b5f62a0
VZ
192 if ( HasFlag(wxCB_READONLY) )
193 SetStringSelection(rsValue);
0cf6acbf 194 else
0fba44b4 195 ::WinSetWindowText(GetHwnd(), (PSZ)rsValue.c_str());
0cf6acbf 196} // end of wxComboBox::SetValue
0e320a79 197
0cf6acbf 198//
0e320a79 199// Clipboard operations
0cf6acbf 200//
0e320a79
DW
201void wxComboBox::Copy()
202{
0cf6acbf
DW
203 HWND hWnd = GetHwnd();
204
205 ::WinSendMsg(hWnd, EM_COPY, (MPARAM)0, (MPARAM)0);
206} // end of wxComboBox::Copy
0e320a79
DW
207
208void wxComboBox::Cut()
209{
0cf6acbf
DW
210 HWND hWnd = GetHwnd();
211
212 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
213} // end of wxComboBox::Cut
0e320a79
DW
214
215void wxComboBox::Paste()
216{
0cf6acbf 217 HWND hWnd = GetHwnd();
0e320a79 218
0cf6acbf
DW
219 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0);
220} // end of wxComboBox::Paste
221
222void wxComboBox::SetEditable(
223 bool bEditable
224)
0e320a79 225{
0cf6acbf
DW
226 HWND hWnd = GetHwnd();
227
228 ::WinSendMsg(hWnd, EM_SETREADONLY, (MPARAM)!bEditable, (MPARAM)0L);
229} // end of wxComboBox::SetEditable
0e320a79 230
0cf6acbf
DW
231void wxComboBox::SetInsertionPoint(
232 long lPos
233)
0e320a79 234{
0cf6acbf
DW
235 HWND hWnd = GetHwnd();
236
237 ::WinSendMsg(hWnd, EM_SETFIRSTCHAR, MPFROMLONG(lPos), (MPARAM)0);
238} // end of wxComboBox::SetInsertionPoint
0e320a79
DW
239
240void wxComboBox::SetInsertionPointEnd()
241{
7d8268a1 242 wxTextPos lPos = GetLastPosition();
0cf6acbf
DW
243
244 SetInsertionPoint(lPos);
245} // end of wxComboBox::SetInsertionPointEnd
0e320a79
DW
246
247long wxComboBox::GetInsertionPoint() const
248{
0cf6acbf
DW
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
0e320a79 258
7d8268a1 259wxTextPos wxComboBox::GetLastPosition() const
0e320a79 260{
0cf6acbf
DW
261 long lLineLength = 0L;
262 WNDPARAMS vParams;
0e320a79 263
0cf6acbf
DW
264 //
265 // Get number of characters in the last (only) line. We'll add this to the character
37f214d5 266 // index for the last line, 1st position.
0cf6acbf 267 //
0e320a79 268
0e320a79 269
0cf6acbf
DW
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
6670f564
WS
284void wxComboBox::Replace( long lFrom,
285 long lTo,
286 const wxString& rsValue )
0e320a79 287{
37f214d5 288#if wxUSE_CLIPBOARD
0cf6acbf 289 HWND hWnd = GetHwnd();
0e320a79 290
0cf6acbf 291 //
37f214d5 292 // Set selection and remove it
0cf6acbf
DW
293 //
294 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
295 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
0e320a79 296
0cf6acbf 297 //
37f214d5 298 // Now replace with 'value', by pasting.
0cf6acbf
DW
299 //
300 wxSetClipboardData( wxDF_TEXT
301 ,(wxObject *)rsValue.c_str()
302 ,0
303 ,0
304 );
305
306 //
37f214d5 307 // Paste into edit control
0cf6acbf
DW
308 //
309 ::WinSendMsg(hWnd, EM_PASTE, (MPARAM)0, (MPARAM)0L);
6670f564
WS
310#else
311 wxUnusedVar(lFrom);
312 wxUnusedVar(lTo);
313 wxUnusedVar(rsValue);
37f214d5 314#endif
0cf6acbf 315} // end of wxComboBox::Replace
0e320a79 316
6670f564 317void wxComboBox::Remove( long lFrom, long lTo)
0e320a79 318{
0cf6acbf
DW
319#if wxUSE_CLIPBOARD
320 HWND hWnd = GetHwnd();
0e320a79 321
0cf6acbf
DW
322 ::WinSendMsg(hWnd, EM_SETSEL, MPFROM2SHORT((USHORT)lFrom, (USHORT)lTo), 0);
323 ::WinSendMsg(hWnd, EM_CUT, (MPARAM)0, (MPARAM)0);
6670f564
WS
324#else
325 wxUnusedVar(lFrom);
326 wxUnusedVar(lTo);
0cf6acbf
DW
327#endif
328} // end of wxComboBox::Remove
0e320a79 329
a5bbd1cc 330void wxComboBox::SetSelection( long lFrom, long lTo )
0e320a79 331{
a5bbd1cc
WS
332 HWND hWnd = GetHwnd();
333 long lFromChar = 0;
334 long lToChar = 0;
0cf6acbf
DW
335
336 //
337 // If from and to are both -1, it means
77ffb593 338 // (in wxWidgets) that all text should be selected.
37f214d5 339 // This translates into Windows convention
0cf6acbf
DW
340 //
341 if ((lFrom == -1L) && (lTo == -1L))
37f214d5 342 {
0cf6acbf
DW
343 lFromChar = 0;
344 lToChar = -1;
37f214d5
DW
345 }
346
0cf6acbf
DW
347 ::WinSendMsg( hWnd
348 ,EM_SETSEL
349 ,MPFROM2SHORT((USHORT)lFromChar, (USHORT)lToChar)
350 ,(MPARAM)0
351 );
352} // end of wxComboBox::SetSelection
353
0cf6acbf
DW
354bool wxComboBox::ProcessEditMsg(
355 WXUINT uMsg
356, WXWPARAM wParam
357, WXLPARAM lParam)
0e320a79 358{
0cf6acbf
DW
359 SHORT vFlag;
360 switch (uMsg)
361 {
362 case WM_CHAR:
363 vFlag = SHORT1FROMMP(wParam);
364 switch(vFlag)
365 {
366 case KC_CHAR:
598d8cac 367 return (HandleChar( wParam
0cf6acbf 368 ,lParam
7d8268a1 369 ,true /* isASCII */
0cf6acbf
DW
370 ));
371
372 case KC_PREVDOWN:
a086de98 373 return (HandleKeyDown( wParam
0cf6acbf
DW
374 ,lParam
375 ));
376
377 case KC_KEYUP:
a086de98 378 return (HandleKeyUp( wParam
0cf6acbf
DW
379 ,lParam
380 ));
381 }
382 break;
598d8cac
DW
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));
0cf6acbf 389 }
7d8268a1 390 return false;
0cf6acbf
DW
391} // end of WinGuiBase_CComboBox::ProcessEditMsg
392
393MRESULT EXPENTRY wxComboEditWndProc(
394 HWND hWnd
395, UINT uMessage
396, MPARAM wParam
397, MPARAM lParam
398)
399{
0cf6acbf
DW
400 switch (uMessage)
401 {
402 //
403 // Forward some messages to the combobox
404 //
598d8cac 405 case WM_SETFOCUS:
0cf6acbf
DW
406 case WM_CHAR:
407 {
d804ec69
SN
408 wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd
409 ,QWL_USER
410 );
0cf6acbf
DW
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
37f214d5
DW
426
427#endif
428 // wxUSE_COMBOBOX