void SelectionState::DeselectAll(BOOL RenderBlobs) { // Find the selected objects in the tree; SelRange* Selected = GetApplication()->FindSelection(); ERROR3IF( Selected==NULL, "Selection object is null in DeselectAll()"); // Get the selected spread Spread* pSpread = Document::GetSelectedSpread(); ERROR3IF(pSpread == NULL,"NULL selected spread"); // Make sure that we have a spread and a selection if (pSpread == NULL || Selected == NULL) return; // Find first selected node #if !defined(EXCLUDE_FROM_RALPH) Node* pFirstSelectedNode = Selected->FindFirst(); // If there is a selection, EOR blobs off, deselect nodes, and inform everybody if (pFirstSelectedNode != NULL && RenderBlobs) { // Go though and render all the EOR blobs off the screen // Find the Blob Manager BlobManager* BlobMgr = GetApplication()->GetBlobManager(); ENSURE( BlobMgr!=NULL, "Blob Manager unexpectedly not there."); // Render all the blobs BlobMgr->RenderOff(NULL, pFirstSelectedNode->FindParentSpread()); Tool* pTool = Tool::GetCurrent(); // Get the tool to remove all its blobs before we deselect the nodes. // Only do this if the current tool dosent update itself on sel changed messages if (pSpread!=NULL && pTool!=NULL && !pTool->AreToolBlobsRenderedOnSelection()) pTool->RenderToolBlobs(pSpread,NULL); } #endif DeselectAll(pSpread->FindFirstChild()); // Selection cache is no longer valid, so update and tell everyone that it has changed // *Note*, This used to be 'Selected->Update(TRUE)', but I (Will) removed the TRUE, so // that a message is NOT broadcast. This should only be called from an operation, // and the op will send a message when it ends. Selected->Update(); }
/******************************************************************************************** > virtual void OpRemoveClipView::Do(OpDescriptor* pOpDesc, OpParam* pOpParam) Author: Karim_MacDonald (Xara Group Ltd) <*****@*****.**> Created: 01 February 2000 Inputs: Outputs: Returns: Purpose: Errors: See also: ********************************************************************************************/ void OpRemoveClipView::Do(OpDescriptor* pOpDesc) { // try to record the selection state. if (DoStartSelOp(FALSE, FALSE)) { // obtain the current selection. Range Sel(*(GetApplication()->FindSelection())); RangeControl rc = Sel.GetRangeControlFlags(); rc.PromoteToParent = TRUE; Sel.Range::SetRangeControl(rc); // check that the selection is one lone NodeClipViewController. BOOL ok = FALSE; Node* pFirstNode = Sel.FindFirst(); if (pFirstNode != NULL && pFirstNode->IsANodeClipViewController()) if (Sel.FindNext(pFirstNode) == NULL) ok = TRUE; // remove tool blobs and localise any common attributes. Tool* pTool = NULL; Spread* pSpread = NULL; if (ok) { // render blobs off for tools which don't automatically redraw their blobs. pTool = Tool::GetCurrent(); pSpread = Document::GetSelectedSpread(); if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection()) pTool->RenderToolBlobs(pSpread, NULL); // invalidate the region of screen covering the selection. DoInvalidateNodesRegions(*(GetApplication()->FindSelection()), TRUE, FALSE, FALSE); // localise any common attributes. ok = DoLocaliseCommonAttributes((NodeGroup*)pFirstNode); } // deselect and hide the NCVC. NodeHidden* pHiddenNode = NULL; if (ok) { // deselect the NCVC, but don't ask for its blobs to be redrawn. ((NodeRenderable*)pFirstNode)->DeSelect(FALSE); ERROR3IF(pFirstNode->IsSelected(), "Deselect failed to deselect current node"); // hide the NodeClipViewController. ok = DoHideNode(pFirstNode, FALSE, &pHiddenNode, FALSE); ERROR3IF(!ok, "Unable to hide NodeClipViewController!"); } // hide the NCVC's NodeClipView node. if (ok) { NodeHidden* pDummy; NodeClipView* pClipView = ((NodeClipViewController*)pFirstNode)->GetClipView(); ok = DoHideNode(pClipView, FALSE, &pDummy, FALSE); ERROR3IF(!ok, "Unable to hide NodeClipView!"); } // show and select the NCVC's children. // a straight loop-over should do, as it should skip the now-hidden NodeClipView. if (ok) { // get the first child node (the NCVC's keyhole node). Node* pChildNode = pFirstNode->FindFirstChild(); if (pChildNode == NULL) TRACEUSER( "Karim", _T("OpRemoveClipView::Do(); Found an empty NodeClipViewController!\n")); // move and select the child nodes in turn. Node* pAnchorNode = pHiddenNode; Node* pNextChildNode = NULL; while (pChildNode != NULL) { // get the next child-node. pNextChildNode = pChildNode->FindNext(); // if the node is not a NodeHidden then move the node to its new location in // the tree - there is no need to render the node. if (!pChildNode->IsAnAttribute() && !pChildNode->IsNodeHidden()) { // move pChildNode to be the next-sibling of the anchor node. ok = DoMoveNode(pChildNode, pAnchorNode, NEXT); if (!ok) break; pAnchorNode = pChildNode; } // select the child node and invalidate its bounding rect, // but don't bother redrawing its blobs yet. if (pChildNode->IsAnObject()) { ((NodeRenderableInk*)pChildNode)->Select(FALSE); ((NodeRenderableInk*)pChildNode)->InvalidateBoundingRect(); ok = this->DoInvalidateNodeRegion(((NodeRenderableInk*)pChildNode), TRUE); if (!ok) break; } pChildNode = pNextChildNode; } } // render blobs back on for tools which don't automatically redraw their blobs. if (ok) { if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection()) pTool->RenderToolBlobs(pSpread, NULL); } // fail gracefully if things went pear-shaped. else FailAndExecute(); } End(); }
void SelectionState::Restore(BOOL RestoreSelBlobs, BOOL RemoveBlobs) { DeselectAll(RemoveBlobs); // Deselect all selections #ifdef _DEBUG UINT32 NumRestored = 0; #endif // ---------------------------------------------------------------------------------- // Restore all nodes in the SelNdList UINT32 i; for (i=0; i < NumNd; i++) { // Only NodeRenderableInk nodes should be selected ENSURE(SelNdList[i]->IsKindOf(CC_RUNTIME_CLASS(NodeRenderableInk)), "Node to be selected is not a NodeRenderableInk"); // Ensure node to be selected is not already selected //ENSURE(!(SelNdList[i]->IsSelected()), "Invalid selected node"); // Select the node SelNdList[i]->SetSelected(TRUE); #ifdef _DEBUG NumRestored++; #endif } // ---------------------------------------------------------------------------------- // Restore all nodes in the SelNdRngList Node* Current; for (i=0; i < NumNdRng; i++) { // A SelNdRng shold represent at least two contiguous selected nodes ENSURE(SelNdRngList[i].NumSelected >= 2, "Number of nodes in SelNdRng < 2"); UINT32 NumNodesSelected = 0; Current = SelNdRngList[i].FirstNode; // First node in range // Select the next SelNdRng->NumSelected nodes do { ENSURE((Current != NULL), "Node in a SelNdRng is NULL, Has tree changed ?" ); // Only NodeRenderableInk nodes should be selected ENSURE(Current->IsKindOf(CC_RUNTIME_CLASS(NodeRenderableInk)), "Selected node is not a NodeRenderableInk"); // [Phil, 11/10/2005] The Current node may be a Caret node // because Carets are included in the selection, even when // a sub-selection of characters is present, so that attributes // optimise correctly within the text story // However, the Record function treats them as single selected // nodes, not part of a contiguous run of selected nodes to // allow for them moving around... // So we should ignore carets here if (!IS_A(Current, CaretNode)) { // Ensure SelNode not already selected ENSURE(!(Current->IsSelected()), "Invalid selected node"); Current->SetSelected(TRUE); // Set the nodes selected flag NumNodesSelected++; #ifdef _DEBUG NumRestored++; #endif } Current = Current->FindNextNonHidden(); } while (NumNodesSelected != SelNdRngList[i].NumSelected); } #if !defined(EXCLUDE_FROM_RALPH) // Only restore the blobs if any selections have been restored if (((NumNdRng != 0) || (NumNd !=0)) && RestoreSelBlobs) // We need to restore the selection blobs { // Find the current selections SelRange* pSel; pSel = GetApplication()->FindSelection(); Current = pSel->FindFirst(); // The first selected node Spread *pSpread = NULL; if (Current != NULL) pSpread = Current->FindParentSpread(); // ENSURE(pSpread != NULL, "First selected node does not have a parent spread"); // It's a legal state to not find a selected node - the layers may all be locked. if (pSpread == NULL) { AttrFillGeometry::LastRenderedMesh = NULL; return; } // Go get the blob manager BlobManager* BlobMgr = GetApplication()->GetBlobManager(); ENSURE( BlobMgr!=NULL, "Blob Manger was not there when we needed him!"); if (BlobMgr==NULL) return; Current = pSel->FindFirst(); // The first selected node while (Current != NULL) { ENSURE(Current->IsSelected(), "Node not selected"); ENSURE(Current->IsKindOf(CC_RUNTIME_CLASS(NodeRenderable)), "Selected Node not a NodeRenderable"); // Tell the node to add selection blobs BlobMgr->RenderMyBlobsOn(NULL, pSpread, (NodeRenderable*)Current); Current = pSel->FindNext(Current); // Get next selected node } Tool* pTool = Tool::GetCurrent(); // Get the tool to remove all its blobs before we deselect the nodes. // Only do this if the current tool dosent update itself on sel changed messages if (pSpread!=NULL && pTool!=NULL && !pTool->AreToolBlobsRenderedOnSelection()) pTool->RenderToolBlobs(pSpread,NULL); AttrFillGeometry::LastRenderedMesh = NULL; } #endif #ifdef _DEBUG //if (IsUserName("Simon")) // TRACE( _T(" Num Restored = %lu\n"), NumRestored); #endif }
/******************************************************************************************** > virtual void OpApplyClipView::Do(OpDescriptor* pOpDesc, OpParam* pOpParam) Author: Karim_MacDonald (Xara Group Ltd) <*****@*****.**> Created: 01 February 2000 Inputs: Outputs: Returns: Purpose: Errors: See also: ********************************************************************************************/ void OpApplyClipView::Do(OpDescriptor* pOpDesc) { // obtain the current selection. Range Sel(*(GetApplication()->FindSelection())); RangeControl rc = Sel.GetRangeControlFlags(); rc.PromoteToParent = TRUE; Sel.Range::SetRangeControl(rc); // check that at least two nodes are selected. Node* pNode = NULL; Node* pFirstNode = Sel.FindFirst(); if (pFirstNode != NULL) pNode = Sel.FindNext(pFirstNode); if (pFirstNode == NULL || pNode == NULL) { ERROR3("OpApplyClipView invoked with less than two selected nodes. This should never occur."); End(); return; } // render blobs off for tools which don't automatically redraw their blobs. Tool* pTool = Tool::GetCurrent(); Spread* pSpread = Document::GetSelectedSpread(); if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection()) pTool->RenderToolBlobs(pSpread, NULL); // record the current selection state and if required, render off any selection blobs. if (!DoStartSelOp(FALSE, FALSE)) { End(); return; } // invalidate the region bounding the selection. // the commented code doesn't do the job properly (doesn't tackle undo) // though it should - I get the feeling I'm not using it correctly. // so we'll just have to invalidate the selection node by node. // if (!DoInvalidateNodesRegions(Sel, TRUE, FALSE, FALSE)) // { // End(); // return; // } Node* pSelNode = Sel.FindFirst(); while (pSelNode != NULL) { if (pSelNode->IsAnObject()) { if (!DoInvalidateNodeRegion((NodeRenderableInk*)pSelNode, TRUE)) { End(); return; } } pSelNode = Sel.FindNext(pSelNode); } // we need to insert the controller node at the position of the highest // selected node in the z-order, ie last in the selection, so find it. Node* pLastNode = NULL; while (pNode != NULL) { pLastNode = pNode; pNode = Sel.FindNext(pLastNode); } // loop terminates with pNode == NULL, pLastNode == last-node-in-sel. // create a new NodeClipViewController, which we will shortly insert into the tree; // note that ALLOC_WITH_FAIL automatically calls FailAndExecute() if things go wrong. NodeClipViewController* pClipViewController = NULL; ALLOC_WITH_FAIL(pClipViewController, new NodeClipViewController, this); BOOL ok = (pClipViewController != NULL); // put an action to hide the NodeClipViewController onto the undo action-list, // so that if the user presses undo then it will be hidden. if (ok) { HideNodeAction* pUndoHideNodeAction = NULL; ActionCode ac = HideNodeAction::Init(this, &UndoActions, pClipViewController, FALSE, // don't include subtree size (Action**)&pUndoHideNodeAction, FALSE); // don't tell subtree when undone if (ac == AC_FAIL) { delete pClipViewController; End(); return; } else { // right! we've got our node, we've got our action - lets stick it in the tree // (at a position just next to the last node which will go in the group). pClipViewController->AttachNode(pLastNode, NEXT); } } // move each item from the selection into our ClipView group, // remembering to deselect them as we go. // TODO: // sneaky suspicion I should be putting this in a Do fn in UndoableOperation... if (ok) { pNode = Sel.FindNext(pFirstNode); // the node we're moving now. ok = DoMoveNode(pFirstNode, pClipViewController, FIRSTCHILD); if (ok) ((NodeRenderable*)pFirstNode)->DeSelect(FALSE); } Node* pNextNode = NULL; // the next node to move. Node* pAnchorNode = pFirstNode; // the node we've just moved. while (ok && pNode != NULL) { // get the next node to move. pNextNode = Sel.FindNext(pNode); // now move the current node next to the anchor and deselect it. ok = DoMoveNode(pNode, pAnchorNode, NEXT); if (ok) ((NodeRenderable*)pNode)->DeSelect(FALSE); // get the new anchor node and the next node to move. pAnchorNode = pNode; pNode = pNextNode; } // try and locate a suitable candidate for a keyhole node. Node* pKeyhole = NULL; if (ok) { // now get the keyhole node, which is the first object-node child of the NCVC. pKeyhole = pClipViewController->FindFirstChild(); while (pKeyhole != NULL && !pKeyhole->IsAnObject()) { pKeyhole = pKeyhole->FindNext(); } // doh! can't find _one_ NodeRenderableInk child! I don't know... if (pKeyhole == NULL) { ok = FALSE; ERROR2RAW("ClipViewController has no object children"); } } // now attach a new NodeClipView, as the immediate NEXT-sibling of the keyhole node. NodeClipView* pClipView = NULL; if (ok) { ALLOC_WITH_FAIL(pClipView, new NodeClipView(pKeyhole, NEXT), this); ok = (pClipView != NULL); } // wow - succeeded! now all we need to do is some house-keeping. if (ok) { // tell the new NodeClipViewController that its current keyhole path is now invalid. pClipViewController->MarkKeyholeInvalid(); // invalidate ours and our parent's bounding rects. our bounding rect is almost // certainly already invalid, as we haven't done anything to make it valid yet. // this is why we invalidate *both* rects - just to cover all cases. pClipViewController->InvalidateBoundingRect(); Node* pParent = pClipViewController->FindParent(); if (pParent != NULL && pParent->IsBounded()) ((NodeRenderableBounded*)pParent)->InvalidateBoundingRect(); // select the new NodeClipViewController, but don't draw any blobs yet. pClipViewController->Select(FALSE); // invalidate the region bounding the selection. if (!DoInvalidateNodesRegions(*(GetApplication()->FindSelection()), TRUE, FALSE, FALSE)) { End(); return; } // factor out any common attributes. if (!DoFactorOutCommonChildAttributes(pClipViewController)) { End(); return; } // render blobs back on if the current tool doesn't automatically redraw its blobs. if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection()) pTool->RenderToolBlobs(pSpread, NULL); } else { FailAndExecute(); } // end the operation. End(); }