#include <cutop.h>
Inheritance diagram for OpPasteAttributes:
Public Member Functions | |
OpPasteAttributes () | |
OpPasteAttributesAttributes constructor. | |
void | Do (OpDescriptor *) |
Performs the PasteAttributes operation. | |
Static Public Member Functions | |
static BOOL | Init () |
OpPasteAttributes initialiser method. | |
static OpState | GetState (String_256 *, OpDescriptor *) |
For finding OpPasteAttributes's state. |
Definition at line 251 of file cutop.h.
|
OpPasteAttributesAttributes constructor.
Definition at line 2633 of file cutop.cpp. 02633 : SelOperation() 02634 { 02635 }
|
|
Performs the PasteAttributes operation.
Reimplemented from Operation. Definition at line 2773 of file cutop.cpp. 02774 { 02775 BOOL ok = TRUE; // Until something goes wrong 02776 InternalClipboard* pSrcDoc = InternalClipboard::Instance(); 02777 Document* pDestDoc = GetWorkingDoc(); 02778 02779 02780 // Start the op in the usual way 02781 DoStartSelOp(FALSE, FALSE, TRUE, TRUE); 02782 02783 // Obtain a set of common attribute values for all attribute types 02784 // remember these values are cached 02785 Range* pClipboardRange = InternalClipboard::GetClipboardRange(); 02786 if (!pClipboardRange) 02787 { 02788 ok = FALSE; 02789 } 02790 02791 CommonAttrSet CommonAttrs; 02792 02793 if (ok) 02794 { 02795 if (!pClipboardRange->FindCommonAttributes(&CommonAttrs, TRUE ) ) 02796 { 02797 // Our GetState fn will have greyed the op if there were no common attributes 02798 ok = FALSE; 02799 } 02800 } 02801 02802 if (ok) 02803 { 02804 ERROR3IF(CommonAttrs.IsEmpty(), "Empty CommonAttribute set in OpPasteAttributes::Do"); 02805 02806 // We will require the bounds of all objects on the clipboard to scale AttrFillGeometry 02807 // attributes. 02808 DocRect ClipBounds = pClipboardRange->GetBoundingRect(); 02809 02810 // Create a list of attributes to apply 02811 List AttribsToApply; 02812 NodeAttributePtrItem* pAttrToApplyItem; 02813 NodeAttribute* pAttr; 02814 CommonAttributeItem* pAttrItem; 02815 // For each item in the common attribute set 02816 //TRACE( _T("Attributes being applied\n\n")); 02817 02818 for (pAttrItem = (CommonAttributeItem*)(CommonAttrs.GetHead()); 02819 pAttrItem; 02820 pAttrItem = (CommonAttributeItem*)(CommonAttrs.GetNext(pAttrItem))) 02821 { 02822 pAttr = pAttrItem->pAttr; 02823 if (pAttrItem->Status == Range::ATTR_COMMON && pAttr) 02824 { 02825 // Ask the attribute if it wants to be applied. 02826 if (pAttr->CanBeAppliedToObject()) 02827 { 02828 // DEBUG 02829 //TRACE( _T("%s \n"), pAttrItem->AttrType->m_lpszClassName); 02830 // This attribute is common. Add it to the list of attributes to apply 02831 pAttrToApplyItem = new NodeAttributePtrItem; 02832 if (pAttrToApplyItem) 02833 { 02834 // We need to make a copy of the attribute because it's component data 02835 // will soon be in the document we are pasting into. 02836 NodeAttribute* pAttribClone = (NodeAttribute*)(pAttr->SimpleCopy()); 02837 if (pAttribClone) 02838 { 02839 if (!pAttribClone->IsAnObjectName() || OpPaste::RemoveNamesAlreadyUsedInStretching(pAttribClone, (UndoableOperation *)this)) 02840 { 02841 AttribsToApply.AddHead(pAttrToApplyItem); 02842 02843 pAttrToApplyItem->NodeAttribPtr = pAttribClone; 02844 02845 if (pAttribClone->IsAFillAttr()) 02846 { 02847 // Set the bounds of the attribute. This is of course the bounds 02848 // of the clipboard objects. 02849 ((AttrFillGeometry*)pAttribClone)->SetBoundingRect(ClipBounds); 02850 } 02851 02852 // I'm not sure if this is neccessary but Will does it when making an attribute 02853 // current. 02854 if (pAttribClone->IsAFractalFill()) 02855 { 02856 // The attr, should always use the default DPI for fractals. 02857 ((AttrFillGeometry*)pAttribClone)->SetFractalDPI(AttrFillGeometry::FractalDPI); 02858 } 02859 } 02860 } 02861 else 02862 ok = FALSE; 02863 } 02864 else 02865 ok = FALSE; 02866 } 02867 } 02868 } 02869 02870 if (ok) 02871 { 02872 // Copy the component data from all attributes before we try to apply them. 02873 // (this is the safest way). 02874 // Inform all DocComponents in the destination doc that a copy is about to take place 02875 BOOL ok; 02876 CALL_WITH_FAIL((pDestDoc->StartComponentCopy()),this, ok) 02877 if (ok) 02878 { 02879 // Now ask all attributes to copy accross their component data 02880 NodeAttributePtrItem* pAttrItem = (NodeAttributePtrItem*)AttribsToApply.GetHead(); 02881 while (pAttrItem && ok) 02882 { 02883 NodeAttribute* pAttr = pAttrItem->NodeAttribPtr; 02884 ERROR3IF(pAttr == NULL, "Where has our attribute gone ??"); 02885 if (!pAttr->CopyComponentData(pSrcDoc, pDestDoc)) 02886 { 02887 pDestDoc->AbortComponentCopy(); // Cancel all data which has been copied 02888 ok = FALSE; // stop what were doing 02889 } 02890 pAttrItem = (NodeAttributePtrItem*)AttribsToApply.GetNext(pAttrItem); 02891 } 02892 if (ok) 02893 ok = pDestDoc->EndComponentCopy(); 02894 } 02895 } 02896 02897 if (ok) 02898 { 02899 // This fn will invoke an operation to apply the attributes to the selection. 02900 02901 // DMc - change the range to include parents 02902 // This is inconsistent with all other apply operations 02903 // So don't do it! 02904 // SelRange * pSel = GetApplication()->FindSelection(); 02905 // RangeControl rg = pSel->GetRangeControlFlags(); 02906 // rg.PromoteToParent = TRUE; 02907 // pSel->Range::SetRangeControl(rg); 02908 02909 // Do the attribute application, adding actions to this op 02910 // AttributeManager::AttributesSelected(AttribsToApply, _R(IDS_PASTE_ATTRIBUTES)); 02911 DoAttributesSelected(AttribsToApply, _R(IDS_PASTE_ATTRIBUTES), TRUE); 02912 02913 // rg.PromoteToParent = FALSE; 02914 // pSel->Range::SetRangeControl(rg); 02915 } 02916 02917 { 02918 // We don't need the list of attrs anymore 02919 NodeAttributePtrItem* pAttrItem = (NodeAttributePtrItem*)AttribsToApply.GetHead(); 02920 while (pAttrItem) 02921 { 02922 delete (pAttrItem->NodeAttribPtr); 02923 pAttrItem->NodeAttribPtr = NULL; 02924 pAttrItem = (NodeAttributePtrItem*)AttribsToApply.GetNext(pAttrItem); 02925 } 02926 AttribsToApply.DeleteAll(); // tidyup 02927 } 02928 } 02929 02930 // --------------------------------------------------------------------------- 02931 // Now do the LiveEffects 02932 if (pClipboardRange && ok) 02933 { 02934 Range* pTempRange = new Range(*pClipboardRange); 02935 ENSURE(pTempRange!=NULL, "OpPasteAttributes::Do couldn't allocate memory for Range\n"); 02936 if (pTempRange) 02937 { 02938 RangeControl rg = pTempRange->GetRangeControlFlags(); 02939 rg.PromoteToParent = FALSE; 02940 pTempRange->SetRangeControl(rg); 02941 02942 EffectsStack* pEffectsStack = EffectsStack::GetEffectsStackFromSelection(pTempRange, TRUE, TRUE); // Include locked effects 02943 if (pEffectsStack!=NULL && !pEffectsStack->IsEmpty()) 02944 { 02945 PORTNOTE("effects", "Call to DoCopyPPStackToSelection removed from OpPasteAttributes") 02946 #ifndef EXCLUDE_FROM_XARALX 02947 // Do the effect stack copy, adding actions to this op 02948 OpLiveEffect::DoCopyPPStackToSelection(this, pEffectsStack, pSrcDoc, pDestDoc); 02949 #endif 02950 } 02951 if (pEffectsStack) 02952 delete pEffectsStack; 02953 02954 delete pTempRange; 02955 } 02956 } 02957 02958 End(); 02959 }
|
|
For finding OpPasteAttributes's state.
Definition at line 2692 of file cutop.cpp. 02693 { 02694 OpState OpSt; 02695 // Greyed if the clipboard is empty 02696 if (InternalClipboard::IsEmpty(FALSE)) // Only look at internal clipboard 02697 { 02698 OpSt.Greyed = TRUE; 02699 // Determine if the External clipboard is empty 02700 if (InternalClipboard::IsEmpty(TRUE)) 02701 { 02702 // There is no data on either the Internal or external clipboards. 02703 // tell the user that the clipboard is empty 02704 *UIDescription = String_256(_R(IDS_CLIPBOARD_EMPTY)); 02705 } 02706 else 02707 { 02708 // There is data on the external clipboard. 02709 // We can't paste attributes until the user has done a paste 02710 *UIDescription = String_256(_R(IDS_EXTERNAL_CLIP_OBJECTS)); 02711 } 02712 } 02713 else 02714 { 02715 // There is data on the internal clipboard 02716 // Are there any common attributes 02717 BOOL CommonAttrsExist = FALSE; 02718 BOOL bCommonLEsExist = FALSE; 02719 Range* pClipboardRange = InternalClipboard::GetClipboardRange(); 02720 // Finds all common attributes. Remember common attributes are cached 02721 if (pClipboardRange) 02722 { 02723 CommonAttrSet CommonAttrs; 02724 if( pClipboardRange->FindCommonAttributes(&CommonAttrs , TRUE ) ) 02725 { 02726 if (CommonAttrs.IsAnyItemCommon()) 02727 CommonAttrsExist = TRUE; 02728 } 02729 } 02730 02731 // Check for LiveEffects 02732 if (pClipboardRange) 02733 { 02734 Range* pTempRange = new Range(*pClipboardRange); 02735 ENSURE(pTempRange!=NULL, "OpPasteAttributes::Do couldn't allocate memory for Range\n"); 02736 if (pTempRange) 02737 { 02738 RangeControl rg = pTempRange->GetRangeControlFlags(); 02739 rg.PromoteToParent = FALSE; 02740 pTempRange->SetRangeControl(rg); 02741 02742 EffectsStack* pEffectsStack = EffectsStack::GetEffectsStackFromSelection(pTempRange, TRUE, TRUE); // Include locked effects in this stack 02743 bCommonLEsExist = (pEffectsStack!=NULL && pEffectsStack->LockableNonEmpty()); 02744 if (pEffectsStack) 02745 delete pEffectsStack; 02746 } 02747 delete pTempRange; 02748 } 02749 02750 if (!CommonAttrsExist && !bCommonLEsExist) 02751 { 02752 OpSt.Greyed = TRUE; 02753 // The objects on the clipboard share no common attributes. Report this to the user 02754 *UIDescription = String_256(_R(IDS_NO_COMMON_CLIP_ATTRS)); 02755 } 02756 } 02757 return(OpSt); 02758 }
|
|
OpPasteAttributes initialiser method.
Reimplemented from SimpleCCObject. Definition at line 2655 of file cutop.cpp. 02656 { 02657 BOOL ok = RegisterOpDescriptor(0, 02658 _R(IDS_PASTEATTRIBUTESOP), 02659 CC_RUNTIME_CLASS(OpPasteAttributes), 02660 OPTOKEN_PASTEATTRIBUTES, 02661 OpPasteAttributes::GetState, 02662 0, // help ID 02663 _R(IDBBL_PASTEATTRIBUTES), 02664 0, // bitmap ID 02665 0, 02666 SYSTEMBAR_ILLEGAL, // For now ! 02667 TRUE, // Receive messages 02668 FALSE, 02669 FALSE, 02670 0, 02671 (GREY_WHEN_NO_CURRENT_DOC | DONT_GREY_WHEN_SELECT_INSIDE) 02672 ); 02673 02674 return ok; 02675 }
|