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
[]
99 , const wxValidator
& rValidator
101 , const wxString
& rsName
106 if (!CreateControl( pParent
119 // Get the right style
123 lSstyle
= WS_TABSTOP
|
126 if (lStyle
& wxCLIP_SIBLINGS
)
127 lSstyle
|= WS_CLIPSIBLINGS
;
128 if (lStyle
& wxCB_READONLY
)
129 lSstyle
|= CBS_DROPDOWNLIST
;
130 else if (lStyle
& wxCB_SIMPLE
)
131 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
133 lSstyle
|= CBS_DROPDOWN
;
136 if (!OS2CreateControl( "COMBOBOX"
142 // A choice/combobox normally has a white background (or other, depending
143 // on global settings) rather than inheriting the parent's background colour.
145 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
147 SetFont(*wxSMALL_FONT
);
150 for (i
= 0; i
< n
; i
++)
152 Append(asChoices
[i
]);
160 if (!rsValue
.IsEmpty())
164 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
165 ,(PFNWP
)wxComboEditWndProc
167 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
170 } // end of wxComboBox::Create
172 void wxComboBox::SetValue(
173 const wxString
& rsValue
176 if ( HasFlag(wxCB_READONLY
) )
177 SetStringSelection(rsValue
);
179 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
180 } // end of wxComboBox::SetValue
183 // Clipboard operations
185 void wxComboBox::Copy()
187 HWND hWnd
= GetHwnd();
189 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
190 } // end of wxComboBox::Copy
192 void wxComboBox::Cut()
194 HWND hWnd
= GetHwnd();
196 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
197 } // end of wxComboBox::Cut
199 void wxComboBox::Paste()
201 HWND hWnd
= GetHwnd();
203 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
204 } // end of wxComboBox::Paste
206 void wxComboBox::SetEditable(
210 HWND hWnd
= GetHwnd();
212 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
213 } // end of wxComboBox::SetEditable
215 void wxComboBox::SetInsertionPoint(
219 HWND hWnd
= GetHwnd();
221 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
222 } // end of wxComboBox::SetInsertionPoint
224 void wxComboBox::SetInsertionPointEnd()
226 long lPos
= GetLastPosition();
228 SetInsertionPoint(lPos
);
229 } // end of wxComboBox::SetInsertionPointEnd
231 long wxComboBox::GetInsertionPoint() const
233 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
238 if (lPos
== LIT_NONE
)
241 } // end of wxComboBox::GetInsertionPoint
243 long wxComboBox::GetLastPosition() const
245 HWND hEditWnd
= GetHwnd();
246 long lLineLength
= 0L;
250 // Get number of characters in the last (only) line. We'll add this to the character
251 // index for the last line, 1st position.
255 vParams
.fsStatus
= WPM_CCHTEXT
;
256 if (::WinSendMsg( GetHwnd()
257 ,WM_QUERYWINDOWPARAMS
262 lLineLength
= (long)vParams
.cchText
;
267 } // end of wxComboBox::GetLastPosition
269 void wxComboBox::Replace(
272 , const wxString
& rsValue
276 HWND hWnd
= GetHwnd();
277 long lFromChar
= lFrom
;
281 // Set selection and remove it
283 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
284 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
287 // Now replace with 'value', by pasting.
289 wxSetClipboardData( wxDF_TEXT
290 ,(wxObject
*)rsValue
.c_str()
296 // Paste into edit control
298 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
300 } // end of wxComboBox::Replace
302 void wxComboBox::Remove(
308 HWND hWnd
= GetHwnd();
309 long lFromChar
= lFrom
;
312 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
313 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
315 } // end of wxComboBox::Remove
317 void wxComboBox::SetSelection(
322 HWND hWnd
= GetHwnd();
323 long lFromChar
= lFrom
;
327 // If from and to are both -1, it means
328 // (in wxWindows) that all text should be selected.
329 // This translates into Windows convention
331 if ((lFrom
== -1L) && (lTo
== -1L))
339 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
342 } // end of wxComboBox::SetSelection
344 void wxComboBox::DoSetSize(
352 wxControl::DoSetSize( nX
358 } // end of wxComboBox::DoSetSize
360 bool wxComboBox::ProcessEditMsg(
369 vFlag
= SHORT1FROMMP(wParam
);
373 return (HandleChar( wParam
379 return (HandleKeyDown( wParam
384 return (HandleKeyUp( wParam
391 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
392 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
394 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
398 } // end of WinGuiBase_CComboBox::ProcessEditMsg
400 MRESULT EXPENTRY
wxComboEditWndProc(
408 wxWindow
* pWin
= NULL
;
410 hWndCombo
= ::WinQueryWindow(hWnd
, QW_PARENT
);
411 pWin
= (wxWindow
*)wxFindWinFromHandle((WXHWND
)hWndCombo
);
415 // Forward some messages to the combobox
420 wxComboBox
* pCombo
= wxDynamicCast( pWin
424 if (pCombo
->ProcessEditMsg( uMessage
433 // TODO: Deal with tooltips here
436 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
437 } // end of wxComboEditWndProc