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
95 , const wxArrayString
& asChoices
97 , const wxValidator
& rValidator
98 , const wxString
& rsName
101 wxCArrayString
chs(asChoices
);
103 return Create(pParent
, vId
, rsValue
, rPos
, rSize
, chs
.GetCount(),
104 chs
.GetStrings(), lStyle
, rValidator
, rsName
);
107 bool wxComboBox::Create(
110 , const wxString
& rsValue
111 , const wxPoint
& rPos
112 , const wxSize
& rSize
114 , const wxString asChoices
[]
116 , const wxValidator
& rValidator
117 , const wxString
& rsName
122 if (!CreateControl( pParent
133 // Get the right style
137 lSstyle
= WS_TABSTOP
|
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
147 lSstyle
|= CBS_DROPDOWN
;
150 if (!OS2CreateControl( "COMBOBOX"
156 // A choice/combobox normally has a white background (or other, depending
157 // on global settings) rather than inheriting the parent's background colour.
159 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
161 SetFont(*wxSMALL_FONT
);
164 for (i
= 0; i
< n
; i
++)
166 Append(asChoices
[i
]);
174 if (!rsValue
.IsEmpty())
178 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
179 ,(PFNWP
)wxComboEditWndProc
181 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
184 } // end of wxComboBox::Create
186 void wxComboBox::SetValue(
187 const wxString
& rsValue
190 if ( HasFlag(wxCB_READONLY
) )
191 SetStringSelection(rsValue
);
193 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
194 } // end of wxComboBox::SetValue
197 // Clipboard operations
199 void wxComboBox::Copy()
201 HWND hWnd
= GetHwnd();
203 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
204 } // end of wxComboBox::Copy
206 void wxComboBox::Cut()
208 HWND hWnd
= GetHwnd();
210 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
211 } // end of wxComboBox::Cut
213 void wxComboBox::Paste()
215 HWND hWnd
= GetHwnd();
217 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
218 } // end of wxComboBox::Paste
220 void wxComboBox::SetEditable(
224 HWND hWnd
= GetHwnd();
226 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
227 } // end of wxComboBox::SetEditable
229 void wxComboBox::SetInsertionPoint(
233 HWND hWnd
= GetHwnd();
235 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
236 } // end of wxComboBox::SetInsertionPoint
238 void wxComboBox::SetInsertionPointEnd()
240 long lPos
= GetLastPosition();
242 SetInsertionPoint(lPos
);
243 } // end of wxComboBox::SetInsertionPointEnd
245 long wxComboBox::GetInsertionPoint() const
247 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
252 if (lPos
== LIT_NONE
)
255 } // end of wxComboBox::GetInsertionPoint
257 long wxComboBox::GetLastPosition() const
259 HWND hEditWnd
= GetHwnd();
260 long lLineLength
= 0L;
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.
269 vParams
.fsStatus
= WPM_CCHTEXT
;
270 if (::WinSendMsg( GetHwnd()
271 ,WM_QUERYWINDOWPARAMS
276 lLineLength
= (long)vParams
.cchText
;
281 } // end of wxComboBox::GetLastPosition
283 void wxComboBox::Replace(
286 , const wxString
& rsValue
290 HWND hWnd
= GetHwnd();
291 long lFromChar
= lFrom
;
295 // Set selection and remove it
297 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
298 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
301 // Now replace with 'value', by pasting.
303 wxSetClipboardData( wxDF_TEXT
304 ,(wxObject
*)rsValue
.c_str()
310 // Paste into edit control
312 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
314 } // end of wxComboBox::Replace
316 void wxComboBox::Remove(
322 HWND hWnd
= GetHwnd();
323 long lFromChar
= lFrom
;
326 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
327 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
329 } // end of wxComboBox::Remove
331 void wxComboBox::SetSelection(
336 HWND hWnd
= GetHwnd();
337 long lFromChar
= lFrom
;
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
345 if ((lFrom
== -1L) && (lTo
== -1L))
353 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
356 } // end of wxComboBox::SetSelection
358 void wxComboBox::DoSetSize(
366 wxControl::DoSetSize( nX
372 } // end of wxComboBox::DoSetSize
374 bool wxComboBox::ProcessEditMsg(
383 vFlag
= SHORT1FROMMP(wParam
);
387 return (HandleChar( wParam
393 return (HandleKeyDown( wParam
398 return (HandleKeyUp( wParam
405 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
406 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
408 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
412 } // end of WinGuiBase_CComboBox::ProcessEditMsg
414 MRESULT EXPENTRY
wxComboEditWndProc(
422 wxWindow
* pWin
= NULL
;
424 hWndCombo
= ::WinQueryWindow(hWnd
, QW_PARENT
);
425 pWin
= (wxWindow
*)wxFindWinFromHandle((WXHWND
)hWndCombo
);
429 // Forward some messages to the combobox
434 wxComboBox
* pCombo
= wxDynamicCast( pWin
438 if (pCombo
->ProcessEditMsg( uMessage
447 // TODO: Deal with tooltips here
450 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
451 } // end of wxComboEditWndProc