bool TreeView::moveUp(HTREEITEM itemToMove) { HTREEITEM hItemToDown = getPrevSibling(itemToMove); if (!hItemToDown) return false; return swapTreeViewItem(hItemToDown, itemToMove); }
Component* Component::getPrevDepthFirstComponent(void) const { if(getParentContainer() != NULL) { Component* TestComp(getPrevSibling()); if(TestComp == NULL) { TestComp = getParentContainer(); while(TestComp != NULL && TestComp->getPrevSibling() == NULL) { TestComp = TestComp->getParentContainer(); } if(TestComp != NULL) { TestComp = TestComp->getPrevSibling(); } } if(TestComp != NULL && TestComp->getType().isDerivedFrom(ComponentContainer::getClassType())) { return TestComp->getRightmostDecendent(); } else { return TestComp; } } return NULL; }
INode::node_t::SP INode::rewindRange(Size& size, const bool bChk) const { if(bChk) { if(auto ret = _rewindRange(size)) return ret; } else size -= _getThisSize(); if(size > 0) { if(auto ps = getPrevSibling()) return ps->rewindRange(size, true); if(auto p = getParent()) return p->rewindRange(size, false); } return const_cast<INode*>(this)->shared_from_this(); }
INode::node_t::SP Node::_rewindRange(Size& size) const { const auto cs = _getCachedSize(); if(isExpanded()) { if(size <= cs) { // このノードを精査 auto cur = getChild(); while(auto next = cur->getSibling()) cur = next; for(;;) { if(auto ret = cur->rewindRange(size)) return ret; if(auto next = cur->getPrevSibling()) cur = next; else break; } AssertP(Trap, size <= _getThisSize()) return const_cast<Node*>(this)->shared_from_this(); } size -= cs; } else {
bool TreeView::swapTreeViewItem(HTREEITEM itemGoDown, HTREEITEM itemGoUp) { HTREEITEM selectedItem = getSelection(); int itemSelected = selectedItem == itemGoDown?1:(selectedItem == itemGoUp?2:0); // get previous and next for both items with () function HTREEITEM itemTop = getPrevSibling(itemGoDown); itemTop = itemTop?itemTop:(HTREEITEM)TVI_FIRST; HTREEITEM parentGoDown = getParent(itemGoDown); HTREEITEM parentGoUp = getParent(itemGoUp); if (parentGoUp != parentGoDown) return false; // get both item infos TCHAR textBufferUp[MAX_PATH]; TCHAR textBufferDown[MAX_PATH]; TVITEM tvUpItem; TVITEM tvDownItem; tvUpItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvDownItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvUpItem.pszText = textBufferUp; tvDownItem.pszText = textBufferDown; tvUpItem.cchTextMax = MAX_PATH; tvDownItem.cchTextMax = MAX_PATH; tvUpItem.hItem = itemGoUp; tvDownItem.hItem = itemGoDown; SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvUpItem); SendMessage(_hSelf, TVM_GETITEM, 0,(LPARAM)&tvDownItem); // make copy recursively for both items if (tvUpItem.lParam) tvUpItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvUpItem.lParam)))); if (tvDownItem.lParam) tvDownItem.lParam = (LPARAM)(new generic_string(*((generic_string *)(tvDownItem.lParam)))); // add 2 new items TVINSERTSTRUCT tvInsertUp; tvInsertUp.item = tvUpItem; tvInsertUp.hInsertAfter = itemTop; tvInsertUp.hParent = parentGoUp; HTREEITEM hTreeParent1stInserted = (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertUp); dupTree(itemGoUp, hTreeParent1stInserted); TVINSERTSTRUCT tvInsertDown; tvInsertDown.item = tvDownItem; tvInsertDown.hInsertAfter = hTreeParent1stInserted; tvInsertDown.hParent = parentGoDown; HTREEITEM hTreeParent2ndInserted = (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)(LPTVINSERTSTRUCT)&tvInsertDown); dupTree(itemGoDown, hTreeParent2ndInserted); // remove 2 old items removeItem(itemGoUp); removeItem(itemGoDown); // Restore the selection if needed if (itemSelected != 0) { if (itemSelected == 1) { selectItem(hTreeParent2ndInserted); } else if (itemSelected == 2) { selectItem(hTreeParent1stInserted); } } return true; }