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