+
+
+ // column reordering events
+ // ------------------------
+
+ case HDN_BEGINDRAG:
+ // Windows sometimes sends us events with invalid column indices
+ if ( nmhdr->iItem == -1 )
+ break;
+
+ // column must have the appropriate flag to be draggable
+ if ( !GetColumn(idx).IsReorderable() )
+ {
+ veto = true;
+ break;
+ }
+
+ evtType = wxEVT_COMMAND_HEADER_BEGIN_REORDER;
+ break;
+
+ case HDN_ENDDRAG:
+ wxASSERT_MSG( nmhdr->pitem->mask & HDI_ORDER, "should have order" );
+ order = nmhdr->pitem->iOrder;
+
+ // we also get messages with invalid order when column reordering
+ // is cancelled (e.g. by pressing Esc)
+ if ( order == -1 )
+ break;
+
+ order = MSWFromNativeOrder(order);
+
+ evtType = wxEVT_COMMAND_HEADER_END_REORDER;
+ break;
+
+ case NM_RELEASEDCAPTURE:
+ evtType = wxEVT_COMMAND_HEADER_DRAGGING_CANCELLED;
+ break;
+ }
+
+
+ // do generate the corresponding wx event
+ if ( evtType != wxEVT_NULL )
+ {
+ wxHeaderCtrlEvent event(evtType, GetId());
+ event.SetEventObject(this);
+ event.SetColumn(idx);
+ event.SetWidth(width);
+ if ( order != -1 )
+ event.SetNewOrder(order);
+
+ if ( GetEventHandler()->ProcessEvent(event) )
+ {
+ if ( event.IsAllowed() )
+ return true; // skip default message handling below
+
+ // we need to veto the default handling of this message, don't
+ // return to execute the code in the "if veto" branch below
+ veto = true;
+ }
+ else // not processed
+ {
+ // special post-processing for HDN_ENDDRAG: we need to update the
+ // internal column indices array if this is allowed to go ahead as
+ // the native control is going to reorder its columns now
+ if ( evtType == wxEVT_COMMAND_HEADER_END_REORDER )
+ MoveColumnInOrderArray(m_colIndices, idx, order);
+ }
+ }
+
+ if ( veto )
+ {
+ // all of HDN_BEGIN{DRAG,TRACK}, HDN_TRACK and HDN_ITEMCHANGING
+ // interpret TRUE return value as meaning to stop the control
+ // default handling of the message
+ *result = TRUE;
+
+ return true;