headerctrlg.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/headerctrlg.h
  3. // Purpose: Generic wxHeaderCtrl implementation
  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_GENERIC_HEADERCTRLG_H_
  10. #define _WX_GENERIC_HEADERCTRLG_H_
  11. #include "wx/event.h"
  12. #include "wx/vector.h"
  13. #include "wx/overlay.h"
  14. // ----------------------------------------------------------------------------
  15. // wxHeaderCtrl
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_CORE wxHeaderCtrl : public wxHeaderCtrlBase
  18. {
  19. public:
  20. wxHeaderCtrl()
  21. {
  22. Init();
  23. }
  24. wxHeaderCtrl(wxWindow *parent,
  25. wxWindowID id = wxID_ANY,
  26. const wxPoint& pos = wxDefaultPosition,
  27. const wxSize& size = wxDefaultSize,
  28. long style = wxHD_DEFAULT_STYLE,
  29. const wxString& name = wxHeaderCtrlNameStr)
  30. {
  31. Init();
  32. Create(parent, id, pos, size, style, name);
  33. }
  34. bool Create(wxWindow *parent,
  35. wxWindowID id = wxID_ANY,
  36. const wxPoint& pos = wxDefaultPosition,
  37. const wxSize& size = wxDefaultSize,
  38. long style = wxHD_DEFAULT_STYLE,
  39. const wxString& name = wxHeaderCtrlNameStr);
  40. virtual ~wxHeaderCtrl();
  41. protected:
  42. virtual wxSize DoGetBestSize() const;
  43. private:
  44. // implement base class pure virtuals
  45. virtual void DoSetCount(unsigned int count);
  46. virtual unsigned int DoGetCount() const;
  47. virtual void DoUpdate(unsigned int idx);
  48. virtual void DoScrollHorz(int dx);
  49. virtual void DoSetColumnsOrder(const wxArrayInt& order);
  50. virtual wxArrayInt DoGetColumnsOrder() const;
  51. // common part of all ctors
  52. void Init();
  53. // event handlers
  54. void OnPaint(wxPaintEvent& event);
  55. void OnMouse(wxMouseEvent& event);
  56. void OnKeyDown(wxKeyEvent& event);
  57. void OnCaptureLost(wxMouseCaptureLostEvent& event);
  58. // move the column with given idx at given position (this doesn't generate
  59. // any events but does refresh the display)
  60. void DoMoveCol(unsigned int idx, unsigned int pos);
  61. // return the horizontal start position of the given column in physical
  62. // coordinates
  63. int GetColStart(unsigned int idx) const;
  64. // and the end position
  65. int GetColEnd(unsigned int idx) const;
  66. // refresh the given column [only]; idx must be valid
  67. void RefreshCol(unsigned int idx);
  68. // refresh the given column if idx is valid
  69. void RefreshColIfNotNone(unsigned int idx);
  70. // refresh all the controls starting from (and including) the given one
  71. void RefreshColsAfter(unsigned int idx);
  72. // return the column at the given position or -1 if it is beyond the
  73. // rightmost column and put true into onSeparator output parameter if the
  74. // position is near the divider at the right end of this column (notice
  75. // that this means that we return column 0 even if the position is over
  76. // column 1 but close enough to the divider separating it from column 0)
  77. unsigned int FindColumnAtPoint(int x, bool *onSeparator = NULL) const;
  78. // return true if a drag resizing operation is currently in progress
  79. bool IsResizing() const;
  80. // return true if a drag reordering operation is currently in progress
  81. bool IsReordering() const;
  82. // return true if any drag operation is currently in progress
  83. bool IsDragging() const { return IsResizing() || IsReordering(); }
  84. // end any drag operation currently in progress (resizing or reordering)
  85. void EndDragging();
  86. // cancel the drag operation currently in progress and generate an event
  87. // about it
  88. void CancelDragging();
  89. // start (if m_colBeingResized is -1) or continue resizing the column
  90. //
  91. // this generates wxEVT_HEADER_BEGIN_RESIZE/RESIZING events and can
  92. // cancel the operation if the user handler decides so
  93. void StartOrContinueResizing(unsigned int col, int xPhysical);
  94. // end the resizing operation currently in progress and generate an event
  95. // about it with its cancelled flag set if xPhysical is -1
  96. void EndResizing(int xPhysical);
  97. // same functions as above but for column moving/reordering instead of
  98. // resizing
  99. void StartReordering(unsigned int col, int xPhysical);
  100. // returns true if we did drag the column somewhere else or false if we
  101. // didn't really move it -- in this case we consider that no reordering
  102. // took place and that a normal column click event should be generated
  103. bool EndReordering(int xPhysical);
  104. // constrain the given position to be larger than the start position of the
  105. // given column plus its minimal width and return the effective width
  106. int ConstrainByMinWidth(unsigned int col, int& xPhysical);
  107. // update the information displayed while a column is being moved around
  108. void UpdateReorderingMarker(int xPhysical);
  109. // clear any overlaid markers
  110. void ClearMarkers();
  111. // number of columns in the control currently
  112. unsigned int m_numColumns;
  113. // index of the column under mouse or -1 if none
  114. unsigned int m_hover;
  115. // the column being resized or -1 if there is no resizing operation in
  116. // progress
  117. unsigned int m_colBeingResized;
  118. // the column being moved or -1 if there is no reordering operation in
  119. // progress
  120. unsigned int m_colBeingReordered;
  121. // the distance from the start of m_colBeingReordered and the mouse
  122. // position when the user started to drag it
  123. int m_dragOffset;
  124. // the horizontal scroll offset
  125. int m_scrollOffset;
  126. // the overlay display used during the dragging operations
  127. wxOverlay m_overlay;
  128. // the indices of the column appearing at the given position on the display
  129. // (its size is always m_numColumns)
  130. wxArrayInt m_colIndices;
  131. DECLARE_EVENT_TABLE()
  132. wxDECLARE_NO_COPY_CLASS(wxHeaderCtrl);
  133. };
  134. #endif // _WX_GENERIC_HEADERCTRLG_H_