1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/headerctrlg.h
3 // Purpose: Generic wxHeaderCtrl implementation
4 // Author: Vadim Zeitlin
6 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_GENERIC_HEADERCTRLG_H_
11 #define _WX_GENERIC_HEADERCTRLG_H_
14 #include "wx/vector.h"
15 #include "wx/overlay.h"
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 class WXDLLIMPEXP_CORE wxHeaderCtrl
: public wxHeaderCtrlBase
29 wxHeaderCtrl(wxWindow
*parent
,
30 wxWindowID id
= wxID_ANY
,
31 const wxPoint
& pos
= wxDefaultPosition
,
32 const wxSize
& size
= wxDefaultSize
,
33 long style
= wxHD_DEFAULT_STYLE
,
34 const wxString
& name
= wxHeaderCtrlNameStr
)
38 Create(parent
, id
, pos
, size
, style
, name
);
41 bool Create(wxWindow
*parent
,
42 wxWindowID id
= wxID_ANY
,
43 const wxPoint
& pos
= wxDefaultPosition
,
44 const wxSize
& size
= wxDefaultSize
,
45 long style
= wxHD_DEFAULT_STYLE
,
46 const wxString
& name
= wxHeaderCtrlNameStr
);
48 virtual ~wxHeaderCtrl();
51 virtual wxSize
DoGetBestSize() const;
55 // implement base class pure virtuals
56 virtual void DoSetCount(unsigned int count
);
57 virtual unsigned int DoGetCount() const;
58 virtual void DoUpdate(unsigned int idx
);
60 virtual void DoScrollHorz(int dx
);
62 virtual void DoSetColumnsOrder(const wxArrayInt
& order
);
63 virtual wxArrayInt
DoGetColumnsOrder() const;
65 // common part of all ctors
69 void OnPaint(wxPaintEvent
& event
);
70 void OnMouse(wxMouseEvent
& event
);
71 void OnKeyDown(wxKeyEvent
& event
);
72 void OnCaptureLost(wxMouseCaptureLostEvent
& event
);
74 // move the column with given idx at given position (this doesn't generate
75 // any events but does refresh the display)
76 void DoMoveCol(unsigned int idx
, unsigned int pos
);
78 // return the horizontal start position of the given column in physical
80 int GetColStart(unsigned int idx
) const;
82 // and the end position
83 int GetColEnd(unsigned int idx
) const;
85 // refresh the given column [only]; idx must be valid
86 void RefreshCol(unsigned int idx
);
88 // refresh the given column if idx is valid
89 void RefreshColIfNotNone(unsigned int idx
);
91 // refresh all the controls starting from (and including) the given one
92 void RefreshColsAfter(unsigned int idx
);
94 // return the column at the given position or -1 if it is beyond the
95 // rightmost column and put true into onSeparator output parameter if the
96 // position is near the divider at the right end of this column (notice
97 // that this means that we return column 0 even if the position is over
98 // column 1 but close enough to the divider separating it from column 0)
99 unsigned int FindColumnAtPoint(int x
, bool *onSeparator
= NULL
) const;
101 // return true if a drag resizing operation is currently in progress
102 bool IsResizing() const;
104 // return true if a drag reordering operation is currently in progress
105 bool IsReordering() const;
107 // return true if any drag operation is currently in progress
108 bool IsDragging() const { return IsResizing() || IsReordering(); }
110 // end any drag operation currently in progress (resizing or reordering)
113 // cancel the drag operation currently in progress and generate an event
115 void CancelDragging();
117 // start (if m_colBeingResized is -1) or continue resizing the column
119 // this generates wxEVT_HEADER_BEGIN_RESIZE/RESIZING events and can
120 // cancel the operation if the user handler decides so
121 void StartOrContinueResizing(unsigned int col
, int xPhysical
);
123 // end the resizing operation currently in progress and generate an event
124 // about it with its cancelled flag set if xPhysical is -1
125 void EndResizing(int xPhysical
);
127 // same functions as above but for column moving/reordering instead of
129 void StartReordering(unsigned int col
, int xPhysical
);
131 // returns true if we did drag the column somewhere else or false if we
132 // didn't really move it -- in this case we consider that no reordering
133 // took place and that a normal column click event should be generated
134 bool EndReordering(int xPhysical
);
136 // constrain the given position to be larger than the start position of the
137 // given column plus its minimal width and return the effective width
138 int ConstrainByMinWidth(unsigned int col
, int& xPhysical
);
140 // update the information displayed while a column is being moved around
141 void UpdateReorderingMarker(int xPhysical
);
143 // clear any overlaid markers
147 // number of columns in the control currently
148 unsigned int m_numColumns
;
150 // index of the column under mouse or -1 if none
151 unsigned int m_hover
;
153 // the column being resized or -1 if there is no resizing operation in
155 unsigned int m_colBeingResized
;
157 // the column being moved or -1 if there is no reordering operation in
159 unsigned int m_colBeingReordered
;
161 // the distance from the start of m_colBeingReordered and the mouse
162 // position when the user started to drag it
165 // the horizontal scroll offset
168 // the overlay display used during the dragging operations
171 // the indices of the column appearing at the given position on the display
172 // (its size is always m_numColumns)
173 wxArrayInt m_colIndices
;
176 DECLARE_EVENT_TABLE()
177 wxDECLARE_NO_COPY_CLASS(wxHeaderCtrl
);
180 #endif // _WX_GENERIC_HEADERCTRLG_H_