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