OpDelete Class Reference

This class represents the Delete operation. When executed this operation hides all selected objects. More...

#include <cutop.h>

Inheritance diagram for OpDelete:

SelOperation UndoableOperation Operation MessageHandler ListItem CCObject SimpleCCObject List of all members.

Public Member Functions

 OpDelete ()
 OpDelete constructor.
void Do (OpDescriptor *)
 Performs the Delete operation.

Static Public Member Functions

static BOOL Init ()
 OpDelete initialiser method.
static OpState GetState (String_256 *, OpDescriptor *)
 For finding OpDelete's state.

Private Member Functions

BOOL DeleteFillRampBlobs ()
 Deletes the selected fill ramp blobs. If any exist, we shouldn't delete any objects as this could be confusing. Only delete objects i.e. return FALSE if (a) the blob interest is for fill blobs and (b) if no fill ramp blobs are selected.

Detailed Description

This class represents the Delete operation. When executed this operation hides all selected objects.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
9/7/93

Definition at line 274 of file cutop.h.


Constructor & Destructor Documentation

OpDelete::OpDelete  ) 
 

OpDelete constructor.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/9/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1355 of file cutop.cpp.

01355                   : SelOperation()                              
01356 {                              
01357 }


Member Function Documentation

BOOL OpDelete::DeleteFillRampBlobs  )  [private]
 

Deletes the selected fill ramp blobs. If any exist, we shouldn't delete any objects as this could be confusing. Only delete objects i.e. return FALSE if (a) the blob interest is for fill blobs and (b) if no fill ramp blobs are selected.

Author:
David_McClarnon (Xara Group Ltd) <camelotdev@xara.com> Mc
Date:
24/10/99
Parameters:
[INPUTS] 
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1605 of file cutop.cpp.

01606 {
01607     // run through the selection seeing if any fill ramp blobs are selected
01608     Range * pSel = GetApplication()->FindSelection();
01609 
01610     if (!pSel)
01611         return FALSE;
01612 
01613     Node * pNode = pSel->FindFirst();
01614     AttrFillGeometry * pFill = NULL;
01615 //  AttrFillGeometry * pNewFill = NULL;
01616 
01617     Document * pDoc = Document::GetCurrent();
01618 
01619     BOOL bHasBegun = FALSE;
01620 
01621     BOOL bFoundBlobs = FALSE;
01622 //  NodeHidden * pHidden = NULL;
01623 
01624     while (pNode)
01625     {
01626         if (pNode->IsAnObject())
01627         {
01628             // find out the fill attribute associated with this node
01629             if (((NodeRenderableInk *)pNode)->FindAppliedAttribute(CC_RUNTIME_CLASS(AttrFillGeometry),
01630                 (NodeAttribute **)(&pFill)))
01631             {
01632                 // we've found a fill
01633                 if (pFill)
01634                 {
01635                     // now, does this fill have a colour ramp ?
01636                     if (pFill->GetColourRamp())
01637                     {
01638                         // if it does have a colour ramp, see if any of the ramp's nodes are
01639                         // selected
01640                         FillRamp * pRamp = pFill->GetColourRamp();
01641 
01642                         if (pRamp->CountSelBlobs() != 0)
01643                         {
01644                             // ok, we have more than one so remove the selected items
01645                             bFoundBlobs = TRUE;
01646 
01647                             if (!bHasBegun)
01648                             {
01649                                 if (!DoStartSelOp(TRUE, TRUE))
01650                                 {
01651                                     goto ErrorEnd;
01652                                 }
01653 
01654                                 bHasBegun = TRUE;
01655                             }
01656 
01657                             // invalidate the node region
01658                             ((NodeRenderableInk *)pNode)->ReleaseCached();
01659                             if (!DoInvalidateRegion(pNode->FindParentSpread(), 
01660                                 ((NodeRenderableInk *)pNode)->GetBoundingRect()))
01661 //                          if (!DoInvalidateNodeRegion((NodeRenderableBounded*)pItem->pNode))
01662                                 goto ErrorEnd;
01663 
01664                             RestoreFillRampAction * pAction = NULL;
01665                             
01666                             if (RestoreFillRampAction::Init(this, this->GetUndoActionList(), pFill,
01667                                 &pAction) != AC_OK)
01668                             {
01669                                 goto ErrorEnd;
01670                             }
01671 
01672                             pRamp = pFill->GetColourRamp();
01673 
01674                             // now, remove all selected nodes from the colour ramp
01675                             RampItem * pThisItem = (RampItem *)pRamp->GetHead();
01676                             RampItem * pNextItem = NULL;
01677 
01678                             while (pThisItem)
01679                             {
01680                                 if (pThisItem->IsSelected())
01681                                 {
01682                                     // remove it !
01683                                     pNextItem = (RampItem *)pRamp->GetNext(pThisItem);
01684                                     delete pRamp->RemoveItem(pThisItem);
01685                                     pThisItem = pNextItem;
01686 
01687                                     if (pRamp->IsEmpty ())
01688                                     {
01689                                         //delete (pRamp);
01690                                         
01691                                         // CGS
01692                                         // we cannot do the following line - since deleting the fillramp leads
01693                                         // us into trouble with the undo/redo system!
01694                                         ((GradFillAttribute*) (pFill->GetAttributeValue ()))->DeleteColourRamp ();
01695 
01696                                         // CGS
01697                                         // we also need to re-toggle the status of the profile gadget ....
01698 
01699                                         //Tool* CurrentTool = Tool::GetCurrent();
01700                                         //CurrentTool->     // possibly test this as well ....
01701 
01702 PORTNOTE("other", "Removed use of DialogBarOp in OpDelete::DeleteFillRampBlobs")
01703 #ifndef EXCLUDE_FROM_XARALX
01704                                         String_32 str = String_32(_R(IDS_FILLTOOL_FILLINFOBARNAME));
01705                                         GradInfoBarOp* pDialogBarOp = (GradInfoBarOp*) DialogBarOp::FindDialogBarOp(str);
01706                                         
01707                                         if (pDialogBarOp)
01708                                         {
01709                                             if (pDialogBarOp->IsVisible ())
01710                                             {
01711                                                 pDialogBarOp->EnableControls ();
01712                                             }
01713                                         }
01714 #endif
01715 
01716                                         pThisItem = NULL;
01717                                     }
01718                                 }
01719                                 else
01720                                 {
01721                                     pThisItem = (RampItem *)pRamp->GetNext(pThisItem);
01722                                 }
01723                             }
01724 
01725                             ((NodeRenderableInk *)pNode)->ReleaseCached();
01726                             if (!DoInvalidateRegion(pNode->FindParentSpread(), 
01727                                 ((NodeRenderableInk *)pNode)->GetBoundingRect()))
01728 //                          if (!DoInvalidateNodeRegion((NodeRenderableBounded*)pItem->pNode))
01729                                 goto ErrorEnd;
01730 
01731                             if (pDoc)
01732                                 pDoc->ForceRedraw(pNode->FindParentSpread(),
01733                                     ((NodeRenderableInk *)pNode)->GetBoundingRect(), FALSE, pNode);
01734 
01735                         }
01736                     }
01737                 }
01738             }
01739         }
01740 
01741         pNode = pSel->FindNext(pNode);
01742     }
01743 
01744     if (bHasBegun)
01745         End();
01746 
01747     return bFoundBlobs;
01748 
01749 ErrorEnd:
01750     if (bHasBegun)
01751     {
01752         FailAndExecute();
01753         End();
01754     }
01755     return TRUE;
01756 }

void OpDelete::Do OpDescriptor  )  [virtual]
 

Performs the Delete operation.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
16/8/93
Parameters:
OpDescriptor (unused) [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Reimplemented from Operation.

Definition at line 1457 of file cutop.cpp.

01458 {   
01459     ObjectSet CompoundSet;
01460 
01461     // DMc
01462     // first, try deleting selected fill ramp blobs
01463     // check the fill interest first
01464     BlobManager * pBlobMgr = GetApplication()->GetBlobManager();
01465 
01466     if (pBlobMgr)
01467     {
01468         if (pBlobMgr->GetCurrentInterest().Fill)
01469         {
01470             if (DeleteFillRampBlobs())
01471             {
01472                 // we've deleted fill ramp blobs, then drop out - job done
01473                 return;
01474             }   
01475         }
01476     }
01477 
01478     // Obtain the current selections 
01479     Range Sel(*(GetApplication()->FindSelection()));
01480     RangeControl rg = Sel.GetRangeControlFlags();
01481     rg.PromoteToParent = TRUE;
01482     Sel.Range::SetRangeControl(rg);
01483 
01484     // Prepare an ObjChangeParam so we can mark which nodes will allow this op to happen to them
01485     ObjChangeFlags cFlags(TRUE);
01486     ObjChangeParam ObjChange(OBJCHANGE_STARTING,cFlags,NULL,this);
01487 
01488     if (!DoStartSelOp(TRUE,FALSE))  // Try to record the selection state
01489         goto EndOperation;
01490 
01491     // Mark nodes that will allow this to happen, and error if no nodes will let it happen
01492     if (!Sel.AllowOp(&ObjChange))
01493     {
01494         ERROR3("AllowOp() returned FALSE, i.e. op should have been greyed out");
01495         goto EndOperation;
01496     }
01497 
01498 
01499     // We need to invalidate the region
01500     if (!DoInvalidateNodesRegions(Sel, TRUE))
01501         goto EndOperation; 
01502 
01503     // Prior to hiding anything lets get ourselves a set of compound nodes which 
01504     // we will need to factor out attributes on. We cannot use the SelRange because
01505     // this will be empty after the deletion has taken place. 
01506 
01507     if (!(Sel.GetCompoundObjectSet(&CompoundSet, TRUE /* Exclude TextObjects*/)))
01508     {
01509         goto EndOperation; 
01510     }
01511     
01512     // Because of complex deletion we must also add the TextStory objects 
01513     // of selected chars. This code will hopefuly be removed in future. It is
01514     // inefficient cos we will need to factor out more than once for each line !.
01515     
01516     //if (!(Sel.AddTextStoryCompoundsForDel(&CompoundSet)))
01517     //{
01518     //  goto EndOperation;
01519     //} 
01520 
01521     // We know must localise the attributes on every item marked for deletion
01522     if (!DoLocaliseForAttrChange(&Sel, (AttrTypeSet*)NULL, TRUE /* Exclude TextStory objects */))
01523     {
01524         goto EndOperation;
01525     }
01526 
01527     // Go through one pass, asking nodes to hide themselves
01528     if (!DoHideComplexRange(Sel))
01529         goto EndOperation;
01530 
01531     {
01532         SelRange* pRange = GetApplication()->FindSelection();
01533 
01534         rg = Sel.GetRangeControlFlags();
01535         rg.PromoteToParent = TRUE;
01536         
01537         if (pRange)
01538         {
01539             // freshen the selection range by counting the currently selected objects
01540             pRange->Update(FALSE,NULL);
01541             pRange->Range::SetRangeControl(rg);
01542 
01543             /*INT32 num =*/ pRange->Count();
01544         
01545             // Obtain the current selection (should be up-to-date now!)
01546             Range NewSel(*pRange);
01547 
01548             NewSel.Range::SetRangeControl(rg);
01549 
01550             // Now go through a second pass snip the remainder out of the tree
01551             if (!DoHideNodes(NewSel,TRUE))   // Hide the nodes (IncludeSubtreeSize)
01552                 goto EndOperation;
01553         }
01554     }
01555 
01556     // Finally try to factor out the attributes on all compounds. Note that if a particular compound
01557     // is hidden then it will  be it's parent that has its attributes factored out !
01558     if (!DoFactorOutAfterAttrChange(&CompoundSet,(AttrTypeSet*)NULL))
01559     {
01560         goto EndOperation; 
01561     }
01562 
01563 
01564 EndOperation:
01565     // Delete all items in the CompoundSet
01566     CompoundSet.DeleteAll();
01567 
01568     // Update all the changed nodes, i.e tell all the parents of the children that have been effected
01569     ObjChange.Define(OBJCHANGE_FINISHED,cFlags,NULL,this);
01570     if (!UpdateChangedNodes(&ObjChange))
01571         FailAndExecute();
01572 
01573     // Invalidate sel range as it may have been cached in the middle of the op while the tree is
01574     // in an invalid state (i.e. some selected nodes may have had the PERMISSION_DENIED state set during caching).
01575     {
01576         SelRange* pRange = GetApplication()->FindSelection();
01577         if (pRange)
01578             pRange->Update(FALSE,NULL);
01579 
01580         rg.PromoteToParent = FALSE;
01581         pRange->Range::SetRangeControl(rg);
01582     }
01583 
01584     End(); 
01585 }           

OpState OpDelete::GetState String_256 UIDescription,
OpDescriptor
[static]
 

For finding OpDelete's state.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/9/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
The state of the OpDelete

Errors: -

See also:
-

Definition at line 1414 of file cutop.cpp.

01415 {
01416     OpState OpSt;
01417 
01418     SelRange *pSelRange = GetApplication()->FindSelection(); 
01419 
01420     // Set up the ObjChangeParam so we can ask the selected nodes if they mind being deleted
01421     ObjChangeFlags cFlags(TRUE);
01422     ObjChangeParam ObjChange(OBJCHANGE_STARTING,cFlags,NULL,NULL);
01423 
01424     // Will one or more selected nodes allow this op?
01425     if (!pSelRange->AllowOp(&ObjChange,FALSE))
01426     {
01427         // No nodes can be deleted
01428         OpSt.Greyed = TRUE;
01429 
01430         // Load reason why operation is disabled
01431         UINT32 IDS = ObjChange.GetReasonForDenial();
01432         if (IDS == 0) IDS = _R(IDS_NO_OBJECTS_SELECTED);    // if 0 (i.e. not been set), then assume there's no selection
01433         *UIDescription = String_256(IDS);               // Resolve the string ID
01434     }
01435     else
01436         SetCutOpText(UIDescription, _R(IDS_CLIPBOARD_PREDELETE));
01437 
01438     return(OpSt);   
01439 }

BOOL OpDelete::Init void   )  [static]
 

OpDelete initialiser method.

Author:
Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
Date:
28/9/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
TRUE if the operation could be successfully initialised FALSE if no more memory could be allocated

Errors: ERROR will be called if there was insufficient memory to allocate the operation.

See also:
-

Reimplemented from SimpleCCObject.

Definition at line 1377 of file cutop.cpp.

01378 {
01379     return (RegisterOpDescriptor(0,
01380                             _R(IDS_DELETEOP),
01381                             CC_RUNTIME_CLASS(OpDelete),
01382                             OPTOKEN_DELETE,
01383                             OpDelete::GetState,
01384                             0,                          // help ID
01385                             _R(IDBBL_DELETE),
01386                             0,
01387                             0,
01388                             SYSTEMBAR_ILLEGAL,          // For now !
01389                             TRUE,                       // Receive messages
01390                             FALSE,
01391                             FALSE,
01392                             0,
01393                             0 // (GREY_WHEN_NO_CURRENT_DOC | GREY_WHEN_NO_SELECTION)
01394            ));
01395 
01396     return true;
01397 }               


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:57:51 2007 for Camelot by  doxygen 1.4.4