#include <cutop.h>
Inheritance diagram for OpPaste:
Public Member Functions | |
OpPaste () | |
OpPaste constructor. | |
void | Do (OpDescriptor *) |
Performs the Paste operation. | |
void | DoWithParam (OpDescriptor *, OpParam *pOpParam) |
Performs the Paste operation using the give param object. This mechanism is used by the "paste at position" op, utilised by the OLE drag & drop system. | |
Static Public Member Functions | |
static BOOL | Init () |
OpPaste initialiser method. | |
static OpState | GetState (String_256 *, OpDescriptor *) |
For finding OpPaste's state. | |
static BOOL | RemoveNamesAlreadyUsedInStretching (Node *pAttrib, UndoableOperation *pOp) |
Remove set information from pasted attributes if that name would interfere with stretching if added... Notes: Made static so that it can also be used by the PasteAttributes operation. | |
Protected Member Functions | |
void | DoPaste (OpDescriptor *, Spread *pSpread, DocCoord *pCentre) |
Helper function for Do() & DoWithParam(), which in turn interfaces with DoPasteStandard() (don't look at me - I didn't design this stuff). | |
BOOL | FindCentreInsertionPosition (Spread **Spread, DocCoord *Position) |
Finds the centre insertion position for clipboard objects. | |
BOOL | DoPasteStandard (BOOL PasteAtSamePos, BOOL ExternalData, Spread *pSpread=NULL, DocCoord *pCentre=NULL) |
Pastes the contents of the clipboard into the current document. |
Definition at line 213 of file cutop.h.
|
OpPaste constructor.
Definition at line 727 of file cutop.cpp. 00727 : SelOperation() 00728 { 00729 }
|
|
Performs the Paste operation.
Reimplemented from Operation. Reimplemented in OpTextPaste. Definition at line 852 of file cutop.cpp.
|
|
Helper function for Do() & DoWithParam(), which in turn interfaces with DoPasteStandard() (don't look at me - I didn't design this stuff).
Definition at line 917 of file cutop.cpp. 00918 { 00919 BeginSlowJob(-1, FALSE); // Make sure we have a simple hourglass, without a delay 00920 00921 // Check with the clipboard if it is OK to go ahead. If the clipboard contents are 00922 // currently external, this means it'll have to import them into the InternalClipboard 00923 // before we can actually copy them into our document. 00924 InternalClipboard *Clipboard = InternalClipboard::Instance(); 00925 BOOL ExternalObjects; 00926 BOOL ok = (Clipboard!=NULL && Clipboard->PrepareForPaste(&ExternalObjects)); 00927 00928 if (ok) 00929 { 00930 // We paste at the same position if the operation was invoked via the PASTEATSAMEPOS OpDescriptor 00931 // and the stuff we are pasting has not come from an external source. 00932 BOOL PasteAtSamePos = (((WhichOp->Token) == String(OPTOKEN_PASTEATSAMEPOS)) && (!ExternalObjects)); 00933 ok = DoPasteStandard(PasteAtSamePos, ExternalObjects, pSpread, pCentre); 00934 } 00935 00936 if (ok) 00937 ok = Clipboard->PasteCompleted(); 00938 00939 if (!ok) 00940 FailAndExecute(); 00941 00942 EndSlowJob(); 00943 End(); 00944 }
|
|
Pastes the contents of the clipboard into the current document.
pSpread: ptr to insertion spread. If NULL, spread in the centre of the current view is used AND pCentre is ignored. pCentre: ptr to coord defining the centre of the paste. if PasteAtSamePos is TRUE, this coord is not used (I think! - Markn)
Definition at line 1071 of file cutop.cpp. 01072 { 01073 // Assume failure until told otherwise 01074 BOOL HasFailed=TRUE; 01075 01076 Spread* InsertionSpread = pSpread; 01077 DocCoord PastePosition; 01078 01079 if (InsertionSpread == NULL) 01080 { 01081 if (!FindCentreInsertionPosition(&InsertionSpread, &PastePosition)) 01082 return FALSE; 01083 } 01084 else 01085 { 01086 ERROR3IF(pCentre == NULL,"You've supplied a spread, but no centre coord. Are you mad?"); 01087 01088 if (pCentre != NULL) 01089 PastePosition = *pCentre; 01090 } 01091 01092 ERROR3IF(InsertionSpread == NULL,"Spread is NULL"); 01093 01094 // ----------------------------------- 01095 // This is an horrendous bodge! 01096 // What's the point passing in a centre of the routine insists on calculating it for itself? 01097 // Ho hum... 01098 // If the data has come from the outside world it's original position is unknown 01099 // So now that the user has committed themselves to pasting at a certain position 01100 // record that as being the data's "original position". 01101 if (ExternalData) 01102 { 01103 InternalClipboard::SetOriginalCentrePoint(PastePosition); 01104 } 01105 01106 // If trying to paste data at its original position 01107 // Then retrieve that info from the clipboard and use it as the paste position 01108 if (PasteAtSamePos) 01109 { 01110 PastePosition = InternalClipboard::GetOriginalCentrePoint(); 01111 } 01112 // ----------------------------------- 01113 01114 if (InsertionSpread != NULL) 01115 { 01116 Node* Current; 01117 01118 InternalClipboard* IntClip = InternalClipboard::Instance(); 01119 if (IntClip==NULL) 01120 { 01121 ERROR3("Could not find internal clipboard"); 01122 goto EndOperation; 01123 } 01124 01125 BOOL FirstObjectCopied = TRUE; 01126 DocRect ObjectsBounds; 01127 DocCoord CentreOfObjectsBounds; 01128 01129 // Create the transform to be applied to all pasted objects 01130 ObjectsBounds = IntClip->GetObjectsBounds(); 01131 01132 CentreOfObjectsBounds.x = ObjectsBounds.lo.x + (ObjectsBounds.Width()/2); 01133 CentreOfObjectsBounds.y = ObjectsBounds.lo.y + (ObjectsBounds.Height()/2); 01134 01135 Trans2DMatrix ObjectTrans (PastePosition.x - CentreOfObjectsBounds.x, 01136 PastePosition.y - CentreOfObjectsBounds.y); 01137 01138 // Set the selected spread (assume it is in the Selected Doc and DocView - an 01139 // ENSURE will occur if this turns out not to be the case!) 01140 // NOTE selected spread should change due to a change in the sel range! 01141 Document::SetSelectedViewAndSpread(NULL, NULL, InsertionSpread); 01142 01143 // Get the current tool 01144 Tool* pTool = Tool::GetCurrent(); 01145 Spread* pSelSpread = Document::GetSelectedSpread(); 01146 01147 // Get the tool to remove all its blobs before we deselect the nodes. 01148 // Only do this if the current tool dosent update itself on sel changed messages 01149 if (pSelSpread!=NULL && pTool!=NULL && !pTool->AreToolBlobsRenderedOnSelection()) 01150 pTool->RenderToolBlobs(pSelSpread,NULL); 01151 01152 if (!DoStartSelOp(FALSE, TRUE)) // Try to record the selection state 01153 goto EndOperation; 01154 01155 // After the operation ends we will need to inform all DocComponents in the 01156 // destination document of the outcome. 01157 InformDocComponentsOfOperationsOutcome(GetWorkingDoc()); 01158 01159 // Inform all DocComponents in the destination doc that a copy is about to take place 01160 BOOL ok; 01161 CALL_WITH_FAIL((GetWorkingDoc()->StartComponentCopy()),this, ok) 01162 01163 if (!ok) 01164 { 01165 // Start Component copy has failed so abort operation 01166 // Note that AbortComponentCopy will have been called 01167 goto EndOperation; 01168 } 01169 01170 01171 Current = IntClip->GetInsertionLayer()->FindFirstChild(); 01172 01173 // Create a range of all clipboard objects which are about to be copied 01174 // Selected + Unselected + don't cross layers 01175 01176 // DMc - also need to set the PromoteToParent flag 01177 Range ClipRange(Current,NULL,RangeControl(TRUE,TRUE,FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)); 01178 01179 Node* FirstCopiedObj = NULL; 01180 Node* Copy; 01181 01182 // Now we try and copy all clipboard nodes 01183 while (Current != NULL) 01184 { 01185 // Make a copy of Current 01186 CALL_WITH_FAIL(Current->NodeCopy(&Copy), this, ok); 01187 01188 if (!ok) 01189 goto EndOperation; 01190 01191 // Sanity check, will vapourise in retails 01192 ENSURE(Copy->IsKindOf(CC_RUNTIME_CLASS(NodeRenderableBounded)), 01193 "Object being pasted is not a NodeRenderableBounded"); 01194 01195 // Remember the first copy we make 01196 if (FirstCopiedObj == NULL) 01197 FirstCopiedObj = Copy; 01198 01199 NodeRenderableBounded* pBoundCopy = (NodeRenderableBounded*)Copy; 01200 01201 // Insert object 01202 if (!DoInsertNewNode(pBoundCopy, 01203 (Spread*)NULL, // Selected spread 01204 FALSE, // Dont Invalidate region 01205 FirstObjectCopied // Only clear the selection if this is the 01206 // first object being copied 01207 )) 01208 { 01209 // Tidyup 01210 Copy->CascadeDelete(); 01211 delete Copy; 01212 goto EndOperation; 01213 } 01214 01215 // Now translate the object into the correct position. 01216 // Note: This has to be done even when PasteInPlace is operational because 01217 // the clipboard may have moved the objects ready for OLE external use. 01218 pBoundCopy->Transform(ObjectTrans); 01219 01220 // Now call PostDuplicate on the copied node aand all it's children 01221 BOOL ok = TRUE; 01222 Node* pCurrent = pBoundCopy->FindFirstDepthFirst(); 01223 while (pCurrent!=NULL && ok) 01224 { 01225 ok = pCurrent->PostDuplicate(this); 01226 01227 pCurrent = pCurrent->FindNextDepthFirst(pBoundCopy); 01228 } 01229 01230 // We also need to invalidate the region of the node now that it has been transformed 01231 if (!ok || !DoInvalidateNodeRegion(pBoundCopy, TRUE, FALSE)) 01232 { 01233 // Tidyup 01234 Copy->CascadeDelete(); 01235 delete Copy; 01236 goto EndOperation; 01237 } 01238 01239 // Normalise the attributes 01240 ((NodeRenderableInk*) pBoundCopy)->NormaliseAttributes(); 01241 01242 // remove any name attribs from the clipboard pasted object (sjk 15/8/00) 01243 Node * pAttrib = SliceHelper::FindNextNameNode(pBoundCopy,pBoundCopy); 01244 while (pAttrib) 01245 { 01246 BOOL leave = RemoveNamesAlreadyUsedInStretching(pAttrib, this); 01247 01248 Node * pDelMe = pAttrib; 01249 pAttrib = SliceHelper::FindNextNameNode(pAttrib,pBoundCopy); 01250 if (!leave) 01251 { 01252 pDelMe->UnlinkNodeFromTree(); 01253 delete pDelMe; 01254 } 01255 } 01256 01257 // Get the next object from the clipboard to copy 01258 Current = Current->FindNext(); 01259 FirstObjectCopied = FALSE; 01260 } 01261 01262 ENSURE(FirstCopiedObj != NULL, "No nodes were copied"); 01263 if (FirstCopiedObj == NULL) 01264 goto EndOperation; 01265 01266 01267 // We now need to ask all copied nodes to copy their component data to the 01268 // current document 01269 Range CopiedRange(FirstCopiedObj, Copy, RangeControl(TRUE,TRUE,FALSE)); 01270 01271 CALL_WITH_FAIL((CopiedRange.CopyComponentDataToDoc(IntClip, pOurDoc)), this, ok); 01272 if (!ok) 01273 goto EndOperation; 01274 01275 // THIS MUST BE LAST! 01276 HasFailed = FALSE; 01277 } 01278 01279 EndOperation: 01280 return (!HasFailed); 01281 }
|
|
Performs the Paste operation using the give param object. This mechanism is used by the "paste at position" op, utilised by the OLE drag & drop system.
If pOpParam is not an OpParamPasteAtPosition, the op fails
Reimplemented from Operation. Definition at line 880 of file cutop.cpp. 00881 { 00882 if (pOpParam != NULL && IS_A(pOpParam,OpParamPasteAtPosition)) 00883 { 00884 OpParamPasteAtPosition* pPasteParam = (OpParamPasteAtPosition*)pOpParam; 00885 00886 Spread* pSpread = pPasteParam->GetSpread(); 00887 DocCoord Centre = pPasteParam->GetCentre(); 00888 00889 DoPaste(WhichOp,pSpread,&Centre); 00890 } 00891 else 00892 { 00893 FailAndExecute(); 00894 End(); 00895 } 00896 }
|
|
Finds the centre insertion position for clipboard objects.
Definition at line 966 of file cutop.cpp. 00967 { 00968 // Let's chuck in a smattering of defensive programming 00969 ERROR3IF(Spread == NULL || Position == NULL, "Illegal NULL params"); 00970 *Spread = NULL; 00971 *Position = DocCoord(0,0); // A default value if we fail 00972 00973 // --------------------------------------------------------------------------------- 00974 // Find out which spread is in the centre of the view 00975 // this is the spread that the pasted objects will be placed on 00976 00977 // Obtain the current DocView 00978 DocView* CurDocView = DocView::GetCurrent(); 00979 00980 ENSURE(CurDocView != NULL, "The current DocView is NULL"); 00981 if (CurDocView == NULL) 00982 { 00983 return FALSE; // No DocView 00984 } 00985 00986 // Get the view rect 00987 WorkRect WrkViewRect = CurDocView->GetViewRect(); 00988 00989 if (WrkViewRect.IsEmpty() || (!WrkViewRect.IsValid()) ) 00990 { 00991 return FALSE; // Defensive 00992 } 00993 00994 // Determine the centre of the view 00995 WorkCoord WrkCentreOfView; 00996 WrkCentreOfView.x = WrkViewRect.lo.x + (WrkViewRect.Width()/2); 00997 WrkCentreOfView.y = WrkViewRect.lo.y + (WrkViewRect.Height()/2); 00998 00999 // FindEnclosing spread requires an OilCoord 01000 OilCoord OilCentreOfView = WrkCentreOfView.ToOil(CurDocView->GetScrollOffsets()); 01001 01002 // Find out which spread to insert the pasteboard objects onto 01003 (*Spread) = CurDocView->FindEnclosingSpread(OilCentreOfView); 01004 if ((*Spread) == NULL) 01005 { 01006 // There is no spread 01007 return FALSE; 01008 } 01009 01010 // Phew 01011 // --------------------------------------------------------------------------------- 01012 // Now lets find the spread coordinate of the centre of the view 01013 DocRect DocViewRect = CurDocView->GetDocViewRect(*Spread); 01014 01015 if ( DocViewRect.IsEmpty() || (!DocViewRect.IsValid()) ) 01016 { 01017 ERROR3("DocViewRect is invalid"); 01018 return FALSE; // Defensive 01019 } 01020 01021 // Find the centre of the DocViewRect 01022 DocCoord DocCentreOfView; 01023 DocCentreOfView.x = DocViewRect.lo.x + (DocViewRect.Width()/2); 01024 DocCentreOfView.y = DocViewRect.lo.y + (DocViewRect.Height()/2); 01025 01026 // -------------------------------------------------------------------------------- 01027 // Now convert from DocCoords to spread coords 01028 (*Spread)->DocCoordToSpreadCoord(&DocCentreOfView); 01029 01030 // Finally, copy the result into the output parameter 01031 *Position = DocCentreOfView; 01032 01033 return TRUE; 01034 }
|
|
For finding OpPaste's state.
Reimplemented in OpTextPaste. Definition at line 808 of file cutop.cpp. 00809 { 00810 OpState OpSt; 00811 00812 if (InternalClipboard::IsEmpty()) 00813 { 00814 // There is no data to paste, so grey out, and return a reason for greying 00815 OpSt.Greyed = TRUE; 00816 *UIDescription = String_256(_R(IDS_CLIPBOARD_EMPTY)); 00817 } 00818 else 00819 { 00820 // Otherwise, determine a string to display - always show "Paste", but if possible 00821 // add a description, e.g. "Paste quickshape", "Paste bitmap" 00822 00823 String_64 Type; 00824 InternalClipboard::DescribeContents(&Type); 00825 if (!Type.IsEmpty() && pOpDesc->Token==String_256(OPTOKEN_PASTE)) 00826 { 00827 *UIDescription = String_256(_R(IDS_CLIPBOARD_PREPASTE)); 00828 *UIDescription += Type; 00829 } 00830 } 00831 return(OpSt); 00832 }
|
|
OpPaste initialiser method.
Reimplemented from SimpleCCObject. Reimplemented in OpTextPaste. Definition at line 749 of file cutop.cpp. 00750 { 00751 BOOL ok = (RegisterOpDescriptor(0, 00752 _R(IDS_PASTEOP), 00753 CC_RUNTIME_CLASS(OpPaste), 00754 OPTOKEN_PASTE, 00755 OpPaste::GetState, 00756 0, // help ID 00757 _R(IDBBL_PASTE), 00758 0, // bitmap ID 00759 0, 00760 SYSTEMBAR_ILLEGAL, // For now ! 00761 TRUE, // Receive messages 00762 FALSE, 00763 FALSE, 00764 0, 00765 (GREY_WHEN_NO_CURRENT_DOC | DONT_GREY_WHEN_SELECT_INSIDE) 00766 )); 00767 if (ok) 00768 { 00769 // Register a second OpDescriptor, for paste at same position. This OpDescriptor 00770 // will probably never appear directly on a bar/menu so it uses the same strings 00771 // as the above. 00772 ok = (RegisterOpDescriptor(0, 00773 _R(IDS_PASTEATSAMEPOSOP), 00774 CC_RUNTIME_CLASS(OpPaste), 00775 OPTOKEN_PASTEATSAMEPOS, 00776 OpPaste::GetState, 00777 0, // help ID 00778 _R(IDBBL_PASTEATSAMEPOS), 00779 _R(IDD_BARCONTROLSTORE), // resource ID 00780 _R(IDC_PASTEATSAMEPOS), // control ID 00781 SYSTEMBAR_EDIT, // Bar ID 00782 TRUE, // Receive messages 00783 FALSE, 00784 FALSE, 00785 0, 00786 (GREY_WHEN_NO_CURRENT_DOC | DONT_GREY_WHEN_SELECT_INSIDE) 00787 )); 00788 } 00789 00790 return ok; 00791 }
|
|
Remove set information from pasted attributes if that name would interfere with stretching if added... Notes: Made static so that it can also be used by the PasteAttributes operation.
Definition at line 1299 of file cutop.cpp. 01300 { 01301 // try only removing names that has anything to do with extending 01302 String_256 Temp = SliceHelper::GetBarName((TemplateAttribute *)pAttrib); 01303 // is it a bar element? 01304 BOOL ok = Temp.IsEmpty(); 01305 SGNameItem* pGalleryItem = NULL; 01306 if (ok) 01307 { 01308 Temp = ((TemplateAttribute *)pAttrib)->GetParam(); 01309 pGalleryItem = SliceHelper::LookupNameGalleryItem(Temp); 01310 if (pGalleryItem) 01311 { 01312 // is it a trigger? 01313 if (pGalleryItem->m_IsATrigger == TRUE) // use == TRUE since it is often undefined 01314 ok = FALSE; 01315 else 01316 { 01317 // is it a target? 01318 NamedStretchProp* pProp = (NamedStretchProp*)pGalleryItem->GetProperty(NamedStretchProp::nIndex); 01319 if (pProp && !pProp->GetTriggers().empty()) 01320 ok = FALSE; 01321 } 01322 } 01323 else 01324 { 01325 // create a default property for a new set 01326 SliceHelper::CreatePropertiesForSet(Temp, 01327 TEXT(""), 01328 TRUE, FALSE, FALSE, 0, 01329 TEXT(""), TRUE, NULL, NULL, pOp); 01330 } 01331 } 01332 01333 return ok; 01334 }
|