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