1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/combobox.cpp
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"
18 #include "wx/settings.h"
21 #include "wx/combobox.h"
22 #include "wx/clipbrd.h"
23 #include "wx/os2/private.h"
25 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
27 MRESULT EXPENTRY
wxComboEditWndProc( HWND hWnd
33 // The pointer to standard wnd proc
35 static WXFARPROC gfnWndprocEdit
= (WXFARPROC
)NULL
;
37 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
39 bool wxComboBox::OS2Command(
41 , WXWORD
WXUNUSED(wId
)
50 if (GetSelection() > -1)
52 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
56 vEvent
.SetInt(GetSelection());
57 vEvent
.SetEventObject(this);
58 vEvent
.SetString(GetStringSelection());
59 ProcessCommand(vEvent
);
65 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
73 vEvent
.SetString(GetValue());
74 vEvent
.SetEventObject(this);
75 ProcessCommand(vEvent
);
80 // There is no return value for the CBN_ notifications, so always return
81 // false from here to pass the message to DefWindowProc()
84 } // end of wxComboBox::OS2Command
86 bool wxComboBox::Create(
89 , const wxString
& rsValue
92 , const wxArrayString
& asChoices
94 , const wxValidator
& rValidator
95 , const wxString
& rsName
98 wxCArrayString
chs(asChoices
);
100 return Create(pParent
, vId
, rsValue
, rPos
, rSize
, chs
.GetCount(),
101 chs
.GetStrings(), lStyle
, rValidator
, rsName
);
104 bool wxComboBox::Create(
107 , const wxString
& rsValue
108 , const wxPoint
& rPos
109 , const wxSize
& rSize
111 , const wxString asChoices
[]
113 , const wxValidator
& rValidator
114 , const wxString
& rsName
119 if (!CreateControl( pParent
130 // Get the right style
134 lSstyle
= WS_TABSTOP
|
137 if (lStyle
& wxCLIP_SIBLINGS
)
138 lSstyle
|= WS_CLIPSIBLINGS
;
139 if (lStyle
& wxCB_READONLY
)
140 lSstyle
|= CBS_DROPDOWNLIST
;
141 else if (lStyle
& wxCB_SIMPLE
)
142 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
144 lSstyle
|= CBS_DROPDOWN
;
147 if (!OS2CreateControl( _T("COMBOBOX")
153 // A choice/combobox normally has a white background (or other, depending
154 // on global settings) rather than inheriting the parent's background colour.
156 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
158 for (int i
= 0; i
< n
; i
++)
160 Append(asChoices
[i
]);
168 if (!rsValue
.empty())
172 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
173 ,(PFNWP
)wxComboEditWndProc
175 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
178 } // end of wxComboBox::Create
180 void wxComboBox::SetValue(
181 const wxString
& rsValue
184 if ( HasFlag(wxCB_READONLY
) )
185 SetStringSelection(rsValue
);
187 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
188 } // end of wxComboBox::SetValue
191 // Clipboard operations
193 void wxComboBox::Copy()
195 HWND hWnd
= GetHwnd();
197 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
198 } // end of wxComboBox::Copy
200 void wxComboBox::Cut()
202 HWND hWnd
= GetHwnd();
204 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
205 } // end of wxComboBox::Cut
207 void wxComboBox::Paste()
209 HWND hWnd
= GetHwnd();
211 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
212 } // end of wxComboBox::Paste
214 void wxComboBox::SetEditable(
218 HWND hWnd
= GetHwnd();
220 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
221 } // end of wxComboBox::SetEditable
223 void wxComboBox::SetInsertionPoint(
227 HWND hWnd
= GetHwnd();
229 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
230 } // end of wxComboBox::SetInsertionPoint
232 void wxComboBox::SetInsertionPointEnd()
234 wxTextPos lPos
= GetLastPosition();
236 SetInsertionPoint(lPos
);
237 } // end of wxComboBox::SetInsertionPointEnd
239 long wxComboBox::GetInsertionPoint() const
241 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
246 if (lPos
== LIT_NONE
)
249 } // end of wxComboBox::GetInsertionPoint
251 wxTextPos
wxComboBox::GetLastPosition() const
253 long lLineLength
= 0L;
257 // Get number of characters in the last (only) line. We'll add this to the character
258 // index for the last line, 1st position.
262 vParams
.fsStatus
= WPM_CCHTEXT
;
263 if (::WinSendMsg( GetHwnd()
264 ,WM_QUERYWINDOWPARAMS
269 lLineLength
= (long)vParams
.cchText
;
274 } // end of wxComboBox::GetLastPosition
276 void wxComboBox::Replace( long lFrom
,
278 const wxString
& rsValue
)
281 HWND hWnd
= GetHwnd();
284 // Set selection and remove it
286 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
287 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
290 // Now replace with 'value', by pasting.
292 wxSetClipboardData( wxDF_TEXT
293 ,(wxObject
*)rsValue
.c_str()
299 // Paste into edit control
301 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
305 wxUnusedVar(rsValue
);
307 } // end of wxComboBox::Replace
309 void wxComboBox::Remove( long lFrom
, long lTo
)
312 HWND hWnd
= GetHwnd();
314 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
315 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
320 } // end of wxComboBox::Remove
322 void wxComboBox::SetSelection(
327 HWND hWnd
= GetHwnd();
332 // If from and to are both -1, it means
333 // (in wxWidgets) that all text should be selected.
334 // This translates into Windows convention
336 if ((lFrom
== -1L) && (lTo
== -1L))
344 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
347 } // end of wxComboBox::SetSelection
349 void wxComboBox::DoSetSize(
357 wxControl::DoSetSize( nX
363 } // end of wxComboBox::DoSetSize
365 bool wxComboBox::ProcessEditMsg(
374 vFlag
= SHORT1FROMMP(wParam
);
378 return (HandleChar( wParam
384 return (HandleKeyDown( wParam
389 return (HandleKeyUp( wParam
396 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
397 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
399 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
402 } // end of WinGuiBase_CComboBox::ProcessEditMsg
404 MRESULT EXPENTRY
wxComboEditWndProc(
414 // Forward some messages to the combobox
419 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
423 if (pCombo
->ProcessEditMsg( uMessage
432 // TODO: Deal with tooltips here
435 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
436 } // end of wxComboEditWndProc