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