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
) )
42 long lSel
= GetSelection();
50 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
, GetId() );
53 vEvent
.SetEventObject(this);
54 vEvent
.SetString(GetStringSelection());
56 ProcessCommand(vEvent
);
62 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
, GetId() );
67 sValue
= GetStringSelection();
68 vEvent
.SetString(sValue
);
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
]);
164 // Set height to use with sizers i.e. without the dropdown listbox
165 wxFont vFont
= GetFont();
167 wxGetCharSize( GetHWND(), &nCx
, &nCy
, &vFont
);
168 int nEditHeight
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
);
169 SetBestFittingSize(wxSize(-1,nEditHeight
));
171 if (!rsValue
.empty())
175 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
176 ,(PFNWP
)wxComboEditWndProc
178 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
181 } // end of wxComboBox::Create
183 wxString
wxComboBox::GetValue() const
185 return wxGetWindowText(GetHwnd());
188 void wxComboBox::SetValue(
189 const wxString
& rsValue
192 if ( HasFlag(wxCB_READONLY
) )
193 SetStringSelection(rsValue
);
195 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
196 } // end of wxComboBox::SetValue
199 // Clipboard operations
201 void wxComboBox::Copy()
203 HWND hWnd
= GetHwnd();
205 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
206 } // end of wxComboBox::Copy
208 void wxComboBox::Cut()
210 HWND hWnd
= GetHwnd();
212 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
213 } // end of wxComboBox::Cut
215 void wxComboBox::Paste()
217 HWND hWnd
= GetHwnd();
219 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
220 } // end of wxComboBox::Paste
222 void wxComboBox::SetEditable(
226 HWND hWnd
= GetHwnd();
228 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
229 } // end of wxComboBox::SetEditable
231 void wxComboBox::SetInsertionPoint(
235 HWND hWnd
= GetHwnd();
237 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
238 } // end of wxComboBox::SetInsertionPoint
240 void wxComboBox::SetInsertionPointEnd()
242 wxTextPos lPos
= GetLastPosition();
244 SetInsertionPoint(lPos
);
245 } // end of wxComboBox::SetInsertionPointEnd
247 long wxComboBox::GetInsertionPoint() const
249 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
254 if (lPos
== LIT_NONE
)
257 } // end of wxComboBox::GetInsertionPoint
259 wxTextPos
wxComboBox::GetLastPosition() const
261 long lLineLength
= 0L;
265 // Get number of characters in the last (only) line. We'll add this to the character
266 // index for the last line, 1st position.
270 vParams
.fsStatus
= WPM_CCHTEXT
;
271 if (::WinSendMsg( GetHwnd()
272 ,WM_QUERYWINDOWPARAMS
277 lLineLength
= (long)vParams
.cchText
;
282 } // end of wxComboBox::GetLastPosition
284 void wxComboBox::Replace( long lFrom
,
286 const wxString
& rsValue
)
289 HWND hWnd
= GetHwnd();
292 // Set selection and remove it
294 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
295 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
298 // Now replace with 'value', by pasting.
300 wxSetClipboardData( wxDF_TEXT
301 ,(wxObject
*)rsValue
.c_str()
307 // Paste into edit control
309 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
313 wxUnusedVar(rsValue
);
315 } // end of wxComboBox::Replace
317 void wxComboBox::Remove( long lFrom
, long lTo
)
320 HWND hWnd
= GetHwnd();
322 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
323 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
328 } // end of wxComboBox::Remove
330 void wxComboBox::SetSelection( long lFrom
, long lTo
)
332 HWND hWnd
= GetHwnd();
337 // If from and to are both -1, it means
338 // (in wxWidgets) that all text should be selected.
339 // This translates into Windows convention
341 if ((lFrom
== -1L) && (lTo
== -1L))
349 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
352 } // end of wxComboBox::SetSelection
354 bool wxComboBox::ProcessEditMsg(
363 vFlag
= SHORT1FROMMP(wParam
);
367 return (HandleChar( wParam
373 return (HandleKeyDown( wParam
378 return (HandleKeyUp( wParam
385 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
386 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
388 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
391 } // end of WinGuiBase_CComboBox::ProcessEditMsg
393 MRESULT EXPENTRY
wxComboEditWndProc(
403 // Forward some messages to the combobox
408 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
412 if (pCombo
->ProcessEditMsg( uMessage
421 // TODO: Deal with tooltips here
424 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
425 } // end of wxComboEditWndProc