]> git.saurik.com Git - wxWidgets.git/blob - src/msw/headerctrl.cpp
suppress (harmless) unused parameter warnings
[wxWidgets.git] / src / msw / headerctrl.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/headerctrl.cpp
3 // Purpose: implementation of wxHeaderCtrl for wxMSW
4 // Author: Vadim Zeitlin
5 // Created: 2008-12-01
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 #include "wx/log.h"
28 #endif // WX_PRECOMP
29
30 #include "wx/headerctrl.h"
31 #include "wx/imaglist.h"
32
33 #include "wx/msw/wrapcctl.h"
34 #include "wx/msw/private.h"
35
36 // ============================================================================
37 // wxHeaderCtrl implementation
38 // ============================================================================
39
40 // ----------------------------------------------------------------------------
41 // wxHeaderCtrl construction/destruction
42 // ----------------------------------------------------------------------------
43
44 void wxHeaderCtrl::Init()
45 {
46 m_imageList = NULL;
47 }
48
49 bool wxHeaderCtrl::Create(wxWindow *parent,
50 wxWindowID id,
51 const wxPoint& pos,
52 const wxSize& size,
53 long style,
54 const wxString& name)
55 {
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
59
60 if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
61 return false;
62
63 if ( !MSWCreateControl(WC_HEADER, _T(""), pos, size) )
64 return false;
65
66 return true;
67 }
68
69 WXDWORD wxHeaderCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const
70 {
71 WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
72
73 if ( style & wxHD_DRAGDROP )
74 msStyle |= HDS_DRAGDROP;
75
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;
80
81 return msStyle;
82 }
83
84 wxHeaderCtrl::~wxHeaderCtrl()
85 {
86 delete m_imageList;
87 }
88
89 // ----------------------------------------------------------------------------
90 // wxHeaderCtrl scrolling
91 // ----------------------------------------------------------------------------
92
93 void wxHeaderCtrl::DoScrollHorz(int dx)
94 {
95 // as the native control doesn't support offsetting its contents, we use a
96 // hack here to make it appear correctly when the parent is scrolled:
97 // instead of scrolling or repainting we simply move the control window
98 // itself: to be precise, offset it by the scroll increment to the left and
99 // increment its width to still extend to the right boundary to compensate
100 // for it (notice that dx is negative when scrolling to the right)
101 SetSize(GetPosition().x + dx, -1, GetSize().x - dx, -1, wxSIZE_USE_EXISTING);
102 }
103
104 // ----------------------------------------------------------------------------
105 // wxHeaderCtrl geometry calculation
106 // ----------------------------------------------------------------------------
107
108 wxSize wxHeaderCtrl::DoGetBestSize() const
109 {
110 RECT rc = wxGetClientRect(GetHwndOf(GetParent()));
111 WINDOWPOS wpos;
112 HDLAYOUT layout = { &rc, &wpos };
113 if ( !Header_Layout(GetHwnd(), &layout) )
114 {
115 wxLogLastError(_T("Header_Layout"));
116 return wxControl::DoGetBestSize();
117 }
118
119 return wxSize(wpos.cx, wpos.cy);
120 }
121
122 // ----------------------------------------------------------------------------
123 // wxHeaderCtrl columns managements
124 // ----------------------------------------------------------------------------
125
126 unsigned int wxHeaderCtrl::DoGetCount() const
127 {
128 return Header_GetItemCount(GetHwnd());
129 }
130
131 void wxHeaderCtrl::DoInsert(const wxHeaderColumn& col, unsigned int idx)
132 {
133 // copy the HDITEM because we may modify it below
134 HDITEM hdi = col.GetHDI();
135
136 const wxBitmap bmp = col.GetBitmap();
137 if ( bmp.IsOk() )
138 {
139 const int bmpWidth = bmp.GetWidth(),
140 bmpHeight = bmp.GetHeight();
141
142 if ( !m_imageList )
143 {
144 m_imageList = new wxImageList(bmpWidth, bmpHeight);
145 Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList));
146 }
147 else // already have an image list
148 {
149 // check that all bitmaps we use have the same size
150 int imageWidth,
151 imageHeight;
152 m_imageList->GetSize(0, imageWidth, imageHeight);
153
154 wxASSERT_MSG( imageWidth == bmpWidth && imageHeight == bmpHeight,
155 "all column bitmaps must have the same size" );
156 }
157
158 m_imageList->Add(bmp);
159 hdi.mask |= HDI_IMAGE;
160 hdi.iImage = m_imageList->GetImageCount() - 1;
161 }
162
163 if ( col.IsHidden() )
164 {
165 hdi.mask |= HDI_WIDTH;
166 hdi.cxy = 0;
167 }
168
169 if ( Header_InsertItem(GetHwnd(), idx, &hdi) == -1 )
170 {
171 wxLogLastError(_T("Header_InsertItem"));
172 }
173 }
174
175 void wxHeaderCtrl::DoDelete(unsigned int idx)
176 {
177 if ( !Header_DeleteItem(GetHwnd(), idx) )
178 {
179 wxLogLastError(_T("Header_DeleteItem"));
180 }
181 }
182
183 // ----------------------------------------------------------------------------
184 // wxHeaderCtrl columns attributes
185 // ----------------------------------------------------------------------------
186
187 void wxHeaderCtrl::DoShowColumn(unsigned int idx, bool show)
188 {
189 wxHDITEM hdi;
190 hdi.mask = HDI_WIDTH;
191
192 if ( !Header_GetItem(GetHwnd(), idx, &hdi) )
193 {
194 wxLogLastError(_T("Header_GetItem(HDI_WIDTH)"));
195 return;
196 }
197
198 if ( show )
199 hdi.cxy = 80; // FIXME: we don't have the column width here any more
200 else
201 hdi.cxy = 0;
202
203 if ( !Header_SetItem(GetHwnd(), idx, &hdi) )
204 {
205 wxLogLastError(_T("Header_SetItem(HDI_WIDTH)"));
206 return;
207 }
208 }
209
210 void wxHeaderCtrl::DoShowSortIndicator(unsigned int idx, int sortOrder)
211 {
212 wxHDITEM hdi;
213 hdi.mask = HDI_FORMAT;
214
215 if ( !Header_GetItem(GetHwnd(), idx, &hdi) )
216 {
217 wxLogLastError(_T("Header_GetItem(HDI_FORMAT)"));
218 return;
219 }
220
221 if ( sortOrder == -1 )
222 hdi.fmt &= ~(HDF_SORTDOWN | HDF_SORTUP);
223 else
224 hdi.fmt |= sortOrder ? HDF_SORTUP : HDF_SORTDOWN;
225
226 if ( !Header_SetItem(GetHwnd(), idx, &hdi) )
227 {
228 wxLogLastError(_T("Header_SetItem(HDI_FORMAT)"));
229 }
230 }
231