]> git.saurik.com Git - wxWidgets.git/blob - src/msw/headercol.cpp
0c96cc35a4850dcded54e8bbc677b307cd4f740a
[wxWidgets.git] / src / msw / headercol.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/headercol.cpp
3 // Purpose: wxHeaderColumn implementation for wxMSW
4 // Author: Vadim Zeitlin
5 // Created: 2008-12-03
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/headercol.h"
30
31 #include "wx/msw/wrapcctl.h"
32
33 // ----------------------------------------------------------------------------
34 // wxMSWHeaderColumnImpl
35 // ----------------------------------------------------------------------------
36
37 struct wxMSWHeaderColumnImpl
38 {
39 wxMSWHeaderColumnImpl()
40 {
41 flags = wxCOL_DEFAULT_FLAGS;
42 minWidth = 0;
43 ascending = true;
44 }
45
46 wxHDITEM hdi;
47 wxWxCharBuffer bufTitle;
48 wxBitmap bmp;
49 int flags; // combination of wxCOL_XXX constants
50 int minWidth; // 0 if not set
51 bool ascending; // sort order
52
53 DECLARE_NO_COPY_CLASS(wxMSWHeaderColumnImpl)
54 };
55
56 // ============================================================================
57 // wxHeaderColumn implementation
58 // ============================================================================
59
60 // ----------------------------------------------------------------------------
61 // wxHeaderColumn construction/destruction
62 // ----------------------------------------------------------------------------
63
64 void wxHeaderColumn::Init()
65 {
66 m_impl = new wxMSWHeaderColumnImpl;
67 }
68
69 wxHeaderColumn::wxHeaderColumn(const wxString& title,
70 int width,
71 wxAlignment align,
72 int flags)
73 {
74 Init();
75
76 SetTitle(title);
77 SetWidth(width);
78 SetAlignment(align);
79 SetFlags(flags);
80 }
81
82 wxHeaderColumn::wxHeaderColumn(const wxBitmap& bitmap,
83 int width,
84 wxAlignment align,
85 int flags)
86 {
87 Init();
88
89 SetBitmap(bitmap);
90 SetWidth(width);
91 SetAlignment(align);
92 SetFlags(flags);
93 }
94
95 wxHeaderColumn::~wxHeaderColumn()
96 {
97 delete m_impl;
98 }
99
100 // ----------------------------------------------------------------------------
101 // wxHeaderColumn accessors corresponding to HDITEM fields
102 // ----------------------------------------------------------------------------
103
104 wxHDITEM& wxHeaderColumn::GetHDI()
105 {
106 return m_impl->hdi;
107 }
108
109 void wxHeaderColumn::SetTitle(const wxString& title)
110 {
111 HDITEM& hdi = m_impl->hdi;
112
113 hdi.mask |= HDI_TEXT;
114
115 // notice that we need to store the string we use the pointer to
116 wxWxCharBuffer& buf = m_impl->bufTitle;
117 buf = title.wc_str();
118 hdi.pszText = buf.data();
119 hdi.cchTextMax = wxStrlen(buf);
120 }
121
122 wxString wxHeaderColumn::GetTitle() const
123 {
124 HDITEM& hdi = m_impl->hdi;
125
126 wxASSERT_MSG( hdi.mask & HDI_TEXT, "title not set" );
127
128 return hdi.pszText;
129 }
130
131 void wxHeaderColumn::SetWidth(int width)
132 {
133 HDITEM& hdi = m_impl->hdi;
134
135 if ( width != wxCOL_WIDTH_DEFAULT )
136 {
137 hdi.mask |= HDI_WIDTH;
138 hdi.cxy = width;
139 }
140 }
141
142 int wxHeaderColumn::GetWidth() const
143 {
144 HDITEM& hdi = m_impl->hdi;
145
146 return hdi.mask & HDI_WIDTH ? hdi.cxy : wxCOL_WIDTH_DEFAULT;
147 }
148
149 void wxHeaderColumn::SetAlignment(wxAlignment align)
150 {
151 HDITEM& hdi = m_impl->hdi;
152
153 if ( align != wxALIGN_NOT )
154 {
155 hdi.mask |= HDI_FORMAT;
156 switch ( align )
157 {
158 case wxALIGN_LEFT:
159 hdi.fmt |= HDF_LEFT;
160 break;
161
162 case wxALIGN_CENTER:
163 case wxALIGN_CENTER_HORIZONTAL:
164 hdi.fmt |= HDF_CENTER;
165 break;
166
167 case wxALIGN_RIGHT:
168 hdi.fmt |= HDF_RIGHT;
169 break;
170
171 default:
172 wxFAIL_MSG( "invalid column header alignment" );
173 }
174 }
175 }
176
177 wxAlignment wxHeaderColumn::GetAlignment() const
178 {
179 HDITEM& hdi = m_impl->hdi;
180
181 if ( !(hdi.mask & HDI_FORMAT) )
182 return wxALIGN_NOT;
183
184 if ( hdi.fmt & HDF_CENTER )
185 return wxALIGN_CENTER;
186
187 if ( hdi.fmt & HDF_RIGHT )
188 return wxALIGN_RIGHT;
189
190 // HDF_LEFT == 0 so it doesn't make sense to test for it with bit and
191 return wxALIGN_LEFT;
192 }
193
194 void wxHeaderColumn::SetClientData(wxUIntPtr data)
195 {
196 HDITEM& hdi = m_impl->hdi;
197
198 hdi.mask |= HDI_LPARAM;
199 hdi.lParam = data;
200 }
201
202 wxUIntPtr wxHeaderColumn::GetClientData() const
203 {
204 HDITEM& hdi = m_impl->hdi;
205
206 wxASSERT_MSG( hdi.mask & HDI_LPARAM, "client data not set" );
207
208 return hdi.lParam;
209 }
210
211 // ----------------------------------------------------------------------------
212 // wxHeaderColumn trivial accessors for fields stored internally
213 // ----------------------------------------------------------------------------
214
215 void wxHeaderColumn::SetBitmap(const wxBitmap& bitmap)
216 {
217 m_impl->bmp = bitmap;
218 }
219
220 wxBitmap wxHeaderColumn::GetBitmap() const
221 {
222 return m_impl->bmp;
223 }
224
225 void wxHeaderColumn::SetMinWidth(int minWidth)
226 {
227 m_impl->minWidth = minWidth;
228 }
229
230 int wxHeaderColumn::GetMinWidth() const
231 {
232 return m_impl->minWidth;
233 }
234
235 void wxHeaderColumn::SetFlags(int flags)
236 {
237 m_impl->flags = flags;
238 }
239
240 int wxHeaderColumn::GetFlags() const
241 {
242 return m_impl->flags;
243 }
244
245 void wxHeaderColumn::SetSortOrder(bool ascending)
246 {
247 m_impl->ascending = ascending;
248 }
249
250 bool wxHeaderColumn::IsSortOrderAscending() const
251 {
252 return m_impl->ascending;
253 }
254
255