]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/comboctrl.tex
Remove use of GetVolumeInformation since it causes long delays on network drives.
[wxWidgets.git] / docs / latex / wx / comboctrl.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %% Name: comboctrl.tex
3 %% Purpose: wxComboCtrl docs
4 %% Author: Jaakko Salli
5 %% Modified by:
6 %% Created:
7 %% RCS-ID: $Id$
8 %% Copyright: (c) Jaakko Salli
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \section{\class{wxComboCtrl}}\label{wxcomboctrl}
13
14 A combo control is a generic combobox that allows totally
15 custom popup. In addition it has other customization features.
16 For instance, position and size of the dropdown button
17 can be changed.
18
19 \wxheading{Setting Custom Popup for wxComboCtrl}
20
21 wxComboCtrl needs to be told somehow which control to use
22 and this is done by SetPopupControl(). However, we need
23 something more than just a wxControl in this method as,
24 for example, we need to call SetStringValue("initial text value")
25 and wxControl doesn't have such method. So we also need a
26 \helpref{wxComboPopup}{wxcombopopup} which is an interface which
27 must be implemented by a control to be usable as a popup.
28
29 We couldn't derive wxComboPopup from wxControl as this would make it
30 impossible to have a class deriving from a wxWidgets control and from
31 it, so instead it is just a mix-in.
32
33 Here's a minimal sample of \helpref{wxListView}{wxlistview} popup:
34
35 \begin{verbatim}
36
37 #include <wx/combo.h>
38 #include <wx/listctrl.h>
39
40 class wxListViewComboPopup : public wxListView,
41 public wxComboPopup
42 {
43 public:
44
45 // Initialize member variables
46 virtual void Init()
47 {
48 m_value = -1;
49 }
50
51 // Create popup control
52 virtual bool Create(wxWindow* parent)
53 {
54 return wxListView::Create(parent,1,wxPoint(0,0),wxDefaultSize);
55 }
56
57 // Return pointer to the created control
58 virtual wxWindow *GetControl() { return this; }
59
60 // Translate string into a list selection
61 virtual void SetStringValue(const wxString& s)
62 {
63 int n = wxListView::FindItem(-1,s);
64 if ( n >= 0 && n < wxListView::GetItemCount() )
65 wxListView::Select(n);
66 }
67
68 // Get list selection as a string
69 virtual wxString GetStringValue() const
70 {
71 if ( m_value >= 0 )
72 return wxListView::GetItemText(m_value);
73 return wxEmptyString;
74 }
75
76 // Do mouse hot-tracking (which is typical in list popups)
77 void OnMouseMove(wxMouseEvent& event)
78 {
79 // TODO: Move selection to cursor
80 }
81
82 // On mouse left up, set the value and close the popup
83 void OnMouseClick(wxMouseEvent& WXUNUSED(event))
84 {
85 m_value = wxListView::GetFirstSelected();
86
87 // TODO: Send event as well
88
89 Dismiss();
90 }
91
92 protected:
93
94 int m_value; // current item index
95
96 private:
97 DECLARE_EVENT_TABLE()
98 };
99
100 BEGIN_EVENT_TABLE(wxListViewComboPopup, wxListView)
101 EVT_MOTION(wxListViewComboPopup::OnMouseMove)
102 EVT_LEFT_UP(wxListViewComboPopup::OnMouseClick)
103 END_EVENT_TABLE()
104
105 \end{verbatim}
106
107 Here's how you would create and populate it in a dialog constructor:
108
109 \begin{verbatim}
110
111 wxComboCtrl* comboCtrl = new wxComboCtrl(this,wxID_ANY,wxEmptyString);
112
113 wxListViewComboPopup* popupCtrl = new wxListViewComboPopup();
114
115 comboCtrl->SetPopupControl(popupCtrl);
116
117 // Populate using wxListView methods
118 popupCtrl->InsertItem(popupCtrl->GetItemCount(),wxT("First Item"));
119 popupCtrl->InsertItem(popupCtrl->GetItemCount(),wxT("Second Item"));
120 popupCtrl->InsertItem(popupCtrl->GetItemCount(),wxT("Third Item"));
121
122 \end{verbatim}
123
124 \wxheading{Derived from}
125
126 \helpref{wxControl}{wxcontrol}\\
127 \helpref{wxWindow}{wxwindow}\\
128 \helpref{wxEvtHandler}{wxevthandler}\\
129 \helpref{wxObject}{wxobject}
130
131 \wxheading{Include files}
132
133 <combo.h>
134
135 \wxheading{Window styles}
136
137 \begin{twocollist}\itemsep=0pt
138 \twocolitem{\windowstyle{wxCB\_READONLY}}{Text will not be editable.}
139 \twocolitem{\windowstyle{wxCB\_SORT}}{Sorts the entries in the list alphabetically.}
140 \twocolitem{\windowstyle{wxPROCESS\_ENTER}}{The control will generate
141 the event wxEVT\_COMMAND\_TEXT\_ENTER (otherwise pressing Enter key
142 is either processed internally by the control or used for navigation between
143 dialog controls). Windows only.}
144 \twocolitem{\windowstyle{wxCC\_SPECIAL\_DCLICK}}{Double-clicking triggers a call
145 to popup's OnComboDoubleClick. Actual behaviour is defined by a derived
146 class. For instance, wxOwnerDrawnComboBox will cycle an item. This style only
147 applies if wxCB\_READONLY is used as well.}
148 \twocolitem{\windowstyle{wxCC\_ALT\_KEYS}}{Use keyboard behaviour alternate
149 to platform default: up and down keys will show popup (instead of cycling value,
150 for instance, on wxMSW).}
151 \twocolitem{\windowstyle{wxCC\_STD\_BUTTON}}{Drop button will behave
152 more like a standard push button.}
153 \end{twocollist}
154
155 See also \helpref{window styles overview}{windowstyles}.
156
157 \wxheading{Event handling}
158
159 \twocolwidtha{7cm}
160 \begin{twocollist}\itemsep=0pt
161 \twocolitem{{\bf EVT\_TEXT(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_UPDATED event,
162 when the text changes.}
163 \twocolitem{{\bf EVT\_TEXT\_ENTER(id, func)}}{Process a wxEVT\_COMMAND\_TEXT\_ENTER event,
164 when <RETURN> is pressed in the combo control.}
165 \end{twocollist}
166
167 \wxheading{See also}
168
169 \helpref{wxComboBox}{wxcombobox}, \helpref{wxChoice}{wxchoice},
170 \helpref{wxOwnerDrawnComboBox}{wxownerdrawncombobox},
171 \rtfsp\helpref{wxComboPopup}{wxcombopopup}, \helpref{wxCommandEvent}{wxcommandevent}
172
173 \latexignore{\rtfignore{\wxheading{Members}}}
174
175
176 \membersection{wxComboCtrl::wxComboCtrl}\label{wxcomboctrlctor}
177
178 \func{}{wxComboCtrl}{\void}
179
180 Default constructor.
181
182 \func{}{wxComboCtrl}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
183 \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
184 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboCtrl"}}
185
186 Constructor, creating and showing a combo control.
187
188 \wxheading{Parameters}
189
190 \docparam{parent}{Parent window. Must not be NULL.}
191
192 \docparam{id}{Window identifier. A value of -1 indicates a default value.}
193
194 \docparam{value}{Initial selection string. An empty string indicates no selection.}
195
196 \docparam{pos}{Window position.}
197
198 \docparam{size}{Window size. If the default size (-1, -1) is specified then the window is sized
199 appropriately.}
200
201 \docparam{style}{Window style. See \helpref{wxComboCtrl}{wxcomboctrl}.}
202
203 \docparam{validator}{Window validator.}
204
205 \docparam{name}{Window name.}
206
207 \wxheading{See also}
208
209 \helpref{wxComboCtrl::Create}{wxcomboctrlcreate}, \helpref{wxValidator}{wxvalidator}
210
211
212 \membersection{wxComboCtrl::\destruct{wxComboCtrl}}\label{wxcomboctrldtor}
213
214 \func{}{\destruct{wxComboCtrl}}{\void}
215
216 Destructor, destroying the combo control.
217
218
219 \membersection{wxComboCtrl::Create}\label{wxcomboctrlcreate}
220
221 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
222 \param{const wxString\& }{value = ``"}, \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},\rtfsp
223 \param{long}{ style = 0}, \param{const wxValidator\& }{validator = wxDefaultValidator}, \param{const wxString\& }{name = ``comboCtrl"}}
224
225 Creates the combo control for two-step construction. Derived classes
226 should call or replace this function. See \helpref{wxComboCtrl::wxComboCtrl}{wxcomboctrlctor}\rtfsp
227 for further details.
228
229
230 \membersection{wxComboCtrl::Copy}\label{wxcomboctrlcopy}
231
232 \func{void}{Copy}{\void}
233
234 Copies the selected text to the clipboard.
235
236
237 \membersection{wxComboCtrl::Cut}\label{wxcomboctrlcut}
238
239 \func{void}{Cut}{\void}
240
241 Copies the selected text to the clipboard and removes the selection.
242
243
244 \membersection{wxComboCtrl::GetBitmapDisabled}\label{wxcomboctrlgetbitmapdisabled}
245
246 \constfunc{const wxBitmap\&}{GetBitmapDisabled}{\void}
247
248 Returns disabled button bitmap that has been set with
249 \helpref{SetButtonBitmaps}{wxcomboctrlsetbuttonbitmaps}.
250
251 \wxheading{Return value}
252
253 A reference to the disabled state bitmap.
254
255
256 \membersection{wxComboCtrl::GetBitmapHover}\label{wxcomboctrlgetbitmaphover}
257
258 \constfunc{const wxBitmap\&}{GetBitmapHover}{\void}
259
260 Returns button mouse hover bitmap that has been set with
261 \helpref{SetButtonBitmaps}{wxcomboctrlsetbuttonbitmaps}.
262
263 \wxheading{Return value}
264
265 A reference to the mouse hover state bitmap.
266
267
268 \membersection{wxComboCtrl::GetBitmapNormal}\label{wxcomboctrlgetbitmapnormal}
269
270 \constfunc{const wxBitmap\&}{GetBitmapNormal}{\void}
271
272 Returns default button bitmap that has been set with
273 \helpref{SetButtonBitmaps}{wxcomboctrlsetbuttonbitmaps}.
274
275 \wxheading{Return value}
276
277 A reference to the normal state bitmap.
278
279
280 \membersection{wxComboCtrl::GetBitmapPressed}\label{wxcomboctrlgetbitmappressed}
281
282 \constfunc{const wxBitmap\&}{GetBitmapPressed}{\void}
283
284 Returns depressed button bitmap that has been set with
285 \helpref{SetButtonBitmaps}{wxcomboctrlsetbuttonbitmaps}.
286
287 \wxheading{Return value}
288
289 A reference to the depressed state bitmap.
290
291
292 \membersection{wxComboCtrl::GetCustomPaintWidth}\label{wxcomboctrlgetcustompaintwidth}
293
294 \constfunc{int}{GetCustomPaintWidth}{\void}
295
296 Returns custom painted area in control.
297
298 \wxheading{See also}
299
300 \helpref{wxComboCtrl::SetCustomPaintWidth}{wxcomboctrlsetcustompaintwidth}.
301
302
303 \membersection{wxComboCtrl::GetFeatures}\label{wxcomboctrlgetfeatures}
304
305 \func{static int}{GetFeatures}{\void}
306
307 Returns features supported by wxComboCtrl. If needed feature is missing,
308 you need to instead use wxGenericComboCtrl, which however may lack
309 native look and feel (but otherwise sports identical API).
310
311 \wxheading{Return value}
312
313 Value returned is a combination of following flags:
314
315 \twocolwidtha{8cm}%
316 \begin{twocollist}\itemsep=0pt
317 \twocolitem{{\tt wxComboCtrlFeatures::MovableButton}}{Button can
318 be on either side of the control.}
319 \twocolitem{{\tt wxComboCtrlFeatures::BitmapButton}}{Button may
320 be replaced with bitmap.}
321 \twocolitem{{\tt wxComboCtrlFeatures::ButtonSpacing}}{Button can
322 have spacing.}
323 \twocolitem{{\tt wxComboCtrlFeatures::TextIndent}}{SetTextIndent
324 works.}
325 \twocolitem{{\tt wxComboCtrlFeatures::PaintControl}}{Combo control
326 itself can be custom painted.}
327 \twocolitem{{\tt wxComboCtrlFeatures::PaintWritable}}{A variable-
328 width area in front of writable combo control's textctrl can
329 be custom painted.}
330 \twocolitem{{\tt wxComboCtrlFeatures::Borderless}}{wxNO\_BORDER
331 window style works.}
332 \twocolitem{{\tt wxComboCtrlFeatures::All}}{All of the
333 above.}
334 \end{twocollist}
335
336
337 \membersection{wxComboCtrl::GetInsertionPoint}\label{wxcomboctrlgetinsertionpoint}
338
339 \constfunc{long}{GetInsertionPoint}{\void}
340
341 Returns the insertion point for the combo control's text field.
342
343 \textbf{Note:} Under wxMSW, this function always returns $0$ if the combo control
344 doesn't have the focus.
345
346
347 \membersection{wxComboCtrl::GetLastPosition}\label{wxcomboctrlgetlastposition}
348
349 \constfunc{long}{GetLastPosition}{\void}
350
351 Returns the last position in the combo control text field.
352
353
354 \membersection{wxComboCtrl::GetPopupControl}\label{wxcomboctrlgetpopupcontrol}
355
356 \func{wxComboPopup*}{GetPopupControl}{\void}
357
358 Returns current popup interface that has been set with SetPopupControl.
359
360
361 \membersection{wxComboCtrl::GetPopupWindow}\label{wxcomboctrlgetpopupwindow}
362
363 \constfunc{wxWindow*}{GetPopupWindow}{\void}
364
365 Returns popup window containing the popup control.
366
367
368 \membersection{wxComboCtrl::GetTextCtrl}\label{wxcomboctrlgettextctrl}
369
370 \constfunc{wxTextCtrl*}{GetTextCtrl}{\void}
371
372 Get the text control which is part of the combo control.
373
374
375 \membersection{wxComboCtrl::GetTextIndent}\label{wxcomboctrlgettextindent}
376
377 \constfunc{wxCoord}{GetTextIndent}{\void}
378
379 Returns actual indentation in pixels.
380
381
382 \membersection{wxComboCtrl::GetValue}\label{wxcomboctrlgetvalue}
383
384 \constfunc{wxString}{GetValue}{\void}
385
386 Returns text representation of the current value. For writable
387 combo control it always returns the value in the text field.
388
389
390 \membersection{wxComboCtrl::HidePopup}\label{wxcomboctrlhidepopup}
391
392 \func{void}{HidePopup}{\void}
393
394 Dismisses the popup window.
395
396
397 \membersection{wxComboCtrl::IsPopupShown}\label{wxcomboctrlispopupshown}
398
399 \constfunc{bool}{IsPopupShown}{\void}
400
401 Returns \true if the popup is currently shown
402
403
404 \membersection{wxComboCtrl::OnButtonClick}\label{wxcomboctrlonbuttonclick}
405
406 \func{void}{OnButtonClick}{\void}
407
408 Implement in a derived class to define what happens on
409 dropdown button click.
410
411 Default action is to show the popup.
412
413
414 \membersection{wxComboCtrl::Paste}\label{wxcomboctrlpaste}
415
416 \func{void}{Paste}{\void}
417
418 Pastes text from the clipboard to the text field.
419
420
421 \membersection{wxComboCtrl::Remove}\label{wxcomboctrlremove}
422
423 \func{void}{Remove}{\param{long }{from}, \param{long }{to}}
424
425 Removes the text between the two positions in the combo control text field.
426
427 \wxheading{Parameters}
428
429 \docparam{from}{The first position.}
430
431 \docparam{to}{The last position.}
432
433
434 \membersection{wxComboCtrl::Replace}\label{wxcomboctrlreplace}
435
436 \func{void}{Replace}{\param{long }{from}, \param{long }{to}, \param{const wxString\& }{value}}
437
438 Replaces the text between two positions with the given text, in the combo control text field.
439
440 \wxheading{Parameters}
441
442 \docparam{from}{The first position.}
443
444 \docparam{to}{The second position.}
445
446 \docparam{text}{The text to insert.}
447
448
449 \membersection{wxComboCtrl::SetButtonBitmaps}\label{wxcomboctrlsetbuttonbitmaps}
450
451 \func{void}{SetButtonBitmaps}{\param{const wxBitmap\& }{bmpNormal}, \param{bool }{pushButtonBg = false}, \param{const wxBitmap\& }{bmpPressed = wxNullBitmap}, \param{const wxBitmap\& }{bmpHover = wxNullBitmap}, \param{const wxBitmap\& }{bmpDisabled = wxNullBitmap}}
452
453 Sets custom dropdown button graphics.
454
455 \wxheading{Parameters}
456
457 \docparam{bmpNormal}{Default button image.}
458 \docparam{pushButtonBg}{If \true, blank push button background is painted
459 below the image.}
460 \docparam{bmpPressed}{Depressed button image.}
461 \docparam{bmpHover}{Button image when mouse hovers above it. This
462 should be ignored on platforms and themes that do not generally draw
463 different kind of button on mouse hover.}
464 \docparam{bmpDisabled}{Disabled button image.}
465
466
467 \membersection{wxComboCtrl::SetButtonPosition}\label{wxcomboctrlsetbuttonposition}
468
469 \func{void}{SetButtonPosition}{\param{int }{width = 0}, \param{int }{height = 0}, \param{int }{side = wxRIGHT}, \param{int }{spacingX = 0}}
470
471 Sets size and position of dropdown button.
472
473 \wxheading{Parameters}
474
475 \docparam{width}{If > $0$, defines specific button width. $0$ means platform default,
476 while negative numbers allow adjusting smaller than default.}
477 \docparam{height}{Same as width.}
478 \docparam{side}{Indicates which side the button will be placed.
479 Value can be {\tt wxLEFT} or {\tt wxRIGHT}.}
480 \docparam{spacingX}{Horizontal spacing around the button. Default is $0$.}
481
482
483 \membersection{wxComboCtrl::SetCustomPaintWidth}\label{wxcomboctrlsetcustompaintwidth}
484
485 \func{void}{SetCustomPaintWidth}{\param{int }{width}}
486
487 Set width, in pixels, of custom painted area in control without {\tt wxCB\_READONLY}
488 style. In read-only \helpref{wxOwnerDrawnComboBox}{wxownerdrawncombobox}, this is used
489 to indicate area that is not covered by the focus rectangle.
490
491
492 \membersection{wxComboCtrl::SetInsertionPoint}\label{wxcomboctrlsetinsertionpoint}
493
494 \func{void}{SetInsertionPoint}{\param{long }{pos}}
495
496 Sets the insertion point in the text field.
497
498 \wxheading{Parameters}
499
500 \docparam{pos}{The new insertion point.}
501
502
503 \membersection{wxComboCtrl::SetInsertionPointEnd}\label{wxcomboctrlsetinsertionpointend}
504
505 \func{void}{SetInsertionPointEnd}{\void}
506
507 Sets the insertion point at the end of the combo control text field.
508
509
510 \membersection{wxComboCtrl::SetPopupAnchor}\label{wxcomboctrlsetpopupanchor}
511
512 \func{void}{SetPopupAnchor}{\param{int }{anchorSide}}
513
514 Set side of the control to which the popup will align itself. Valid values are
515 {\tt wxLEFT}, {\tt wxRIGHT} and $0$. The default value $0$ means that the most appropriate
516 side is used (which, currently, is always {\tt wxLEFT}).
517
518
519 \membersection{wxComboCtrl::SetPopupControl}\label{wxcomboctrlsetpopupcontrol}
520
521 \func{void}{SetPopupControl}{\param{wxComboPopup* }{popup}}
522
523 Set popup interface class derived from wxComboPopup.
524 This method should be called as soon as possible after the control
525 has been created, unless \helpref{OnButtonClick}{wxcomboctrlonbuttonclick}
526 has been overridden.
527
528
529 \membersection{wxComboCtrl::SetPopupExtents}\label{wxcomboctrlsetpopupextents}
530
531 \func{void}{SetPopupExtents}{\param{int }{extLeft}, \param{int }{extRight}}
532
533 Extends popup size horizontally, relative to the edges of the combo control.
534
535 \wxheading{Parameters}
536
537 \docparam{extLeft}{How many pixel to extend beyond the left edge of the
538 control. Default is $0$.}
539 \docparam{extRight}{How many pixel to extend beyond the right edge of the
540 control. Default is $0$.}
541
542 \wxheading{Remarks}
543
544 Popup minimum width may override arguments.
545
546 It is up to the popup to fully take this into account.
547
548
549 \membersection{wxComboCtrl::SetPopupMaxHeight}\label{wxcomboctrlsetpopupmaxheight}
550
551 \func{void}{SetPopupMaxHeight}{\param{int }{height}}
552
553 Sets preferred maximum height of the popup.
554
555 \wxheading{Remarks}
556
557 Value -1 indicates the default.
558
559 Also, popup implementation may choose to ignore this.
560
561
562 \membersection{wxComboCtrl::SetPopupMinWidth}\label{wxcomboctrlsetpopupminwidth}
563
564 \func{void}{SetPopupMinWidth}{\param{int }{width}}
565
566 Sets minimum width of the popup. If wider than combo control, it will extend to the left.
567
568 \wxheading{Remarks}
569
570 Value -1 indicates the default.
571
572 Also, popup implementation may choose to ignore this.
573
574
575 \membersection{wxComboCtrl::SetSelection}\label{wxcomboctrlsetselection}
576
577 \func{void}{SetSelection}{\param{long }{from}, \param{long }{to}}
578
579 Selects the text between the two positions, in the combo control text field.
580
581 \wxheading{Parameters}
582
583 \docparam{from}{The first position.}
584
585 \docparam{to}{The second position.}
586
587
588 \membersection{wxComboCtrl::SetText}\label{wxcomboctrlsettext}
589
590 \func{void}{SetText}{\param{const wxString\& }{value}}
591
592 Sets the text for the text field without affecting the
593 popup. Thus, unlike \helpref{SetValue}{wxcomboctrlsetvalue}, it works
594 equally well with combo control using {\tt wxCB\_READONLY} style.
595
596
597 \membersection{wxComboCtrl::SetTextIndent}\label{wxcomboctrlsettextindent}
598
599 \func{void}{SetTextIndent}{\param{int }{indent}}
600
601 This will set the space in pixels between left edge of the control and the
602 text, regardless whether control is read-only or not. Value -1 can be
603 given to indicate platform default.
604
605
606 \membersection{wxComboCtrl::SetValue}\label{wxcomboctrlsetvalue}
607
608 \func{void}{SetValue}{\param{const wxString\& }{value}}
609
610 Sets the text for the combo control text field.
611
612 {\bf NB:} For a combo control with {\tt wxCB\_READONLY} style the
613 string must be accepted by the popup (for instance, exist in the dropdown
614 list), otherwise the call to SetValue() is ignored
615
616
617 \membersection{wxComboCtrl::ShowPopup}\label{wxcomboctrlshowpopup}
618
619 \func{void}{ShowPopup}{\void}
620
621 Show the popup.
622
623
624 \membersection{wxComboCtrl::Undo}\label{wxcomboctrlundo}
625
626 \func{void}{Undo}{\void}
627
628 Undoes the last edit in the text field. Windows only.