]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/headerctrl.cpp
426c374e1e79b2b59f185fa9cfd3395b6a534a91
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"
29 #include "wx/headerctrl.h"
30 #include "wx/imaglist.h"
32 #include "wx/msw/wrapcctl.h"
34 // ============================================================================
35 // wxHeaderCtrl implementation
36 // ============================================================================
38 // ----------------------------------------------------------------------------
39 // wxHeaderCtrl construction/destruction
40 // ----------------------------------------------------------------------------
42 void wxHeaderCtrl::Init()
47 bool wxHeaderCtrl::Create(wxWindow
*parent
,
54 // notice that we don't need InitCommonControlsEx(ICC_LISTVIEW_CLASSES)
55 // here as we already call InitCommonControls() in wxApp initialization
56 // code which covers this
58 if ( !CreateControl(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
61 if ( !MSWCreateControl(WC_HEADER
, _T(""), pos
, size
) )
67 WXDWORD
wxHeaderCtrl::MSWGetStyle(long style
, WXDWORD
*exstyle
) const
69 WXDWORD msStyle
= wxControl::MSWGetStyle(style
, exstyle
);
71 if ( style
& wxHD_DRAGDROP
)
72 msStyle
|= HDS_DRAGDROP
;
74 // the control looks nicer with these styles and there doesn't seem to be
75 // any reason to not use them so we always do (as for HDS_HORZ it is 0
76 // anyhow but include it for clarity)
77 msStyle
|= HDS_HORZ
| HDS_BUTTONS
| HDS_FLAT
| HDS_FULLDRAG
| HDS_HOTTRACK
;
82 wxHeaderCtrl::~wxHeaderCtrl()
87 // ----------------------------------------------------------------------------
88 // wxHeaderCtrl geometry calculation
89 // ----------------------------------------------------------------------------
91 wxSize
wxHeaderCtrl::DoGetBestSize() const
93 RECT rc
= wxGetClientRect(GetHwndOf(GetParent()));
95 HDLAYOUT layout
= { &rc
, &wpos
};
96 if ( !Header_Layout(GetHwnd(), &layout
) )
98 wxLogLastError(_T("Header_Layout"));
99 return wxControl::DoGetBestSize();
102 return wxSize(wpos
.cx
, wpos
.cy
);
105 // ----------------------------------------------------------------------------
106 // wxHeaderCtrl columns managements
107 // ----------------------------------------------------------------------------
109 unsigned int wxHeaderCtrl::DoGetCount() const
111 return Header_GetItemCount(GetHwnd());
114 void wxHeaderCtrl::DoInsert(const wxHeaderColumn
& col
, unsigned int idx
)
116 // copy the HDITEM because we may modify it below
117 HDITEM hdi
= col
.GetHDI();
119 const wxBitmap bmp
= col
.GetBitmap();
122 const int bmpWidth
= bmp
.GetWidth(),
123 bmpHeight
= bmp
.GetHeight();
127 m_imageList
= new wxImageList(bmpWidth
, bmpHeight
);
128 Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList
));
130 else // already have an image list
132 // check that all bitmaps we use have the same size
135 m_imageList
->GetSize(0, imageWidth
, imageHeight
);
137 wxASSERT_MSG( imageWidth
== bmpWidth
&& imageHeight
== bmpHeight
,
138 "all column bitmaps must have the same size" );
141 m_imageList
->Add(bmp
);
142 hdi
.mask
|= HDI_IMAGE
;
143 hdi
.iImage
= m_imageList
->GetImageCount() - 1;
146 if ( Header_InsertItem(GetHwnd(), idx
, &hdi
) == -1 )
148 wxLogLastError(_T("Header_InsertItem"));
152 void wxHeaderCtrl::DoDelete(unsigned int idx
)
154 if ( !Header_DeleteItem(GetHwnd(), idx
) )
156 wxLogLastError(_T("Header_DeleteItem"));
160 // ----------------------------------------------------------------------------
161 // wxHeaderCtrl columns attributes
162 // ----------------------------------------------------------------------------
164 void wxHeaderCtrl::DoShowSortIndicator(unsigned int idx
, int sortOrder
)
167 hdi
.mask
= HDI_FORMAT
;
169 if ( !Header_GetItem(GetHwnd(), idx
, &hdi
) )
171 wxLogLastError(_T("Header_GetItem"));
175 if ( sortOrder
== -1 )
176 hdi
.fmt
&= ~(HDF_SORTDOWN
| HDF_SORTUP
);
178 hdi
.fmt
|= sortOrder
? HDF_SORTUP
: HDF_SORTDOWN
;
180 if ( !Header_SetItem(GetHwnd(), idx
, &hdi
) )
182 wxLogLastError(_T("Header_SetItem"));