combobox.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/combobox.h
  3. // Purpose: the universal combobox
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 30.08.00
  7. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_COMBOBOX_H_
  11. #define _WX_UNIV_COMBOBOX_H_
  12. #include "wx/combo.h"
  13. class WXDLLIMPEXP_FWD_CORE wxListBox;
  14. // ----------------------------------------------------------------------------
  15. // NB: some actions supported by this control are in wx/generic/combo.h
  16. // ----------------------------------------------------------------------------
  17. // choose the next/prev/specified (by numArg) item
  18. #define wxACTION_COMBOBOX_SELECT_NEXT wxT("next")
  19. #define wxACTION_COMBOBOX_SELECT_PREV wxT("prev")
  20. #define wxACTION_COMBOBOX_SELECT wxT("select")
  21. // ----------------------------------------------------------------------------
  22. // wxComboBox: a combination of text control and a listbox
  23. // ----------------------------------------------------------------------------
  24. // NB: Normally we'd like wxComboBox to inherit from wxComboBoxBase, but here
  25. // we can't really do that since both wxComboBoxBase and wxComboCtrl inherit
  26. // from wxTextCtrl.
  27. class WXDLLIMPEXP_CORE wxComboBox :
  28. public wxWindowWithItems<wxComboCtrl, wxItemContainer>
  29. {
  30. public:
  31. // ctors and such
  32. wxComboBox() { Init(); }
  33. wxComboBox(wxWindow *parent,
  34. wxWindowID id,
  35. const wxString& value = wxEmptyString,
  36. const wxPoint& pos = wxDefaultPosition,
  37. const wxSize& size = wxDefaultSize,
  38. int n = 0,
  39. const wxString choices[] = (const wxString *) NULL,
  40. long style = 0,
  41. const wxValidator& validator = wxDefaultValidator,
  42. const wxString& name = wxComboBoxNameStr)
  43. {
  44. Init();
  45. (void)Create(parent, id, value, pos, size, n, choices,
  46. style, validator, name);
  47. }
  48. wxComboBox(wxWindow *parent,
  49. wxWindowID id,
  50. const wxString& value,
  51. const wxPoint& pos,
  52. const wxSize& size,
  53. const wxArrayString& choices,
  54. long style = 0,
  55. const wxValidator& validator = wxDefaultValidator,
  56. const wxString& name = wxComboBoxNameStr);
  57. bool Create(wxWindow *parent,
  58. wxWindowID id,
  59. const wxString& value = wxEmptyString,
  60. const wxPoint& pos = wxDefaultPosition,
  61. const wxSize& size = wxDefaultSize,
  62. int n = 0,
  63. const wxString choices[] = (const wxString *) NULL,
  64. long style = 0,
  65. const wxValidator& validator = wxDefaultValidator,
  66. const wxString& name = wxComboBoxNameStr);
  67. bool Create(wxWindow *parent,
  68. wxWindowID id,
  69. const wxString& value,
  70. const wxPoint& pos,
  71. const wxSize& size,
  72. const wxArrayString& choices,
  73. long style = 0,
  74. const wxValidator& validator = wxDefaultValidator,
  75. const wxString& name = wxComboBoxNameStr);
  76. virtual ~wxComboBox();
  77. // the wxUniversal-specific methods
  78. // --------------------------------
  79. // implement the combobox interface
  80. // wxTextCtrl methods
  81. virtual wxString GetValue() const { return DoGetValue(); }
  82. virtual void SetValue(const wxString& value);
  83. virtual void WriteText(const wxString& value);
  84. virtual void Copy();
  85. virtual void Cut();
  86. virtual void Paste();
  87. virtual void SetInsertionPoint(long pos);
  88. virtual void SetInsertionPointEnd();
  89. virtual long GetInsertionPoint() const;
  90. virtual wxTextPos GetLastPosition() const;
  91. virtual void Replace(long from, long to, const wxString& value);
  92. virtual void Remove(long from, long to);
  93. virtual void SetSelection(long from, long to);
  94. virtual void GetSelection(long *from, long *to) const;
  95. virtual void SetEditable(bool editable);
  96. virtual bool IsEditable() const;
  97. virtual void Undo();
  98. virtual void Redo();
  99. virtual void SelectAll();
  100. virtual bool CanCopy() const;
  101. virtual bool CanCut() const;
  102. virtual bool CanPaste() const;
  103. virtual bool CanUndo() const;
  104. virtual bool CanRedo() const;
  105. // override these methods to disambiguate between two base classes versions
  106. virtual void Clear()
  107. {
  108. wxComboCtrl::Clear();
  109. wxItemContainer::Clear();
  110. }
  111. // See wxComboBoxBase discussion of IsEmpty().
  112. bool IsListEmpty() const { return wxItemContainer::IsEmpty(); }
  113. bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); }
  114. // wxControlWithItems methods
  115. virtual void DoClear();
  116. virtual void DoDeleteOneItem(unsigned int n);
  117. virtual unsigned int GetCount() const;
  118. virtual wxString GetString(unsigned int n) const;
  119. virtual void SetString(unsigned int n, const wxString& s);
  120. virtual int FindString(const wxString& s, bool bCase = false) const;
  121. virtual void SetSelection(int n);
  122. virtual int GetSelection() const;
  123. virtual wxString GetStringSelection() const;
  124. // we have our own input handler and our own actions
  125. // (but wxComboCtrl already handled Popup/Dismiss)
  126. /*
  127. virtual bool PerformAction(const wxControlAction& action,
  128. long numArg = 0l,
  129. const wxString& strArg = wxEmptyString);
  130. */
  131. static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
  132. virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
  133. {
  134. return GetStdInputHandler(handlerDef);
  135. }
  136. // we delegate our client data handling to wxListBox which we use for the
  137. // items, so override this and other methods dealing with the client data
  138. virtual wxClientDataType GetClientDataType() const;
  139. virtual void SetClientDataType(wxClientDataType clientDataItemsType);
  140. protected:
  141. virtual wxString DoGetValue() const;
  142. virtual int DoInsertItems(const wxArrayStringsAdapter& items,
  143. unsigned int pos,
  144. void **clientData, wxClientDataType type);
  145. virtual void DoSetItemClientData(unsigned int n, void* clientData);
  146. virtual void* DoGetItemClientData(unsigned int n) const;
  147. // common part of all ctors
  148. void Init();
  149. // get the associated listbox
  150. wxListBox *GetLBox() const { return m_lbox; }
  151. private:
  152. // implement wxTextEntry pure virtual method
  153. virtual wxWindow *GetEditableWindow() { return this; }
  154. // the popup listbox
  155. wxListBox *m_lbox;
  156. //DECLARE_EVENT_TABLE()
  157. DECLARE_DYNAMIC_CLASS(wxComboBox)
  158. };
  159. #endif // _WX_UNIV_COMBOBOX_H_