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"
17 #include "wx/combobox.h"
20 #include "wx/settings.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( WXUINT uParam
, WXWORD
WXUNUSED(wId
) )
48 if (GetSelection() > -1)
50 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
, GetId() );
52 vEvent
.SetInt(GetSelection());
53 vEvent
.SetEventObject(this);
54 vEvent
.SetString(GetStringSelection());
56 ProcessCommand(vEvent
);
62 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
, GetId() );
68 vEvent
.SetString(GetValue());
69 vEvent
.SetEventObject(this);
70 ProcessCommand(vEvent
);
75 // There is no return value for the CBN_ notifications, so always return
76 // false from here to pass the message to DefWindowProc()
79 } // end of wxComboBox::OS2Command
81 bool wxComboBox::Create(
84 , const wxString
& rsValue
87 , const wxArrayString
& asChoices
89 , const wxValidator
& rValidator
90 , const wxString
& rsName
93 wxCArrayString
chs(asChoices
);
95 return Create(pParent
, vId
, rsValue
, rPos
, rSize
, chs
.GetCount(),
96 chs
.GetStrings(), lStyle
, rValidator
, rsName
);
99 bool wxComboBox::Create(
102 , const wxString
& rsValue
103 , const wxPoint
& rPos
104 , const wxSize
& rSize
106 , const wxString asChoices
[]
108 , const wxValidator
& rValidator
109 , const wxString
& rsName
114 if (!CreateControl( pParent
125 // Get the right style
129 lSstyle
= WS_TABSTOP
|
132 if (lStyle
& wxCLIP_SIBLINGS
)
133 lSstyle
|= WS_CLIPSIBLINGS
;
134 if (lStyle
& wxCB_READONLY
)
135 lSstyle
|= CBS_DROPDOWNLIST
;
136 else if (lStyle
& wxCB_SIMPLE
)
137 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
139 lSstyle
|= CBS_DROPDOWN
;
142 if (!OS2CreateControl( _T("COMBOBOX")
148 // A choice/combobox normally has a white background (or other, depending
149 // on global settings) rather than inheriting the parent's background colour.
151 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
153 for (int i
= 0; i
< n
; i
++)
155 Append(asChoices
[i
]);
163 if (!rsValue
.empty())
167 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
168 ,(PFNWP
)wxComboEditWndProc
170 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
173 } // end of wxComboBox::Create
175 void wxComboBox::SetValue(
176 const wxString
& rsValue
179 if ( HasFlag(wxCB_READONLY
) )
180 SetStringSelection(rsValue
);
182 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
183 } // end of wxComboBox::SetValue
186 // Clipboard operations
188 void wxComboBox::Copy()
190 HWND hWnd
= GetHwnd();
192 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
193 } // end of wxComboBox::Copy
195 void wxComboBox::Cut()
197 HWND hWnd
= GetHwnd();
199 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
200 } // end of wxComboBox::Cut
202 void wxComboBox::Paste()
204 HWND hWnd
= GetHwnd();
206 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
207 } // end of wxComboBox::Paste
209 void wxComboBox::SetEditable(
213 HWND hWnd
= GetHwnd();
215 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
216 } // end of wxComboBox::SetEditable
218 void wxComboBox::SetInsertionPoint(
222 HWND hWnd
= GetHwnd();
224 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
225 } // end of wxComboBox::SetInsertionPoint
227 void wxComboBox::SetInsertionPointEnd()
229 wxTextPos lPos
= GetLastPosition();
231 SetInsertionPoint(lPos
);
232 } // end of wxComboBox::SetInsertionPointEnd
234 long wxComboBox::GetInsertionPoint() const
236 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
241 if (lPos
== LIT_NONE
)
244 } // end of wxComboBox::GetInsertionPoint
246 wxTextPos
wxComboBox::GetLastPosition() const
248 long lLineLength
= 0L;
252 // Get number of characters in the last (only) line. We'll add this to the character
253 // index for the last line, 1st position.
257 vParams
.fsStatus
= WPM_CCHTEXT
;
258 if (::WinSendMsg( GetHwnd()
259 ,WM_QUERYWINDOWPARAMS
264 lLineLength
= (long)vParams
.cchText
;
269 } // end of wxComboBox::GetLastPosition
271 void wxComboBox::Replace( long lFrom
,
273 const wxString
& rsValue
)
276 HWND hWnd
= GetHwnd();
279 // Set selection and remove it
281 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
282 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
285 // Now replace with 'value', by pasting.
287 wxSetClipboardData( wxDF_TEXT
288 ,(wxObject
*)rsValue
.c_str()
294 // Paste into edit control
296 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
300 wxUnusedVar(rsValue
);
302 } // end of wxComboBox::Replace
304 void wxComboBox::Remove( long lFrom
, long lTo
)
307 HWND hWnd
= GetHwnd();
309 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
310 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
315 } // end of wxComboBox::Remove
317 void wxComboBox::SetSelection( long lFrom
, long lTo
)
319 HWND hWnd
= GetHwnd();
324 // If from and to are both -1, it means
325 // (in wxWidgets) that all text should be selected.
326 // This translates into Windows convention
328 if ((lFrom
== -1L) && (lTo
== -1L))
336 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
339 } // end of wxComboBox::SetSelection
341 void wxComboBox::DoSetSize(
349 wxControl::DoSetSize( nX
355 } // end of wxComboBox::DoSetSize
357 bool wxComboBox::ProcessEditMsg(
366 vFlag
= SHORT1FROMMP(wParam
);
370 return (HandleChar( wParam
376 return (HandleKeyDown( wParam
381 return (HandleKeyUp( wParam
388 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
389 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
391 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
394 } // end of WinGuiBase_CComboBox::ProcessEditMsg
396 MRESULT EXPENTRY
wxComboEditWndProc(
406 // Forward some messages to the combobox
411 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
415 if (pCombo
->ProcessEditMsg( uMessage
424 // TODO: Deal with tooltips here
427 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
428 } // end of wxComboEditWndProc