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 for (int i
= 0; i
< n
; i
++)
161 Append(asChoices
[i
]);
169 if (!rsValue
.empty())
173 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
174 ,(PFNWP
)wxComboEditWndProc
176 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
179 } // end of wxComboBox::Create
181 void wxComboBox::SetValue(
182 const wxString
& rsValue
185 if ( HasFlag(wxCB_READONLY
) )
186 SetStringSelection(rsValue
);
188 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
189 } // end of wxComboBox::SetValue
192 // Clipboard operations
194 void wxComboBox::Copy()
196 HWND hWnd
= GetHwnd();
198 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
199 } // end of wxComboBox::Copy
201 void wxComboBox::Cut()
203 HWND hWnd
= GetHwnd();
205 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
206 } // end of wxComboBox::Cut
208 void wxComboBox::Paste()
210 HWND hWnd
= GetHwnd();
212 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
213 } // end of wxComboBox::Paste
215 void wxComboBox::SetEditable(
219 HWND hWnd
= GetHwnd();
221 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
222 } // end of wxComboBox::SetEditable
224 void wxComboBox::SetInsertionPoint(
228 HWND hWnd
= GetHwnd();
230 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
231 } // end of wxComboBox::SetInsertionPoint
233 void wxComboBox::SetInsertionPointEnd()
235 wxTextPos lPos
= GetLastPosition();
237 SetInsertionPoint(lPos
);
238 } // end of wxComboBox::SetInsertionPointEnd
240 long wxComboBox::GetInsertionPoint() const
242 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
247 if (lPos
== LIT_NONE
)
250 } // end of wxComboBox::GetInsertionPoint
252 wxTextPos
wxComboBox::GetLastPosition() const
254 long lLineLength
= 0L;
258 // Get number of characters in the last (only) line. We'll add this to the character
259 // index for the last line, 1st position.
263 vParams
.fsStatus
= WPM_CCHTEXT
;
264 if (::WinSendMsg( GetHwnd()
265 ,WM_QUERYWINDOWPARAMS
270 lLineLength
= (long)vParams
.cchText
;
275 } // end of wxComboBox::GetLastPosition
277 void wxComboBox::Replace( long lFrom
,
279 const wxString
& rsValue
)
282 HWND hWnd
= GetHwnd();
285 // Set selection and remove it
287 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
288 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
291 // Now replace with 'value', by pasting.
293 wxSetClipboardData( wxDF_TEXT
294 ,(wxObject
*)rsValue
.c_str()
300 // Paste into edit control
302 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
306 wxUnusedVar(rsValue
);
308 } // end of wxComboBox::Replace
310 void wxComboBox::Remove( long lFrom
, long lTo
)
313 HWND hWnd
= GetHwnd();
315 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
316 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
321 } // end of wxComboBox::Remove
323 void wxComboBox::SetSelection(
328 HWND hWnd
= GetHwnd();
333 // If from and to are both -1, it means
334 // (in wxWidgets) that all text should be selected.
335 // This translates into Windows convention
337 if ((lFrom
== -1L) && (lTo
== -1L))
345 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
348 } // end of wxComboBox::SetSelection
350 void wxComboBox::DoSetSize(
358 wxControl::DoSetSize( nX
364 } // end of wxComboBox::DoSetSize
366 bool wxComboBox::ProcessEditMsg(
375 vFlag
= SHORT1FROMMP(wParam
);
379 return (HandleChar( wParam
385 return (HandleKeyDown( wParam
390 return (HandleKeyUp( wParam
397 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
398 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
400 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
403 } // end of WinGuiBase_CComboBox::ProcessEditMsg
405 MRESULT EXPENTRY
wxComboEditWndProc(
415 // Forward some messages to the combobox
420 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
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