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 // clipping siblings does not yet work
133 // if (lStyle & wxCLIP_SIBLINGS )
134 // lSstyle |= WS_CLIPSIBLINGS;
135 if (lStyle
& wxCB_READONLY
)
136 lSstyle
|= CBS_DROPDOWNLIST
;
137 else if (lStyle
& wxCB_SIMPLE
)
138 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
140 lSstyle
|= CBS_DROPDOWN
;
143 if (!OS2CreateControl( _T("COMBOBOX")
149 // A choice/combobox normally has a white background (or other, depending
150 // on global settings) rather than inheriting the parent's background colour.
152 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
154 for (int i
= 0; i
< n
; i
++)
156 Append(asChoices
[i
]);
165 // Set height to use with sizers i.e. without the dropdown listbox
166 wxFont vFont
= GetFont();
168 wxGetCharSize( GetHWND(), NULL
, &nEditHeight
, &vFont
);
169 nEditHeight
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nEditHeight
);
170 SetBestFittingSize(wxSize(-1,nEditHeight
+4)); // +2x2 for the border
172 if (!rsValue
.empty())
176 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
177 ,(PFNWP
)wxComboEditWndProc
179 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
182 } // end of wxComboBox::Create
184 wxString
wxComboBox::GetValue() const
186 return wxGetWindowText(GetHwnd());
189 void wxComboBox::SetValue(
190 const wxString
& rsValue
193 if ( HasFlag(wxCB_READONLY
) )
194 SetStringSelection(rsValue
);
196 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
197 } // end of wxComboBox::SetValue
200 // Clipboard operations
202 void wxComboBox::Copy()
204 HWND hWnd
= GetHwnd();
206 ::WinSendMsg(hWnd
, EM_COPY
, (MPARAM
)0, (MPARAM
)0);
207 } // end of wxComboBox::Copy
209 void wxComboBox::Cut()
211 HWND hWnd
= GetHwnd();
213 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
214 } // end of wxComboBox::Cut
216 void wxComboBox::Paste()
218 HWND hWnd
= GetHwnd();
220 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
221 } // end of wxComboBox::Paste
223 void wxComboBox::SetEditable(
227 HWND hWnd
= GetHwnd();
229 ::WinSendMsg(hWnd
, EM_SETREADONLY
, (MPARAM
)!bEditable
, (MPARAM
)0L);
230 } // end of wxComboBox::SetEditable
232 void wxComboBox::SetInsertionPoint(
236 HWND hWnd
= GetHwnd();
238 ::WinSendMsg(hWnd
, EM_SETFIRSTCHAR
, MPFROMLONG(lPos
), (MPARAM
)0);
239 } // end of wxComboBox::SetInsertionPoint
241 void wxComboBox::SetInsertionPointEnd()
243 wxTextPos lPos
= GetLastPosition();
245 SetInsertionPoint(lPos
);
246 } // end of wxComboBox::SetInsertionPointEnd
248 long wxComboBox::GetInsertionPoint() const
250 long lPos
= LONGFROMMR(::WinSendMsg( GetHwnd()
255 if (lPos
== LIT_NONE
)
258 } // end of wxComboBox::GetInsertionPoint
260 wxTextPos
wxComboBox::GetLastPosition() const
262 long lLineLength
= 0L;
266 // Get number of characters in the last (only) line. We'll add this to the character
267 // index for the last line, 1st position.
271 vParams
.fsStatus
= WPM_CCHTEXT
;
272 if (::WinSendMsg( GetHwnd()
273 ,WM_QUERYWINDOWPARAMS
278 lLineLength
= (long)vParams
.cchText
;
283 } // end of wxComboBox::GetLastPosition
285 void wxComboBox::Replace( long lFrom
,
287 const wxString
& rsValue
)
290 HWND hWnd
= GetHwnd();
293 // Set selection and remove it
295 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
296 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
299 // Now replace with 'value', by pasting.
301 wxSetClipboardData( wxDF_TEXT
302 ,(wxObject
*)rsValue
.c_str()
308 // Paste into edit control
310 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0L);
314 wxUnusedVar(rsValue
);
316 } // end of wxComboBox::Replace
318 void wxComboBox::Remove( long lFrom
, long lTo
)
321 HWND hWnd
= GetHwnd();
323 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
324 ::WinSendMsg(hWnd
, EM_CUT
, (MPARAM
)0, (MPARAM
)0);
329 } // end of wxComboBox::Remove
331 void wxComboBox::SetSelection( long lFrom
, long lTo
)
333 HWND hWnd
= GetHwnd();
338 // If from and to are both -1, it means
339 // (in wxWidgets) that all text should be selected.
340 // This translates into Windows convention
342 if ((lFrom
== -1L) && (lTo
== -1L))
350 ,MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
)
353 } // end of wxComboBox::SetSelection
355 bool wxComboBox::ProcessEditMsg(
364 vFlag
= SHORT1FROMMP(wParam
);
368 return (HandleChar( wParam
374 return (HandleKeyDown( wParam
379 return (HandleKeyUp( wParam
386 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
387 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
389 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
392 } // end of wxComboBox::ProcessEditMsg
394 MRESULT EXPENTRY
wxComboEditWndProc(
404 // Forward some messages to the combobox
409 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
413 if (pCombo
->ProcessEditMsg( uMessage
422 // TODO: Deal with tooltips here
425 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
426 } // end of wxComboEditWndProc