combobox.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/combobox.h
  3. // Purpose: wxComboBox class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_COMBOBOX_H_
  11. #define _WX_COMBOBOX_H_
  12. #include "wx/choice.h"
  13. #include "wx/textentry.h"
  14. #if wxUSE_COMBOBOX
  15. // ----------------------------------------------------------------------------
  16. // Combobox control
  17. // ----------------------------------------------------------------------------
  18. class WXDLLIMPEXP_CORE wxComboBox : public wxChoice,
  19. public wxTextEntry
  20. {
  21. public:
  22. wxComboBox() { Init(); }
  23. wxComboBox(wxWindow *parent, wxWindowID id,
  24. const wxString& value = wxEmptyString,
  25. const wxPoint& pos = wxDefaultPosition,
  26. const wxSize& size = wxDefaultSize,
  27. int n = 0, const wxString choices[] = NULL,
  28. long style = 0,
  29. const wxValidator& validator = wxDefaultValidator,
  30. const wxString& name = wxComboBoxNameStr)
  31. {
  32. Init();
  33. Create(parent, id, value, pos, size, n, choices, style, validator, name);
  34. }
  35. wxComboBox(wxWindow *parent, wxWindowID id,
  36. const wxString& value,
  37. const wxPoint& pos,
  38. const wxSize& size,
  39. const wxArrayString& choices,
  40. long style = 0,
  41. const wxValidator& validator = wxDefaultValidator,
  42. const wxString& name = wxComboBoxNameStr)
  43. {
  44. Init();
  45. Create(parent, id, value, pos, size, choices, style, validator, name);
  46. }
  47. bool Create(wxWindow *parent,
  48. wxWindowID id,
  49. const wxString& value = wxEmptyString,
  50. const wxPoint& pos = wxDefaultPosition,
  51. const wxSize& size = wxDefaultSize,
  52. int n = 0,
  53. const wxString choices[] = NULL,
  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,
  60. const wxPoint& pos,
  61. const wxSize& size,
  62. const wxArrayString& choices,
  63. long style = 0,
  64. const wxValidator& validator = wxDefaultValidator,
  65. const wxString& name = wxComboBoxNameStr);
  66. // See wxComboBoxBase discussion of IsEmpty().
  67. bool IsListEmpty() const { return wxItemContainer::IsEmpty(); }
  68. bool IsTextEmpty() const { return wxTextEntry::IsEmpty(); }
  69. // resolve ambiguities among virtual functions inherited from both base
  70. // classes
  71. virtual void Clear();
  72. virtual wxString GetValue() const;
  73. virtual void SetValue(const wxString& value);
  74. virtual wxString GetStringSelection() const
  75. { return wxChoice::GetStringSelection(); }
  76. virtual void Popup() { MSWDoPopupOrDismiss(true); }
  77. virtual void Dismiss() { MSWDoPopupOrDismiss(false); }
  78. virtual void SetSelection(int n) { wxChoice::SetSelection(n); }
  79. virtual void SetSelection(long from, long to)
  80. { wxTextEntry::SetSelection(from, to); }
  81. virtual int GetSelection() const { return wxChoice::GetSelection(); }
  82. virtual bool ContainsHWND(WXHWND hWnd) const;
  83. virtual void GetSelection(long *from, long *to) const;
  84. virtual bool IsEditable() const;
  85. // implementation only from now on
  86. virtual bool MSWCommand(WXUINT param, WXWORD id);
  87. bool MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam);
  88. virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  89. bool MSWShouldPreProcessMessage(WXMSG *pMsg);
  90. // Standard event handling
  91. void OnCut(wxCommandEvent& event);
  92. void OnCopy(wxCommandEvent& event);
  93. void OnPaste(wxCommandEvent& event);
  94. void OnUndo(wxCommandEvent& event);
  95. void OnRedo(wxCommandEvent& event);
  96. void OnDelete(wxCommandEvent& event);
  97. void OnSelectAll(wxCommandEvent& event);
  98. void OnUpdateCut(wxUpdateUIEvent& event);
  99. void OnUpdateCopy(wxUpdateUIEvent& event);
  100. void OnUpdatePaste(wxUpdateUIEvent& event);
  101. void OnUpdateUndo(wxUpdateUIEvent& event);
  102. void OnUpdateRedo(wxUpdateUIEvent& event);
  103. void OnUpdateDelete(wxUpdateUIEvent& event);
  104. void OnUpdateSelectAll(wxUpdateUIEvent& event);
  105. virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
  106. #if wxUSE_UXTHEME
  107. // override wxTextEntry method to work around Windows bug
  108. virtual bool SetHint(const wxString& hint);
  109. #endif // wxUSE_UXTHEME
  110. protected:
  111. #if wxUSE_TOOLTIPS
  112. virtual void DoSetToolTip(wxToolTip *tip);
  113. #endif
  114. virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
  115. // Override this one to avoid eating events from our popup listbox.
  116. virtual wxWindow *MSWFindItem(long id, WXHWND hWnd) const;
  117. // this is the implementation of GetEditHWND() which can also be used when
  118. // we don't have the edit control, it simply returns NULL then
  119. //
  120. // try not to use this function unless absolutely necessary (as in the
  121. // message handling code where the edit control might not be created yet
  122. // for the messages we receive during the control creation) as normally
  123. // just testing for IsEditable() and using GetEditHWND() should be enough
  124. WXHWND GetEditHWNDIfAvailable() const;
  125. virtual void EnableTextChangedEvents(bool enable)
  126. {
  127. m_allowTextEvents = enable;
  128. }
  129. private:
  130. // there are the overridden wxTextEntry methods which should only be called
  131. // when we do have an edit control so they assert if this is not the case
  132. virtual wxWindow *GetEditableWindow();
  133. virtual WXHWND GetEditHWND() const;
  134. // common part of all ctors
  135. void Init()
  136. {
  137. m_allowTextEvents = true;
  138. }
  139. // normally true, false if text events are currently disabled
  140. bool m_allowTextEvents;
  141. DECLARE_DYNAMIC_CLASS_NO_COPY(wxComboBox)
  142. DECLARE_EVENT_TABLE()
  143. };
  144. #endif // wxUSE_COMBOBOX
  145. #endif // _WX_COMBOBOX_H_