]> git.saurik.com Git - wxWidgets.git/blame - interface/ctrlsub.h
mention the problem with writing enums to wxConfig (see #8656)
[wxWidgets.git] / interface / ctrlsub.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: ctrlsub.h
e54c96f1 3// Purpose: interface of wxControlWithItems
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
bf84f3e2 9
23324ae1 10/**
dc215c81 11 @class wxItemContainerImmutable
23324ae1 12 @wxheader{ctrlsub.h}
7c913512 13
bf84f3e2
VS
14 wxItemContainer defines an interface which is implemented by all controls
15 which have string subitems each of which may be selected.
7c913512 16
bf84f3e2
VS
17 It is decomposed in wxItemContainerImmutable which omits all methods
18 adding/removing items and is used by wxRadioBox and wxItemContainer itself.
7c913512 19
bf84f3e2
VS
20 Note that this is not a control, it's a mixin interface that classes
21 have to derive from in addition to wxControl or wxWindow.
22
23 Examples: wxListBox, wxCheckListBox, wxChoice and wxComboBox (which
24 implements an extended interface deriving from this one)
7c913512 25
23324ae1 26 @library{wxcore}
bf84f3e2 27 @category{ctrl}
7c913512 28
bf84f3e2 29 @see wxControlWithItems, wxItemContainer
23324ae1 30*/
bf84f3e2 31class wxItemContainerImmutable
23324ae1
FM
32{
33public:
bf84f3e2
VS
34 /// Constructor
35 wxItemContainerImmutable();
36
23324ae1 37 //@{
bf84f3e2 38
23324ae1 39 /**
bf84f3e2
VS
40 Returns the number of items in the control.
41
42 @see IsEmpty()
43 */
44 virtual unsigned int GetCount() const;
45
46 /**
47 Returns @true if the control is empty or @false if it has some items.
48
49 @see GetCount()
50 */
51 bool IsEmpty() const;
52
bf84f3e2
VS
53 /**
54 Returns the label of the item with the given index.
3c4f71cc 55
7c913512 56 @param n
bf84f3e2 57 The zero-based index.
3c4f71cc 58
d29a9a8a
BP
59 @return The label of the item or an empty string if the position was
60 invalid.
23324ae1 61 */
bf84f3e2 62 virtual wxString GetString(unsigned int n) const;
23324ae1
FM
63
64 /**
bf84f3e2 65 Returns the array of the labels of all items in the control.
23324ae1 66 */
bf84f3e2 67 wxArrayString GetStrings() const;
23324ae1
FM
68
69 /**
bf84f3e2 70 Sets the label for the given item.
3c4f71cc 71
7c913512 72 @param n
4cc4bfaf 73 The zero-based item index.
bf84f3e2
VS
74 @param string
75 The label to set.
23324ae1 76 */
bf84f3e2 77 virtual void SetString(unsigned int n, const wxString& s);
23324ae1
FM
78
79 /**
80 Finds an item whose label matches the given string.
3c4f71cc 81
7c913512 82 @param string
4cc4bfaf 83 String to find.
7c913512 84 @param caseSensitive
4cc4bfaf 85 Whether search is case sensitive (default is not).
3c4f71cc 86
d29a9a8a
BP
87 @return The zero-based position of the item, or wxNOT_FOUND if the
88 string was not found.
23324ae1 89 */
bf84f3e2 90 virtual int FindString(const wxString& s, bool bCase = false) const;
3c4f71cc 91
bf84f3e2 92 //@}
3c4f71cc 93
dc215c81 94 /// @name Selection
bf84f3e2 95 //@{
23324ae1
FM
96
97 /**
bf84f3e2
VS
98 Sets the selection to the given item @a n or removes the selection
99 entirely if @a n == @c wxNOT_FOUND.
3c4f71cc 100
bf84f3e2
VS
101 Note that this does not cause any command events to be emitted nor does
102 it deselect any other items in the controls which support multiple
103 selections.
23324ae1 104
bf84f3e2
VS
105 @param n
106 The string position to select, starting from zero.
3c4f71cc 107
bf84f3e2 108 @see SetString(), SetStringSelection()
23324ae1 109 */
bf84f3e2 110 virtual void SetSelection(int n);
23324ae1
FM
111
112 /**
113 Returns the index of the selected item or @c wxNOT_FOUND if no item is
114 selected.
3c4f71cc 115
d29a9a8a 116 @return The position of the current selection.
3c4f71cc 117
23324ae1 118 @remarks This method can be used with single selection list boxes only,
bf84f3e2 119 you should use wxListBox::GetSelections() for the list
4cc4bfaf 120 boxes with wxLB_MULTIPLE style.
3c4f71cc 121
4cc4bfaf 122 @see SetSelection(), GetStringSelection()
23324ae1 123 */
bf84f3e2 124 virtual int GetSelection() const;
23324ae1
FM
125
126 /**
bf84f3e2
VS
127 Selects the item with the specified string in the control. This doesn't
128 cause any command events to be emitted.
3c4f71cc 129
bf84f3e2
VS
130 @param string
131 The string to select.
3c4f71cc 132
d29a9a8a
BP
133 @return @true if the specified string has been selected, @false if it
134 wasn't found in the control.
23324ae1 135 */
bf84f3e2 136 bool SetStringSelection(const wxString& string);
23324ae1
FM
137
138 /**
139 Returns the label of the selected item or an empty string if no item is
140 selected.
3c4f71cc 141
4cc4bfaf 142 @see GetSelection()
23324ae1 143 */
bf84f3e2 144 virtual wxString GetStringSelection() const;
23324ae1
FM
145
146 /**
bf84f3e2
VS
147 This is the same as SetSelection() and exists only because it is
148 slightly more natural for controls which support multiple selection.
23324ae1 149 */
bf84f3e2
VS
150 void Select(int n);
151
152 //@}
153};
154
155
156/**
dc215c81 157 @class wxItemContainer
bf84f3e2
VS
158 @wxheader{ctrlsub.h}
159
160 This class is an abstract base class for some wxWidgets controls which
161 contain several items such as wxListBox, wxCheckListBox, wxComboBox or
162 wxChoice. It defines an interface which is implemented by all controls
163 which have string subitems each of which may be selected.
23324ae1 164
bf84f3e2
VS
165 wxItemContainer extends wxItemContainerImmutable interface with methods
166 for adding/removing items.
167
168 It defines the methods for accessing the controls items and although each
169 of the derived classes implements them differently, they still all conform
170 to the same interface.
171
172 The items in a wxItemContainer have (non-empty) string labels and,
173 optionally, client data associated with them. Client data may be of two
174 different kinds: either simple untyped (@c void *) pointers which are
175 simply stored by the control but not used in any way by it, or typed
176 pointers (wxClientData*) which are owned by the control meaning that the
177 typed client data (and only it) will be deleted when an item is deleted
dc215c81
BP
178 using Delete() or the entire control is cleared using Clear(), which also
179 happens when it is destroyed.
bf84f3e2
VS
180
181 Finally note that in the same control all items must have client data of
182 the same type (typed or untyped), if any. This type is determined by the
dc215c81
BP
183 first call to Append() (the version with client data pointer) or
184 SetClientData().
bf84f3e2
VS
185
186 Note that this is not a control, it's a mixin interface that classes
187 have to derive from in addition to wxControl or wxWindow. Convenience
188 class wxControlWithItems is provided for this purpose.
189
190 @library{wxcore}
191 @category{ctrl}
192
193 @see wxControlWithItems, wxItemContainerImmutable
194*/
195class wxItemContainer : public wxItemContainerImmutable
196{
197public:
23324ae1 198 //@{
bf84f3e2 199
23324ae1 200 /**
bf84f3e2
VS
201 Appends item into the control.
202
203 @param item
204 String to add.
205
d29a9a8a
BP
206 @return The return value is the index of the newly inserted item.
207 Note that this may be different from the last one if the
208 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
209 style).
bf84f3e2
VS
210 */
211 int Append(const wxString& item);
212
213 /**
214 Appends item into the control.
3c4f71cc 215
7c913512 216 @param item
4cc4bfaf 217 String to add.
7c913512 218 @param clientData
bf84f3e2 219 Pointer to client data to associate with the new item.
3c4f71cc 220
d29a9a8a
BP
221 @return The return value is the index of the newly inserted item.
222 Note that this may be different from the last one if the
223 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
224 style).
23324ae1 225 */
bf84f3e2
VS
226 int Append(const wxString& item, void* clientData);
227
228 /**
229 Appends item into the control.
230
231 @param item
232 String to add.
233 @param clientData
234 Pointer to client data to associate with the new item.
235
d29a9a8a
BP
236 @return The return value is the index of the newly inserted item.
237 Note that this may be different from the last one if the
238 control is sorted (e.g. has @c wxLB_SORT or @c wxCB_SORT
239 style).
bf84f3e2
VS
240 */
241 int Append(const wxString& item, wxClientData* clientData);
242
243 /**
244 Appends several items at once into the control.
245
246 Notice that calling this method is usually much faster than appending
247 them one by one if you need to add a lot of items.
248
249 @param items
250 Array of strings to insert.
251 */
252 void Append(const wxArrayString& items);
253
254 /**
255 Appends several items at once into the control.
256
257 Notice that calling this method is usually much faster than appending
258 them one by one if you need to add a lot of items.
259
260 @param items
261 Array of strings to insert.
262 @param clientData
263 Array of client data pointers of the same size as @a items to
264 associate with the new items.
265 */
266 void Append(const wxArrayString& items, void **clientData);
267
268 /**
269 Appends several items at once into the control.
270
271 Notice that calling this method is usually much faster than appending
272 them one by one if you need to add a lot of items.
273
274 @param items
275 Array of strings to insert.
276 @param clientData
277 Array of client data pointers of the same size as @a items to
278 associate with the new items.
279 */
280 void Append(const wxArrayString& items, wxClientData **clientData);
281
282 /**
283 Appends several items at once into the control.
284
285 Notice that calling this method is usually much faster than appending
286 them one by one if you need to add a lot of items.
287
288 @param n
289 Number of items in the @a items array.
290 @param items
291 Array of strings of size @a n.
292 */
293 void Append(unsigned int n, const wxString* items);
294
295 /**
296 Appends several items at once into the control.
297
298 Notice that calling this method is usually much faster than appending
299 them one by one if you need to add a lot of items.
300
301 @param n
302 Number of items in the @a items array.
303 @param items
304 Array of strings of size @a n.
305 @param clientData
306 Array of client data pointers of size @a n to associate with the
307 new items.
308 */
309 void Append(unsigned int n, const wxString* items,
4cc4bfaf 310 void** clientData);
bf84f3e2
VS
311
312 /**
313 Appends several items at once into the control.
314
315 Notice that calling this method is usually much faster than appending
316 them one by one if you need to add a lot of items.
317
318 @param n
319 Number of items in the @a items array.
320 @param items
321 Array of strings of size @a n.
322 @param clientData
323 Array of client data pointers of size @a n to associate with the
324 new items.
325 */
326 void Append(unsigned int n, const wxString* items,
4cc4bfaf 327 wxClientData** clientData);
23324ae1
FM
328 //@}
329
330 /**
bf84f3e2
VS
331 Removes all items from the control.
332 Clear() also deletes the client data of the existing items if it is
333 owned by the control.
23324ae1 334 */
bf84f3e2 335 void Clear();
23324ae1
FM
336
337 /**
bf84f3e2
VS
338 Deletes an item from the control.
339
340 The client data associated with the item will be also deleted if it is
341 owned by the control. Note that it is an error (signalled by an assert
342 failure in debug builds) to remove an item with the index negative or
343 greater or equal than the number of items in the control.
344
345 @param n
346 The zero-based item index.
347
348 @see Clear()
23324ae1 349 */
bf84f3e2 350 void Delete(unsigned int n);
23324ae1
FM
351
352 //@{
bf84f3e2 353
23324ae1 354 /**
bf84f3e2
VS
355 Returns a pointer to the client data associated with the given item (if
356 any). It is an error to call this function for a control which doesn't
357 have untyped client data at all although it is OK to call it even if
358 the given item doesn't have any client data associated with it (but
359 other items do).
3c4f71cc 360
7c913512 361 @param n
bf84f3e2
VS
362 The zero-based position of the item.
363
d29a9a8a 364 @return A pointer to the client data, or @NULL if not present.
23324ae1 365 */
bf84f3e2
VS
366 void* GetClientData(unsigned int n) const;
367
368 /**
369 Returns a pointer to the client data associated with the given item (if
370 any). It is an error to call this function for a control which doesn't
371 have typed client data at all although it is OK to call it even if the
372 given item doesn't have any client data associated with it (but other
373 items do).
374
375 @param n
376 The zero-based position of the item.
377
d29a9a8a 378 @return A pointer to the client data, or @NULL if not present.
bf84f3e2
VS
379 */
380 wxClientData* GetClientObject(unsigned int n) const;
23324ae1
FM
381
382 /**
bf84f3e2
VS
383 Associates the given untyped client data pointer with the given item.
384 Note that it is an error to call this function if any typed client data
385 pointers had been associated with the control items before.
3c4f71cc 386
7c913512 387 @param n
4cc4bfaf 388 The zero-based item index.
7c913512 389 @param data
4cc4bfaf 390 The client data to associate with the item.
23324ae1 391 */
4cc4bfaf 392 void SetClientData(unsigned int n, void* data);
23324ae1
FM
393
394 /**
395 Associates the given typed client data pointer with the given item: the
bf84f3e2
VS
396 @a data object will be deleted when the item is deleted (either
397 explicitly by using Delete() or implicitly when the control itself is
398 destroyed). Note that it is an error to call this function if any
399 untyped client data pointers had been associated with the control items
400 before.
3c4f71cc 401
7c913512 402 @param n
4cc4bfaf 403 The zero-based item index.
7c913512 404 @param data
4cc4bfaf 405 The client data to associate with the item.
23324ae1 406 */
4cc4bfaf 407 void SetClientObject(unsigned int n, wxClientData* data);
23324ae1 408
bf84f3e2
VS
409 //@}
410
411 //@{
412
413 /**
414 Inserts item into the control.
415
416 @param item
417 String to add.
418 @param pos
419 Position to insert item before, zero based.
420
d29a9a8a
BP
421 @return The return value is the index of the newly inserted item.
422 If the insertion failed for some reason, -1 is returned.
bf84f3e2
VS
423 */
424 int Insert(const wxString& item, unsigned int pos);
425
426 /**
427 Inserts item into the control.
428
429 @param item
430 String to add.
431 @param pos
432 Position to insert item before, zero based.
433 @param clientData
434 Pointer to client data to associate with the new item.
435
d29a9a8a
BP
436 @return The return value is the index of the newly inserted item.
437 If the insertion failed for some reason, -1 is returned.
bf84f3e2
VS
438 */
439 int Insert(const wxString& item, unsigned int pos, void* clientData);
440
441 /**
442 Inserts item into the control.
443
444 @param item
445 String to add.
446 @param pos
447 Position to insert item before, zero based.
448 @param clientData
449 Pointer to client data to associate with the new item.
450
d29a9a8a
BP
451 @return The return value is the index of the newly inserted item.
452 If the insertion failed for some reason, -1 is returned.
bf84f3e2
VS
453 */
454 int Insert(const wxString& item, unsigned int pos,
455 wxClientData* clientData);
456
457 /**
458 Inserts several items at once into the control.
459
460 Notice that calling this method is usually much faster than inserting
461 them one by one if you need to insert a lot of items.
462
463 @param items
464 Array of strings to insert.
465 @param pos
466 Position to insert the items before, zero based.
467 */
468 void Insert(const wxArrayString& items, unsigned int pos);
469
470 /**
471 Inserts several items at once into the control.
472
473 Notice that calling this method is usually much faster than inserting
474 them one by one if you need to insert a lot of items.
475
476 @param items
477 Array of strings to insert.
478 @param pos
479 Position to insert the items before, zero based.
480 @param clientData
481 Array of client data pointers of the same size as @a items to
482 associate with the new items.
483 */
484 void Insert(const wxArrayString& items, unsigned int pos,
485 void **clientData);
486
23324ae1 487 /**
bf84f3e2
VS
488 Inserts several items at once into the control.
489
490 Notice that calling this method is usually much faster than inserting
491 them one by one if you need to insert a lot of items.
492
493 @param items
494 Array of strings to insert.
495 @param pos
496 Position to insert the items before, zero based.
497 @param clientData
498 Array of client data pointers of the same size as @a items to
499 associate with the new items.
500 */
501 void Insert(const wxArrayString& items, unsigned int pos,
502 wxClientData **clientData);
503
504 /**
505 Inserts several items at once into the control.
506
507 Notice that calling this method is usually much faster than inserting
508 them one by one if you need to insert a lot of items.
3c4f71cc 509
7c913512 510 @param n
bf84f3e2
VS
511 Number of items in the @a items array.
512 @param items
513 Array of strings of size @a n.
514 @param pos
515 Position to insert the items before, zero based.
516 */
517 void Insert(unsigned int n, const wxString* items,
518 unsigned int pos);
3c4f71cc 519
bf84f3e2
VS
520 /**
521 Inserts several items at once into the control.
522
523 Notice that calling this method is usually much faster than inserting
524 them one by one if you need to insert a lot of items.
525
526 @param n
527 Number of items in the @a items array.
528 @param items
529 Array of strings of size @a n.
530 @param pos
531 Position to insert the new items before, zero based.
532 @param clientData
533 Array of client data pointers of size @a n to associate with the
534 new items.
23324ae1 535 */
bf84f3e2
VS
536 void Insert(unsigned int n, const wxString* items,
537 unsigned int pos,
538 void** clientData);
23324ae1
FM
539
540 /**
bf84f3e2
VS
541 Inserts several items at once into the control.
542
543 Notice that calling this method is usually much faster than inserting
544 them one by one if you need to insert a lot of items.
3c4f71cc 545
7c913512 546 @param n
bf84f3e2
VS
547 Number of items in the @a items array.
548 @param items
549 Array of strings of size @a n.
550 @param pos
551 Position to insert the new items before, zero based.
552 @param clientData
553 Array of client data pointers of size @a n to associate with the
554 new items.
23324ae1 555 */
bf84f3e2
VS
556 void Insert(unsigned int n, const wxString* items,
557 unsigned int pos,
558 wxClientData** clientData);
559 //@}
23324ae1 560
bf84f3e2 561 //@{
23324ae1 562 /**
bf84f3e2 563 Replaces the current control contents with the given items.
3c4f71cc 564
bf84f3e2
VS
565 Notice that calling this method is usually much faster than appending
566 them one by one if you need to add a lot of items.
3c4f71cc 567
bf84f3e2
VS
568 @param items
569 Array of strings to insert.
23324ae1 570 */
bf84f3e2
VS
571 void Set(const wxArrayString& items);
572
573 /**
574 Replaces the current control contents with the given items.
575
576 Notice that calling this method is usually much faster than appending
577 them one by one if you need to add a lot of items.
578
579 @param items
580 Array of strings to insert.
581 @param clientData
582 Array of client data pointers of the same size as @a items to
583 associate with the new items.
584 */
585 void Set(const wxArrayString& items, void **clientData);
586
587 /**
588 Replaces the current control contents with the given items.
589
590 Notice that calling this method is usually much faster than appending
591 them one by one if you need to add a lot of items.
592
593 @param items
594 Array of strings to insert.
595 @param clientData
596 Array of client data pointers of the same size as @a items to
597 associate with the new items.
598 */
599 void Set(const wxArrayString& items, wxClientData **clientData);
600
601 /**
602 Replaces the current control contents with the given items.
603
604 Notice that calling this method is usually much faster than appending
605 them one by one if you need to add a lot of items.
606
607 @param n
608 Number of items in the @a items array.
609 @param items
610 Array of strings of size @a n.
611 */
612 void Set(unsigned int n, const wxString* items);
613
614 /**
615 Replaces the current control contents with the given items.
616
617 Notice that calling this method is usually much faster than appending
618 them one by one if you need to add a lot of items.
619
620 @param n
621 Number of items in the @a items array.
622 @param items
623 Array of strings of size @a n.
624 @param clientData
625 Array of client data pointers of size @a n to associate with the
626 new items.
627 */
628 void Set(unsigned int n, const wxString* items, void** clientData);
629
630 /**
631 Replaces the current control contents with the given items.
632
633 Notice that calling this method is usually much faster than appending
634 them one by one if you need to add a lot of items.
635
636 @param n
637 Number of items in the @a items array.
638 @param items
639 Array of strings of size @a n.
640 @param clientData
641 Array of client data pointers of size @a n to associate with the
642 new items.
643 */
644 void Set(unsigned int n, const wxString* items, wxClientData** clientData);
645 //@}
646};
647
648
649/**
650 @class wxControlWithItems
651 @wxheader{ctrlsub.h}
652
653 This is convenience class that derives from both wxControl and
654 wxItemContainer. It is used as basis for some wxWidgets controls
655 (wxChoice and wxListBox).
656
657 @library{wxcore}
658 @category{ctrl}
659
660 @see wxItemContainer, wxItemContainerImmutable
661*/
662class wxControlWithItems : public wxControl, public wxItemContainer
663{
23324ae1 664};
e54c96f1 665