1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/headercol.cpp
3 // Purpose: wxHeaderColumn implementation for wxMSW
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/headercol.h"
31 #include "wx/msw/wrapcctl.h"
33 // ----------------------------------------------------------------------------
34 // wxMSWHeaderColumnImpl
35 // ----------------------------------------------------------------------------
37 struct wxMSWHeaderColumnImpl
39 wxMSWHeaderColumnImpl()
41 flags
= wxCOL_DEFAULT_FLAGS
;
47 wxWxCharBuffer bufTitle
;
49 int flags
; // combination of wxCOL_XXX constants
50 int minWidth
; // 0 if not set
51 bool ascending
; // sort order
53 DECLARE_NO_COPY_CLASS(wxMSWHeaderColumnImpl
)
56 // ============================================================================
57 // wxHeaderColumn implementation
58 // ============================================================================
60 // ----------------------------------------------------------------------------
61 // wxHeaderColumn construction/destruction
62 // ----------------------------------------------------------------------------
64 void wxHeaderColumn::Init()
66 m_impl
= new wxMSWHeaderColumnImpl
;
69 wxHeaderColumn::wxHeaderColumn(const wxString
& title
,
82 wxHeaderColumn::wxHeaderColumn(const wxBitmap
& bitmap
,
95 wxHeaderColumn::~wxHeaderColumn()
100 // ----------------------------------------------------------------------------
101 // wxHeaderColumn accessors corresponding to HDITEM fields
102 // ----------------------------------------------------------------------------
104 wxHDITEM
& wxHeaderColumn::GetHDI()
109 void wxHeaderColumn::SetTitle(const wxString
& title
)
111 HDITEM
& hdi
= m_impl
->hdi
;
113 hdi
.mask
|= HDI_TEXT
;
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
);
122 wxString
wxHeaderColumn::GetTitle() const
124 HDITEM
& hdi
= m_impl
->hdi
;
126 wxASSERT_MSG( hdi
.mask
& HDI_TEXT
, "title not set" );
131 void wxHeaderColumn::SetWidth(int width
)
133 HDITEM
& hdi
= m_impl
->hdi
;
135 if ( width
!= wxCOL_WIDTH_DEFAULT
)
137 hdi
.mask
|= HDI_WIDTH
;
142 int wxHeaderColumn::GetWidth() const
144 HDITEM
& hdi
= m_impl
->hdi
;
146 return hdi
.mask
& HDI_WIDTH
? hdi
.cxy
: wxCOL_WIDTH_DEFAULT
;
149 void wxHeaderColumn::SetAlignment(wxAlignment align
)
151 HDITEM
& hdi
= m_impl
->hdi
;
153 if ( align
!= wxALIGN_NOT
)
155 hdi
.mask
|= HDI_FORMAT
;
163 case wxALIGN_CENTER_HORIZONTAL
:
164 hdi
.fmt
|= HDF_CENTER
;
168 hdi
.fmt
|= HDF_RIGHT
;
172 wxFAIL_MSG( "invalid column header alignment" );
177 wxAlignment
wxHeaderColumn::GetAlignment() const
179 HDITEM
& hdi
= m_impl
->hdi
;
181 if ( !(hdi
.mask
& HDI_FORMAT
) )
184 if ( hdi
.fmt
& HDF_CENTER
)
185 return wxALIGN_CENTER
;
187 if ( hdi
.fmt
& HDF_RIGHT
)
188 return wxALIGN_RIGHT
;
190 // HDF_LEFT == 0 so it doesn't make sense to test for it with bit and
194 void wxHeaderColumn::SetClientData(wxUIntPtr data
)
196 HDITEM
& hdi
= m_impl
->hdi
;
198 hdi
.mask
|= HDI_LPARAM
;
202 wxUIntPtr
wxHeaderColumn::GetClientData() const
204 HDITEM
& hdi
= m_impl
->hdi
;
206 wxASSERT_MSG( hdi
.mask
& HDI_LPARAM
, "client data not set" );
211 // ----------------------------------------------------------------------------
212 // wxHeaderColumn trivial accessors for fields stored internally
213 // ----------------------------------------------------------------------------
215 void wxHeaderColumn::SetBitmap(const wxBitmap
& bitmap
)
217 m_impl
->bmp
= bitmap
;
220 wxBitmap
wxHeaderColumn::GetBitmap() const
225 void wxHeaderColumn::SetMinWidth(int minWidth
)
227 m_impl
->minWidth
= minWidth
;
230 int wxHeaderColumn::GetMinWidth() const
232 return m_impl
->minWidth
;
235 void wxHeaderColumn::SetFlags(int flags
)
237 m_impl
->flags
= flags
;
240 int wxHeaderColumn::GetFlags() const
242 return m_impl
->flags
;
245 void wxHeaderColumn::SetSortOrder(bool ascending
)
247 m_impl
->ascending
= ascending
;
250 bool wxHeaderColumn::IsSortOrderAscending() const
252 return m_impl
->ascending
;