choice.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: choice.h
  3. // Purpose: interface of wxChoice
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxChoice
  9. A choice item is used to select one of a list of strings. Unlike a
  10. wxListBox, only the selection is visible until the user pulls down the
  11. menu of choices.
  12. @beginStyleTable
  13. @style{wxCB_SORT}
  14. Sorts the entries alphabetically.
  15. @endStyleTable
  16. @beginEventEmissionTable{wxCommandEvent}
  17. @event{EVT_CHOICE(id, func)}
  18. Process a @c wxEVT_CHOICE event, when an item on the
  19. list is selected.
  20. @endEventTable
  21. @library{wxcore}
  22. @category{ctrl}
  23. @appearance{choice}
  24. @see wxListBox, wxComboBox, wxCommandEvent
  25. */
  26. class wxChoice : public wxControl,
  27. public wxItemContainer
  28. {
  29. public:
  30. /**
  31. Default constructor.
  32. @see Create(), wxValidator
  33. */
  34. wxChoice();
  35. /**
  36. Constructor, creating and showing a choice.
  37. @param parent
  38. Parent window. Must not be @NULL.
  39. @param id
  40. Window identifier. The value wxID_ANY indicates a default value.
  41. @param pos
  42. Window position.
  43. If ::wxDefaultPosition is specified then a default position is chosen.
  44. @param size
  45. Window size.
  46. If ::wxDefaultSize is specified then the choice is sized appropriately.
  47. @param n
  48. Number of strings with which to initialise the choice control.
  49. @param choices
  50. An array of strings with which to initialise the choice control.
  51. @param style
  52. Window style. See wxChoice.
  53. @param validator
  54. Window validator.
  55. @param name
  56. Window name.
  57. @see Create(), wxValidator
  58. @beginWxPerlOnly
  59. Not supported by wxPerl.
  60. @endWxPerlOnly
  61. */
  62. wxChoice( wxWindow *parent, wxWindowID id,
  63. const wxPoint& pos = wxDefaultPosition,
  64. const wxSize& size = wxDefaultSize,
  65. int n = 0, const wxString choices[] = NULL,
  66. long style = 0,
  67. const wxValidator& validator = wxDefaultValidator,
  68. const wxString& name = wxChoiceNameStr );
  69. /**
  70. Constructor, creating and showing a choice.
  71. @param parent
  72. Parent window. Must not be @NULL.
  73. @param id
  74. Window identifier. The value wxID_ANY indicates a default value.
  75. @param pos
  76. Window position.
  77. @param size
  78. Window size. If wxDefaultSize is specified then the choice is sized
  79. appropriately.
  80. @param choices
  81. An array of strings with which to initialise the choice control.
  82. @param style
  83. Window style. See wxChoice.
  84. @param validator
  85. Window validator.
  86. @param name
  87. Window name.
  88. @see Create(), wxValidator
  89. @beginWxPerlOnly
  90. Use an array reference for the @a choices parameter.
  91. @endWxPerlOnly
  92. */
  93. wxChoice( wxWindow *parent, wxWindowID id,
  94. const wxPoint& pos,
  95. const wxSize& size,
  96. const wxArrayString& choices,
  97. long style = 0,
  98. const wxValidator& validator = wxDefaultValidator,
  99. const wxString& name = wxChoiceNameStr );
  100. /**
  101. Destructor, destroying the choice item.
  102. */
  103. virtual ~wxChoice();
  104. //@{
  105. /**
  106. Creates the choice for two-step construction. See wxChoice().
  107. */
  108. bool Create( wxWindow *parent, wxWindowID id,
  109. const wxPoint& pos = wxDefaultPosition,
  110. const wxSize& size = wxDefaultSize,
  111. int n = 0, const wxString choices[] = NULL,
  112. long style = 0,
  113. const wxValidator& validator = wxDefaultValidator,
  114. const wxString& name = wxChoiceNameStr );
  115. bool Create( wxWindow *parent, wxWindowID id,
  116. const wxPoint& pos,
  117. const wxSize& size,
  118. const wxArrayString& choices,
  119. long style = 0,
  120. const wxValidator& validator = wxDefaultValidator,
  121. const wxString& name = wxChoiceNameStr );
  122. //@}
  123. /**
  124. Gets the number of columns in this choice item.
  125. @remarks This is implemented for GTK and Motif only and always
  126. returns 1 for the other platforms.
  127. */
  128. virtual int GetColumns() const;
  129. /**
  130. Unlike wxControlWithItems::GetSelection() which only returns the
  131. accepted selection value (the selection in the control once the
  132. user closes the dropdown list), this function returns the current
  133. selection. That is, while the dropdown list is shown, it returns the
  134. currently selected item in it. When it is not shown, its result is the
  135. same as for the other function.
  136. @since 2.6.2.
  137. In older versions, wxControlWithItems::GetSelection() itself
  138. behaved like this.
  139. */
  140. virtual int GetCurrentSelection() const;
  141. /**
  142. Sets the number of columns in this choice item.
  143. @param n
  144. Number of columns.
  145. @remarks This is implemented for GTK and Motif only and doesn’t do
  146. anything under other platforms.
  147. */
  148. virtual void SetColumns(int n = 1);
  149. virtual bool IsSorted() const;
  150. virtual unsigned int GetCount() const ;
  151. virtual int GetSelection() const ;
  152. virtual void SetSelection(int n);
  153. virtual int FindString(const wxString& s, bool bCase = false) const;
  154. virtual wxString GetString(unsigned int n) const ;
  155. virtual void SetString(unsigned int pos, const wxString& s);
  156. };