1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboBox class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/settings.h"
22 #include "wx/combobox.h"
23 #include "wx/clipbrd.h"
24 #include "wx/os2/private.h"
26 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
28 MRESULT EXPENTRY
wxComboEditWndProc( HWND hWnd
34 // The pointer to standard wnd proc
36 static WXFARPROC gfnWndprocEdit
= (WXFARPROC
)NULL
;
38 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
40 bool wxComboBox::OS2Command(
42 , WXWORD
WXUNUSED(wId
)
51 if (GetSelection() > -1)
53 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
57 vEvent
.SetInt(GetSelection());
58 vEvent
.SetEventObject(this);
59 vEvent
.SetString(GetStringSelection());
60 ProcessCommand(vEvent
);
66 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
74 vEvent
.SetString(GetValue());
75 vEvent
.SetEventObject(this);
76 ProcessCommand(vEvent
);
81 // There is no return value for the CBN_ notifications, so always return
82 // false from here to pass the message to DefWindowProc()
85 } // end of wxComboBox::OS2Command
87 bool wxComboBox::Create(
90 , const wxString
& rsValue
93 , const wxArrayString
& asChoices
95 , const wxValidator
& rValidator
96 , const wxString
& rsName
99 wxCArrayString
chs(asChoices
);
101 return Create(pParent
, vId
, rsValue
, rPos
, rSize
, chs
.GetCount(),
102 chs
.GetStrings(), lStyle
, rValidator
, rsName
);
105 bool wxComboBox::Create(
108 , const wxString
& rsValue
109 , const wxPoint
& rPos
110 , const wxSize
& rSize
112 , const wxString asChoices
[]
114 , const wxValidator
& rValidator
115 , const wxString
& rsName
120 if (!CreateControl( pParent
131 // Get the right style
135 lSstyle
= WS_TABSTOP
|
138 if (lStyle
& wxCLIP_SIBLINGS
)
139 lSstyle
|= WS_CLIPSIBLINGS
;
140 if (lStyle
& wxCB_READONLY
)
141 lSstyle
|= CBS_DROPDOWNLIST
;
142 else if (lStyle
& wxCB_SIMPLE
)
143 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
145 lSstyle
|= CBS_DROPDOWN
;
148 if (!OS2CreateControl( _T("COMBOBOX")
154 // A choice/combobox normally has a white background (or other, depending
155 // on global settings) rather than inheriting the parent's background colour.
157 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
159 SetFont(*wxSMALL_FONT
);
162 for (i
= 0; i
< n
; i
++)
164 Append(asChoices
[i
]);
172 if (!rsValue
.empty())
176 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
177 ,(PFNWP
)wxComboEditWndProc
179 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
182 } // end of wxComboBox::Create
184 void wxComboBox::SetValue(
185 const wxString
& rsValue
188 if ( HasFlag(wxCB_READONLY
) )
189 SetStringSelection(rsValue
);
191 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
192 } // end of wxComboBox::SetValue
195 // Clipboard operations
197 void wxComboBox::Copy()
199 HWND hWnd
= GetHwnd();
201 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
202 } // end of wxComboBox::Copy
204 void wxComboBox::Cut()
206 HWND hWnd
= GetHwnd();
208 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
209 } // end of wxComboBox::Cut
211 void wxComboBox::Paste()
213 HWND hWnd
= GetHwnd();
215 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
216 } // end of wxComboBox::Paste
218 void wxComboBox::SetEditable(
222 HWND hWnd
= GetHwnd();
224 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
225 } // end of wxComboBox::SetEditable
227 void wxComboBox::SetInsertionPoint(
231 HWND hWnd
= GetHwnd();
233 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
234 } // end of wxComboBox::SetInsertionPoint
236 void wxComboBox::SetInsertionPointEnd()
238 wxTextPos lPos
= GetLastPosition();
240 SetInsertionPoint(lPos
);
241 } // end of wxComboBox::SetInsertionPointEnd
243 long wxComboBox::GetInsertionPoint() const
245 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
250 if (lPos
== LIT_NONE
)
253 } // end of wxComboBox::GetInsertionPoint
255 wxTextPos
wxComboBox::GetLastPosition() const
257 long lLineLength
= 0L;
261 // Get number of characters in the last (only) line. We'll add this to the character
262 // index for the last line, 1st position.
266 vParams
.fsStatus
= WPM_CCHTEXT
;
267 if (::WinSendMsg( GetHwnd()
268 ,WM_QUERYWINDOWPARAMS
273 lLineLength
= (long)vParams
.cchText
;
278 } // end of wxComboBox::GetLastPosition
280 void wxComboBox::Replace( long lFrom
,
282 const wxString
& rsValue
)
285 HWND hWnd
= GetHwnd();
288 // Set selection and remove it
290 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
291 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
294 // Now replace with 'value', by pasting.
296 wxSetClipboardData( wxDF_TEXT
297 ,(wxObject
*)rsValue
.c_str()
303 // Paste into edit control
305 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
309 wxUnusedVar(rsValue
);
311 } // end of wxComboBox::Replace
313 void wxComboBox::Remove( long lFrom
, long lTo
)
316 HWND hWnd
= GetHwnd();
318 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
319 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
324 } // end of wxComboBox::Remove
326 void wxComboBox::SetSelection(
331 HWND hWnd
= GetHwnd();
336 // If from and to are both -1, it means
337 // (in wxWidgets) that all text should be selected.
338 // This translates into Windows convention
340 if ((lFrom
== -1L) && (lTo
== -1L))
348 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
351 } // end of wxComboBox::SetSelection
353 void wxComboBox::DoSetSize(
361 wxControl::DoSetSize( nX
367 } // end of wxComboBox::DoSetSize
369 bool wxComboBox::ProcessEditMsg(
378 vFlag
= SHORT1FROMMP(wParam
);
382 return (HandleChar( wParam
388 return (HandleKeyDown( wParam
393 return (HandleKeyUp( wParam
400 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
401 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
403 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
406 } // end of WinGuiBase_CComboBox::ProcessEditMsg
408 MRESULT EXPENTRY
wxComboEditWndProc(
418 // Forward some messages to the combobox
423 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
427 if (pCombo
->ProcessEditMsg( uMessage
436 // TODO: Deal with tooltips here
439 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
440 } // end of wxComboEditWndProc