]> git.saurik.com Git - wxWidgets.git/blame - src/common/headerctrlcmn.cpp
make first column non-draggable to test support for this flag
[wxWidgets.git] / src / common / headerctrlcmn.cpp
CommitLineData
56873923
VZ
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
e2bfe673
VZ
31// ----------------------------------------------------------------------------
32// constants
33// ----------------------------------------------------------------------------
34
35namespace
36{
37
38const unsigned int wxNO_COLUMN = static_cast<unsigned>(-1);
39
40} // anonymous namespace
41
56873923
VZ
42// ============================================================================
43// wxHeaderCtrlBase implementation
44// ============================================================================
45
9a382f1f 46extern WXDLLIMPEXP_DATA_CORE(const char) wxHeaderCtrlNameStr[] = "wxHeaderCtrl";
56873923 47
3bfaa5a7
VZ
48BEGIN_EVENT_TABLE(wxHeaderCtrlBase, wxControl)
49 EVT_HEADER_SEPARATOR_DCLICK(wxID_ANY, wxHeaderCtrlBase::OnSeparatorDClick)
50END_EVENT_TABLE()
51
d8fc3398
VZ
52void wxHeaderCtrlBase::ScrollWindow(int dx,
53 int WXUNUSED_UNLESS_DEBUG(dy),
54 const wxRect * WXUNUSED_UNLESS_DEBUG(rect))
55
56{
57 // this doesn't make sense at all
58 wxASSERT_MSG( !dy, "header window can't be scrolled vertically" );
59
60 // this would actually be nice to support for "frozen" headers but it isn't
61 // supported currently
62 wxASSERT_MSG( !rect, "header window can't be scrolled partially" );
63
64 DoScrollHorz(dx);
65}
66
3bfaa5a7
VZ
67void wxHeaderCtrlBase::OnSeparatorDClick(wxHeaderCtrlEvent& event)
68{
69 const unsigned col = event.GetColumn();
70
71 int w = wxWindowBase::GetTextExtent(GetColumn(col).GetTitle()).x;
72 w += 2*GetCharWidth(); // add some arbitrary margins around text
73
74 if ( !UpdateColumnWidthToFit(col, w) )
75 event.Skip();
76 else
77 UpdateColumn(col);
78}
79
e2bfe673
VZ
80// ============================================================================
81// wxHeaderCtrlSimple implementation
82// ============================================================================
83
84void wxHeaderCtrlSimple::Init()
85{
86 m_sortKey = wxNO_COLUMN;
87}
88
89wxHeaderColumnBase& wxHeaderCtrlSimple::GetColumn(unsigned int idx)
90{
91 return m_cols[idx];
92}
93
94void wxHeaderCtrlSimple::DoInsert(const wxHeaderColumnSimple& col, unsigned int idx)
95{
96 m_cols.insert(m_cols.begin() + idx, col);
97
98 UpdateColumnCount();
99}
100
101void wxHeaderCtrlSimple::DoDelete(unsigned int idx)
102{
103 m_cols.erase(m_cols.begin() + idx);
104 if ( idx == m_sortKey )
105 m_sortKey = wxNO_COLUMN;
106
107 UpdateColumnCount();
108}
109
110void wxHeaderCtrlSimple::DeleteAllColumns()
111{
112 m_cols.clear();
113 m_sortKey = wxNO_COLUMN;
114
115 UpdateColumnCount();
116}
117
118
119void wxHeaderCtrlSimple::DoShowColumn(unsigned int idx, bool show)
120{
121 if ( show != m_cols[idx].IsShown() )
122 {
123 m_cols[idx].SetHidden(!show);
124
125 UpdateColumn(idx);
126 }
127}
128
129void wxHeaderCtrlSimple::DoShowSortIndicator(unsigned int idx, bool ascending)
130{
131 RemoveSortIndicator();
132
133 m_cols[idx].SetAsSortKey(ascending);
134 m_sortKey = idx;
135
136 UpdateColumn(idx);
137}
138
139void wxHeaderCtrlSimple::RemoveSortIndicator()
140{
141 if ( m_sortKey != wxNO_COLUMN )
142 {
143 const unsigned sortOld = m_sortKey;
144 m_sortKey = wxNO_COLUMN;
145
146 m_cols[sortOld].UnsetAsSortKey();
147
148 UpdateColumn(sortOld);
149 }
150}
151
e5a16353
VZ
152bool
153wxHeaderCtrlSimple::UpdateColumnWidthToFit(unsigned int idx, int widthTitle)
154{
155 const int widthContents = GetBestFittingWidth(idx);
156 if ( widthContents == -1 )
157 return false;
158
159 m_cols[idx].SetWidth(wxMax(widthContents, widthTitle));
160 UpdateColumn(idx);
161
162 return true;
163}
164
fa3d4aaf
VZ
165// ============================================================================
166// wxHeaderCtrlEvent implementation
167// ============================================================================
168
169IMPLEMENT_DYNAMIC_CLASS(wxHeaderCtrlEvent, wxNotifyEvent)
170
171const wxEventType wxEVT_COMMAND_HEADER_CLICK = wxNewEventType();
172const wxEventType wxEVT_COMMAND_HEADER_RIGHT_CLICK = wxNewEventType();
173const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_CLICK = wxNewEventType();
174
175const wxEventType wxEVT_COMMAND_HEADER_DCLICK = wxNewEventType();
176const wxEventType wxEVT_COMMAND_HEADER_RIGHT_DCLICK = wxNewEventType();
177const wxEventType wxEVT_COMMAND_HEADER_MIDDLE_DCLICK = wxNewEventType();
3bfaa5a7
VZ
178
179const wxEventType wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK = wxNewEventType();
aef252d9 180
396825dc
VZ
181const wxEventType wxEVT_COMMAND_HEADER_BEGIN_RESIZE = wxNewEventType();
182const wxEventType wxEVT_COMMAND_HEADER_RESIZING = wxNewEventType();
183const wxEventType wxEVT_COMMAND_HEADER_END_RESIZE = wxNewEventType();