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