]>
Commit | Line | Data |
---|---|---|
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 |
0e320a79 | 7 | // RCS-ID: $Id$ |
37f214d5 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
37f214d5 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
7520f3da WS |
15 | #if wxUSE_COMBOBOX |
16 | ||
a5bbd1cc WS |
17 | #include "wx/combobox.h" |
18 | ||
37f214d5 | 19 | #ifndef WX_PRECOMP |
a4a16252 | 20 | #include "wx/settings.h" |
0e320a79 DW |
21 | #endif |
22 | ||
37f214d5 DW |
23 | #include "wx/clipbrd.h" |
24 | #include "wx/os2/private.h" | |
0e320a79 | 25 | |
0cf6acbf DW |
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 | ||
a5bbd1cc | 38 | bool wxComboBox::OS2Command( WXUINT uParam, WXWORD WXUNUSED(wId) ) |
0e320a79 | 39 | { |
331f1e07 | 40 | long lSel = GetSelection(); |
a5bbd1cc | 41 | wxString sValue; |
0e320a79 | 42 | |
0cf6acbf DW |
43 | switch (uParam) |
44 | { | |
1de4baa3 | 45 | case CBN_LBSELECT: |
331f1e07 | 46 | if (lSel > -1) |
0cf6acbf | 47 | { |
ce7fe42e | 48 | wxCommandEvent vEvent( wxEVT_COMBOBOX, GetId() ); |
0cf6acbf | 49 | |
331f1e07 | 50 | vEvent.SetInt(lSel); |
0cf6acbf | 51 | vEvent.SetEventObject(this); |
0fba44b4 | 52 | vEvent.SetString(GetStringSelection()); |
a5bbd1cc | 53 | |
0cf6acbf DW |
54 | ProcessCommand(vEvent); |
55 | } | |
56 | break; | |
57 | ||
1de4baa3 | 58 | case CBN_EFCHANGE: |
0cf6acbf | 59 | { |
ce7fe42e | 60 | wxCommandEvent vEvent( wxEVT_TEXT, GetId() ); |
0cf6acbf DW |
61 | |
62 | if (lSel == -1L) | |
63 | sValue = GetValue(); | |
64 | else | |
331f1e07 SN |
65 | sValue = GetStringSelection(); |
66 | vEvent.SetString(sValue); | |
0cf6acbf DW |
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 | |
7d8268a1 | 74 | // false from here to pass the message to DefWindowProc() |
0cf6acbf | 75 | // |
7d8268a1 | 76 | return false; |
0cf6acbf DW |
77 | } // end of wxComboBox::OS2Command |
78 | ||
584ad2a3 MB |
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 | ||
0cf6acbf DW |
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 | |
0cf6acbf | 106 | , const wxValidator& rValidator |
0cf6acbf DW |
107 | , const wxString& rsName |
108 | ) | |
0e320a79 | 109 | { |
7d8268a1 | 110 | m_isShown = false; |
0cf6acbf | 111 | |
b9b1d6c8 | 112 | if (!CreateControl( pParent |
0cf6acbf DW |
113 | ,vId |
114 | ,rPos | |
115 | ,rSize | |
116 | ,lStyle | |
0cf6acbf | 117 | ,rValidator |
0cf6acbf DW |
118 | ,rsName |
119 | )) | |
7d8268a1 | 120 | return false; |
0cf6acbf DW |
121 | |
122 | // | |
123 | // Get the right style | |
124 | // | |
125 | long lSstyle = 0L; | |
126 | ||
127 | lSstyle = WS_TABSTOP | | |
128 | WS_VISIBLE; | |
129 | ||
2fbb8fbb SN |
130 | // clipping siblings does not yet work |
131 | // if (lStyle & wxCLIP_SIBLINGS ) | |
132 | // lSstyle |= WS_CLIPSIBLINGS; | |
0cf6acbf DW |
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 | ||
9a83f860 | 141 | if (!OS2CreateControl( wxT("COMBOBOX") |
0cf6acbf DW |
142 | ,lSstyle |
143 | )) | |
7d8268a1 | 144 | return false; |
0cf6acbf DW |
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 | // | |
a756f210 | 150 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); |
0cf6acbf | 151 | |
154daa94 | 152 | for (int i = 0; i < n; i++) |
0cf6acbf DW |
153 | { |
154 | Append(asChoices[i]); | |
155 | } | |
156 | ||
157 | SetSize( rPos.x | |
158 | ,rPos.y | |
159 | ,rSize.x | |
160 | ,rSize.y | |
161 | ); | |
331f1e07 SN |
162 | |
163 | // Set height to use with sizers i.e. without the dropdown listbox | |
164 | wxFont vFont = GetFont(); | |
2fbb8fbb SN |
165 | int nEditHeight; |
166 | wxGetCharSize( GetHWND(), NULL, &nEditHeight, &vFont ); | |
167 | nEditHeight = EDIT_HEIGHT_FROM_CHAR_HEIGHT(nEditHeight); | |
823189ee | 168 | SetInitialSize(wxSize(-1,nEditHeight+4)); // +2x2 for the border |
331f1e07 | 169 | |
7d8268a1 | 170 | if (!rsValue.empty()) |
0cf6acbf DW |
171 | { |
172 | SetValue(rsValue); | |
173 | } | |
174 | gfnWndprocEdit = (WXFARPROC)::WinSubclassWindow( (HWND)GetHwnd() | |
175 | ,(PFNWP)wxComboEditWndProc | |
176 | ); | |
5d44b24e | 177 | ::WinSetWindowULong(GetHwnd(), QWL_USER, (ULONG)this); |
7d8268a1 WS |
178 | Show(true); |
179 | return true; | |
0cf6acbf DW |
180 | } // end of wxComboBox::Create |
181 | ||
331f1e07 SN |
182 | wxString wxComboBox::GetValue() const |
183 | { | |
72cb72bf SN |
184 | return HasFlag(wxCB_READONLY) ? GetStringSelection() |
185 | : wxTextEntry::GetValue(); | |
331f1e07 SN |
186 | } |
187 | ||
72cb72bf | 188 | void wxComboBox::SetValue(const wxString& value) |
0e320a79 | 189 | { |
2b5f62a0 | 190 | if ( HasFlag(wxCB_READONLY) ) |
72cb72bf | 191 | SetStringSelection(value); |
0cf6acbf | 192 | else |
72cb72bf SN |
193 | wxTextEntry::SetValue(value); |
194 | } | |
0e320a79 | 195 | |
72cb72bf | 196 | void wxComboBox::Clear() |
0e320a79 | 197 | { |
72cb72bf SN |
198 | wxChoice::Clear(); |
199 | if ( !HasFlag(wxCB_READONLY) ) | |
200 | wxTextEntry::Clear(); | |
201 | } | |
0e320a79 | 202 | |
72cb72bf | 203 | bool wxComboBox::IsEditable() const |
0e320a79 | 204 | { |
72cb72bf SN |
205 | return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable(); |
206 | } | |
0cf6acbf | 207 | |
0cf6acbf DW |
208 | bool wxComboBox::ProcessEditMsg( |
209 | WXUINT uMsg | |
210 | , WXWPARAM wParam | |
211 | , WXLPARAM lParam) | |
0e320a79 | 212 | { |
0cf6acbf DW |
213 | SHORT vFlag; |
214 | switch (uMsg) | |
215 | { | |
216 | case WM_CHAR: | |
217 | vFlag = SHORT1FROMMP(wParam); | |
218 | switch(vFlag) | |
219 | { | |
220 | case KC_CHAR: | |
598d8cac | 221 | return (HandleChar( wParam |
0cf6acbf | 222 | ,lParam |
7d8268a1 | 223 | ,true /* isASCII */ |
0cf6acbf DW |
224 | )); |
225 | ||
226 | case KC_PREVDOWN: | |
a086de98 | 227 | return (HandleKeyDown( wParam |
0cf6acbf DW |
228 | ,lParam |
229 | )); | |
230 | ||
231 | case KC_KEYUP: | |
a086de98 | 232 | return (HandleKeyUp( wParam |
0cf6acbf DW |
233 | ,lParam |
234 | )); | |
235 | } | |
236 | break; | |
598d8cac DW |
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)); | |
0cf6acbf | 243 | } |
7d8268a1 | 244 | return false; |
2fbb8fbb | 245 | } // end of wxComboBox::ProcessEditMsg |
0cf6acbf DW |
246 | |
247 | MRESULT EXPENTRY wxComboEditWndProc( | |
248 | HWND hWnd | |
249 | , UINT uMessage | |
250 | , MPARAM wParam | |
251 | , MPARAM lParam | |
252 | ) | |
253 | { | |
0cf6acbf DW |
254 | switch (uMessage) |
255 | { | |
256 | // | |
257 | // Forward some messages to the combobox | |
258 | // | |
598d8cac | 259 | case WM_SETFOCUS: |
0cf6acbf DW |
260 | case WM_CHAR: |
261 | { | |
d804ec69 SN |
262 | wxComboBox* pCombo = (wxComboBox *)::WinQueryWindowULong( hWnd |
263 | ,QWL_USER | |
264 | ); | |
0cf6acbf DW |
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 | |
37f214d5 DW |
280 | |
281 | #endif | |
282 | // wxUSE_COMBOBOX |