private unsafe bool WmSelChanging(ref Message m) { if (!bEnableSelectEvents) { return(false); } Native.NMTREEVIEW *nmtv = (Native.NMTREEVIEW *)m.LParam; TreeNode node = TreeNode.FromHandle(this, nmtv->itemNew.hItem); OnBeforeMultiSelectStart(new CMSTreeViewMultiSelectEventArgs(SelectedNodes, TreeViewAction.Unknown)); bool bIsSelected = true; CMSTreeViewCancelEventArgs e = new CMSTreeViewCancelEventArgs(node, false, bIsSelected, TreeViewAction.Unknown); OnBeforeSelect(e); if (e.Cancel) { // user canceled operation, cancel changing of the selection m.Result = (IntPtr)1; return(true); } return(false); }
private unsafe bool WmNotify(ref Message m) { Native.NMHDR *nmhdr = (Native.NMHDR *)m.LParam; // Custom draw code is handled separately. // if (nmhdr->code == (int)Native.NotifyMsg.NM_CUSTOMDRAW) { return(false); } Native.NMTREEVIEW *nmtv = (Native.NMTREEVIEW *)m.LParam; switch (nmtv->nmhdr.code) { //case Native.TVN_DELETEITEMA: //case Native.TVN_DELETEITEMW: // return WmDeleteItem(ref m); case Native.TVM_SETITEMA: case Native.TVM_SETITEMW: break; case Native.TVN_ITEMEXPANDEDA: case Native.TVN_ITEMEXPANDEDW: break; case Native.TVN_ITEMEXPANDINGA: case Native.TVN_ITEMEXPANDINGW: return(WmExpanding(ref m)); case Native.TVN_SELCHANGINGA: case Native.TVN_SELCHANGINGW: return(WmSelChanging(ref m)); case Native.TVN_SELCHANGEDA: case Native.TVN_SELCHANGEDW: return(WmSelChanged(ref m)); } return(false); }
private unsafe bool WmSelChanged(ref Message m) { if (!bEnableSelectEvents) { return(false); } Native.NMTREEVIEW *nmtv = (Native.NMTREEVIEW *)m.LParam; TreeNode node = TreeNode.FromHandle(this, nmtv->itemNew.hItem); bool bIsSelected = true;//(nmtv->itemNew.state & Native.TVIS.SELECTED) != 0; TreeNode oldNode = TreeNode.FromHandle(this, nmtv->itemOld.hItem); AddSelectedItem(node); CMSTreeViewEventArgs e = new CMSTreeViewEventArgs(node, bIsSelected, TreeViewAction.Unknown); OnAfterSelect(e); OnAfterMultiSelectComplete(new CMSTreeViewMultiSelectEventArgs(SelectedNodes, TreeViewAction.Unknown)); return(false); }
private unsafe bool WmExpanding(ref Message m) { Native.NMTREEVIEW *nmtv = (Native.NMTREEVIEW *)m.LParam; bool bCollapse = nmtv->action == Native.TVE_COLLAPSE; if (bCollapse) { TreeNode node = TreeNode.FromHandle(this, nmtv->itemNew.hItem); if (node.GetNodeCount(false) == 0) { return(false); } TreeNode firstChild = node.FirstNode; TreeNode nextSibling = node.NextNode; TreeNode focusedNode = GetFocusedItem(); bool bCancel = false; // cancel event processing // change focus if necessary bool bChangeSelection = CompareNodes(focusedNode, firstChild) >= 0 && (nextSibling == null || CompareNodes(focusedNode, nextSibling) < 0); if (bChangeSelection) { OnBeforeMultiSelectStart(new CMSTreeViewMultiSelectEventArgs(SelectedNodes, TreeViewAction.Collapse)); if (!SetFocusedItem(node, true, focusedNode, TreeViewAction.Collapse)) { // user canceled operation, cancel collapsing bCancel = true; goto cleanup; } } // get the first selected child node int i = 0; for (; i < this.selectedNodes.Count; i++) { if (CompareNodes((TreeNode)this.selectedNodes[i], firstChild) >= 0) { break; } } if (i >= this.selectedNodes.Count) { goto cleanup; } // drop all selected nodes starting from i for (; i < this.selectedNodes.Count && (nextSibling == null || CompareNodes((TreeNode)this.selectedNodes[i], nextSibling) < 0);) { if (!bChangeSelection) { // OnBeforeMultiSelectStart should be called only once OnBeforeMultiSelectStart(new CMSTreeViewMultiSelectEventArgs(SelectedNodes, TreeViewAction.Collapse)); bChangeSelection = true; } // drop selection int count = this.selectedNodes.Count; SetSelectedState((TreeNode)this.selectedNodes[i], false); int countAfter = this.selectedNodes.Count; if (countAfter == count) { // user canceled operation, cancel collapsing m.Result = (IntPtr)1; break; } // SetSelectedState changes selectedNodes array, so we don't need to shift i } cleanup :; if (bChangeSelection) { OnAfterMultiSelectComplete(new CMSTreeViewMultiSelectEventArgs(SelectedNodes, TreeViewAction.Collapse)); } if (bCancel) { bCancel = true; } return(bCancel); } return(false); }