- Rewrite wxHeaderCtrl to be virtual-like: even if we don't need an infinite
[wxWidgets.git] / src / common / headerctrlcmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/headerctrlcmn.cpp
3 // Purpose: implementation of wxHeaderCtrlBase
4 // Author: Vadim Zeitlin
5 // Created: 2008-12-02
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #endif // WX_PRECOMP
28
29 #include "wx/headerctrl.h"
30
31 // ----------------------------------------------------------------------------
32 // constants
33 // ----------------------------------------------------------------------------
34
35 namespace
36 {
37
38 const unsigned int wxNO_COLUMN = static_cast<unsigned>(-1);
39
40 } // anonymous namespace
41
42 // ============================================================================
43 // wxHeaderCtrlBase implementation
44 // ============================================================================
45
46 extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[] = "wxHeaderCtrl";
47
48 void wxHeaderCtrlBase::ScrollWindow(int dx,
49 int WXUNUSED_UNLESS_DEBUG(dy),
50 const wxRect * WXUNUSED_UNLESS_DEBUG(rect))
51
52 {
53 // this doesn't make sense at all
54 wxASSERT_MSG( !dy, "header window can't be scrolled vertically" );
55
56 // this would actually be nice to support for "frozen" headers but it isn't
57 // supported currently
58 wxASSERT_MSG( !rect, "header window can't be scrolled partially" );
59
60 DoScrollHorz(dx);
61 }
62
63 // ============================================================================
64 // wxHeaderCtrlSimple implementation
65 // ============================================================================
66
67 void wxHeaderCtrlSimple::Init()
68 {
69 m_sortKey = wxNO_COLUMN;
70 }
71
72 wxHeaderColumnBase& wxHeaderCtrlSimple::GetColumn(unsigned int idx)
73 {
74 return m_cols[idx];
75 }
76
77 void wxHeaderCtrlSimple::DoInsert(const wxHeaderColumnSimple& col, unsigned int idx)
78 {
79 m_cols.insert(m_cols.begin() + idx, col);
80
81 UpdateColumnCount();
82 }
83
84 void wxHeaderCtrlSimple::DoDelete(unsigned int idx)
85 {
86 m_cols.erase(m_cols.begin() + idx);
87 if ( idx == m_sortKey )
88 m_sortKey = wxNO_COLUMN;
89
90 UpdateColumnCount();
91 }
92
93 void wxHeaderCtrlSimple::DeleteAllColumns()
94 {
95 m_cols.clear();
96 m_sortKey = wxNO_COLUMN;
97
98 UpdateColumnCount();
99 }
100
101
102 void wxHeaderCtrlSimple::DoShowColumn(unsigned int idx, bool show)
103 {
104 if ( show != m_cols[idx].IsShown() )
105 {
106 m_cols[idx].SetHidden(!show);
107
108 UpdateColumn(idx);
109 }
110 }
111
112 void wxHeaderCtrlSimple::DoShowSortIndicator(unsigned int idx, bool ascending)
113 {
114 RemoveSortIndicator();
115
116 m_cols[idx].SetAsSortKey(ascending);
117 m_sortKey = idx;
118
119 UpdateColumn(idx);
120 }
121
122 void wxHeaderCtrlSimple::RemoveSortIndicator()
123 {
124 if ( m_sortKey != wxNO_COLUMN )
125 {
126 const unsigned sortOld = m_sortKey;
127 m_sortKey = wxNO_COLUMN;
128
129 m_cols[sortOld].UnsetAsSortKey();
130
131 UpdateColumn(sortOld);
132 }
133 }
134