choice.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/choice.h
  3. // Purpose: wxChoice class
  4. // Author: Julian Smart
  5. // Modified by: Vadim Zeitlin to derive from wxChoiceBase
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_CHOICE_H_
  11. #define _WX_CHOICE_H_
  12. struct tagCOMBOBOXINFO;
  13. // ----------------------------------------------------------------------------
  14. // Choice item
  15. // ----------------------------------------------------------------------------
  16. class WXDLLIMPEXP_CORE wxChoice : public wxChoiceBase
  17. {
  18. public:
  19. // ctors
  20. wxChoice() { Init(); }
  21. virtual ~wxChoice();
  22. wxChoice(wxWindow *parent,
  23. wxWindowID id,
  24. const wxPoint& pos = wxDefaultPosition,
  25. const wxSize& size = wxDefaultSize,
  26. int n = 0, const wxString choices[] = NULL,
  27. long style = 0,
  28. const wxValidator& validator = wxDefaultValidator,
  29. const wxString& name = wxChoiceNameStr)
  30. {
  31. Init();
  32. Create(parent, id, pos, size, n, choices, style, validator, name);
  33. }
  34. wxChoice(wxWindow *parent,
  35. wxWindowID id,
  36. const wxPoint& pos,
  37. const wxSize& size,
  38. const wxArrayString& choices,
  39. long style = 0,
  40. const wxValidator& validator = wxDefaultValidator,
  41. const wxString& name = wxChoiceNameStr)
  42. {
  43. Init();
  44. Create(parent, id, pos, size, choices, style, validator, name);
  45. }
  46. bool Create(wxWindow *parent,
  47. wxWindowID id,
  48. const wxPoint& pos = wxDefaultPosition,
  49. const wxSize& size = wxDefaultSize,
  50. int n = 0, const wxString choices[] = NULL,
  51. long style = 0,
  52. const wxValidator& validator = wxDefaultValidator,
  53. const wxString& name = wxChoiceNameStr);
  54. bool Create(wxWindow *parent,
  55. wxWindowID id,
  56. const wxPoint& pos,
  57. const wxSize& size,
  58. const wxArrayString& choices,
  59. long style = 0,
  60. const wxValidator& validator = wxDefaultValidator,
  61. const wxString& name = wxChoiceNameStr);
  62. virtual bool Show(bool show = true);
  63. virtual void SetLabel(const wxString& label);
  64. virtual unsigned int GetCount() const;
  65. virtual int GetSelection() const;
  66. virtual int GetCurrentSelection() const;
  67. virtual void SetSelection(int n);
  68. virtual int FindString(const wxString& s, bool bCase = false) const;
  69. virtual wxString GetString(unsigned int n) const;
  70. virtual void SetString(unsigned int n, const wxString& s);
  71. virtual wxVisualAttributes GetDefaultAttributes() const
  72. {
  73. return GetClassDefaultAttributes(GetWindowVariant());
  74. }
  75. static wxVisualAttributes
  76. GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
  77. // MSW only
  78. virtual bool MSWCommand(WXUINT param, WXWORD id);
  79. WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
  80. virtual WXHBRUSH MSWControlColor(WXHDC hDC, WXHWND hWnd);
  81. virtual bool MSWShouldPreProcessMessage(WXMSG *pMsg);
  82. virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
  83. // returns true if the platform should explicitly apply a theme border
  84. virtual bool CanApplyThemeBorder() const { return false; }
  85. protected:
  86. // choose the default border for this window
  87. virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  88. // common part of all ctors
  89. void Init()
  90. {
  91. m_lastAcceptedSelection =
  92. m_pendingSelection = wxID_NONE;
  93. m_heightOwn = wxDefaultCoord;
  94. }
  95. virtual void DoDeleteOneItem(unsigned int n);
  96. virtual void DoClear();
  97. virtual int DoInsertItems(const wxArrayStringsAdapter& items,
  98. unsigned int pos,
  99. void **clientData, wxClientDataType type);
  100. virtual void DoMoveWindow(int x, int y, int width, int height);
  101. virtual void DoSetItemClientData(unsigned int n, void* clientData);
  102. virtual void* DoGetItemClientData(unsigned int n) const;
  103. // MSW implementation
  104. virtual wxSize DoGetBestSize() const;
  105. virtual void DoGetSize(int *w, int *h) const;
  106. virtual void DoSetSize(int x, int y,
  107. int width, int height,
  108. int sizeFlags = wxSIZE_AUTO);
  109. virtual wxSize DoGetSizeFromTextSize(int xlen, int ylen = -1) const;
  110. // Show or hide the popup part of the control.
  111. void MSWDoPopupOrDismiss(bool show);
  112. // update the height of the drop down list to fit the number of items we
  113. // have (without changing the visible height)
  114. void MSWUpdateDropDownHeight();
  115. // set the height of the visible part of the control to m_heightOwn
  116. void MSWUpdateVisibleHeight();
  117. // Call GetComboBoxInfo() and return false if it's not supported by this
  118. // system. Notice that the caller must initialize info.cbSize.
  119. bool MSWGetComboBoxInfo(tagCOMBOBOXINFO* info) const;
  120. // create and initialize the control
  121. bool CreateAndInit(wxWindow *parent, wxWindowID id,
  122. const wxPoint& pos,
  123. const wxSize& size,
  124. int n, const wxString choices[],
  125. long style,
  126. const wxValidator& validator,
  127. const wxString& name);
  128. // free all memory we have (used by Clear() and dtor)
  129. void Free();
  130. // set the height for simple combo box
  131. int SetHeightSimpleComboBox(int nItems) const;
  132. #if wxUSE_DEFERRED_SIZING
  133. virtual void MSWEndDeferWindowPos();
  134. #endif // wxUSE_DEFERRED_SIZING
  135. // These variables are only used while the drop down is opened.
  136. //
  137. // The first one contains the item that had been originally selected before
  138. // the drop down was opened and the second one the item we should select
  139. // when the drop down is closed again.
  140. int m_lastAcceptedSelection,
  141. m_pendingSelection;
  142. // the height of the control itself if it was set explicitly or
  143. // wxDefaultCoord if it hadn't
  144. int m_heightOwn;
  145. DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoice)
  146. };
  147. #endif // _WX_CHOICE_H_