]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
Fix horizontal mouse wheel scrolling in wxGTK.
[wxWidgets.git] / src / os2 / combobox.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
7520f3da 2// Name: src/os2/combobox.cpp
0e320a79 3// Purpose: wxComboBox class
37f214d5 4// Author: David Webster
0e320a79 5// Modified by:
37f214d5 6// Created: 10/13/99
37f214d5 7// Copyright: (c) David Webster
65571936 8// Licence: wxWindows licence
0e320a79
DW
9/////////////////////////////////////////////////////////////////////////////
10
37f214d5
DW
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
7520f3da
WS
14#if wxUSE_COMBOBOX
15
a5bbd1cc
WS
16#include "wx/combobox.h"
17
37f214d5 18#ifndef WX_PRECOMP
a4a16252 19 #include "wx/settings.h"
0e320a79
DW
20#endif
21
37f214d5
DW
22#include "wx/clipbrd.h"
23#include "wx/os2/private.h"
0e320a79 24
0cf6acbf
DW
25#define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
26
27MRESULT EXPENTRY wxComboEditWndProc( HWND hWnd
28 ,UINT uMessage
29 ,MPARAM wParam
30 ,MPARAM lParam
31 );
32//
33// The pointer to standard wnd proc
34//
35static WXFARPROC gfnWndprocEdit = (WXFARPROC)NULL;
36
a5bbd1cc 37bool wxComboBox::OS2Command( WXUINT uParam, WXWORD WXUNUSED(wId) )
0e320a79 38{
331f1e07 39 long lSel = GetSelection();
a5bbd1cc 40 wxString sValue;
0e320a79 41
0cf6acbf
DW
42 switch (uParam)
43 {
1de4baa3 44 case CBN_LBSELECT:
331f1e07 45 if (lSel > -1)
0cf6acbf 46 {
ce7fe42e 47 wxCommandEvent vEvent( wxEVT_COMBOBOX, GetId() );
0cf6acbf 48
331f1e07 49 vEvent.SetInt(lSel);
0cf6acbf 50 vEvent.SetEventObject(this);
0fba44b4 51 vEvent.SetString(GetStringSelection());
a5bbd1cc 52
0cf6acbf
DW
53 ProcessCommand(vEvent);
54 }
55 break;
56
1de4baa3 57 case CBN_EFCHANGE:
0cf6acbf 58 {
ce7fe42e 59 wxCommandEvent vEvent( wxEVT_TEXT, GetId() );
0cf6acbf
DW
60
61 if (lSel == -1L)
62 sValue = GetValue();
63 else
331f1e07
SN
64 sValue = GetStringSelection();
65 vEvent.SetString(sValue);
0cf6acbf
DW
66 vEvent.SetEventObject(this);
67 ProcessCommand(vEvent);
68 }
69 break;
70 }
71 //
72 // There is no return value for the CBN_ notifications, so always return
7d8268a1 73 // false from here to pass the message to DefWindowProc()
0cf6acbf 74 //
7d8268a1 75 return false;
0cf6acbf
DW
76} // end of wxComboBox::OS2Command
77
584ad2a3
MB
78bool wxComboBox::Create(
79 wxWindow* pParent
80, wxWindowID vId
81, const wxString& rsValue
82, const wxPoint& rPos
83, const wxSize& rSize
84, const wxArrayString& asChoices
85, long lStyle
86, const wxValidator& rValidator
87, const wxString& rsName
88)
89{
90 wxCArrayString chs(asChoices);
91
92 return Create(pParent, vId, rsValue, rPos, rSize, chs.GetCount(),
93 chs.GetStrings(), lStyle, rValidator, rsName);
94}
95
0cf6acbf
DW
96bool wxComboBox::Create(
97 wxWindow* pParent
98, wxWindowID vId
99, const wxString& rsValue
100, const wxPoint& rPos
101, const wxSize& rSize
102, int n
103, const wxString asChoices[]
104, long lStyle
0cf6acbf 105, const wxValidator& rValidator
0cf6acbf
DW
106, const wxString& rsName
107)
0e320a79 108{
7d8268a1 109 m_isShown = false;
0cf6acbf 110
b9b1d6c8 111 if (!CreateControl( pParent
0cf6acbf
DW
112 ,vId
113 ,rPos
114 ,rSize
115 ,lStyle
0cf6acbf 116 ,rValidator
0cf6acbf
DW
117 ,rsName
118 ))
7d8268a1 119 return false;
0cf6acbf
DW
120
121 //
122 // Get the right style
123 //
124 long lSstyle = 0L;
125
126 lSstyle = WS_TABSTOP |
127 WS_VISIBLE;
128
2fbb8fbb
SN
129 // clipping siblings does not yet work
130 // if (lStyle & wxCLIP_SIBLINGS )
131 // lSstyle |= WS_CLIPSIBLINGS;
0cf6acbf
DW
132 if (lStyle & wxCB_READONLY)
133 lSstyle |= CBS_DROPDOWNLIST;
134 else if (lStyle & wxCB_SIMPLE)
135 lSstyle |= CBS_SIMPLE; // A list (shown always) and edit control
136 else
137 lSstyle |= CBS_DROPDOWN;
138
139
9a83f860 140 if (!OS2CreateControl( wxT("COMBOBOX")
0cf6acbf
DW
141 ,lSstyle
142 ))
7d8268a1 143 return false;
0cf6acbf
DW
144
145 //
146 // A choice/combobox normally has a white background (or other, depending
147 // on global settings) rather than inheriting the parent's background colour.
148 //
a756f210 149 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
0cf6acbf 150
154daa94 151 for (int i = 0; i < n; i++)
0cf6acbf
DW
152 {
153 Append(asChoices[i]);
154 }
155
156 SetSize( rPos.x
157 ,rPos.y
158 ,rSize.x
159 ,rSize.y
160 );
331f1e07
SN
161
162 // Set height to use with sizers i.e. without the dropdown listbox
163 wxFont vFont = GetFont();
2fbb8fbb
SN
164 int nEditHeight;
165 wxGetCharSize( GetHWND(), NULL, &nEditHeight, &vFont );
166 nEditHeight = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nEditHeight);
823189ee 167 SetInitialSize(wxSize(-1,nEditHeight+4)); // +2x2 for the border
331f1e07 168
7d8268a1 169 if (!rsValue.empty())
0cf6acbf
DW
170 {
171 SetValue(rsValue);
172 }
173 gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd()
174 ,(PFNWP)wxComboEditWndProc
175 );
5d44b24e 176 ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this);
7d8268a1
WS
177 Show(true);
178 return true;
0cf6acbf
DW
179} // end of wxComboBox::Create
180
331f1e07
SN
181wxString wxComboBox::GetValue() const
182{
72cb72bf
SN
183 return HasFlag(wxCB_READONLY) ? GetStringSelection()
184 : wxTextEntry::GetValue();
331f1e07
SN
185}
186
72cb72bf 187void wxComboBox::SetValue(const wxString& value)
0e320a79 188{
2b5f62a0 189 if ( HasFlag(wxCB_READONLY) )
72cb72bf 190 SetStringSelection(value);
0cf6acbf 191 else
72cb72bf
SN
192 wxTextEntry::SetValue(value);
193}
0e320a79 194
72cb72bf 195void wxComboBox::Clear()
0e320a79 196{
72cb72bf
SN
197 wxChoice::Clear();
198 if ( !HasFlag(wxCB_READONLY) )
199 wxTextEntry::Clear();
200}
0e320a79 201
72cb72bf 202bool wxComboBox::IsEditable() const
0e320a79 203{
72cb72bf
SN
204 return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable();
205}
0cf6acbf 206
0cf6acbf
DW
207bool wxComboBox::ProcessEditMsg(
208 WXUINT uMsg
209, WXWPARAM wParam
210, WXLPARAM lParam)
0e320a79 211{
0cf6acbf
DW
212 SHORT vFlag;
213 switch (uMsg)
214 {
215 case WM_CHAR:
216 vFlag = SHORT1FROMMP(wParam);
217 switch(vFlag)
218 {
219 case KC_CHAR:
598d8cac 220 return (HandleChar( wParam
0cf6acbf 221 ,lParam
7d8268a1 222 ,true /* isASCII */
0cf6acbf
DW
223 ));
224
225 case KC_PREVDOWN:
a086de98 226 return (HandleKeyDown( wParam
0cf6acbf
DW
227 ,lParam
228 ));
229
230 case KC_KEYUP:
a086de98 231 return (HandleKeyUp( wParam
0cf6acbf
DW
232 ,lParam
233 ));
234 }
235 break;
598d8cac
DW
236
237 case WM_SETFOCUS:
238 if (SHORT1FROMMP((MPARAM)lParam) == TRUE)
239 return(HandleSetFocus((WXHWND)(HWND)wParam));
240 else
241 return(HandleKillFocus((WXHWND)(HWND)wParam));
0cf6acbf 242 }
7d8268a1 243 return false;
2fbb8fbb 244} // end of wxComboBox::ProcessEditMsg
0cf6acbf
DW
245
246MRESULT EXPENTRY wxComboEditWndProc(
247 HWND hWnd
248, UINT uMessage
249, MPARAM wParam
250, MPARAM lParam
251)
252{
0cf6acbf
DW
253 switch (uMessage)
254 {
255 //
256 // Forward some messages to the combobox
257 //
598d8cac 258 case WM_SETFOCUS:
0cf6acbf
DW
259 case WM_CHAR:
260 {
d804ec69
SN
261 wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd
262 ,QWL_USER
263 );
0cf6acbf
DW
264
265 if (pCombo->ProcessEditMsg( uMessage
266 ,wParam
267 ,lParam
268 ))
269 return ((MRESULT)0);
270 }
271 break;
272
273 //
274 // TODO: Deal with tooltips here
275 //
276 }
277 return (gfnWndprocEdit(hWnd, (ULONG)uMessage, (MPARAM)wParam, (MPARAM)lParam));
278} // end of wxComboEditWndProc
37f214d5
DW
279
280#endif
281 // wxUSE_COMBOBOX