headerctrl.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/headerctrl.h
  3. // Purpose: wxMSW native wxHeaderCtrl
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-12-01
  6. // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_MSW_HEADERCTRL_H_
  10. #define _WX_MSW_HEADERCTRL_H_
  11. class WXDLLIMPEXP_FWD_CORE wxImageList;
  12. // ----------------------------------------------------------------------------
  13. // wxHeaderCtrl
  14. // ----------------------------------------------------------------------------
  15. class WXDLLIMPEXP_CORE wxHeaderCtrl : public wxHeaderCtrlBase
  16. {
  17. public:
  18. wxHeaderCtrl()
  19. {
  20. Init();
  21. }
  22. wxHeaderCtrl(wxWindow *parent,
  23. wxWindowID id = wxID_ANY,
  24. const wxPoint& pos = wxDefaultPosition,
  25. const wxSize& size = wxDefaultSize,
  26. long style = wxHD_DEFAULT_STYLE,
  27. const wxString& name = wxHeaderCtrlNameStr)
  28. {
  29. Init();
  30. Create(parent, id, pos, size, style, name);
  31. }
  32. bool Create(wxWindow *parent,
  33. wxWindowID id = wxID_ANY,
  34. const wxPoint& pos = wxDefaultPosition,
  35. const wxSize& size = wxDefaultSize,
  36. long style = wxHD_DEFAULT_STYLE,
  37. const wxString& name = wxHeaderCtrlNameStr);
  38. virtual ~wxHeaderCtrl();
  39. protected:
  40. // override wxWindow methods which must be implemented by a new control
  41. virtual wxSize DoGetBestSize() const;
  42. virtual void DoSetSize(int x, int y,
  43. int width, int height,
  44. int sizeFlags = wxSIZE_AUTO);
  45. private:
  46. // implement base class pure virtuals
  47. virtual void DoSetCount(unsigned int count);
  48. virtual unsigned int DoGetCount() const;
  49. virtual void DoUpdate(unsigned int idx);
  50. virtual void DoScrollHorz(int dx);
  51. virtual void DoSetColumnsOrder(const wxArrayInt& order);
  52. virtual wxArrayInt DoGetColumnsOrder() const;
  53. // override MSW-specific methods needed for new control
  54. virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
  55. virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
  56. // common part of all ctors
  57. void Init();
  58. // wrapper around Header_InsertItem(): insert the item using information
  59. // from the given column at the given index
  60. void DoInsertItem(const wxHeaderColumn& col, unsigned int idx);
  61. // get the number of currently visible items: this is also the total number
  62. // of items contained in the native control
  63. int GetShownColumnsCount() const;
  64. // due to the discrepancy for the hidden columns which we know about but
  65. // the native control does not, there can be a difference between the
  66. // column indices we use and the ones used by the native control; these
  67. // functions translate between them
  68. //
  69. // notice that MSWToNativeIdx() shouldn't be called for hidden columns and
  70. // MSWFromNativeIdx() always returns an index of a visible column
  71. int MSWToNativeIdx(int idx);
  72. int MSWFromNativeIdx(int item);
  73. // this is the same as above but for order, not index
  74. int MSWToNativeOrder(int order);
  75. int MSWFromNativeOrder(int order);
  76. // get the event type corresponding to a click or double click event
  77. // (depending on dblclk value) with the specified (using MSW convention)
  78. // mouse button
  79. wxEventType GetClickEventType(bool dblclk, int button);
  80. // the number of columns in the control, including the hidden ones (not
  81. // taken into account by the native control, see comment in DoGetCount())
  82. unsigned int m_numColumns;
  83. // this is a lookup table allowing us to check whether the column with the
  84. // given index is currently shown in the native control, in which case the
  85. // value of this array element with this index is 0, or hidden
  86. //
  87. // notice that this may be different from GetColumn(idx).IsHidden() and in
  88. // fact we need this array precisely because it will be different from it
  89. // in DoUpdate() when the column hidden flag gets toggled and we need it to
  90. // handle this transition correctly
  91. wxArrayInt m_isHidden;
  92. // the order of our columns: this array contains the index of the column
  93. // shown at the position n as the n-th element
  94. //
  95. // this is necessary only to handle the hidden columns: the native control
  96. // doesn't know about them and so we can't use Header_GetOrderArray()
  97. wxArrayInt m_colIndices;
  98. // the image list: initially NULL, created on demand
  99. wxImageList *m_imageList;
  100. // the offset of the window used to emulate scrolling it
  101. int m_scrollOffset;
  102. // actual column we are dragging or -1 if not dragging anything
  103. int m_colBeingDragged;
  104. wxDECLARE_NO_COPY_CLASS(wxHeaderCtrl);
  105. };
  106. #endif // _WX_MSW_HEADERCTRL_H_