]>
Commit | Line | Data |
---|---|---|
56873923 VZ |
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 | |
9ef3e400 | 27 | #include "wx/log.h" |
56873923 VZ |
28 | #endif // WX_PRECOMP |
29 | ||
30 | #include "wx/headerctrl.h" | |
3bfaa5a7 VZ |
31 | |
32 | #ifndef wxHAS_GENERIC_HEADERCTRL | |
33 | ||
56873923 VZ |
34 | #include "wx/imaglist.h" |
35 | ||
36 | #include "wx/msw/wrapcctl.h" | |
9ef3e400 | 37 | #include "wx/msw/private.h" |
56873923 | 38 | |
fa3d4aaf VZ |
39 | // from src/msw/listctrl.cpp |
40 | extern int WXDLLIMPEXP_CORE wxMSWGetColumnClicked(NMHDR *nmhdr, POINT *ptClick); | |
41 | ||
56873923 VZ |
42 | // ============================================================================ |
43 | // wxHeaderCtrl implementation | |
44 | // ============================================================================ | |
45 | ||
46 | // ---------------------------------------------------------------------------- | |
47 | // wxHeaderCtrl construction/destruction | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | void wxHeaderCtrl::Init() | |
51 | { | |
040b9528 | 52 | m_numColumns = 0; |
56873923 | 53 | m_imageList = NULL; |
38cd07c4 | 54 | m_scrollOffset = 0; |
56873923 VZ |
55 | } |
56 | ||
57 | bool wxHeaderCtrl::Create(wxWindow *parent, | |
58 | wxWindowID id, | |
59 | const wxPoint& pos, | |
60 | const wxSize& size, | |
61 | long style, | |
62 | const wxString& name) | |
63 | { | |
64 | // notice that we don't need InitCommonControlsEx(ICC_LISTVIEW_CLASSES) | |
65 | // here as we already call InitCommonControls() in wxApp initialization | |
66 | // code which covers this | |
67 | ||
68 | if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) ) | |
69 | return false; | |
70 | ||
71 | if ( !MSWCreateControl(WC_HEADER, _T(""), pos, size) ) | |
72 | return false; | |
73 | ||
74 | return true; | |
75 | } | |
76 | ||
77 | WXDWORD wxHeaderCtrl::MSWGetStyle(long style, WXDWORD *exstyle) const | |
78 | { | |
79 | WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle); | |
80 | ||
613de0e8 | 81 | if ( style & wxHD_ALLOW_REORDER ) |
56873923 VZ |
82 | msStyle |= HDS_DRAGDROP; |
83 | ||
84 | // the control looks nicer with these styles and there doesn't seem to be | |
85 | // any reason to not use them so we always do (as for HDS_HORZ it is 0 | |
86 | // anyhow but include it for clarity) | |
87 | msStyle |= HDS_HORZ | HDS_BUTTONS | HDS_FLAT | HDS_FULLDRAG | HDS_HOTTRACK; | |
88 | ||
89 | return msStyle; | |
90 | } | |
91 | ||
92 | wxHeaderCtrl::~wxHeaderCtrl() | |
93 | { | |
94 | delete m_imageList; | |
95 | } | |
96 | ||
f24f6579 VZ |
97 | // ---------------------------------------------------------------------------- |
98 | // wxHeaderCtrl scrolling | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
38cd07c4 VZ |
101 | void wxHeaderCtrl::DoSetSize(int x, int y, |
102 | int w, int h, | |
103 | int sizeFlags) | |
104 | { | |
105 | wxHeaderCtrlBase::DoSetSize(x + m_scrollOffset, y, w - m_scrollOffset, h, | |
106 | sizeFlags); | |
107 | } | |
108 | ||
d8fc3398 | 109 | void wxHeaderCtrl::DoScrollHorz(int dx) |
f24f6579 | 110 | { |
d8fc3398 VZ |
111 | // as the native control doesn't support offsetting its contents, we use a |
112 | // hack here to make it appear correctly when the parent is scrolled: | |
113 | // instead of scrolling or repainting we simply move the control window | |
114 | // itself: to be precise, offset it by the scroll increment to the left and | |
115 | // increment its width to still extend to the right boundary to compensate | |
116 | // for it (notice that dx is negative when scrolling to the right) | |
38cd07c4 VZ |
117 | m_scrollOffset += dx; |
118 | ||
119 | wxHeaderCtrlBase::DoSetSize(GetPosition().x + dx, -1, | |
120 | GetSize().x - dx, -1, | |
121 | wxSIZE_USE_EXISTING); | |
f24f6579 VZ |
122 | } |
123 | ||
56873923 VZ |
124 | // ---------------------------------------------------------------------------- |
125 | // wxHeaderCtrl geometry calculation | |
126 | // ---------------------------------------------------------------------------- | |
127 | ||
128 | wxSize wxHeaderCtrl::DoGetBestSize() const | |
129 | { | |
130 | RECT rc = wxGetClientRect(GetHwndOf(GetParent())); | |
131 | WINDOWPOS wpos; | |
132 | HDLAYOUT layout = { &rc, &wpos }; | |
133 | if ( !Header_Layout(GetHwnd(), &layout) ) | |
134 | { | |
135 | wxLogLastError(_T("Header_Layout")); | |
136 | return wxControl::DoGetBestSize(); | |
137 | } | |
138 | ||
139 | return wxSize(wpos.cx, wpos.cy); | |
140 | } | |
141 | ||
142 | // ---------------------------------------------------------------------------- | |
143 | // wxHeaderCtrl columns managements | |
144 | // ---------------------------------------------------------------------------- | |
145 | ||
146 | unsigned int wxHeaderCtrl::DoGetCount() const | |
147 | { | |
040b9528 VZ |
148 | // we can't use Header_GetItemCount() here because it doesn't take the |
149 | // hidden columns into account and we can't find the hidden columns after | |
150 | // the last shown one in MSWFromNativeIdx() without knowing where to stop | |
151 | // so we have to store the columns count internally | |
152 | return m_numColumns; | |
153 | } | |
154 | ||
155 | int wxHeaderCtrl::GetShownColumnsCount() const | |
156 | { | |
157 | const int numItems = Header_GetItemCount(GetHwnd()); | |
158 | ||
159 | wxASSERT_MSG( numItems >= 0 && (unsigned)numItems <= m_numColumns, | |
160 | "unexpected number of items in the native control" ); | |
161 | ||
162 | return numItems; | |
56873923 VZ |
163 | } |
164 | ||
e2bfe673 | 165 | void wxHeaderCtrl::DoSetCount(unsigned int count) |
56873923 | 166 | { |
e2bfe673 VZ |
167 | unsigned n; |
168 | ||
169 | // first delete all old columns | |
040b9528 | 170 | const unsigned countOld = GetShownColumnsCount(); |
e2bfe673 VZ |
171 | for ( n = 0; n < countOld; n++ ) |
172 | { | |
173 | if ( !Header_DeleteItem(GetHwnd(), 0) ) | |
174 | { | |
175 | wxLogLastError(_T("Header_DeleteItem")); | |
176 | } | |
177 | } | |
178 | ||
040b9528 VZ |
179 | // update the column indices order array before changing m_numColumns |
180 | DoResizeColumnIndices(m_colIndices, count); | |
181 | ||
e2bfe673 | 182 | // and add the new ones |
040b9528 VZ |
183 | m_numColumns = count; |
184 | m_isHidden.resize(m_numColumns); | |
e2bfe673 VZ |
185 | for ( n = 0; n < count; n++ ) |
186 | { | |
040b9528 VZ |
187 | const wxHeaderColumn& col = GetColumn(n); |
188 | if ( col.IsShown() ) | |
189 | { | |
190 | m_isHidden[n] = false; | |
191 | ||
192 | DoInsertItem(col, n); | |
193 | } | |
194 | else // hidden initially | |
195 | { | |
196 | m_isHidden[n] = true; | |
197 | } | |
e2bfe673 VZ |
198 | } |
199 | } | |
200 | ||
201 | void wxHeaderCtrl::DoUpdate(unsigned int idx) | |
202 | { | |
4de60a27 VZ |
203 | // the native control does provide Header_SetItem() but it's inconvenient |
204 | // to use it because it sends HDN_ITEMCHANGING messages and we'd have to | |
205 | // arrange not to block setting the width from there and the logic would be | |
206 | // more complicated as we'd have to reset the old values as well as setting | |
207 | // the new ones -- so instead just recreate the column | |
702f5349 | 208 | |
040b9528 VZ |
209 | const wxHeaderColumn& col = GetColumn(idx); |
210 | if ( col.IsHidden() ) | |
211 | { | |
212 | // column is hidden now | |
213 | if ( !m_isHidden[idx] ) | |
214 | { | |
215 | // but it wasn't hidden before, so remove it | |
216 | Header_DeleteItem(GetHwnd(), MSWToNativeIdx(idx)); | |
217 | ||
218 | m_isHidden[idx] = true; | |
219 | } | |
220 | //else: nothing to do, updating hidden column doesn't have any effect | |
221 | } | |
222 | else // column is shown now | |
223 | { | |
224 | if ( m_isHidden[idx] ) | |
225 | { | |
226 | m_isHidden[idx] = false; | |
227 | } | |
228 | else // and it was shown before as well | |
229 | { | |
230 | // we need to remove the old column | |
231 | Header_DeleteItem(GetHwnd(), MSWToNativeIdx(idx)); | |
232 | } | |
233 | ||
234 | DoInsertItem(col, idx); | |
235 | } | |
e2bfe673 VZ |
236 | } |
237 | ||
040b9528 | 238 | void wxHeaderCtrl::DoInsertItem(const wxHeaderColumn& col, unsigned int idx) |
e2bfe673 | 239 | { |
040b9528 | 240 | wxASSERT_MSG( !col.IsHidden(), "should only be called for shown columns" ); |
e2bfe673 VZ |
241 | |
242 | wxHDITEM hdi; | |
243 | ||
244 | // notice that we need to store the string we use the pointer to until we | |
245 | // pass it to the control | |
89c73d54 VZ |
246 | hdi.mask |= HDI_TEXT; |
247 | wxWxCharBuffer buf = col.GetTitle().wx_str(); | |
248 | hdi.pszText = buf.data(); | |
249 | hdi.cchTextMax = wxStrlen(buf); | |
56873923 VZ |
250 | |
251 | const wxBitmap bmp = col.GetBitmap(); | |
4de60a27 | 252 | if ( bmp.IsOk() ) |
56873923 | 253 | { |
89c73d54 | 254 | hdi.mask |= HDI_IMAGE; |
56873923 | 255 | |
89c73d54 | 256 | if ( bmp.IsOk() ) |
56873923 | 257 | { |
89c73d54 VZ |
258 | const int bmpWidth = bmp.GetWidth(), |
259 | bmpHeight = bmp.GetHeight(); | |
260 | ||
261 | if ( !m_imageList ) | |
262 | { | |
263 | m_imageList = new wxImageList(bmpWidth, bmpHeight); | |
264 | Header_SetImageList(GetHwnd(), GetHimagelistOf(m_imageList)); | |
265 | } | |
266 | else // already have an image list | |
267 | { | |
268 | // check that all bitmaps we use have the same size | |
269 | int imageWidth, | |
270 | imageHeight; | |
271 | m_imageList->GetSize(0, imageWidth, imageHeight); | |
272 | ||
273 | wxASSERT_MSG( imageWidth == bmpWidth && imageHeight == bmpHeight, | |
274 | "all column bitmaps must have the same size" ); | |
275 | } | |
276 | ||
277 | m_imageList->Add(bmp); | |
278 | hdi.iImage = m_imageList->GetImageCount() - 1; | |
56873923 | 279 | } |
89c73d54 | 280 | else // no bitmap but we still need to update the item |
56873923 | 281 | { |
89c73d54 | 282 | hdi.iImage = I_IMAGENONE; |
56873923 | 283 | } |
56873923 VZ |
284 | } |
285 | ||
4de60a27 | 286 | if ( col.GetAlignment() != wxALIGN_NOT ) |
a0009205 | 287 | { |
e2bfe673 VZ |
288 | hdi.mask |= HDI_FORMAT; |
289 | switch ( col.GetAlignment() ) | |
290 | { | |
291 | case wxALIGN_LEFT: | |
292 | hdi.fmt |= HDF_LEFT; | |
293 | break; | |
56873923 | 294 | |
e2bfe673 VZ |
295 | case wxALIGN_CENTER: |
296 | case wxALIGN_CENTER_HORIZONTAL: | |
297 | hdi.fmt |= HDF_CENTER; | |
298 | break; | |
56873923 | 299 | |
e2bfe673 VZ |
300 | case wxALIGN_RIGHT: |
301 | hdi.fmt |= HDF_RIGHT; | |
302 | break; | |
56873923 | 303 | |
e2bfe673 VZ |
304 | default: |
305 | wxFAIL_MSG( "invalid column header alignment" ); | |
306 | } | |
307 | } | |
a0009205 | 308 | |
e2bfe673 | 309 | if ( col.IsSortKey() ) |
a0009205 | 310 | { |
e2bfe673 VZ |
311 | hdi.mask |= HDI_FORMAT; |
312 | hdi.fmt |= col.IsSortOrderAscending() ? HDF_SORTUP : HDF_SORTDOWN; | |
a0009205 VZ |
313 | } |
314 | ||
040b9528 | 315 | if ( col.GetWidth() != wxCOL_WIDTH_DEFAULT ) |
a0009205 | 316 | { |
e2bfe673 | 317 | hdi.mask |= HDI_WIDTH; |
040b9528 | 318 | hdi.cxy = col.GetWidth(); |
a0009205 | 319 | } |
a0009205 | 320 | |
040b9528 | 321 | hdi.mask |= HDI_ORDER; |
2e733ec7 | 322 | hdi.iOrder = MSWToNativeOrder(m_colIndices.Index(idx)); |
702f5349 | 323 | |
040b9528 VZ |
324 | if ( ::SendMessage(GetHwnd(), HDM_INSERTITEM, |
325 | MSWToNativeIdx(idx), (LPARAM)&hdi) == -1 ) | |
56873923 | 326 | { |
4de60a27 | 327 | wxLogLastError(_T("Header_InsertItem()")); |
56873923 VZ |
328 | } |
329 | } | |
330 | ||
702f5349 VZ |
331 | void wxHeaderCtrl::DoSetColumnsOrder(const wxArrayInt& order) |
332 | { | |
040b9528 VZ |
333 | wxArrayInt orderShown; |
334 | orderShown.reserve(m_numColumns); | |
335 | ||
336 | for ( unsigned n = 0; n < m_numColumns; n++ ) | |
337 | { | |
338 | const int idx = order[n]; | |
339 | if ( GetColumn(idx).IsShown() ) | |
340 | orderShown.push_back(MSWToNativeIdx(idx)); | |
341 | } | |
342 | ||
343 | if ( !Header_SetOrderArray(GetHwnd(), orderShown.size(), &orderShown[0]) ) | |
702f5349 VZ |
344 | { |
345 | wxLogLastError(_T("Header_GetOrderArray")); | |
346 | } | |
040b9528 VZ |
347 | |
348 | m_colIndices = order; | |
702f5349 VZ |
349 | } |
350 | ||
351 | wxArrayInt wxHeaderCtrl::DoGetColumnsOrder() const | |
352 | { | |
040b9528 VZ |
353 | // we don't use Header_GetOrderArray() here because it doesn't return |
354 | // information about the hidden columns, instead we just save the columns | |
355 | // order array in DoSetColumnsOrder() and update it when they're reordered | |
356 | return m_colIndices; | |
357 | } | |
358 | ||
2e733ec7 VZ |
359 | // ---------------------------------------------------------------------------- |
360 | // wxHeaderCtrl indexes and positions translation | |
361 | // ---------------------------------------------------------------------------- | |
362 | ||
040b9528 VZ |
363 | int wxHeaderCtrl::MSWToNativeIdx(int idx) |
364 | { | |
365 | // don't check for GetColumn(idx).IsShown() as it could have just became | |
366 | // false and we may be called from DoUpdate() to delete the old column | |
367 | wxASSERT_MSG( !m_isHidden[idx], | |
368 | "column must be visible to have an " | |
369 | "index in the native control" ); | |
370 | ||
2e733ec7 | 371 | int item = idx; |
040b9528 | 372 | for ( int i = 0; i < idx; i++ ) |
702f5349 | 373 | { |
040b9528 | 374 | if ( GetColumn(i).IsHidden() ) |
2e733ec7 | 375 | item--; // one less column the native control knows about |
040b9528 VZ |
376 | } |
377 | ||
2e733ec7 VZ |
378 | wxASSERT_MSG( item >= 0 && item <= GetShownColumnsCount(), "logic error" ); |
379 | ||
380 | return item; | |
040b9528 VZ |
381 | } |
382 | ||
383 | int wxHeaderCtrl::MSWFromNativeIdx(int item) | |
384 | { | |
385 | wxASSERT_MSG( item >= 0 && item < GetShownColumnsCount(), | |
386 | "column index out of range" ); | |
387 | ||
388 | // reverse the above function | |
2e733ec7 VZ |
389 | |
390 | unsigned idx = item; | |
391 | for ( unsigned n = 0; n < m_numColumns; n++ ) | |
040b9528 | 392 | { |
2e733ec7 VZ |
393 | if ( n > idx ) |
394 | break; | |
395 | ||
396 | if ( GetColumn(n).IsHidden() ) | |
397 | idx++; | |
040b9528 VZ |
398 | } |
399 | ||
2e733ec7 VZ |
400 | wxASSERT_MSG( MSWToNativeIdx(idx) == item, "logic error" ); |
401 | ||
402 | return idx; | |
040b9528 VZ |
403 | } |
404 | ||
2e733ec7 | 405 | int wxHeaderCtrl::MSWToNativeOrder(int pos) |
040b9528 | 406 | { |
2e733ec7 | 407 | wxASSERT_MSG( pos >= 0 && static_cast<unsigned>(pos) < m_numColumns, |
040b9528 VZ |
408 | "column position out of range" ); |
409 | ||
2e733ec7 VZ |
410 | int order = pos; |
411 | for ( int n = 0; n < pos; n++ ) | |
040b9528 | 412 | { |
2e733ec7 VZ |
413 | if ( GetColumn(m_colIndices[n]).IsHidden() ) |
414 | order--; | |
702f5349 VZ |
415 | } |
416 | ||
2e733ec7 VZ |
417 | wxASSERT_MSG( order >= 0 && order <= GetShownColumnsCount(), "logic error" ); |
418 | ||
702f5349 VZ |
419 | return order; |
420 | } | |
421 | ||
2e733ec7 VZ |
422 | int wxHeaderCtrl::MSWFromNativeOrder(int order) |
423 | { | |
424 | wxASSERT_MSG( order >= 0 && order < GetShownColumnsCount(), | |
425 | "native column position out of range" ); | |
426 | ||
427 | unsigned pos = order; | |
428 | for ( unsigned n = 0; n < m_numColumns; n++ ) | |
429 | { | |
430 | if ( n > pos ) | |
431 | break; | |
432 | ||
433 | if ( GetColumn(m_colIndices[n]).IsHidden() ) | |
434 | pos++; | |
435 | } | |
436 | ||
437 | wxASSERT_MSG( MSWToNativeOrder(pos) == order, "logic error" ); | |
438 | ||
439 | return pos; | |
440 | } | |
441 | ||
fa3d4aaf VZ |
442 | // ---------------------------------------------------------------------------- |
443 | // wxHeaderCtrl events | |
444 | // ---------------------------------------------------------------------------- | |
445 | ||
aef252d9 | 446 | wxEventType wxHeaderCtrl::GetClickEventType(bool dblclk, int button) |
fa3d4aaf VZ |
447 | { |
448 | wxEventType evtType; | |
449 | switch ( button ) | |
450 | { | |
451 | case 0: | |
452 | evtType = dblclk ? wxEVT_COMMAND_HEADER_DCLICK | |
453 | : wxEVT_COMMAND_HEADER_CLICK; | |
454 | break; | |
455 | ||
456 | case 1: | |
457 | evtType = dblclk ? wxEVT_COMMAND_HEADER_RIGHT_DCLICK | |
458 | : wxEVT_COMMAND_HEADER_RIGHT_CLICK; | |
459 | break; | |
460 | ||
461 | case 2: | |
462 | evtType = dblclk ? wxEVT_COMMAND_HEADER_MIDDLE_DCLICK | |
463 | : wxEVT_COMMAND_HEADER_MIDDLE_CLICK; | |
464 | break; | |
465 | ||
466 | default: | |
467 | wxFAIL_MSG( wxS("unexpected event type") ); | |
aef252d9 | 468 | evtType = wxEVT_NULL; |
fa3d4aaf VZ |
469 | } |
470 | ||
aef252d9 | 471 | return evtType; |
fa3d4aaf VZ |
472 | } |
473 | ||
474 | bool wxHeaderCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) | |
475 | { | |
476 | NMHEADER * const nmhdr = (NMHEADER *)lParam; | |
477 | ||
aef252d9 | 478 | wxEventType evtType = wxEVT_NULL; |
aef252d9 | 479 | int width = 0; |
702f5349 | 480 | int order = -1; |
702f5349 | 481 | bool veto = false; |
0c9c5b43 | 482 | const UINT code = nmhdr->hdr.code; |
040b9528 VZ |
483 | |
484 | // we don't have the index for all events, e.g. not for NM_RELEASEDCAPTURE | |
485 | // so only access for header control events (and yes, the direction of | |
486 | // comparisons with FIRST/LAST is correct even if it seems inverted) | |
487 | int idx = code <= HDN_FIRST && code > HDN_LAST ? nmhdr->iItem : -1; | |
488 | if ( idx != -1 ) | |
489 | { | |
490 | // we also get bogus HDN_BEGINDRAG with -1 index so don't call | |
491 | // MSWFromNativeIdx() unconditionally for nmhdr->iItem | |
492 | idx = MSWFromNativeIdx(idx); | |
493 | } | |
494 | ||
0c9c5b43 | 495 | switch ( code ) |
fa3d4aaf | 496 | { |
aef252d9 VZ |
497 | // click events |
498 | // ------------ | |
499 | ||
fa3d4aaf VZ |
500 | case HDN_ITEMCLICK: |
501 | case HDN_ITEMDBLCLICK: | |
aef252d9 | 502 | evtType = GetClickEventType(code == HDN_ITEMDBLCLICK, nmhdr->iButton); |
fa3d4aaf VZ |
503 | break; |
504 | ||
505 | // although we should get the notifications about the right clicks | |
506 | // via HDN_ITEM[DBL]CLICK too according to MSDN this simply doesn't | |
507 | // happen in practice on any Windows system up to 2003 | |
508 | case NM_RCLICK: | |
509 | case NM_RDBLCLK: | |
510 | { | |
511 | POINT pt; | |
aef252d9 VZ |
512 | idx = wxMSWGetColumnClicked(&nmhdr->hdr, &pt); |
513 | if ( idx != wxNOT_FOUND ) | |
040b9528 VZ |
514 | { |
515 | idx = MSWFromNativeIdx(idx); | |
aef252d9 | 516 | evtType = GetClickEventType(code == NM_RDBLCLK, 1); |
040b9528 | 517 | } |
fa3d4aaf VZ |
518 | //else: ignore clicks outside any column |
519 | } | |
520 | break; | |
3bfaa5a7 VZ |
521 | |
522 | case HDN_DIVIDERDBLCLICK: | |
aef252d9 VZ |
523 | evtType = wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; |
524 | break; | |
525 | ||
526 | ||
527 | // column resizing events | |
528 | // ---------------------- | |
529 | ||
530 | // see comments in wxListCtrl::MSWOnNotify() for why we catch both | |
531 | // ASCII and Unicode versions of this message | |
532 | case HDN_BEGINTRACKA: | |
533 | case HDN_BEGINTRACKW: | |
0b2e1483 VZ |
534 | // non-resizeable columns can't be resized no matter what, don't |
535 | // even generate any events for them | |
536 | if ( !GetColumn(idx).IsResizeable() ) | |
537 | { | |
702f5349 VZ |
538 | veto = true; |
539 | break; | |
0b2e1483 VZ |
540 | } |
541 | ||
396825dc | 542 | evtType = wxEVT_COMMAND_HEADER_BEGIN_RESIZE; |
aef252d9 VZ |
543 | // fall through |
544 | ||
aef252d9 VZ |
545 | case HDN_ENDTRACKA: |
546 | case HDN_ENDTRACKW: | |
a45caa71 VZ |
547 | width = nmhdr->pitem->cxy; |
548 | ||
aef252d9 | 549 | if ( evtType == wxEVT_NULL ) |
a45caa71 | 550 | { |
396825dc | 551 | evtType = wxEVT_COMMAND_HEADER_END_RESIZE; |
aef252d9 | 552 | |
a45caa71 VZ |
553 | // don't generate events with invalid width |
554 | const int minWidth = GetColumn(idx).GetMinWidth(); | |
555 | if ( width < minWidth ) | |
556 | width = minWidth; | |
557 | } | |
558 | break; | |
559 | ||
560 | case HDN_ITEMCHANGING: | |
561 | if ( nmhdr->pitem && (nmhdr->pitem->mask & HDI_WIDTH) ) | |
562 | { | |
563 | // prevent the column from being shrunk beneath its min width | |
93e4e62b VZ |
564 | width = nmhdr->pitem->cxy; |
565 | if ( width < GetColumn(idx).GetMinWidth() ) | |
566 | { | |
567 | // don't generate any events and prevent the change from | |
568 | // happening | |
702f5349 | 569 | veto = true; |
93e4e62b VZ |
570 | } |
571 | else // width is acceptable | |
572 | { | |
573 | // generate the resizing event from here as we don't seem | |
574 | // to be getting HDN_TRACK events at all, at least with | |
575 | // comctl32.dll v6 | |
576 | evtType = wxEVT_COMMAND_HEADER_RESIZING; | |
577 | } | |
702f5349 VZ |
578 | } |
579 | break; | |
580 | ||
581 | ||
582 | // column reordering events | |
583 | // ------------------------ | |
584 | ||
585 | case HDN_BEGINDRAG: | |
586 | // Windows sometimes sends us events with invalid column indices | |
040b9528 | 587 | if ( nmhdr->iItem == -1 ) |
702f5349 | 588 | break; |
a45caa71 | 589 | |
702f5349 VZ |
590 | // column must have the appropriate flag to be draggable |
591 | if ( !GetColumn(idx).IsReorderable() ) | |
592 | { | |
593 | veto = true; | |
594 | break; | |
a45caa71 | 595 | } |
702f5349 VZ |
596 | |
597 | evtType = wxEVT_COMMAND_HEADER_BEGIN_REORDER; | |
598 | break; | |
599 | ||
600 | case HDN_ENDDRAG: | |
702f5349 VZ |
601 | wxASSERT_MSG( nmhdr->pitem->mask & HDI_ORDER, "should have order" ); |
602 | order = nmhdr->pitem->iOrder; | |
040b9528 VZ |
603 | |
604 | // we also get messages with invalid order when column reordering | |
605 | // is cancelled (e.g. by pressing Esc) | |
606 | if ( order == -1 ) | |
607 | break; | |
608 | ||
609 | order = MSWFromNativeOrder(order); | |
610 | ||
611 | evtType = wxEVT_COMMAND_HEADER_END_REORDER; | |
a45caa71 VZ |
612 | break; |
613 | ||
614 | case NM_RELEASEDCAPTURE: | |
565804f2 | 615 | evtType = wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED; |
3bfaa5a7 | 616 | break; |
fa3d4aaf VZ |
617 | } |
618 | ||
aef252d9 VZ |
619 | |
620 | // do generate the corresponding wx event | |
621 | if ( evtType != wxEVT_NULL ) | |
622 | { | |
623 | wxHeaderCtrlEvent event(evtType, GetId()); | |
624 | event.SetEventObject(this); | |
625 | event.SetColumn(idx); | |
626 | event.SetWidth(width); | |
702f5349 VZ |
627 | if ( order != -1 ) |
628 | event.SetNewOrder(order); | |
aef252d9 VZ |
629 | |
630 | if ( GetEventHandler()->ProcessEvent(event) ) | |
631 | { | |
702f5349 | 632 | if ( event.IsAllowed() ) |
040b9528 | 633 | return true; // skip default message handling below |
aef252d9 | 634 | |
702f5349 VZ |
635 | // we need to veto the default handling of this message, don't |
636 | // return to execute the code in the "if veto" branch below | |
637 | veto = true; | |
aef252d9 | 638 | } |
040b9528 VZ |
639 | else // not processed |
640 | { | |
641 | // special post-processing for HDN_ENDDRAG: we need to update the | |
642 | // internal column indices array if this is allowed to go ahead as | |
643 | // the native control is going to reorder its columns now | |
644 | if ( evtType == wxEVT_COMMAND_HEADER_END_REORDER ) | |
645 | MoveColumnInOrderArray(m_colIndices, idx, order); | |
646 | } | |
aef252d9 VZ |
647 | } |
648 | ||
702f5349 VZ |
649 | if ( veto ) |
650 | { | |
651 | // all of HDN_BEGIN{DRAG,TRACK}, HDN_TRACK and HDN_ITEMCHANGING | |
652 | // interpret TRUE return value as meaning to stop the control | |
653 | // default handling of the message | |
654 | *result = TRUE; | |
655 | ||
656 | return true; | |
657 | } | |
658 | ||
fa3d4aaf VZ |
659 | return wxHeaderCtrlBase::MSWOnNotify(idCtrl, lParam, result); |
660 | } | |
3bfaa5a7 VZ |
661 | |
662 | #endif // wxHAS_GENERIC_HEADERCTRL |