1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboBox class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/combobox.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
23 #include "wx/combobox.h"
24 #include "wx/clipbrd.h"
25 #include "wx/os2/private.h"
27 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
29 MRESULT EXPENTRY
wxComboEditWndProc( HWND hWnd
35 // The pointer to standard wnd proc
37 static WXFARPROC gfnWndprocEdit
= (WXFARPROC
)NULL
;
39 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
41 bool wxComboBox::OS2Command(
43 , WXWORD
WXUNUSED(wId
)
52 if (GetSelection() > -1)
54 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
58 vEvent
.SetInt(GetSelection());
59 vEvent
.SetEventObject(this);
60 vEvent
.SetString((char*)GetStringSelection().c_str());
61 ProcessCommand(vEvent
);
67 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
75 vEvent
.SetString((char*)GetValue().c_str());
76 vEvent
.SetEventObject(this);
77 ProcessCommand(vEvent
);
82 // There is no return value for the CBN_ notifications, so always return
83 // FALSE from here to pass the message to DefWindowProc()
86 } // end of wxComboBox::OS2Command
88 bool wxComboBox::Create(
91 , const wxString
& rsValue
95 , const wxString asChoices
[]
98 , const wxValidator
& rValidator
100 , const wxString
& rsName
104 if (!OS2CreateControl( pParent
117 // Get the right style
121 lSstyle
= WS_TABSTOP
|
124 if (lStyle
& wxCLIP_SIBLINGS
)
125 lSstyle
|= WS_CLIPSIBLINGS
;
126 if (lStyle
& wxCB_READONLY
)
127 lSstyle
|= CBS_DROPDOWNLIST
;
128 else if (lStyle
& wxCB_SIMPLE
)
129 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
131 lSstyle
|= CBS_DROPDOWN
;
134 if (!OS2CreateControl( "COMBOBOX"
140 // A choice/combobox normally has a white background (or other, depending
141 // on global settings) rather than inheriting the parent's background colour.
143 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
));
145 SetFont(pParent
->GetFont());
149 for (i
= 0; i
< n
; i
++)
151 Append(asChoices
[i
]);
159 if (!rsValue
.IsEmpty())
163 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
164 ,(PFNWP
)wxComboEditWndProc
167 } // end of wxComboBox::Create
169 void wxComboBox::SetValue(
170 const wxString
& rsValue
174 // If newlines are denoted by just 10, must stick 13 in front.
177 int nLen
= rsValue
.Length();
180 for (i
= 0; i
< nLen
; i
++)
182 if ((i
> 0) && (rsValue
[i
] == 10) && (rsValue
[i
- 1] != 13))
187 wxChar
* zTmp
= new wxChar
[nLen
+ nSingletons
+ 1];
190 for (i
= 0; i
< nLen
; i
++)
192 if ((i
> 0) && (rsValue
[i
] == 10) && (rsValue
[i
- 1] != 13))
197 zTmp
[j
] = rsValue
[i
];
201 ::WinSetWindowText(GetHwnd(), zTmp
);
205 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
206 } // end of wxComboBox::SetValue
209 // Clipboard operations
211 void wxComboBox::Copy()
213 HWND hWnd
= GetHwnd();
215 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
216 } // end of wxComboBox::Copy
218 void wxComboBox::Cut()
220 HWND hWnd
= GetHwnd();
222 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
223 } // end of wxComboBox::Cut
225 void wxComboBox::Paste()
227 HWND hWnd
= GetHwnd();
229 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
230 } // end of wxComboBox::Paste
232 void wxComboBox::SetEditable(
236 HWND hWnd
= GetHwnd();
238 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
239 } // end of wxComboBox::SetEditable
241 void wxComboBox::SetInsertionPoint(
245 HWND hWnd
= GetHwnd();
247 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
248 } // end of wxComboBox::SetInsertionPoint
250 void wxComboBox::SetInsertionPointEnd()
252 long lPos
= GetLastPosition();
254 SetInsertionPoint(lPos
);
255 } // end of wxComboBox::SetInsertionPointEnd
257 long wxComboBox::GetInsertionPoint() const
259 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
264 if (lPos
== LIT_NONE
)
267 } // end of wxComboBox::GetInsertionPoint
269 long wxComboBox::GetLastPosition() const
271 HWND hEditWnd
= GetHwnd();
272 long lLineLength
= 0L;
276 // Get number of characters in the last (only) line. We'll add this to the character
277 // index for the last line, 1st position.
281 vParams
.fsStatus
= WPM_CCHTEXT
;
282 if (::WinSendMsg( GetHwnd()
283 ,WM_QUERYWINDOWPARAMS
288 lLineLength
= (long)vParams
.cchText
;
293 } // end of wxComboBox::GetLastPosition
295 void wxComboBox::Replace(
298 , const wxString
& rsValue
302 HWND hWnd
= GetHwnd();
303 long lFromChar
= lFrom
;
307 // Set selection and remove it
309 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
310 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
313 // Now replace with 'value', by pasting.
315 wxSetClipboardData( wxDF_TEXT
316 ,(wxObject
*)rsValue
.c_str()
322 // Paste into edit control
324 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
326 } // end of wxComboBox::Replace
328 void wxComboBox::Remove(
334 HWND hWnd
= GetHwnd();
335 long lFromChar
= lFrom
;
338 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
339 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
341 } // end of wxComboBox::Remove
343 void wxComboBox::SetSelection(
348 HWND hWnd
= GetHwnd();
349 long lFromChar
= lFrom
;
353 // If from and to are both -1, it means
354 // (in wxWindows) that all text should be selected.
355 // This translates into Windows convention
357 if ((lFrom
== -1L) && (lTo
== -1L))
365 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
368 } // end of wxComboBox::SetSelection
370 void wxComboBox::DoSetSize(
378 wxControl::DoSetSize( nX
384 } // end of wxComboBox::DoSetSize
386 bool wxComboBox::ProcessEditMsg(
395 vFlag
= SHORT1FROMMP(wParam
);
399 return (HandleChar( SHORT1FROMMP(wParam
)
405 return (HandleKeyDown( SHORT1FROMMP(wParam
)
410 return (HandleKeyUp( SHORT1FROMMP(wParam
)
417 } // end of WinGuiBase_CComboBox::ProcessEditMsg
419 MRESULT EXPENTRY
wxComboEditWndProc(
427 wxWindow
* pWin
= NULL
;
429 hWndCombo
= ::WinQueryWindow(hWnd
, QW_PARENT
);
430 pWin
= (wxWindow
*)wxFindWinFromHandle((WXHWND
)hWndCombo
);
434 // Forward some messages to the combobox
438 wxComboBox
* pCombo
= wxDynamicCast( pWin
442 if (pCombo
->ProcessEditMsg( uMessage
451 // TODO: Deal with tooltips here
454 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
455 } // end of wxComboEditWndProc