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"
19 #include "wx/settings.h"
24 #include "wx/combobox.h"
25 #include "wx/clipbrd.h"
26 #include "wx/os2/private.h"
28 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
30 MRESULT EXPENTRY
wxComboEditWndProc( HWND hWnd
36 // The pointer to standard wnd proc
38 static WXFARPROC gfnWndprocEdit
= (WXFARPROC
)NULL
;
40 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
42 bool wxComboBox::OS2Command(
44 , WXWORD
WXUNUSED(wId
)
53 if (GetSelection() > -1)
55 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
59 vEvent
.SetInt(GetSelection());
60 vEvent
.SetEventObject(this);
61 vEvent
.SetString((char*)GetStringSelection().c_str());
62 ProcessCommand(vEvent
);
68 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
76 vEvent
.SetString((char*)GetValue().c_str());
77 vEvent
.SetEventObject(this);
78 ProcessCommand(vEvent
);
83 // There is no return value for the CBN_ notifications, so always return
84 // FALSE from here to pass the message to DefWindowProc()
87 } // end of wxComboBox::OS2Command
89 bool wxComboBox::Create(
92 , const wxString
& rsValue
96 , const wxString asChoices
[]
98 , const wxValidator
& rValidator
99 , const wxString
& rsName
104 if (!CreateControl( pParent
115 // Get the right style
119 lSstyle
= WS_TABSTOP
|
122 if (lStyle
& wxCLIP_SIBLINGS
)
123 lSstyle
|= WS_CLIPSIBLINGS
;
124 if (lStyle
& wxCB_READONLY
)
125 lSstyle
|= CBS_DROPDOWNLIST
;
126 else if (lStyle
& wxCB_SIMPLE
)
127 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
129 lSstyle
|= CBS_DROPDOWN
;
132 if (!OS2CreateControl( "COMBOBOX"
138 // A choice/combobox normally has a white background (or other, depending
139 // on global settings) rather than inheriting the parent's background colour.
141 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
143 SetFont(*wxSMALL_FONT
);
146 for (i
= 0; i
< n
; i
++)
148 Append(asChoices
[i
]);
156 if (!rsValue
.IsEmpty())
160 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
161 ,(PFNWP
)wxComboEditWndProc
163 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
166 } // end of wxComboBox::Create
168 void wxComboBox::SetValue(
169 const wxString
& rsValue
172 if ( HasFlag(wxCB_READONLY
) )
173 SetStringSelection(rsValue
);
175 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
176 } // end of wxComboBox::SetValue
179 // Clipboard operations
181 void wxComboBox::Copy()
183 HWND hWnd
= GetHwnd();
185 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
186 } // end of wxComboBox::Copy
188 void wxComboBox::Cut()
190 HWND hWnd
= GetHwnd();
192 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
193 } // end of wxComboBox::Cut
195 void wxComboBox::Paste()
197 HWND hWnd
= GetHwnd();
199 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
200 } // end of wxComboBox::Paste
202 void wxComboBox::SetEditable(
206 HWND hWnd
= GetHwnd();
208 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
209 } // end of wxComboBox::SetEditable
211 void wxComboBox::SetInsertionPoint(
215 HWND hWnd
= GetHwnd();
217 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
218 } // end of wxComboBox::SetInsertionPoint
220 void wxComboBox::SetInsertionPointEnd()
222 long lPos
= GetLastPosition();
224 SetInsertionPoint(lPos
);
225 } // end of wxComboBox::SetInsertionPointEnd
227 long wxComboBox::GetInsertionPoint() const
229 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
234 if (lPos
== LIT_NONE
)
237 } // end of wxComboBox::GetInsertionPoint
239 long wxComboBox::GetLastPosition() const
241 HWND hEditWnd
= GetHwnd();
242 long lLineLength
= 0L;
246 // Get number of characters in the last (only) line. We'll add this to the character
247 // index for the last line, 1st position.
251 vParams
.fsStatus
= WPM_CCHTEXT
;
252 if (::WinSendMsg( GetHwnd()
253 ,WM_QUERYWINDOWPARAMS
258 lLineLength
= (long)vParams
.cchText
;
263 } // end of wxComboBox::GetLastPosition
265 void wxComboBox::Replace(
268 , const wxString
& rsValue
272 HWND hWnd
= GetHwnd();
273 long lFromChar
= lFrom
;
277 // Set selection and remove it
279 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
280 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
283 // Now replace with 'value', by pasting.
285 wxSetClipboardData( wxDF_TEXT
286 ,(wxObject
*)rsValue
.c_str()
292 // Paste into edit control
294 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
296 } // end of wxComboBox::Replace
298 void wxComboBox::Remove(
304 HWND hWnd
= GetHwnd();
305 long lFromChar
= lFrom
;
308 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
309 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
311 } // end of wxComboBox::Remove
313 void wxComboBox::SetSelection(
318 HWND hWnd
= GetHwnd();
319 long lFromChar
= lFrom
;
323 // If from and to are both -1, it means
324 // (in wxWindows) that all text should be selected.
325 // This translates into Windows convention
327 if ((lFrom
== -1L) && (lTo
== -1L))
335 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
338 } // end of wxComboBox::SetSelection
340 void wxComboBox::DoSetSize(
348 wxControl::DoSetSize( nX
354 } // end of wxComboBox::DoSetSize
356 bool wxComboBox::ProcessEditMsg(
365 vFlag
= SHORT1FROMMP(wParam
);
369 return (HandleChar( wParam
375 return (HandleKeyDown( wParam
380 return (HandleKeyUp( wParam
387 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
388 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
390 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
394 } // end of WinGuiBase_CComboBox::ProcessEditMsg
396 MRESULT EXPENTRY
wxComboEditWndProc(
404 wxWindow
* pWin
= NULL
;
406 hWndCombo
= ::WinQueryWindow(hWnd
, QW_PARENT
);
407 pWin
= (wxWindow
*)wxFindWinFromHandle((WXHWND
)hWndCombo
);
411 // Forward some messages to the combobox
416 wxComboBox
* pCombo
= wxDynamicCast( pWin
420 if (pCombo
->ProcessEditMsg( uMessage
429 // TODO: Deal with tooltips here
432 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
433 } // end of wxComboEditWndProc