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
105 if (!OS2CreateControl( pParent
118 // Get the right style
122 lSstyle
= WS_TABSTOP
|
125 if (lStyle
& wxCLIP_SIBLINGS
)
126 lSstyle
|= WS_CLIPSIBLINGS
;
127 if (lStyle
& wxCB_READONLY
)
128 lSstyle
|= CBS_DROPDOWNLIST
;
129 else if (lStyle
& wxCB_SIMPLE
)
130 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
132 lSstyle
|= CBS_DROPDOWN
;
135 if (!OS2CreateControl( "COMBOBOX"
141 // A choice/combobox normally has a white background (or other, depending
142 // on global settings) rather than inheriting the parent's background colour.
144 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
146 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);
169 } // end of wxComboBox::Create
171 void wxComboBox::SetValue(
172 const wxString
& rsValue
176 // If newlines are denoted by just 10, must stick 13 in front.
179 int nLen
= rsValue
.Length();
182 for (i
= 0; i
< nLen
; i
++)
184 if ((i
> 0) && (rsValue
[i
] == 10) && (rsValue
[i
- 1] != 13))
189 wxChar
* zTmp
= new wxChar
[nLen
+ nSingletons
+ 1];
192 for (i
= 0; i
< nLen
; i
++)
194 if ((i
> 0) && (rsValue
[i
] == 10) && (rsValue
[i
- 1] != 13))
199 zTmp
[j
] = rsValue
[i
];
203 ::WinSetWindowText(GetHwnd(), zTmp
);
207 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
208 } // end of wxComboBox::SetValue
211 // Clipboard operations
213 void wxComboBox::Copy()
215 HWND hWnd
= GetHwnd();
217 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
218 } // end of wxComboBox::Copy
220 void wxComboBox::Cut()
222 HWND hWnd
= GetHwnd();
224 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
225 } // end of wxComboBox::Cut
227 void wxComboBox::Paste()
229 HWND hWnd
= GetHwnd();
231 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
232 } // end of wxComboBox::Paste
234 void wxComboBox::SetEditable(
238 HWND hWnd
= GetHwnd();
240 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
241 } // end of wxComboBox::SetEditable
243 void wxComboBox::SetInsertionPoint(
247 HWND hWnd
= GetHwnd();
249 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
250 } // end of wxComboBox::SetInsertionPoint
252 void wxComboBox::SetInsertionPointEnd()
254 long lPos
= GetLastPosition();
256 SetInsertionPoint(lPos
);
257 } // end of wxComboBox::SetInsertionPointEnd
259 long wxComboBox::GetInsertionPoint() const
261 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
266 if (lPos
== LIT_NONE
)
269 } // end of wxComboBox::GetInsertionPoint
271 long wxComboBox::GetLastPosition() const
273 HWND hEditWnd
= GetHwnd();
274 long lLineLength
= 0L;
278 // Get number of characters in the last (only) line. We'll add this to the character
279 // index for the last line, 1st position.
283 vParams
.fsStatus
= WPM_CCHTEXT
;
284 if (::WinSendMsg( GetHwnd()
285 ,WM_QUERYWINDOWPARAMS
290 lLineLength
= (long)vParams
.cchText
;
295 } // end of wxComboBox::GetLastPosition
297 void wxComboBox::Replace(
300 , const wxString
& rsValue
304 HWND hWnd
= GetHwnd();
305 long lFromChar
= lFrom
;
309 // Set selection and remove it
311 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
312 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
315 // Now replace with 'value', by pasting.
317 wxSetClipboardData( wxDF_TEXT
318 ,(wxObject
*)rsValue
.c_str()
324 // Paste into edit control
326 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
328 } // end of wxComboBox::Replace
330 void wxComboBox::Remove(
336 HWND hWnd
= GetHwnd();
337 long lFromChar
= lFrom
;
340 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
341 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
343 } // end of wxComboBox::Remove
345 void wxComboBox::SetSelection(
350 HWND hWnd
= GetHwnd();
351 long lFromChar
= lFrom
;
355 // If from and to are both -1, it means
356 // (in wxWindows) that all text should be selected.
357 // This translates into Windows convention
359 if ((lFrom
== -1L) && (lTo
== -1L))
367 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
370 } // end of wxComboBox::SetSelection
372 void wxComboBox::DoSetSize(
380 wxControl::DoSetSize( nX
386 } // end of wxComboBox::DoSetSize
388 bool wxComboBox::ProcessEditMsg(
397 vFlag
= SHORT1FROMMP(wParam
);
401 return (HandleChar( SHORT1FROMMP(wParam
)
407 return (HandleKeyDown( SHORT1FROMMP(wParam
)
412 return (HandleKeyUp( SHORT1FROMMP(wParam
)
419 } // end of WinGuiBase_CComboBox::ProcessEditMsg
421 MRESULT EXPENTRY
wxComboEditWndProc(
429 wxWindow
* pWin
= NULL
;
431 hWndCombo
= ::WinQueryWindow(hWnd
, QW_PARENT
);
432 pWin
= (wxWindow
*)wxFindWinFromHandle((WXHWND
)hWndCombo
);
436 // Forward some messages to the combobox
440 wxComboBox
* pCombo
= wxDynamicCast( pWin
444 if (pCombo
->ProcessEditMsg( uMessage
453 // TODO: Deal with tooltips here
456 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
457 } // end of wxComboEditWndProc