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
177 // If newlines are denoted by just 10, must stick 13 in front.
180 int nLen
= rsValue
.Length();
183 for (i
= 0; i
< nLen
; i
++)
185 if ((i
> 0) && (rsValue
[i
] == 10) && (rsValue
[i
- 1] != 13))
190 wxChar
* zTmp
= new wxChar
[nLen
+ nSingletons
+ 1];
193 for (i
= 0; i
< nLen
; i
++)
195 if ((i
> 0) && (rsValue
[i
] == 10) && (rsValue
[i
- 1] != 13))
200 zTmp
[j
] = rsValue
[i
];
204 ::WinSetWindowText(GetHwnd(), zTmp
);
208 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
209 } // end of wxComboBox::SetValue
212 // Clipboard operations
214 void wxComboBox::Copy()
216 HWND hWnd
= GetHwnd();
218 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
219 } // end of wxComboBox::Copy
221 void wxComboBox::Cut()
223 HWND hWnd
= GetHwnd();
225 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
226 } // end of wxComboBox::Cut
228 void wxComboBox::Paste()
230 HWND hWnd
= GetHwnd();
232 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
233 } // end of wxComboBox::Paste
235 void wxComboBox::SetEditable(
239 HWND hWnd
= GetHwnd();
241 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
242 } // end of wxComboBox::SetEditable
244 void wxComboBox::SetInsertionPoint(
248 HWND hWnd
= GetHwnd();
250 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
251 } // end of wxComboBox::SetInsertionPoint
253 void wxComboBox::SetInsertionPointEnd()
255 long lPos
= GetLastPosition();
257 SetInsertionPoint(lPos
);
258 } // end of wxComboBox::SetInsertionPointEnd
260 long wxComboBox::GetInsertionPoint() const
262 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
267 if (lPos
== LIT_NONE
)
270 } // end of wxComboBox::GetInsertionPoint
272 long wxComboBox::GetLastPosition() const
274 HWND hEditWnd
= GetHwnd();
275 long lLineLength
= 0L;
279 // Get number of characters in the last (only) line. We'll add this to the character
280 // index for the last line, 1st position.
284 vParams
.fsStatus
= WPM_CCHTEXT
;
285 if (::WinSendMsg( GetHwnd()
286 ,WM_QUERYWINDOWPARAMS
291 lLineLength
= (long)vParams
.cchText
;
296 } // end of wxComboBox::GetLastPosition
298 void wxComboBox::Replace(
301 , const wxString
& rsValue
305 HWND hWnd
= GetHwnd();
306 long lFromChar
= lFrom
;
310 // Set selection and remove it
312 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
313 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
316 // Now replace with 'value', by pasting.
318 wxSetClipboardData( wxDF_TEXT
319 ,(wxObject
*)rsValue
.c_str()
325 // Paste into edit control
327 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
329 } // end of wxComboBox::Replace
331 void wxComboBox::Remove(
337 HWND hWnd
= GetHwnd();
338 long lFromChar
= lFrom
;
341 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
342 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
344 } // end of wxComboBox::Remove
346 void wxComboBox::SetSelection(
351 HWND hWnd
= GetHwnd();
352 long lFromChar
= lFrom
;
356 // If from and to are both -1, it means
357 // (in wxWindows) that all text should be selected.
358 // This translates into Windows convention
360 if ((lFrom
== -1L) && (lTo
== -1L))
368 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
371 } // end of wxComboBox::SetSelection
373 void wxComboBox::DoSetSize(
381 wxControl::DoSetSize( nX
387 } // end of wxComboBox::DoSetSize
389 bool wxComboBox::ProcessEditMsg(
398 vFlag
= SHORT1FROMMP(wParam
);
402 return (HandleChar( wParam
408 return (HandleKeyDown( wParam
413 return (HandleKeyUp( wParam
420 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
421 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
423 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
427 } // end of WinGuiBase_CComboBox::ProcessEditMsg
429 MRESULT EXPENTRY
wxComboEditWndProc(
437 wxWindow
* pWin
= NULL
;
439 hWndCombo
= ::WinQueryWindow(hWnd
, QW_PARENT
);
440 pWin
= (wxWindow
*)wxFindWinFromHandle((WXHWND
)hWndCombo
);
444 // Forward some messages to the combobox
449 wxComboBox
* pCombo
= wxDynamicCast( pWin
453 if (pCombo
->ProcessEditMsg( uMessage
462 // TODO: Deal with tooltips here
465 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
466 } // end of wxComboEditWndProc