]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/headerctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/headerctrl.cpp
3 // Purpose: implementation of wxHeaderCtrl 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"
30 #include "wx/headerctrl.h"
31 #include "wx/imaglist.h"
33 #include "wx/msw/wrapcctl.h"
34 #include "wx/msw/private.h"
36 // ============================================================================
37 // wxHeaderCtrl implementation
38 // ============================================================================
40 // ----------------------------------------------------------------------------
41 // wxHeaderCtrl construction/destruction
42 // ----------------------------------------------------------------------------
44 void wxHeaderCtrl::Init()
49 bool wxHeaderCtrl::Create(wxWindow
*parent
,
56 // notice that we don't need InitCommonControlsEx(ICC_LISTVIEW_CLASSES)
57 // here as we already call InitCommonControls() in wxApp initialization
58 // code which covers this
60 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
63 if ( !MSWCreateControl(WC_HEADER
, _T(""), pos
, size
) )
69 WXDWORD
wxHeaderCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
71 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
73 if ( style
& wxHD_DRAGDROP
)
74 msStyle
|= HDS_DRAGDROP
;
76 // the control looks nicer with these styles and there doesn't seem to be
77 // any reason to not use them so we always do (as for HDS_HORZ it is 0
78 // anyhow but include it for clarity)
79 msStyle
|= HDS_HORZ
| HDS_BUTTONS
| HDS_FLAT
| HDS_FULLDRAG
| HDS_HOTTRACK
;
84 wxHeaderCtrl::~wxHeaderCtrl()
89 // ----------------------------------------------------------------------------
90 // wxHeaderCtrl geometry calculation
91 // ----------------------------------------------------------------------------
93 wxSize
wxHeaderCtrl::DoGetBestSize() const
95 RECT rc
= wxGetClientRect(GetHwndOf(GetParent()));
97 HDLAYOUT layout
= { &rc
, &wpos
};
98 if ( !Header_Layout(GetHwnd(), &layout
) )
100 wxLogLastError(_T("Header_Layout"));
101 return wxControl::DoGetBestSize();
104 return wxSize(wpos
.cx
, wpos
.cy
);
107 // ----------------------------------------------------------------------------
108 // wxHeaderCtrl columns managements
109 // ----------------------------------------------------------------------------
111 unsigned int wxHeaderCtrl::DoGetCount() const
113 return Header_GetItemCount(GetHwnd());
116 void wxHeaderCtrl::DoInsert(const wxHeaderColumn
& col
, unsigned int idx
)
118 // copy the HDITEM because we may modify it below
119 HDITEM hdi
= col
.GetHDI();
121 const wxBitmap bmp
= col
.GetBitmap();
124 const int bmpWidth
= bmp
.GetWidth(),
125 bmpHeight
= bmp
.GetHeight();
129 m_imageList
= new wxImageList(bmpWidth
, bmpHeight
);
130 Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList
));
132 else // already have an image list
134 // check that all bitmaps we use have the same size
137 m_imageList
->GetSize(0, imageWidth
, imageHeight
);
139 wxASSERT_MSG( imageWidth
== bmpWidth
&& imageHeight
== bmpHeight
,
140 "all column bitmaps must have the same size" );
143 m_imageList
->Add(bmp
);
144 hdi
.mask
|= HDI_IMAGE
;
145 hdi
.iImage
= m_imageList
->GetImageCount() - 1;
148 if ( Header_InsertItem(GetHwnd(), idx
, &hdi
) == -1 )
150 wxLogLastError(_T("Header_InsertItem"));
154 void wxHeaderCtrl::DoDelete(unsigned int idx
)
156 if ( !Header_DeleteItem(GetHwnd(), idx
) )
158 wxLogLastError(_T("Header_DeleteItem"));
162 // ----------------------------------------------------------------------------
163 // wxHeaderCtrl columns attributes
164 // ----------------------------------------------------------------------------
166 void wxHeaderCtrl::DoShowSortIndicator(unsigned int idx
, int sortOrder
)
169 hdi
.mask
= HDI_FORMAT
;
171 if ( !Header_GetItem(GetHwnd(), idx
, &hdi
) )
173 wxLogLastError(_T("Header_GetItem"));
177 if ( sortOrder
== -1 )
178 hdi
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
180 hdi
.fmt
|= sortOrder
? HDF_SORTUP
: HDF_SORTDOWN
;
182 if ( !Header_SetItem(GetHwnd(), idx
, &hdi
) )
184 wxLogLastError(_T("Header_SetItem"));