combobox.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/gtk1/combobox.h
  3. // Purpose:
  4. // Author: Robert Roebling
  5. // Created: 01/02/97
  6. // Copyright: (c) 1998 Robert Roebling
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef __GTKCOMBOBOXH__
  10. #define __GTKCOMBOBOXH__
  11. #include "wx/defs.h"
  12. #if wxUSE_COMBOBOX
  13. #include "wx/object.h"
  14. //-----------------------------------------------------------------------------
  15. // classes
  16. //-----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_FWD_CORE wxComboBox;
  18. //-----------------------------------------------------------------------------
  19. // global data
  20. //-----------------------------------------------------------------------------
  21. extern WXDLLIMPEXP_DATA_CORE(const char) wxComboBoxNameStr[];
  22. extern WXDLLIMPEXP_BASE const wxChar* wxEmptyString;
  23. //-----------------------------------------------------------------------------
  24. // wxComboBox
  25. //-----------------------------------------------------------------------------
  26. class WXDLLIMPEXP_CORE wxComboBox :
  27. public wxWindowWithItems<wxControl, wxComboBoxBase>
  28. {
  29. public:
  30. inline wxComboBox() {}
  31. inline wxComboBox(wxWindow *parent, wxWindowID id,
  32. const wxString& value = wxEmptyString,
  33. const wxPoint& pos = wxDefaultPosition,
  34. const wxSize& size = wxDefaultSize,
  35. int n = 0, const wxString choices[] = (const wxString *) NULL,
  36. long style = 0,
  37. const wxValidator& validator = wxDefaultValidator,
  38. const wxString& name = wxComboBoxNameStr)
  39. {
  40. Create(parent, id, value, pos, size, n, choices, style, validator, name);
  41. }
  42. inline wxComboBox(wxWindow *parent, wxWindowID id,
  43. const wxString& value,
  44. const wxPoint& pos,
  45. const wxSize& size,
  46. const wxArrayString& choices,
  47. long style = 0,
  48. const wxValidator& validator = wxDefaultValidator,
  49. const wxString& name = wxComboBoxNameStr)
  50. {
  51. Create(parent, id, value, pos, size, choices, style, validator, name);
  52. }
  53. virtual ~wxComboBox();
  54. bool Create(wxWindow *parent, wxWindowID id,
  55. const wxString& value = wxEmptyString,
  56. const wxPoint& pos = wxDefaultPosition,
  57. const wxSize& size = wxDefaultSize,
  58. int n = 0, const wxString choices[] = (const wxString *) NULL,
  59. long style = 0,
  60. const wxValidator& validator = wxDefaultValidator,
  61. const wxString& name = wxComboBoxNameStr);
  62. bool Create(wxWindow *parent, wxWindowID id,
  63. const wxString& value,
  64. const wxPoint& pos,
  65. const wxSize& size,
  66. const wxArrayString& choices,
  67. long style = 0,
  68. const wxValidator& validator = wxDefaultValidator,
  69. const wxString& name = wxComboBoxNameStr);
  70. void DoClear();
  71. void DoDeleteOneItem(unsigned int n);
  72. virtual int FindString(const wxString& s, bool bCase = false) const;
  73. int GetSelection() const;
  74. int GetCurrentSelection() const;
  75. virtual wxString GetString(unsigned int n) const;
  76. wxString GetStringSelection() const;
  77. virtual unsigned int GetCount() const;
  78. virtual void SetSelection(int n);
  79. virtual void SetString(unsigned int n, const wxString &text);
  80. wxString GetValue() const { return DoGetValue(); }
  81. void SetValue(const wxString& value);
  82. void WriteText(const wxString& value);
  83. void Copy();
  84. void Cut();
  85. void Paste();
  86. bool CanCopy() const;
  87. bool CanCut() const;
  88. bool CanPaste() const;
  89. void SetInsertionPoint( long pos );
  90. void SetInsertionPointEnd() { SetInsertionPoint( -1 ); }
  91. long GetInsertionPoint() const;
  92. virtual wxTextPos GetLastPosition() const;
  93. void Remove(long from, long to) { Replace(from, to, wxEmptyString); }
  94. void Replace( long from, long to, const wxString& value );
  95. void SetSelection( long from, long to );
  96. void GetSelection( long* from, long* to ) const;
  97. void SetEditable( bool editable );
  98. void Undo() ;
  99. void Redo() ;
  100. bool CanUndo() const;
  101. bool CanRedo() const;
  102. void SelectAll();
  103. bool IsEditable() const ;
  104. bool HasSelection() const ;
  105. // implementation
  106. virtual void SetFocus();
  107. void OnSize( wxSizeEvent &event );
  108. void OnChar( wxKeyEvent &event );
  109. // Standard event handling
  110. void OnCut(wxCommandEvent& event);
  111. void OnCopy(wxCommandEvent& event);
  112. void OnPaste(wxCommandEvent& event);
  113. void OnUndo(wxCommandEvent& event);
  114. void OnRedo(wxCommandEvent& event);
  115. void OnDelete(wxCommandEvent& event);
  116. void OnSelectAll(wxCommandEvent& event);
  117. void OnUpdateCut(wxUpdateUIEvent& event);
  118. void OnUpdateCopy(wxUpdateUIEvent& event);
  119. void OnUpdatePaste(wxUpdateUIEvent& event);
  120. void OnUpdateUndo(wxUpdateUIEvent& event);
  121. void OnUpdateRedo(wxUpdateUIEvent& event);
  122. void OnUpdateDelete(wxUpdateUIEvent& event);
  123. void OnUpdateSelectAll(wxUpdateUIEvent& event);
  124. bool m_ignoreNextUpdate:1;
  125. wxList m_clientDataList;
  126. wxList m_clientObjectList;
  127. int m_prevSelection;
  128. void DisableEvents();
  129. void EnableEvents();
  130. GtkWidget* GetConnectWidget();
  131. bool IsOwnGtkWindow( GdkWindow *window );
  132. void DoApplyWidgetStyle(GtkRcStyle *style);
  133. static wxVisualAttributes
  134. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  135. protected:
  136. virtual int DoInsertItems(const wxArrayStringsAdapter& items,
  137. unsigned int pos,
  138. void **clientData, wxClientDataType type);
  139. virtual void DoSetItemClientData(unsigned int n, void* clientData);
  140. virtual void* DoGetItemClientData(unsigned int n) const;
  141. virtual wxSize DoGetBestSize() const;
  142. // implement wxTextEntry pure virtual methods
  143. virtual wxString DoGetValue() const;
  144. virtual wxWindow *GetEditableWindow() { return this; }
  145. // Widgets that use the style->base colour for the BG colour should
  146. // override this and return true.
  147. virtual bool UseGTKStyleBase() const { return true; }
  148. private:
  149. DECLARE_DYNAMIC_CLASS_NO_COPY(wxComboBox)
  150. DECLARE_EVENT_TABLE()
  151. };
  152. #endif
  153. #endif
  154. // __GTKCOMBOBOXH__