]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8e25c198 | 2 | // Name: src/msw/combobox.cpp |
2bda0e17 KB |
3 | // Purpose: wxComboBox class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
f6bcfd97 BP |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
fddfd9e1 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
af79c52d VZ |
27 | #if wxUSE_COMBOBOX |
28 | ||
670f9935 WS |
29 | #include "wx/combobox.h" |
30 | ||
2bda0e17 | 31 | #ifndef WX_PRECOMP |
57bd4c60 | 32 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" |
fddfd9e1 VZ |
33 | #include "wx/settings.h" |
34 | #include "wx/log.h" | |
2b5f62a0 VZ |
35 | // for wxEVT_COMMAND_TEXT_ENTER |
36 | #include "wx/textctrl.h" | |
670f9935 | 37 | #include "wx/app.h" |
c64755ed | 38 | #include "wx/brush.h" |
2bda0e17 KB |
39 | #endif |
40 | ||
2bda0e17 | 41 | #include "wx/clipbrd.h" |
428f8b06 | 42 | #include "wx/wupdlock.h" |
2bda0e17 KB |
43 | #include "wx/msw/private.h" |
44 | ||
63f7d502 VZ |
45 | #if wxUSE_UXTHEME |
46 | #include "wx/msw/uxtheme.h" | |
47 | #endif | |
48 | ||
f6bcfd97 | 49 | #if wxUSE_TOOLTIPS |
f6bcfd97 BP |
50 | #include "wx/tooltip.h" |
51 | #endif // wxUSE_TOOLTIPS | |
52 | ||
53 | // ---------------------------------------------------------------------------- | |
54 | // wxWin macros | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
150e31d2 JS |
57 | BEGIN_EVENT_TABLE(wxComboBox, wxControl) |
58 | EVT_MENU(wxID_CUT, wxComboBox::OnCut) | |
59 | EVT_MENU(wxID_COPY, wxComboBox::OnCopy) | |
60 | EVT_MENU(wxID_PASTE, wxComboBox::OnPaste) | |
61 | EVT_MENU(wxID_UNDO, wxComboBox::OnUndo) | |
62 | EVT_MENU(wxID_REDO, wxComboBox::OnRedo) | |
63 | EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete) | |
64 | EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll) | |
65 | ||
66 | EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut) | |
67 | EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy) | |
68 | EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste) | |
69 | EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo) | |
70 | EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo) | |
71 | EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete) | |
72 | EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll) | |
73 | END_EVENT_TABLE() | |
74 | ||
f6bcfd97 BP |
75 | // ---------------------------------------------------------------------------- |
76 | // function prototypes | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd, | |
80 | UINT message, | |
81 | WPARAM wParam, | |
82 | LPARAM lParam); | |
83 | ||
84 | // --------------------------------------------------------------------------- | |
85 | // global vars | |
86 | // --------------------------------------------------------------------------- | |
87 | ||
88 | // the pointer to standard radio button wnd proc | |
975b6bcf | 89 | static WNDPROC gs_wndprocEdit = (WNDPROC)NULL; |
f6bcfd97 BP |
90 | |
91 | // ============================================================================ | |
92 | // implementation | |
93 | // ============================================================================ | |
94 | ||
75aaa4c5 VZ |
95 | namespace |
96 | { | |
97 | ||
98 | // Check if the given message should be forwarded from the edit control which | |
99 | // is part of the combobox to wxComboBox itself. All messages generating the | |
100 | // events that the code using wxComboBox could be interested in must be | |
101 | // forwarded. | |
102 | bool ShouldForwardFromEditToCombo(UINT message) | |
103 | { | |
104 | switch ( message ) | |
105 | { | |
106 | case WM_KEYUP: | |
107 | case WM_KEYDOWN: | |
108 | case WM_CHAR: | |
109 | case WM_SYSCHAR: | |
110 | case WM_SYSKEYDOWN: | |
111 | case WM_SYSKEYUP: | |
112 | case WM_SETFOCUS: | |
113 | case WM_KILLFOCUS: | |
114 | case WM_CUT: | |
115 | case WM_COPY: | |
116 | case WM_PASTE: | |
117 | return true; | |
118 | } | |
119 | ||
120 | return false; | |
121 | } | |
122 | ||
123 | } // anonymous namespace | |
124 | ||
f6bcfd97 BP |
125 | // ---------------------------------------------------------------------------- |
126 | // wnd proc for subclassed edit control | |
127 | // ---------------------------------------------------------------------------- | |
128 | ||
129 | LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd, | |
130 | UINT message, | |
131 | WPARAM wParam, | |
132 | LPARAM lParam) | |
133 | { | |
134 | HWND hwndCombo = ::GetParent(hWnd); | |
135 | wxWindow *win = wxFindWinFromHandle((WXHWND)hwndCombo); | |
136 | ||
75aaa4c5 | 137 | if ( ShouldForwardFromEditToCombo(message) ) |
f6bcfd97 | 138 | { |
75aaa4c5 VZ |
139 | wxComboBox *combo = wxDynamicCast(win, wxComboBox); |
140 | if ( !combo ) | |
141 | { | |
142 | // we can get WM_KILLFOCUS while our parent is already half | |
143 | // destroyed and hence doesn't look like a combobx any | |
144 | // longer, check for it to avoid bogus assert failures | |
145 | if ( !win->IsBeingDeleted() ) | |
f6bcfd97 | 146 | { |
75aaa4c5 | 147 | wxFAIL_MSG( wxT("should have combo as parent") ); |
f6bcfd97 | 148 | } |
75aaa4c5 VZ |
149 | } |
150 | else if ( combo->MSWProcessEditMsg(message, wParam, lParam) ) | |
151 | { | |
152 | // handled by parent | |
153 | return 0; | |
154 | } | |
155 | } | |
156 | else if ( message == WM_GETDLGCODE ) | |
157 | { | |
158 | wxCHECK_MSG( win, 0, wxT("should have a parent") ); | |
f6bcfd97 | 159 | |
75aaa4c5 VZ |
160 | if ( win->GetWindowStyle() & wxTE_PROCESS_ENTER ) |
161 | { | |
162 | // need to return a custom dlg code or we'll never get it | |
163 | return DLGC_WANTMESSAGE; | |
164 | } | |
f6bcfd97 BP |
165 | } |
166 | ||
167 | return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam); | |
168 | } | |
169 | ||
f6bcfd97 | 170 | // ---------------------------------------------------------------------------- |
3a7d5f7c | 171 | // wxComboBox callbacks |
f6bcfd97 BP |
172 | // ---------------------------------------------------------------------------- |
173 | ||
c140b7e7 | 174 | WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) |
3a7d5f7c | 175 | { |
5301d1f7 VZ |
176 | // TODO: handle WM_CTLCOLOR messages from our EDIT control to be able to |
177 | // set its colour correctly (to be the same as our own one) | |
682214d5 | 178 | |
3a7d5f7c VZ |
179 | switch ( nMsg ) |
180 | { | |
682214d5 | 181 | case WM_SIZE: |
3bce55ac JS |
182 | // wxStaticBox can generate this message, when modifying the control's style. |
183 | // This causes the content of the combobox to be selected, for some reason. | |
184 | case WM_STYLECHANGED: | |
5301d1f7 VZ |
185 | { |
186 | // combobox selection sometimes spontaneously changes when its | |
187 | // size changes, restore it to the old value if necessary | |
e9717bd5 VZ |
188 | if ( !GetEditHWNDIfAvailable() ) |
189 | break; | |
190 | ||
5301d1f7 VZ |
191 | long fromOld, toOld; |
192 | GetSelection(&fromOld, &toOld); | |
428f8b06 VZ |
193 | |
194 | // if an editable combobox has a not empty text not from the | |
195 | // list, it tries to autocomplete it from the list when it is | |
196 | // resized, but we don't want this to happen as it doesn't seem | |
197 | // to make any sense, so we forcefully restore the old text | |
198 | wxString textOld; | |
199 | if ( !HasFlag(wxCB_READONLY) && GetCurrentSelection() == -1 ) | |
200 | textOld = GetValue(); | |
201 | ||
202 | // eliminate flickering during following hacks | |
203 | wxWindowUpdateLocker lock(this); | |
204 | ||
5301d1f7 | 205 | WXLRESULT result = wxChoice::MSWWindowProc(nMsg, wParam, lParam); |
682214d5 | 206 | |
428f8b06 VZ |
207 | if ( !textOld.empty() && GetValue() != textOld ) |
208 | SetLabel(textOld); | |
209 | ||
5301d1f7 VZ |
210 | long fromNew, toNew; |
211 | GetSelection(&fromNew, &toNew); | |
682214d5 | 212 | |
5301d1f7 VZ |
213 | if ( fromOld != fromNew || toOld != toNew ) |
214 | { | |
215 | SetSelection(fromOld, toOld); | |
216 | } | |
682214d5 | 217 | |
5301d1f7 VZ |
218 | return result; |
219 | } | |
3a7d5f7c VZ |
220 | } |
221 | ||
5301d1f7 | 222 | return wxChoice::MSWWindowProc(nMsg, wParam, lParam); |
3a7d5f7c VZ |
223 | } |
224 | ||
f6bcfd97 BP |
225 | bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam) |
226 | { | |
227 | switch ( msg ) | |
228 | { | |
229 | case WM_CHAR: | |
2b5f62a0 VZ |
230 | // for compatibility with wxTextCtrl, generate a special message |
231 | // when Enter is pressed | |
232 | if ( wParam == VK_RETURN ) | |
233 | { | |
a2634d81 RR |
234 | if (SendMessage(GetHwnd(), CB_GETDROPPEDSTATE, 0, 0)) |
235 | return false; | |
f4322df6 | 236 | |
2b5f62a0 | 237 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); |
593ac33e VZ |
238 | |
239 | const int sel = GetSelection(); | |
240 | event.SetInt(sel); | |
2b5f62a0 | 241 | event.SetString(GetValue()); |
593ac33e VZ |
242 | InitCommandEventWithItems(event, sel); |
243 | ||
ffb1629f VZ |
244 | if ( ProcessCommand(event) ) |
245 | { | |
246 | // don't let the event through to the native control | |
247 | // because it doesn't need it and may generate an annoying | |
248 | // beep if it gets it | |
249 | return true; | |
250 | } | |
2b5f62a0 | 251 | } |
75aaa4c5 | 252 | // fall through, WM_CHAR is one of the message we should forward. |
2b5f62a0 | 253 | |
75aaa4c5 VZ |
254 | default: |
255 | if ( ShouldForwardFromEditToCombo(msg) ) | |
256 | { | |
257 | // For all the messages forward from the edit control the | |
258 | // result is not used. | |
259 | WXLRESULT result; | |
260 | return MSWHandleMessage(&result, msg, wParam, lParam); | |
261 | } | |
f6bcfd97 BP |
262 | } |
263 | ||
02b7b6b0 | 264 | return false; |
f6bcfd97 BP |
265 | } |
266 | ||
6ba93d23 | 267 | bool wxComboBox::MSWCommand(WXUINT param, WXWORD id) |
2bda0e17 | 268 | { |
fddfd9e1 | 269 | int sel = -1; |
7d90194c VZ |
270 | wxString value; |
271 | ||
cd0b1709 | 272 | switch ( param ) |
8c1c5302 | 273 | { |
ae3b1487 VZ |
274 | case CBN_DROPDOWN: |
275 | // remember the last selection, just as wxChoice does | |
276 | m_lastAcceptedSelection = GetCurrentSelection(); | |
277 | if ( m_lastAcceptedSelection == -1 ) | |
278 | { | |
279 | // but unlike with wxChoice we may have no selection but still | |
280 | // have some text and we should avoid erasing it if the drop | |
281 | // down is cancelled (see #8474) | |
282 | m_lastAcceptedSelection = wxID_NONE; | |
283 | } | |
8933fbc6 VZ |
284 | { |
285 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId()); | |
286 | event.SetEventObject(this); | |
287 | ProcessCommand(event); | |
288 | } | |
289 | break; | |
290 | case CBN_CLOSEUP: | |
291 | { | |
292 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId()); | |
293 | event.SetEventObject(this); | |
294 | ProcessCommand(event); | |
295 | } | |
ae3b1487 | 296 | break; |
78a87a5d | 297 | case CBN_SELENDOK: |
8e25c198 | 298 | #ifndef __SMARTPHONE__ |
7d90194c VZ |
299 | // we need to reset this to prevent the selection from being undone |
300 | // by wxChoice, see wxChoice::MSWCommand() and comments there | |
301 | m_lastAcceptedSelection = wxID_NONE; | |
8e25c198 | 302 | #endif |
13bcc348 | 303 | |
7d90194c VZ |
304 | // set these variables so that they could be also fixed in |
305 | // CBN_EDITCHANGE below | |
306 | sel = GetSelection(); | |
f5a45ee2 | 307 | value = GetStringSelection(); |
d0b6344d VZ |
308 | |
309 | // this string is going to become the new combobox value soon but | |
310 | // we need it to be done right now, otherwise the event handler | |
311 | // could get a wrong value when it calls our GetValue() | |
017dc06b | 312 | ::SetWindowText(GetHwnd(), value.t_str()); |
d0b6344d | 313 | |
cd0b1709 VZ |
314 | { |
315 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId()); | |
7d90194c VZ |
316 | event.SetInt(sel); |
317 | event.SetString(value); | |
593ac33e VZ |
318 | InitCommandEventWithItems(event, sel); |
319 | ||
cd0b1709 VZ |
320 | ProcessCommand(event); |
321 | } | |
fddfd9e1 VZ |
322 | |
323 | // fall through: for compability with wxGTK, also send the text | |
324 | // update event when the selection changes (this also seems more | |
325 | // logical as the text does change) | |
29006414 | 326 | |
cd0b1709 | 327 | case CBN_EDITCHANGE: |
b7bfef38 | 328 | if ( m_allowTextEvents ) |
cd0b1709 | 329 | { |
7ba166dd | 330 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId()); |
3adc70bf | 331 | |
7d90194c | 332 | // if sel != -1, value was already initialized above |
7ba166dd | 333 | if ( sel == -1 ) |
3adc70bf | 334 | { |
7d90194c | 335 | value = wxGetWindowText(GetHwnd()); |
3adc70bf VZ |
336 | } |
337 | ||
7d90194c | 338 | event.SetString(value); |
593ac33e VZ |
339 | InitCommandEventWithItems(event, sel); |
340 | ||
0ef2ebba | 341 | ProcessCommand(event); |
cd0b1709 VZ |
342 | } |
343 | break; | |
6ba93d23 VZ |
344 | |
345 | default: | |
346 | return wxChoice::MSWCommand(param, id); | |
cd0b1709 | 347 | } |
29006414 | 348 | |
7d90194c | 349 | // skip wxChoice version as it would generate its own events for |
ae3b1487 | 350 | // CBN_SELENDOK and also interfere with our handling of CBN_DROPDOWN |
8cc5e8cf | 351 | return true; |
2bda0e17 KB |
352 | } |
353 | ||
90ac8b50 RR |
354 | bool wxComboBox::MSWShouldPreProcessMessage(WXMSG *pMsg) |
355 | { | |
356 | // prevent command accelerators from stealing editing | |
357 | // hotkeys when we have the focus | |
358 | if (wxIsCtrlDown()) | |
359 | { | |
360 | WPARAM vkey = pMsg->wParam; | |
6b54668b | 361 | |
90ac8b50 RR |
362 | switch (vkey) |
363 | { | |
364 | case 'C': | |
365 | case 'V': | |
366 | case 'X': | |
367 | case VK_INSERT: | |
368 | case VK_DELETE: | |
369 | case VK_HOME: | |
370 | case VK_END: | |
371 | return false; | |
372 | } | |
373 | } | |
6b54668b | 374 | |
90ac8b50 RR |
375 | return wxChoice::MSWShouldPreProcessMessage(pMsg); |
376 | } | |
377 | ||
e9717bd5 VZ |
378 | WXHWND wxComboBox::GetEditHWNDIfAvailable() const |
379 | { | |
1b6010d8 VZ |
380 | // FIXME-VC6: Only VC6 needs this guard, see WINVER definition in |
381 | // include/wx/msw/wrapwin.h | |
382 | #if defined(WINVER) && WINVER >= 0x0500 | |
df74e2d2 VZ |
383 | WinStruct<COMBOBOXINFO> info; |
384 | if ( MSWGetComboBoxInfo(&info) ) | |
e558f953 | 385 | return info.hwndItem; |
1b6010d8 | 386 | #endif // WINVER >= 0x0500 |
e558f953 JS |
387 | |
388 | if (HasFlag(wxCB_SIMPLE)) | |
389 | { | |
390 | POINT pt; | |
391 | pt.x = pt.y = 4; | |
392 | return (WXHWND) ::ChildWindowFromPoint(GetHwnd(), pt); | |
393 | } | |
fe56156f | 394 | |
1690c2ce JS |
395 | // notice that a slightly safer alternative could be to use FindWindowEx() |
396 | // but it's not available under WinCE so just take the first child for now | |
397 | // to keep one version of the code for all platforms and fix it later if | |
398 | // problems are discovered | |
399 | ||
74052fe8 VZ |
400 | // we assume that the only child of the combobox is the edit window |
401 | return (WXHWND)::GetWindow(GetHwnd(), GW_CHILD); | |
e9717bd5 VZ |
402 | } |
403 | ||
f6bcfd97 BP |
404 | WXHWND wxComboBox::GetEditHWND() const |
405 | { | |
406 | // this function should not be called for wxCB_READONLY controls, it is | |
e9717bd5 | 407 | // the callers responsibility to check this |
fa2f57be | 408 | wxASSERT_MSG( !HasFlag(wxCB_READONLY), |
9a83f860 | 409 | wxT("read-only combobox doesn't have any edit control") ); |
f6bcfd97 | 410 | |
e9717bd5 | 411 | WXHWND hWndEdit = GetEditHWNDIfAvailable(); |
9a83f860 | 412 | wxASSERT_MSG( hWndEdit, wxT("combobox without edit control?") ); |
f6bcfd97 | 413 | |
e9717bd5 | 414 | return hWndEdit; |
f6bcfd97 BP |
415 | } |
416 | ||
63f7d502 VZ |
417 | wxWindow *wxComboBox::GetEditableWindow() |
418 | { | |
419 | wxASSERT_MSG( !HasFlag(wxCB_READONLY), | |
9a83f860 | 420 | wxT("read-only combobox doesn't have any edit control") ); |
63f7d502 VZ |
421 | |
422 | return this; | |
423 | } | |
424 | ||
71e57cd6 VZ |
425 | // ---------------------------------------------------------------------------- |
426 | // wxComboBox creation | |
427 | // ---------------------------------------------------------------------------- | |
428 | ||
debe6624 | 429 | bool wxComboBox::Create(wxWindow *parent, wxWindowID id, |
c085e333 VZ |
430 | const wxString& value, |
431 | const wxPoint& pos, | |
432 | const wxSize& size, | |
433 | int n, const wxString choices[], | |
434 | long style, | |
435 | const wxValidator& validator, | |
436 | const wxString& name) | |
2bda0e17 | 437 | { |
bdf5c30d VZ |
438 | // pretend that wxComboBox is hidden while it is positioned and resized and |
439 | // show it only right before leaving this method because otherwise there is | |
440 | // some noticeable flicker while the control rearranges itself | |
02b7b6b0 | 441 | m_isShown = false; |
bdf5c30d | 442 | |
71e57cd6 VZ |
443 | if ( !CreateAndInit(parent, id, pos, size, n, choices, style, |
444 | validator, name) ) | |
02b7b6b0 | 445 | return false; |
f6bcfd97 | 446 | |
6341d824 VZ |
447 | // we shouldn't call SetValue() for an empty string because this would |
448 | // (correctly) result in an assert with a read only combobox and is useless | |
449 | // for the other ones anyhow | |
450 | if ( !value.empty() ) | |
b9b8a2b5 | 451 | SetValue(value); |
db34b147 | 452 | |
f6bcfd97 BP |
453 | // a (not read only) combobox is, in fact, 2 controls: the combobox itself |
454 | // and an edit control inside it and if we want to catch events from this | |
455 | // edit control, we must subclass it as well | |
456 | if ( !(style & wxCB_READONLY) ) | |
457 | { | |
94972183 | 458 | gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(), wxComboEditWndProc); |
f6bcfd97 | 459 | } |
2bda0e17 | 460 | |
bdf5c30d | 461 | // and finally, show the control |
02b7b6b0 | 462 | Show(true); |
bdf5c30d | 463 | |
02b7b6b0 | 464 | return true; |
2bda0e17 KB |
465 | } |
466 | ||
584ad2a3 MB |
467 | bool wxComboBox::Create(wxWindow *parent, wxWindowID id, |
468 | const wxString& value, | |
469 | const wxPoint& pos, | |
470 | const wxSize& size, | |
471 | const wxArrayString& choices, | |
472 | long style, | |
473 | const wxValidator& validator, | |
474 | const wxString& name) | |
475 | { | |
476 | wxCArrayString chs(choices); | |
477 | return Create(parent, id, value, pos, size, chs.GetCount(), | |
478 | chs.GetStrings(), style, validator, name); | |
479 | } | |
480 | ||
71e57cd6 VZ |
481 | WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const |
482 | { | |
483 | // we never have an external border | |
484 | WXDWORD msStyle = wxChoice::MSWGetStyle | |
485 | ( | |
486 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, exstyle | |
487 | ); | |
488 | ||
1dfd425a VZ |
489 | // usually WS_TABSTOP is added by wxControl::MSWGetStyle() but as we're |
490 | // created hidden (see Create() above), it is not done for us but we still | |
491 | // want to have this style | |
492 | msStyle |= WS_TABSTOP; | |
493 | ||
71e57cd6 VZ |
494 | // remove the style always added by wxChoice |
495 | msStyle &= ~CBS_DROPDOWNLIST; | |
496 | ||
497 | if ( style & wxCB_READONLY ) | |
498 | msStyle |= CBS_DROPDOWNLIST; | |
499 | #ifndef __WXWINCE__ | |
500 | else if ( style & wxCB_SIMPLE ) | |
501 | msStyle |= CBS_SIMPLE; // A list (shown always) and edit control | |
502 | #endif | |
503 | else | |
504 | msStyle |= CBS_DROPDOWN; | |
505 | ||
506 | // there is no reason to not always use CBS_AUTOHSCROLL, so do use it | |
507 | msStyle |= CBS_AUTOHSCROLL; | |
508 | ||
509 | // NB: we used to also add CBS_NOINTEGRALHEIGHT here but why? | |
510 | ||
511 | return msStyle; | |
512 | } | |
513 | ||
514 | // ---------------------------------------------------------------------------- | |
515 | // wxComboBox text control-like methods | |
516 | // ---------------------------------------------------------------------------- | |
517 | ||
e9717bd5 VZ |
518 | wxString wxComboBox::GetValue() const |
519 | { | |
520 | return HasFlag(wxCB_READONLY) ? GetStringSelection() | |
521 | : wxTextEntry::GetValue(); | |
522 | } | |
523 | ||
2bda0e17 KB |
524 | void wxComboBox::SetValue(const wxString& value) |
525 | { | |
2b5f62a0 VZ |
526 | if ( HasFlag(wxCB_READONLY) ) |
527 | SetStringSelection(value); | |
b38f3ff3 | 528 | else |
fa2f57be | 529 | wxTextEntry::SetValue(value); |
150e31d2 JS |
530 | } |
531 | ||
e6a84162 VZ |
532 | void wxComboBox::Clear() |
533 | { | |
534 | wxChoice::Clear(); | |
535 | if ( !HasFlag(wxCB_READONLY) ) | |
536 | wxTextEntry::Clear(); | |
537 | } | |
538 | ||
5ddb3b8c VZ |
539 | bool wxComboBox::ContainsHWND(WXHWND hWnd) const |
540 | { | |
541 | return hWnd == GetEditHWNDIfAvailable(); | |
542 | } | |
543 | ||
e9717bd5 VZ |
544 | void wxComboBox::GetSelection(long *from, long *to) const |
545 | { | |
546 | if ( !HasFlag(wxCB_READONLY) ) | |
547 | { | |
548 | wxTextEntry::GetSelection(from, to); | |
549 | } | |
550 | else // text selection doesn't make sense for read only comboboxes | |
551 | { | |
552 | if ( from ) | |
553 | *from = -1; | |
554 | if ( to ) | |
555 | *to = -1; | |
556 | } | |
557 | } | |
558 | ||
150e31d2 JS |
559 | bool wxComboBox::IsEditable() const |
560 | { | |
fa2f57be | 561 | return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable(); |
3f5ca6b1 RN |
562 | } |
563 | ||
150e31d2 JS |
564 | // ---------------------------------------------------------------------------- |
565 | // standard event handling | |
566 | // ---------------------------------------------------------------------------- | |
567 | ||
568 | void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event)) | |
569 | { | |
570 | Cut(); | |
571 | } | |
572 | ||
573 | void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event)) | |
574 | { | |
575 | Copy(); | |
576 | } | |
577 | ||
578 | void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event)) | |
579 | { | |
580 | Paste(); | |
581 | } | |
582 | ||
583 | void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event)) | |
584 | { | |
585 | Undo(); | |
586 | } | |
587 | ||
588 | void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event)) | |
589 | { | |
590 | Redo(); | |
591 | } | |
592 | ||
593 | void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event)) | |
594 | { | |
5a25f858 | 595 | RemoveSelection(); |
150e31d2 JS |
596 | } |
597 | ||
598 | void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
599 | { | |
e976429d | 600 | SelectAll(); |
150e31d2 JS |
601 | } |
602 | ||
603 | void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event) | |
604 | { | |
605 | event.Enable( CanCut() ); | |
606 | } | |
607 | ||
608 | void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event) | |
609 | { | |
610 | event.Enable( CanCopy() ); | |
611 | } | |
612 | ||
613 | void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event) | |
614 | { | |
615 | event.Enable( CanPaste() ); | |
616 | } | |
617 | ||
618 | void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event) | |
619 | { | |
c0e15042 | 620 | event.Enable( IsEditable() && CanUndo() ); |
150e31d2 JS |
621 | } |
622 | ||
623 | void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) | |
624 | { | |
c0e15042 | 625 | event.Enable( IsEditable() && CanRedo() ); |
150e31d2 JS |
626 | } |
627 | ||
628 | void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) | |
629 | { | |
6b54668b | 630 | event.Enable(IsEditable() && HasSelection()); |
150e31d2 JS |
631 | } |
632 | ||
633 | void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
634 | { | |
e976429d | 635 | event.Enable(IsEditable() && !wxTextEntry::IsEmpty()); |
150e31d2 JS |
636 | } |
637 | ||
d6b9cc87 VZ |
638 | #if wxUSE_TOOLTIPS |
639 | ||
640 | void wxComboBox::DoSetToolTip(wxToolTip *tip) | |
641 | { | |
642 | wxChoice::DoSetToolTip(tip); | |
643 | ||
644 | if ( tip && !HasFlag(wxCB_READONLY) ) | |
f7dd07f6 | 645 | tip->AddOtherWindow(GetEditHWND()); |
d6b9cc87 VZ |
646 | } |
647 | ||
648 | #endif // wxUSE_TOOLTIPS | |
649 | ||
63f7d502 VZ |
650 | #if wxUSE_UXTHEME |
651 | ||
652 | bool wxComboBox::SetHint(const wxString& hintOrig) | |
653 | { | |
654 | wxString hint(hintOrig); | |
655 | if ( wxUxThemeEngine::GetIfActive() ) | |
656 | { | |
657 | // under XP (but not Vista) there is a bug in cue banners | |
658 | // implementation for combobox edit control: the first character is | |
659 | // partially chopped off, so prepend a space to make it fully visible | |
660 | hint.insert(0, " "); | |
661 | } | |
662 | ||
663 | return wxTextEntry::SetHint(hint); | |
664 | } | |
665 | ||
666 | #endif // wxUSE_UXTHEME | |
667 | ||
aa24f946 VZ |
668 | wxSize wxComboBox::DoGetSizeFromTextSize(int xlen, int ylen) const |
669 | { | |
670 | wxSize tsize( wxChoice::DoGetSizeFromTextSize(xlen, ylen) ); | |
671 | ||
672 | if ( !HasFlag(wxCB_READONLY) ) | |
673 | { | |
674 | // Add the margins we have previously set | |
675 | wxPoint marg( GetMargins() ); | |
676 | marg.x = wxMax(0, marg.x); | |
677 | marg.y = wxMax(0, marg.y); | |
678 | tsize.IncBy( marg ); | |
679 | } | |
680 | ||
681 | return tsize; | |
682 | } | |
683 | ||
71e57cd6 | 684 | #endif // wxUSE_COMBOBOX |