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