00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 #include "camtypes.h"
00103 #include "opliveeffects.h"
00104
00105 #include "nodeliveeffect.h"
00106 #include "mainfrm.h"
00107
00108 #include "xpehost.h"
00109 #include "progress.h"
00110 #include "liveeffectstool.h"
00111
00112
00113
00114 #include "nodecont.h"
00115 #include "opshadow.h"
00116 #include "nodeshad.h"
00117 #include "grnddib.h"
00118 #include "fthrattr.h"
00119 #include "opfeathr.h"
00120
00121 #include "contmenu.h"
00122 #include "shadtool.h"
00123 #include "objchge.h"
00124 #include "effects_stack.h"
00125
00126
00127 CC_IMPLEMENT_DYNAMIC(OpLiveEffectParam, OpMenuParam);
00128 CC_IMPLEMENT_DYNCREATE(OpLiveEffect, SelOperation);
00129 CC_IMPLEMENT_DYNCREATE(OpApplyLiveEffect, OpLiveEffect);
00130 CC_IMPLEMENT_DYNCREATE(OpEditLiveEffect, OpLiveEffect);
00131 CC_IMPLEMENT_DYNCREATE(OpDeleteLiveEffect, OpLiveEffect);
00132 CC_IMPLEMENT_DYNCREATE(OpDeleteAllLiveEffect, OpLiveEffect);
00133 CC_IMPLEMENT_DYNCREATE(OpEffectRes, OpLiveEffect);
00134 CC_IMPLEMENT_DYNCREATE(OpEffectLock, OpLiveEffect);
00135 CC_IMPLEMENT_DYNCREATE(OpEffectLockAll, OpEffectLock);
00136 CC_IMPLEMENT_DYNCREATE(OpEditLegacyEffect, Operation);
00137 CC_IMPLEMENT_DYNCREATE(MarkEditListAction, Action);
00138 CC_IMPLEMENT_DYNCREATE(ChangeEffectResAction, Action);
00139
00140
00141 #ifdef FEATHER_EFFECT
00142 CC_IMPLEMENT_DYNAMIC(OpFeatherEffectParam, OpLiveEffectParam);
00143 CC_IMPLEMENT_DYNCREATE(OpApplyFeatherEffect, OpLiveEffect);
00144 #endif
00145
00146 DECLARE_SOURCE("$Revision: 1282 $");
00147
00148 #define new CAM_DEBUG_NEW
00149
00150
00151
00152
00154
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 OpLiveEffect::OpLiveEffect()
00169 {
00170 m_pLERange=NULL;
00171 m_bAppliedNewEffects = FALSE;
00172 m_iStackPos = 0;
00173 m_bPreviewQuality = FALSE;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 OpLiveEffect::~OpLiveEffect()
00190 {
00191 if (m_pLERange)
00192 {
00193 delete m_pLERange;
00194 m_pLERange = NULL;
00195 }
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 BOOL OpLiveEffect::Init()
00215 {
00216 BOOL bOK = TRUE;
00217
00218
00219 ParamOpDescriptor* pOD = NULL;
00220 pOD = new ParamOpDescriptor(OPTOKEN_APPLY_LIVEEFFECT,
00221 CC_RUNTIME_CLASS(OpApplyLiveEffect),
00222 OpApplyLiveEffect::GetParamState);
00223 bOK = bOK && (pOD!=NULL);
00224
00225 pOD = new ParamOpDescriptor(OPTOKEN_EDIT_LIVEEFFECT,
00226 CC_RUNTIME_CLASS(OpEditLiveEffect),
00227 OpEditLiveEffect::GetParamState);
00228 bOK = bOK && (pOD!=NULL);
00229
00230 pOD = new ParamOpDescriptor(OPTOKEN_EDIT_LEGACYEFFECT,
00231 CC_RUNTIME_CLASS(OpEditLegacyEffect),
00232 OpEditLegacyEffect::GetParamState);
00233 bOK = bOK && (pOD!=NULL);
00234
00235 #ifdef FEATHER_EFFECT
00236 pOD = new ParamOpDescriptor(OPTOKEN_APPLY_FEATHEREFFECT,
00237 CC_RUNTIME_CLASS(OpApplyFeatherEffect),
00238 OpApplyFeatherEffect::GetParamState);
00239 bOK = bOK && (pOD!=NULL);
00240 #endif
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 bOK = bOK && RegisterOpDescriptor(0,
00260 _R(IDS_DELETE_LIVEEFFECT),
00261 CC_RUNTIME_CLASS(OpDeleteLiveEffect),
00262 OPTOKEN_DELETE_LIVEEFFECT,
00263 OpDeleteLiveEffect::GetState,
00264 0,
00265 _R(IDBBL_DELETE_LIVEEFFECT),
00266 0,
00267 0,
00268 SYSTEMBAR_ILLEGAL,
00269 TRUE,
00270 FALSE,
00271 FALSE,
00272 0,
00273 GREY_WHEN_NO_CURRENT_DOC |
00274 DONT_GREY_WHEN_SELECT_INSIDE);
00275
00276 bOK = bOK && RegisterOpDescriptor(0,
00277 _R(IDS_DELETEALL_LIVEEFFECT),
00278 CC_RUNTIME_CLASS(OpDeleteAllLiveEffect),
00279 OPTOKEN_DELETEALL_LIVEEFFECT,
00280 OpDeleteAllLiveEffect::GetState,
00281 0,
00282 _R(IDBBL_DELETEALL_LIVEEFFECT),
00283 0,
00284 0,
00285 SYSTEMBAR_ILLEGAL,
00286 TRUE,
00287 FALSE,
00288 FALSE,
00289 0,
00290 GREY_WHEN_NO_CURRENT_DOC |
00291 DONT_GREY_WHEN_SELECT_INSIDE);
00292
00293 bOK = bOK && RegisterOpDescriptor(0,
00294 _R(IDS_CHANGE_EFFECT_RES),
00295 CC_RUNTIME_CLASS(OpEffectRes),
00296 OPTOKEN_CHANGE_EFFECT_RES,
00297 OpEffectRes::GetState,
00298 0,
00299 _R(IDBBL_CHANGE_EFFECT_RES),
00300 0,
00301 0,
00302 SYSTEMBAR_ILLEGAL,
00303 TRUE,
00304 FALSE,
00305 FALSE,
00306 0,
00307 GREY_WHEN_NO_CURRENT_DOC |
00308 DONT_GREY_WHEN_SELECT_INSIDE);
00309
00310 bOK = bOK && RegisterOpDescriptor(0,
00311 _R(IDS_CHANGE_EFFECT_LOCK),
00312 CC_RUNTIME_CLASS(OpEffectLock),
00313 OPTOKEN_CHANGE_EFFECT_LOCK,
00314 OpEffectLock::GetState,
00315 0,
00316 _R(IDBBL_CHANGE_EFFECT_LOCK),
00317 0,
00318 0,
00319 SYSTEMBAR_ILLEGAL,
00320 TRUE,
00321 FALSE,
00322 FALSE,
00323 0,
00324 GREY_WHEN_NO_CURRENT_DOC |
00325 DONT_GREY_WHEN_SELECT_INSIDE);
00326
00327 bOK = bOK && RegisterOpDescriptor(0,
00328 _R(IDS_CHANGE_EFFECT_LOCKALL),
00329 CC_RUNTIME_CLASS(OpEffectLockAll),
00330 OPTOKEN_CHANGE_EFFECT_LOCKALL,
00331 OpEffectLockAll::GetState,
00332 0,
00333 _R(IDBBL_CHANGE_EFFECT_LOCKALL),
00334 0,
00335 0,
00336 SYSTEMBAR_ILLEGAL,
00337 TRUE,
00338 FALSE,
00339 FALSE,
00340 0,
00341 GREY_WHEN_NO_CURRENT_DOC |
00342 DONT_GREY_WHEN_SELECT_INSIDE);
00343
00344 return bOK;
00345 }
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365 ListRange* OpLiveEffect::DoApplyLiveEffect(Range* pSel, String_256 strEffectID, String_64 strDisplayName, double dResolution, IXMLDOMDocumentPtr pEditsList, BOOL bMakeLocked, BOOL bDetectDirectBitmaps)
00366 {
00367 ENSURE(pSel, "DoApplyLiveEffect not given a useful range");
00368 ENSURE(strEffectID!=String(""), "DoApplyLiveEffect given blank effect name string");
00369
00370 ListRange* pLERange = new ListRange();
00371 ENSURE(pLERange, "DoApplyEffect can't create a ListRange");
00372 if (pLERange==NULL)
00373 return NULL;
00374
00375 Node* pNode = pSel->FindFirst();
00376 while (pNode)
00377 {
00378
00379
00380 NodeBitmapEffect* pBmpFXNode = NULL;
00381 pBmpFXNode = DoApplyLiveEffect(this, pNode, strEffectID, strDisplayName, dResolution, pEditsList, bMakeLocked);
00382
00383 if (pBmpFXNode)
00384 {
00385
00386
00387 if (bDetectDirectBitmaps &&
00388 pNode->IsAnObject() &&
00389 ((NodeRenderableInk*)pNode)->CanSupplyDirectBitmap() &&
00390 dResolution != 0
00391 )
00392 {
00393
00394
00395 pBmpFXNode->SetPixelsPerInch(0);
00396
00397
00398
00399
00400
00401 if (!pBmpFXNode->EnableDirectCapture())
00402 pBmpFXNode->SetPixelsPerInch(dResolution);
00403 }
00404
00405
00406
00407 ((NodeRenderable*)pNode)->DeSelect(FALSE);
00408 pBmpFXNode->Select(FALSE);
00409
00410 pLERange->AddNode(pBmpFXNode);
00411
00412
00413 BOOL ok = DoFactorOutCommonChildAttributes(pBmpFXNode);
00414 if (!ok)
00415 pBmpFXNode = NULL;
00416 }
00417
00418 if (!pBmpFXNode)
00419 {
00420 if (pLERange->FindFirst()==NULL)
00421 {
00422
00423 delete pLERange;
00424 pLERange = NULL;
00425 }
00426 return pLERange;
00427 }
00428
00429 pNode = pSel->FindNext(pNode);
00430 }
00431
00432 if (pLERange->FindFirst()==NULL)
00433 {
00434
00435 delete pLERange;
00436 pLERange = NULL;
00437 }
00438
00439 return pLERange;
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 NodeBitmapEffect* OpLiveEffect::DoApplyLiveEffect(UndoableOperation* pOp,
00470 Node* pNode,
00471 String_256 strEffectID,
00472 String_64 strDisplayName,
00473 double dResolution,
00474 IXMLDOMDocumentPtr pEditsList,
00475 BOOL bMakeLocked)
00476 {
00477 ERROR2IF(pOp==NULL, NULL, "Missing Op pointer");
00478 ERROR2IF(pNode==NULL, NULL, "Missing Node pointer");
00479 ERROR2IF(strEffectID==String(""), NULL, "DoApplyLiveEffect given blank effect name string");
00480 ERROR2IF(strDisplayName==String(""), NULL, "DoApplyLiveEffect given blank display name string");
00481
00482 BOOL bSelectInside = pNode->IsSelected() || pNode->IsParentOfSelected();
00483
00484
00485
00486
00487
00488
00489
00490 NodeBitmapEffect* pBmpFXNode = NULL;
00491 if (bMakeLocked)
00492 {
00493 ALLOC_WITH_FAIL(pBmpFXNode, new NodeLockedEffect, pOp);
00494 }
00495 else
00496 {
00497 ALLOC_WITH_FAIL(pBmpFXNode, new NodeLiveEffect, pOp);
00498 }
00499 if (pBmpFXNode==NULL)
00500 return NULL;
00501
00502
00503
00504 BOOL bDestructive = FALSE;
00505 XPEHost::GetEffectDetails(strEffectID, &strDisplayName, &bDestructive);
00506 ERROR3IF(bDestructive, "DoApplyLiveEffect asked to apply destructive effect!!!");
00507 if (bDestructive)
00508 return NULL;
00509
00510
00511 pBmpFXNode->SetPostProcessorID(strEffectID);
00512 pBmpFXNode->SetDisplayName(strDisplayName);
00513 pBmpFXNode->SetPixelsPerInch(dResolution);
00514 if (pEditsList)
00515 {
00516 pBmpFXNode->SetEditList(pEditsList);
00517 }
00518 else if (!pBmpFXNode->SetDefaultEditList())
00519 {
00520 return NULL;
00521 }
00522
00523 if (pBmpFXNode->IsLockedEffect())
00524 ((NodeLockedEffect*)pBmpFXNode)->SetLockPermanence(bDestructive);
00525
00526
00527
00528 HideNodeAction* pUndoHideNodeAction = NULL;
00529 ActionCode ac = HideNodeAction::Init(pOp,
00530 pOp->GetUndoActionList(),
00531 pBmpFXNode,
00532 FALSE,
00533 (Action**)&pUndoHideNodeAction,
00534 FALSE);
00535 if (ac == AC_FAIL)
00536 return NULL;
00537
00538
00539
00540 pBmpFXNode->AttachNode(pNode, NEXT);
00541
00542
00543 BOOL ok = pOp->DoMoveNode(pNode, pBmpFXNode, FIRSTCHILD);
00544 if (!ok)
00545 return NULL;
00546
00547
00548
00549 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
00550 ObjChangeParam ObjChange(OBJCHANGE_STARTING, cFlags, NULL, pOp);
00551 pBmpFXNode->AllowOp(&ObjChange);
00552
00553
00554
00555
00556
00557
00558 return pBmpFXNode;
00559 }
00560
00561
00562
00563
00564 #ifdef FEATHER_EFFECT
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585 ListRange* OpLiveEffect::DoApplyFeatherEffect(UndoableOperation* pOp,
00586 Range* pSel,
00587 String_256 strEffectID,
00588 String_64 strDisplayName,
00589 MILLIPOINT FeatherSize,
00590 CProfileBiasGain Profile)
00591 {
00592 ENSURE(pSel, "DoApplyFeatherEffect not given a useful range");
00593 ENSURE(strEffectID!=String(""), "DoApplyFeatherEffect given blank effect name string");
00594
00595 ListRange* pLERange = new ListRange();
00596 ENSURE(pLERange, "DoApplyEffect can't create a ListRange");
00597 if (pLERange==NULL)
00598 return NULL;
00599
00600 Node* pNode = pSel->FindFirst();
00601 BOOL bOK = TRUE;
00602 while (pNode && bOK)
00603 {
00604 NodeFeatherEffect* pEffect = DoApplyFeatherEffectNode(pOp, pNode, strEffectID, strDisplayName, FeatherSize, Profile);
00605 if (pEffect)
00606 {
00607 pLERange->AddNode(pEffect);
00608
00609
00610 bOK = pOp->DoFactorOutCommonChildAttributes(pEffect);
00611 }
00612 else
00613 bOK = FALSE;
00614
00615 pNode = pSel->FindNext(pNode);
00616 }
00617
00618 if (pLERange->FindFirst()==NULL || bOK==FALSE)
00619 {
00620
00621 delete pLERange;
00622 pLERange = NULL;
00623 }
00624
00625 return pLERange;
00626 }
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650 NodeFeatherEffect* OpLiveEffect::DoApplyFeatherEffectNode(UndoableOperation* pOp,
00651 Node* pNode,
00652 String_256 strEffectID,
00653 String_64 strDisplayName,
00654 MILLIPOINT FeatherSize,
00655 CProfileBiasGain Profile)
00656 {
00657 ENSURE(pNode, "DoApplyFeatherEffectNode not given a useful node");
00658 ENSURE(strEffectID!=String(""), "DoApplyFeatherEffectNode given blank effect name string");
00659
00660 BOOL bSelectInside = pNode->IsSelected() || pNode->IsParentOfSelected();
00661
00662
00663
00664 NodeFeatherEffect* pBmpFXNode = NULL;
00665 ALLOC_WITH_FAIL(pBmpFXNode, new NodeFeatherEffect, pOp);
00666 if (pBmpFXNode == NULL)
00667 return NULL;
00668
00669
00670
00671 pBmpFXNode->SetPostProcessorID(strEffectID);
00672 pBmpFXNode->SetDisplayName(strDisplayName);
00673 pBmpFXNode->m_FeatherSize = FeatherSize;
00674 pBmpFXNode->m_Profile = Profile;
00675
00676 HideNodeAction* pUndoHideNodeAction = NULL;
00677 ActionCode ac = HideNodeAction::Init(pOp,
00678 pOp->GetUndoActions(),
00679 pBmpFXNode,
00680 FALSE,
00681 (Action**)&pUndoHideNodeAction,
00682 FALSE);
00683 if (ac == AC_FAIL)
00684 {
00685 delete pBmpFXNode;
00686 return NULL;
00687 }
00688
00689
00690
00691 pBmpFXNode->AttachNode(pNode, NEXT);
00692
00693
00694 BOOL bOK = pOp->DoMoveNode(pNode, pBmpFXNode, FIRSTCHILD);
00695 if (!bOK)
00696 return NULL;
00697
00698
00699 ((NodeRenderable*)pNode)->DeSelect(FALSE);
00700 pBmpFXNode->Select(FALSE);
00701
00702
00703
00704 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
00705 ObjChangeParam ObjChange(OBJCHANGE_STARTING, cFlags, NULL, pOp);
00706 pBmpFXNode->AllowOp(&ObjChange);
00707
00708 return pBmpFXNode;
00709 }
00710 #endif
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 ListRange* OpLiveEffect::DoApplyLockedEffect(Range* pSel,
00738 String_256 strEffectID,
00739 String_64 strDisplayName,
00740 double dResolution,
00741 IXMLDOMDocumentPtr pEditsList,
00742 BOOL bDetectDirectBitmaps)
00743 {
00744 ENSURE(pSel, "DoApplyLockedEffect not given a useful range");
00745 ENSURE(strEffectID!=String(""), "DoApplyLockedEffect given blank effect name string");
00746
00747 ListRange* pLERange = new ListRange();
00748 ENSURE(pLERange, "DoApplyEffect can't create a ListRange");
00749 if (pLERange==NULL)
00750 return NULL;
00751
00752
00753
00754 Node* pFirstNode = pSel->FindFirst();
00755 Node* pNode = pFirstNode;
00756 Node* pLastNode = NULL;
00757 while (pNode != NULL)
00758 {
00759 pLastNode = pNode;
00760 pNode = pSel->FindNext(pLastNode);
00761 }
00762
00763
00764
00765 NodeLockedEffect* pBmpFXNode = NULL;
00766 ALLOC_WITH_FAIL(pBmpFXNode, new NodeLockedEffect, this);
00767 BOOL ok = (pBmpFXNode != NULL);
00768
00769 if (ok)
00770 {
00771
00772
00773
00774 BOOL bDestructive = TRUE;
00775 XPEHost::GetEffectDetails(strEffectID, &strDisplayName, &bDestructive);
00776
00777 pBmpFXNode->SetPostProcessorID(strEffectID);
00778 pBmpFXNode->SetDisplayName(strDisplayName);
00779 pBmpFXNode->SetPixelsPerInch(dResolution);
00780 if (pEditsList)
00781 {
00782 pBmpFXNode->SetEditList(pEditsList);
00783 }
00784 else if (!pBmpFXNode->SetDefaultEditList())
00785 {
00786 delete pBmpFXNode;
00787
00788
00789 delete pLERange;
00790 pLERange = NULL;
00791 return pLERange;
00792 }
00793 pBmpFXNode->SetLockPermanence(bDestructive);
00794
00795
00796
00797 HideNodeAction* pUndoHideNodeAction = NULL;
00798 ActionCode ac = HideNodeAction::Init(this,
00799 &UndoActions,
00800 pBmpFXNode,
00801 FALSE,
00802 (Action**)&pUndoHideNodeAction,
00803 FALSE);
00804 if (ac == AC_FAIL)
00805 {
00806 delete pBmpFXNode;
00807
00808
00809 delete pLERange;
00810 pLERange = NULL;
00811 return pLERange;
00812 }
00813 else
00814 {
00815
00816
00817 pBmpFXNode->AttachNode(pLastNode, NEXT);
00818 pLERange->AddNode(pBmpFXNode);
00819 }
00820 }
00821
00822
00823
00824
00825
00826 if (ok)
00827 {
00828 pNode = pSel->FindNext(pFirstNode);
00829
00830
00831
00832
00833 ok = DoMoveNode(pFirstNode, pBmpFXNode, FIRSTCHILD);
00834 if (ok)
00835 ((NodeRenderable*)pFirstNode)->DeSelect(FALSE, TRUE);
00836 }
00837
00838 Node* pNextNode = NULL;
00839 Node* pAnchorNode = pFirstNode;
00840 while (ok && pNode != NULL)
00841 {
00842
00843 pNextNode = pSel->FindNext(pNode);
00844
00845
00846
00847
00848
00849 ok = DoMoveNode(pNode, pAnchorNode, NEXT);
00850 if (ok)
00851 ((NodeRenderable*)pNode)->DeSelect(FALSE, TRUE);
00852
00853
00854 pAnchorNode = pNode;
00855 pNode = pNextNode;
00856 }
00857
00858
00859
00860 NodeRenderableInk* pInkNode = pBmpFXNode->GetInkNodeFromController();
00861 if (bDetectDirectBitmaps &&
00862 pInkNode &&
00863 pInkNode->CanSupplyDirectBitmap()
00864 )
00865 {
00866
00867
00868 double dDirectRes = 0;
00869 pInkNode->GetDirectBitmap(NULL, NULL, NULL, NULL, NULL, &dDirectRes);
00870 if (dDirectRes!=0)
00871 {
00872 pBmpFXNode->SetPixelsPerInch(dDirectRes);
00873
00874
00875
00876
00877
00878 if (!pBmpFXNode->EnableDirectCapture())
00879 pBmpFXNode->SetPixelsPerInch(dResolution);
00880 }
00881 }
00882
00883 if (ok)
00884 {
00885
00886 pBmpFXNode->Select(FALSE);
00887
00888
00889 DoFactorOutCommonChildAttributes(pBmpFXNode);
00890
00891
00892
00893 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
00894 ObjChangeParam ObjChange(OBJCHANGE_STARTING, cFlags, NULL, this);
00895 pBmpFXNode->AllowOp(&ObjChange);
00896 }
00897
00898 if (pLERange->FindFirst()==NULL)
00899 {
00900
00901 delete pLERange;
00902 pLERange = NULL;
00903 }
00904
00905 return pLERange;
00906 }
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926 BOOL OpLiveEffect::IsTopOfStack(EffectsStack* pPPStack, INT32 iStackPos)
00927 {
00928 return (iStackPos>=(INT32)pPPStack->GetCount());
00929 }
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949 BOOL OpLiveEffect::EnsureLiveEffectOriginalBitmaps()
00950 {
00951 if (m_pLERange==NULL)
00952 return TRUE;
00953
00954 BOOL bRenderingNeeded = FALSE;
00955 DocView* pDocView = DocView::GetSelected();
00956
00957 bRenderingNeeded = FALSE;
00958 Node* pNode = m_pLERange->FindFirst();
00959 while (pNode)
00960 {
00961 ENSURE(pNode->IsBitmapEffect(), "LiveEffects list contains non-LiveEffect in EnsureLiveEffectOriginalBitmaps");
00962 NodeBitmapEffect* pLE = (NodeBitmapEffect*)pNode;
00963 if (!pLE->GetOriginalBitmap(NULL, NULL, NULL) && pLE->CanGenerateBitmap())
00964 {
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 pLE->ReleaseCached(TRUE, FALSE);
00985
00986
00987
00988 if (pLE->IsLockedEffect())
00989 pLE->SetProcessedBitmap(NULL, NULL, DocRect(), 0, 0, 0, 0);
00990
00991 View* pView = View::GetCurrent();
00992 Spread* pSpread = Document::GetSelectedSpread();
00993 Matrix Mat = pView->ConstructScaledRenderingMatrix(pSpread, 1.0);
00994 FIXED16 Scale;
00995 Mat.Decompose(&Scale);
00996 double dpi = 0.0;
00997 GRenderDIB* pNewGRR = new GRenderDIB(pLE->GetBoundingRect(), Mat, Scale, 32, dpi);
00998 ERROR2IF(pNewGRR == NULL, FALSE, "Failed to create a GRenderDIB!");
00999
01000
01001 if (!pNewGRR->AttachDevice(pView, NULL, pSpread))
01002 {
01003 ERROR3("Cannot attach devices");
01004
01005 delete pNewGRR;
01006 pNewGRR = NULL;
01007
01008 return FALSE;
01009 }
01010
01011 pNewGRR->m_DoCompression = FALSE;
01012 pNewGRR->InitDevice();
01013 pNewGRR->InitAttributes();
01014 pNewGRR->SetLineAttributes();
01015 pNewGRR->SetFillAttributes();
01016 pNewGRR->SetBackmostChangedNode(pSpread);
01017
01018
01019 BOOL Started = pNewGRR->StartRender();
01020
01021 if (Started)
01022 {
01023
01024 CCAttrMap* pAttrMap = new CCAttrMap;
01025 if (pAttrMap!=NULL)
01026 {
01027 pLE->FindAppliedAttributes(pAttrMap, 5000, NULL, FALSE, FALSE);
01028 pAttrMap->Render(pNewGRR);
01029 delete pAttrMap;
01030 }
01031
01032
01033
01034
01035 pNewGRR->RRQuality.SetQuality(QUALITY_MAX);
01036 pNewGRR->SetQualityLevel();
01037
01038 pNewGRR->SetImmediateRender(TRUE);
01039
01040 pNewGRR->RenderTree(pLE, FALSE, FALSE);
01041 pNewGRR->StopRender();
01042
01043 }
01044
01045
01046
01047 ERROR2IF(!pLE->GetOriginalBitmap(NULL, NULL, NULL), FALSE, "EnsureLiveEffectOriginalBitmaps failed to generate an original bitmap");
01048
01049 delete pNewGRR;
01050 pNewGRR = NULL;
01051 }
01052
01053 pNode = m_pLERange->FindNext(pNode);
01054 }
01055
01056 return TRUE;
01057 }
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080 BOOL OpLiveEffect::GenerateBitmap(NodeBitmapEffect* pBitmapEffect,
01081 double dResolution,
01082 LPBITMAPINFO* ppInfo,
01083 LPBYTE* ppBits,
01084 DocRect* prectBounds)
01085 {
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105 View* pView = View::GetCurrent();
01106 Spread* pSpread = Document::GetSelectedSpread();
01107 Matrix Mat = pView->ConstructScaledRenderingMatrix(pSpread, 1.0);
01108 FIXED16 Scale;
01109 Mat.Decompose(&Scale);
01110 GRenderDIB* pNewGRR = new GRenderDIB(pBitmapEffect->GetBoundingRect(), Mat, Scale, 32, dResolution);
01111 ERROR2IF(pNewGRR == NULL, FALSE, "Failed to create a GRenderDIB!");
01112
01113
01114 if (!pNewGRR->AttachDevice(pView, NULL, pSpread))
01115 {
01116 ERROR3("Cannot attach devices");
01117
01118 delete pNewGRR;
01119 pNewGRR = NULL;
01120
01121 *ppInfo = NULL;
01122 *ppBits = NULL;
01123
01124 *prectBounds = DocRect();
01125
01126 return FALSE;
01127 }
01128
01129 pNewGRR->m_DoCompression = TRUE;
01130 pNewGRR->InitDevice();
01131 pNewGRR->InitAttributes();
01132 pNewGRR->SetLineAttributes();
01133 pNewGRR->SetFillAttributes();
01134
01135
01136 BOOL Started = pNewGRR->StartRender();
01137
01138 if (Started)
01139 {
01140
01141 CCAttrMap* pAttrMap = new CCAttrMap;
01142 if (pAttrMap!=NULL)
01143 {
01144 pBitmapEffect->FindAppliedAttributes(pAttrMap, 5000, NULL, FALSE, FALSE);
01145 pAttrMap->Render(pNewGRR);
01146 delete pAttrMap;
01147 }
01148
01149
01150
01151
01152 pNewGRR->RRQuality.SetQuality(QUALITY_MAX);
01153 pNewGRR->SetQualityLevel();
01154
01155 pNewGRR->RenderTree(pBitmapEffect, FALSE, FALSE);
01156 pNewGRR->StopRender();
01157 }
01158
01159 *prectBounds = pNewGRR->GetClipRect();
01160 pNewGRR->GetBitmapPointers(ppInfo, ppBits);
01161 pNewGRR->SetBitmapPointers(NULL, NULL);
01162
01163 delete pNewGRR;
01164 pNewGRR = NULL;
01165
01166 return TRUE;
01167 }
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186 BOOL OpLiveEffect::SetChanged(BOOL bNewState)
01187 {
01188 if (m_pLERange==NULL)
01189 return TRUE;
01190
01191 Node* pNode = m_pLERange->FindFirst();
01192 while (pNode)
01193 {
01194 ENSURE(pNode->IsBitmapEffect(), "LiveEffects list contains non-LiveEffect in EnsureLiveEffectOriginalBitmaps");
01195 NodeBitmapEffect* pLE = (NodeBitmapEffect*)pNode;
01196
01197 pLE->SetChanged(bNewState);
01198
01199 pNode = m_pLERange->FindNext(pNode);
01200 }
01201
01202 return TRUE;
01203 }
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225 BOOL OpLiveEffect::HasChanged()
01226 {
01227 if (m_pLERange==NULL)
01228 return FALSE;
01229
01230 Node* pNode = m_pLERange->FindFirst();
01231 while (pNode)
01232 {
01233 ENSURE(pNode->IsBitmapEffect(), "LiveEffects list contains non-LiveEffect in EnsureLiveEffectOriginalBitmaps");
01234 NodeBitmapEffect* pLE = (NodeBitmapEffect*)pNode;
01235
01236 if (pLE->HasChanged())
01237 return TRUE;
01238
01239 pNode = m_pLERange->FindNext(pNode);
01240 }
01241
01242 return FALSE;
01243 }
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256
01257
01258 BOOL OpLiveEffect::UpdateCurrentEditor()
01259 {
01260 OpLiveEffect* pCurrentOp = XPEHost::GetCurrentLEOp();
01261
01262
01263 if (pCurrentOp==NULL)
01264 return FALSE;
01265
01266
01267 ENSURE(pCurrentOp->GetPreviewQuality()==FALSE, "We can't leave the bitmaps in the tree in preview mode!");
01268
01269
01270 String_256 strEffectID = pCurrentOp->m_strEffectID;
01271 INT32 iStackPos = pCurrentOp->m_iStackPos;
01272
01273
01274
01275
01276 pCurrentOp->DoEndEdit(TRUE, TRUE);
01277 XPEHost::SetCurrentLEOp(NULL);
01278
01279
01280
01281 EffectsStack* pPPStack = EffectsStack::GetEffectsStackFromSelection();
01282
01283
01284
01285 BOOL bOK = pPPStack->FindBestProcessor(&strEffectID, &iStackPos);
01286
01287
01288 OpDescriptor* pOp = NULL;
01289 if (bOK)
01290 {
01291
01292 pOp = OpDescriptor::FindOpDescriptor(OPTOKEN_EDIT_LIVEEFFECT);
01293 }
01294 else
01295 {
01296
01297
01298 pOp = OpDescriptor::FindOpDescriptor(OPTOKEN_APPLY_LIVEEFFECT);
01299 iStackPos = STACKPOS_INSERT_TOP;
01300 }
01301
01302
01303 if (pOp)
01304 {
01305 OpLiveEffectParam Param;
01306 Param.strOpUnique = strEffectID;
01307 Param.StackPosition = iStackPos;
01308 Param.pPPStack = pPPStack;
01309 Param.bReUseEditor = TRUE;
01310 BOOL bValid = XPEHost::GetEffectDetails(strEffectID, &Param.strMenuText, &Param.bIsDestructive);
01311
01312 String_256 strDummy;
01313 if (bValid && pOp->GetOpsState(&strDummy).Greyed==FALSE)
01314 {
01315 pOp->Invoke(&Param);
01316
01317
01318
01319
01320 Tool* pTool = Tool::GetCurrent();
01321 if (pTool->GetID()==TOOLID_LIVEEFFECT)
01322 ((LiveEffectsTool*)pTool)->UpdatePPStack(FALSE);
01323
01324
01325 if (XPEHost::GetCurrentLEOp()!=NULL)
01326 {
01327 delete pPPStack;
01328 return TRUE;
01329 }
01330 }
01331 }
01332
01333
01334 XPEHost::EndEditLiveEffect();
01335 delete pPPStack;
01336 return FALSE;
01337 }
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356 void OpLiveEffect::DoEndEdit(BOOL bChangingSelection, BOOL bBroadcast, BOOL bCancelled, BOOL bEmpty)
01357 {
01358 BOOL ok = FALSE;
01359 BOOL bRecache = FALSE;
01360
01361
01362
01363
01364 if (bCancelled || (m_bAppliedNewEffects && (!HasChanged() || bEmpty)))
01365 {
01366 if (bChangingSelection)
01367 FailAndExecuteIgnoreSelActions();
01368 else
01369 FailAndExecute();
01370
01371 GetApplication()->FindSelection()->Update();
01372 End();
01373 return;
01374 }
01375
01376
01377
01378 if (bEmpty && !m_bAppliedNewEffects && m_pLERange!=NULL)
01379 {
01380 BOOL bOK = DoDeletePostProcessor(this, m_pLERange);
01381 if (!bOK)
01382 {
01383 FailAndExecute();
01384
01385 GetApplication()->FindSelection()->Update();
01386 End();
01387 return;
01388 }
01389 }
01390
01391
01392
01393 if (m_pLERange)
01394 {
01395 delete m_pLERange;
01396 m_pLERange = NULL;
01397 }
01398
01399
01400 if (GetPreviewQuality())
01401 {
01402 ERROR3("We would expect XPE to have ended with at least one non-preview bitmap!");
01403 SetPreviewQuality(FALSE);
01404 bRecache = TRUE;
01405 }
01406
01407 Tool* pTool = Tool::GetCurrent();
01408
01409
01410 if (pTool->GetID()==TOOLID_LIVEEFFECT)
01411 {
01412 ((LiveEffectsTool*)pTool)->SetCurrentEffectID(m_strEffectID);
01413 ((LiveEffectsTool*)pTool)->SetCurrentStackPos(m_iStackPos);
01414 }
01415
01416
01417 Spread* pSpread = Document::GetSelectedSpread();
01418
01419
01420 if (!DoInvalidateNodesRegions(*(GetApplication()->FindSelection()), TRUE, FALSE, FALSE, bRecache))
01421 {
01422 End();
01423 return;
01424 }
01425
01426
01427 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
01428 pTool->RenderToolBlobs(pSpread, NULL);
01429
01430 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
01431 ObjChangeParam ObjChange(OBJCHANGE_FINISHED, cFlags, NULL, this);
01432 ok = UpdateChangedNodes(&ObjChange);
01433
01434 if (bBroadcast)
01435 {
01436 BROADCAST_TO_ALL(SelChangingMsg(SelChangingMsg::EFFECTSTACKCHANGED));
01437 }
01438
01439
01440 GetApplication()->FindSelection()->Update();
01441
01442 End();
01443 }
01444
01445
01446
01447
01448
01449
01450
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462
01463
01464 BOOL OpLiveEffect::DoCopyPPStackToSelection(UndoableOperation* pOp, EffectsStack* pPPStack, Document* pSrcDoc, Document* pDestDoc)
01465 {
01466 ERROR2IF(pPPStack==NULL || pPPStack->IsEmpty(), FALSE, "No stack/empty stack given to DoCopyPPStackToSelection\n");
01467
01468 SelRange* pRange = GetApplication()->FindSelection();
01469 ERROR2IF(pRange==NULL, FALSE, "Can't find SelRange\n");
01470
01471 if (pPPStack==NULL)
01472 return TRUE;
01473
01474
01475 ListRange EffectsStack;
01476 INT32 l = 0;
01477 PPStackLevel* pLevel = pPPStack->GetLevel(l);
01478 while (pLevel)
01479 {
01480 ERROR3IF(pLevel->pPPNode==NULL, "PPStack has a badly formed level in it");
01481
01482 if (pLevel->pPPNode->CanBeUnlocked())
01483 EffectsStack.AddNode(pLevel->pPPNode);
01484
01485 pLevel = pPPStack->GetLevel(++l);
01486 }
01487
01488 pOp->DoInvalidateNodesRegions(*pRange, TRUE, FALSE);
01489
01490
01491 if (!EffectsStack.IsEmpty())
01492 {
01493 Node* pNode = pRange->FindFirst();
01494 Node* pNextNode = NULL;
01495 while (pNode)
01496 {
01497 pNextNode = pRange->FindNext(pNode);
01498
01499 DoCopyEffectsStack(pOp, pNode, &EffectsStack, pSrcDoc, pDestDoc);
01500
01501 pNode = pNextNode;
01502 }
01503 }
01504
01505 pOp->DoInvalidateNodesRegions(*pRange, TRUE, FALSE);
01506
01507 return TRUE;
01508 }
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530 BOOL OpLiveEffect::DoCopyEffectsStack(UndoableOperation* pOp, Node* pDestNode, ListRange* pEffectsStack, Document* pSrcDoc, Document* pDestDoc)
01531 {
01532 ERROR2IF(pOp==NULL, FALSE, "No Op given to DoCopyEffectsStack\n");
01533 ERROR2IF(pEffectsStack==NULL || pEffectsStack->IsEmpty(), FALSE, "No stack/empty stack given to DoCopyEffectsStack\n");
01534 ERROR2IF(pDestNode==NULL, FALSE, "No destination node given to DoCopyEffectsStack\n");
01535
01536
01537
01538
01539 if (pDestNode->IsAnObject() && !pDestNode->NeedsParent(pDestNode->FindParent()))
01540 pDestNode = DoDeleteAllPostProcessors(pOp, (NodeRenderableInk*)pDestNode, FALSE, TRUE);
01541
01542
01543
01544
01545 BOOL bWasSelected = pDestNode->IsSelected() || pDestNode->IsParentOfSelected();
01546 Node* pSelectNode = pDestNode;
01547 if (pDestNode->IsNodeRenderableClass())
01548 ((NodeRenderable*)pDestNode)->DeSelect(FALSE, TRUE);
01549
01550 Node* pTopNode = pDestNode;
01551
01552 NodeEffect* pEffect = (NodeEffect*)pEffectsStack->FindFirst();
01553 while (pEffect)
01554 {
01555
01556
01557 if (pEffect->IsAShadowController())
01558 {
01559 if (pTopNode->NeedsParent(pTopNode->FindParent()))
01560 {
01561 if (pTopNode->IsAShadow())
01562 {
01563
01564 }
01565 }
01566 else
01567 {
01568 NodeShadowController* pController = (NodeShadowController*)pEffect;
01569
01570 NodeShadowParam param(pController->GetShadowType(),
01571 pController->GetFloorShadowAngle(),
01572 pController->GetFloorShadowHeight(),
01573 pController->GetOffsetX(),
01574 pController->GetOffsetY(),
01575 pController->GetPenumbraWidth(),
01576 pController->GetShadow()->GetDarkness(),
01577 pController->GetWallShadowScale(),
01578 pController->GetGlowWidth(),
01579 pController->GetShadow()->GetBiasGain(),
01580 TRUE);
01581 param.strOpUnique = pEffect->GetPostProcessorID();
01582 param.StackPosition = STACKPOS_INSERT_TOP;
01583 pTopNode = OpApplyShadow::DoApplyShadow(pOp, pTopNode, ¶m, FALSE);
01584
01585 if (pTopNode == NULL)
01586 {
01587 pOp->FailAndExecute();
01588 return FALSE;
01589 }
01590
01591
01592 NodeShadow* pShadow = pController->GetShadow();
01593 NodeShadow* pNewShadow = NULL;
01594 if (pTopNode->IsAShadowController())
01595 pNewShadow = ((NodeShadowController*)pTopNode)->GetShadow();
01596 ERROR3IF(pShadow==NULL || pNewShadow==NULL, "ShadowController doesn't seem to have a shadow");
01597 if (pShadow && pNewShadow)
01598 {
01599 DoCopyAttributes(pOp, pShadow, pNewShadow, FALSE, pSrcDoc, pDestDoc);
01600 }
01601
01602 delete param.pPPStack;
01603 }
01604 }
01605
01606 else if (pEffect->IsFeatherEffect())
01607 {
01608 NodeFeatherEffect* pFeather = (NodeFeatherEffect*)pEffect;
01609 String_64 strDisplayName;
01610 XPEHost::GetEffectDetails(pEffect->GetPostProcessorID(), &strDisplayName);
01611 pTopNode = DoApplyFeatherEffectNode(pOp, pTopNode, pEffect->GetPostProcessorID(), strDisplayName, pFeather->GetFeatherSize(), pFeather->GetProfile());
01612 if (pTopNode == NULL)
01613 {
01614 pOp->FailAndExecute();
01615 return FALSE;
01616 }
01617 }
01618
01619 else if (pEffect->IsBitmapEffect())
01620 {
01621 if (pEffect->IsLockedEffect() && ((NodeLockedEffect*)pEffect)->CanBeUnlocked())
01622 {
01623 String_64 strDisplayName;
01624 XPEHost::GetEffectDetails(pEffect->GetPostProcessorID(), &strDisplayName);
01625 pTopNode = DoApplyLiveEffect(pOp, pTopNode, pEffect->GetPostProcessorID(), strDisplayName, ((NodeBitmapEffect*)pEffect)->GetPixelsPerInchValue(), ((NodeBitmapEffect*)pEffect)->GetEditList(), TRUE);
01626 if (pTopNode == NULL)
01627 {
01628 pOp->FailAndExecute();
01629 return FALSE;
01630 }
01631 }
01632 else if (!pEffect->IsLockedEffect())
01633 {
01634 String_64 strDisplayName;
01635 XPEHost::GetEffectDetails(pEffect->GetPostProcessorID(), &strDisplayName);
01636 pTopNode = DoApplyLiveEffect(pOp, pTopNode, pEffect->GetPostProcessorID(), strDisplayName, ((NodeBitmapEffect*)pEffect)->GetPixelsPerInchValue(), ((NodeBitmapEffect*)pEffect)->GetEditList(), FALSE);
01637 if (pTopNode == NULL)
01638 {
01639 pOp->FailAndExecute();
01640 return FALSE;
01641 }
01642 }
01643 if (pTopNode->IsEffect() && ((NodeEffect*)pTopNode)->IsLockedEffect())
01644 {
01645
01646 pSelectNode = pTopNode;
01647 }
01648 }
01649
01650
01651 if (pTopNode)
01652 {
01653 DoCopyAttributes(pOp, pEffect, pTopNode, TRUE, pSrcDoc, pDestDoc);
01654 }
01655
01656
01657 pEffect = (NodeEffect*)pEffectsStack->FindNext(pEffect);
01658 }
01659
01660 if (pSelectNode && bWasSelected && pSelectNode->IsNodeRenderableClass())
01661 {
01662 ((NodeRenderable*)pSelectNode)->Select(FALSE);
01663 }
01664
01665 return TRUE;
01666 }
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692 BOOL OpLiveEffect::DoCopyAttributes(UndoableOperation* pOp, Node* pSrcNode, Node* pDestNode, BOOL bEffectsOnly, Document* pSrcDoc, Document* pDestDoc)
01693 {
01694 if (!pDestNode->IsBounded() || !pSrcNode->IsBounded())
01695 return TRUE;
01696
01697 ((NodeRenderableBounded*)pDestNode)->InvalidateBoundingRect();
01698 DocRect NodeBounds = ((NodeRenderableBounded*)pDestNode)->GetBoundingRect(TRUE);
01699 Node* pNode = pSrcNode->FindFirstChild();
01700 while (pNode)
01701 {
01702 if (pNode->IsAnAttribute())
01703 {
01704 NodeAttribute* pAttr = (NodeAttribute*)pNode;
01705 if (!bEffectsOnly || pAttr->IsEffectAttribute())
01706 {
01707 if (pAttr->CanBeAppliedToObject())
01708 {
01709 NodeAttribute* pAttrCopy = NULL;
01710 pAttr->NodeCopy((Node **)(&pAttrCopy));
01711
01712 if (pAttrCopy->IsAFillAttr())
01713 {
01714
01715 ((AttrFillGeometry*)pAttrCopy)->SetBoundingRect(((NodeRenderableBounded*)pSrcNode)->GetBoundingRect());
01716
01717
01718
01719 if (pAttrCopy->IsAFractalFill())
01720 {
01721
01722 ((AttrFillGeometry*)pAttrCopy)->SetFractalDPI(AttrFillGeometry::FractalDPI);
01723 }
01724 }
01725
01726 pAttrCopy->TransformToNewBounds(NodeBounds);
01727 pAttrCopy->AttachNode(pDestNode, LASTCHILD);
01728 pAttrCopy->LinkToGeometry(pDestNode);
01729
01730 if (pAttrCopy->IsAFillAttr())
01731 {
01732
01733
01734
01735
01736
01737 ((AttrFillGeometry*)pAttrCopy)->AttributeChanged();
01738 }
01739
01740
01741 BOOL ok;
01742 CALL_WITH_FAIL((pDestDoc->StartComponentCopy()), pOp, ok)
01743 if (ok)
01744 {
01745 if (!pAttrCopy->CopyComponentData(pSrcDoc, pDestDoc))
01746 {
01747 pDestDoc->AbortComponentCopy();
01748 ok = FALSE;
01749 }
01750
01751 if (ok)
01752 ok = pDestDoc->EndComponentCopy();
01753 }
01754
01755
01756 Node* pCurrent = pDestNode->FindFirstChild();
01757 Node* pNext;
01758 CCRuntimeClass* pAttrType = pAttrCopy->GetAttributeType();
01759 while (pCurrent)
01760 {
01761 pNext = pCurrent->FindNext();
01762
01763 if (pCurrent!=pAttrCopy && pCurrent->IsKindOf(CC_RUNTIME_CLASS(NodeAttribute)))
01764 {
01765 {
01766 if (((NodeAttribute*)pCurrent)->GetAttributeType() == pAttrType)
01767 {
01768 pCurrent->CascadeDelete();
01769 delete pCurrent;
01770 }
01771 }
01772 }
01773 pCurrent = pNext;
01774 }
01775 }
01776 }
01777 }
01778
01779 pNode = pNode->FindNext();
01780 }
01781
01782 return TRUE;
01783 }
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799
01800
01801
01802
01803 BOOL OpLiveEffect::DoLocaliseLiveEffects(UndoableOperation* pOp, Node* pNode)
01804 {
01805 ListRange* pPPStack = EffectsStack::GetEffectsStackFromNode(pNode, FALSE, TRUE, TRUE);
01806 if (pPPStack==NULL)
01807 return TRUE;
01808
01809 NodeRenderableInk* pChild = pNode->FindFirstChildInk();
01810 while (pChild)
01811 {
01812 NodeRenderableInk* pNextChild = pChild->FindNextInk();
01813
01814
01815 if (pChild->GetParentController()==NULL)
01816 {
01817 NodeRenderableInk* pInsertContext = pChild;
01818 NodeBitmapEffect* pLENode = (NodeBitmapEffect*)pPPStack->FindFirst();
01819 ERROR2IF(!pLENode->CanBeUnlocked(), FALSE, "Can't localise Destructive effects");
01820 while (pLENode)
01821 {
01822
01823 NodeBitmapEffect* pCopy = NULL;
01824 BOOL bOK = FALSE;
01825 CALL_WITH_FAIL(pCopy = (NodeBitmapEffect*)pLENode->SimpleCopy(), pOp, bOK);
01826 if (!bOK) return FALSE;
01827
01828
01829
01830 bOK = pOp->DoInsertNewNode(pCopy, pInsertContext, NEXT, TRUE, FALSE, FALSE, FALSE);
01831 if (!bOK) return FALSE;
01832
01833 bOK = pOp->DoMoveNode(pInsertContext, pCopy, FIRSTCHILD);
01834 if (!bOK) return FALSE;
01835
01836 pInsertContext = pCopy;
01837
01838
01839
01840
01841
01842
01843 Node* pNode = pLENode->FindFirstChild();
01844 AttachNodeDirection dir = FIRSTCHILD;
01845 while (pNode)
01846 {
01847 if (pNode->NeedsParent(pNode->FindParent()) && pNode->IsBounded())
01848 {
01849
01850 NodeRenderableBounded* pCopy = NULL;
01851 BOOL bOK = FALSE;
01852 CALL_WITH_FAIL(pNode->NodeCopy((Node**)&pCopy), pOp, bOK);
01853 if (!bOK) return FALSE;
01854
01855 bOK = pOp->DoInsertNewNode(pCopy, pInsertContext, dir, TRUE, FALSE, FALSE, FALSE);
01856 if (!bOK) return FALSE;
01857 }
01858
01859 pNode = pNode->FindNext();
01860 }
01861
01862 pLENode = (NodeBitmapEffect*)pPPStack->FindNext(pLENode);
01863 }
01864 }
01865
01866 pChild = pNextChild;
01867 }
01868
01869 delete pPPStack;
01870
01871
01872
01873
01874 if (pNode->IsAnObject())
01875 return (OpLiveEffect::DoDeleteAllPostProcessors(pOp, (NodeRenderableInk*)pNode)!=NULL);
01876 else
01877 return TRUE;
01878 }
01879
01880
01881
01882
01883
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901 BOOL OpLiveEffect::DoLocaliseEffectAttrs(UndoableOperation* pOp, Node* pNode)
01902 {
01903
01904
01905
01906
01907
01908
01909
01910
01911
01912
01913 ListRange* pPPStack = EffectsStack::GetEffectsStackFromNode(pNode, FALSE, TRUE, TRUE);
01914 if (pPPStack)
01915 {
01916 Node* pEffectNode = pPPStack->FindLast();
01917 while (pEffectNode)
01918 {
01919 NodeAttribute* pAttr = NodeAttribute::FindFirstAppliedAttr(pEffectNode);
01920 while (pAttr && pAttr->IsEffectAttribute() && pAttr->FindParent()==pEffectNode)
01921 {
01922 if (!pAttr->HasEquivalentDefaultValue(TRUE))
01923 DoCopyEffectAttr(pOp, pAttr, pNode);
01924
01925 pAttr = NodeAttribute::FindPrevAppliedAttr(pAttr);
01926 }
01927
01928 pEffectNode = pPPStack->FindPrev(pEffectNode);
01929 }
01930 }
01931
01932
01933 NodeAttribute* pAttr = NodeAttribute::FindFirstAppliedAttr(pNode);
01934 while (pAttr && pAttr->IsEffectAttribute() && pAttr->FindParent()==pNode)
01935 {
01936 if (!pAttr->HasEquivalentDefaultValue(TRUE))
01937 DoCopyEffectAttr(pOp, pAttr, pNode);
01938
01939 pAttr = NodeAttribute::FindPrevAppliedAttr(pAttr);
01940 }
01941
01942 delete pPPStack;
01943
01944 return TRUE;
01945 }
01946
01947
01948
01949
01950
01951
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969 BOOL OpLiveEffect::DoCopyEffectAttr(UndoableOperation* pOp, NodeAttribute* pAttr, Node* pNode)
01970 {
01971 Node* pChildNode = pNode->FindFirstChild();
01972 while (pChildNode)
01973 {
01974 if (pChildNode->IsAnObject())
01975 {
01976 NodeRenderableInk* pInkNode = (NodeRenderableInk*)pChildNode;
01977 if (pInkNode->IsValidEffectAttr(pAttr))
01978 {
01979 NodeAttribute* pExistingAttr = pInkNode->FindAppliedAttribute(pAttr->GetRuntimeClass());
01980 if (pExistingAttr==NULL || pExistingAttr->FindParent()!=pInkNode)
01981 {
01982
01983
01984 NodeAttribute* pCopyAttr = NULL;
01985 BOOL bOK = FALSE;
01986 CALL_WITH_FAIL(pCopyAttr = (NodeAttribute*)pAttr->SimpleCopy(), pOp, bOK);
01987 if (!bOK) return FALSE;
01988
01989
01990
01991
01992 pCopyAttr->AttachNode(pInkNode, LASTCHILD);
01993 HideNodeAction* UndoHideNodeAction;
01994 if (HideNodeAction::Init(pOp, pOp->GetUndoActions(), pCopyAttr, TRUE, (Action**)(&UndoHideNodeAction))
01995 == AC_FAIL)
01996 {
01997 pCopyAttr->CascadeDelete();
01998 delete pCopyAttr;
01999 return FALSE;
02000 }
02001 }
02002 }
02003 else
02004 {
02005 NodeAttribute* pExistingAttr = pInkNode->FindAppliedAttribute(pAttr->GetRuntimeClass());
02006 if (pExistingAttr==NULL || pExistingAttr->FindParent()!=pInkNode)
02007 {
02008
02009 NodeAttribute* pCopyAttr = NULL;
02010 BOOL bOK = FALSE;
02011 CALL_WITH_FAIL(pCopyAttr = (NodeAttribute*)pAttr->SimpleCopy(), pOp, bOK);
02012 if (!bOK) return FALSE;
02013
02014
02015
02016
02017 pCopyAttr->AttachNode(pInkNode, FIRSTCHILD);
02018 HideNodeAction* UndoHideNodeAction;
02019 if (HideNodeAction::Init(pOp, pOp->GetUndoActions(), pCopyAttr, TRUE, (Action**)(&UndoHideNodeAction))
02020 == AC_FAIL)
02021 {
02022 pCopyAttr->CascadeDelete();
02023 delete pCopyAttr;
02024 return FALSE;
02025 }
02026
02027
02028
02029
02030
02031 pOp->DoRemoveAttrTypeFromSubtree(pInkNode, pAttr->GetRuntimeClass(), pCopyAttr);
02032 }
02033 }
02034 }
02035
02036 pChildNode = pChildNode->FindNext();
02037 }
02038
02039 return TRUE;
02040 }
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060 Node* OpLiveEffect::DoDeleteAllPostProcessors(UndoableOperation* pOp, NodeRenderableInk* pNode, BOOL bDeleteOldControllers, BOOL bDeleteBelowLocked)
02061 {
02062 BOOL bOK = TRUE;
02063
02064
02065 Node* pNewBaseNode = pNode;
02066 if (pNode->IsEffect())
02067 {
02068 ENSURE(((NodeEffect*)pNode)->IsLockedEffect(), "Only destructive LiveEffects should be selectable");
02069
02070 if (bDeleteBelowLocked)
02071 {
02072
02073
02074 if (((NodeEffect*)pNewBaseNode)->GetInkNodeFromController()==NULL)
02075 pNewBaseNode = pNewBaseNode->FindFirstChild();
02076 else
02077 {
02078 Node* pChild = pNewBaseNode;
02079 while (pChild && pChild->IsEffect())
02080 {
02081 pChild = ((NodeEffect*)pChild)->GetInkNodeFromController();
02082
02083 if (pChild)
02084 pNewBaseNode = pChild;
02085 }
02086 }
02087 }
02088 }
02089
02090 Node* pHighestLE = NULL;
02091 Node* pEffectScanBase = NULL;
02092
02093
02094
02095
02096
02097
02098
02099
02100
02101
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134 {
02135 Node* pAncestor = pNewBaseNode->FindParent();
02136 Node* pHighestOldController = NULL;
02137 pEffectScanBase = pNewBaseNode;
02138 while (pAncestor && pAncestor->IsController() && !pAncestor->IsEffect())
02139 {
02140 pHighestOldController = pAncestor;
02141 pAncestor = pAncestor->FindParent();
02142 }
02143
02144 if (pHighestOldController)
02145 {
02146 if (bDeleteOldControllers)
02147 pEffectScanBase = pHighestOldController;
02148 else
02149 {
02150 pEffectScanBase = pHighestOldController;
02151 pNewBaseNode = pHighestOldController;
02152 }
02153 }
02154 }
02155
02156
02157
02158 {
02159 Node* pAncestor = pEffectScanBase->FindParent();
02160 while (pAncestor && pAncestor->IsEffect())
02161 {
02162 pHighestLE = pAncestor;
02163 pAncestor = pAncestor->FindParent();
02164 }
02165 }
02166
02167
02168
02169 {
02170 Node* pAncestor = pNewBaseNode->FindParent();
02171 if (pAncestor && pAncestor->IsAnObject())
02172 {
02173 bOK = pOp->DoLocaliseCommonAttributes((NodeRenderableInk*)pAncestor, FALSE, TRUE);
02174 if (!bOK) return NULL;
02175 }
02176 }
02177
02178
02179
02180
02181 if (pHighestLE)
02182 {
02183
02184
02185
02186 Node* pInsertNode = pHighestLE;
02187 Node* pNextChild = NULL;
02188 Node* pChild = pNewBaseNode;
02189 while (pChild)
02190 {
02191 pNextChild = pChild->FindNext();
02192
02193 if (pChild->IsAnObject())
02194 {
02195
02196
02197 if (!((NodeRenderableInk*)pChild)->NeedsParent(pChild->FindParent()))
02198 {
02199 bOK = pOp->DoMoveNode(pChild, pInsertNode, NEXT);
02200 if (!bOK) return NULL;
02201
02202 ((NodeRenderableInk*)pChild)->Select(FALSE);
02203
02204 if (pChild->IsAnObject())
02205 pOp->DoFactorOutCommonAttributes((NodeRenderableInk*)pChild);
02206
02207 pInsertNode = pChild;
02208 }
02209 }
02210
02211 pChild = (NodeRenderableInk*)pNextChild;
02212 }
02213
02214
02215
02216
02217 if (pHighestLE->IsRenderable())
02218 ((NodeRenderable*)pHighestLE)->DeSelect(FALSE);
02219 bOK = pOp->DoHideNode(pHighestLE, FALSE, NULL, FALSE);
02220 }
02221
02222 return pNewBaseNode;
02223 }
02224
02225
02226
02227
02228
02229
02230
02231
02232
02233
02234
02235
02236
02237
02238
02239
02240
02241
02242 BOOL OpLiveEffect::DoDeletePostProcessor(UndoableOperation* pOp, Range* pRange)
02243 {
02244 BOOL ok = FALSE;
02245
02246
02247 ERROR2IF(pRange==NULL, FALSE, "DoDeletePostProcessor given an empty range");
02248
02249
02250
02251
02252 Node* pNode = pRange->FindFirst();
02253 while (pNode)
02254 {
02255 if (pNode->IsEffect())
02256 {
02257 NodeEffect* pLE = (NodeEffect*)pNode;
02258 DoDeletePostProcessor(pOp, pLE);
02259 }
02260
02261 pNode = pRange->FindNext(pNode);
02262 }
02263
02264 return TRUE;
02265 }
02266
02267
02268
02269
02270
02271
02272
02273
02274
02275
02276
02277
02278
02279
02280
02281
02282
02283
02284 BOOL OpLiveEffect::DoDeletePostProcessor(UndoableOperation* pOp, NodeEffect* pLE, BOOL bMoveEffectAttrs)
02285 {
02286 BOOL ok = FALSE;
02287
02288
02289 ERROR2IF(pLE==NULL, FALSE, "DoDeletePostProcessor given NULL node");
02290
02291
02292
02293
02294 BOOL bSelected = pLE->IsSelected();
02295
02296 pOp->DoLocaliseCommonAttributes(pLE);
02297
02298
02299
02300
02301 Node* pInsertNode = pLE;
02302 Node* pNextChild = NULL;
02303 Node* pParent = pLE->FindParent();
02304 NodeEffect* pParentEffect = NULL;
02305 if (pParent && pParent->IsEffect())
02306 pParentEffect = (NodeEffect*)pLE->FindParent();
02307 NodeRenderableInk* pChild = (NodeRenderableInk*)pLE->FindFirstChild(CC_RUNTIME_CLASS(NodeRenderableInk));
02308
02309 while (pChild)
02310 {
02311 pNextChild = pChild->FindNext();
02312
02313 if (pChild->IsAnObject())
02314 {
02315
02316
02317 if (!((NodeRenderableInk*)pChild)->NeedsParent(pChild->FindParent()))
02318 {
02319 pOp->DoMoveNode(pChild, pInsertNode, NEXT);
02320 if (bSelected)
02321 pChild->Select(FALSE);
02322 if (pChild->IsAnObject())
02323 pOp->DoFactorOutCommonAttributes((NodeRenderableInk*)pChild);
02324
02325 pInsertNode = pChild;
02326 }
02327 }
02328
02329 if (bMoveEffectAttrs && pParentEffect && pChild->IsAnAttribute() && ((NodeAttribute*)pChild)->IsEffectAttribute())
02330 {
02331 if (pParentEffect->IsValidEffectAttr((NodeAttribute*)pChild))
02332 {
02333 pOp->DoMoveNode(pChild, pInsertNode, NEXT);
02334 pInsertNode = pChild;
02335 }
02336 }
02337
02338 pChild = (NodeRenderableInk*)pNextChild;
02339 }
02340
02341 pLE->ReleaseCached(TRUE, FALSE, FALSE, FALSE);
02342 if (bSelected)
02343 pLE->DeSelect(FALSE);
02344 pOp->DoHideNode(pLE, FALSE, NULL, FALSE);
02345
02346 return TRUE;
02347 }
02348
02349
02350
02351
02352
02353
02354
02355
02356
02357
02358
02359
02360
02361
02362
02363
02364
02365
02366 BOOL OpLiveEffect::DoEffectRangeOp(UINT32 idsProgress, Range* pRange, OpLiveEffectParam* pParam)
02367 {
02368 BOOL ok = FALSE;
02369 Progress progress(idsProgress, pRange->Count(), FALSE);
02370
02371
02372 ERROR2IF(pRange==NULL, FALSE, "DoEffectRangeOp given an empty range");
02373
02374
02375
02376
02377 INT32 iCount = 0;
02378 INT32 iChanges = 0;
02379 Node* pNode = pRange->FindFirst();
02380 while (pNode && progress.Update(iCount, TRUE) && !OpHasFailed())
02381 {
02382 if (pNode->IsEffect())
02383 {
02384
02385
02386
02387
02388 NodeEffect* pLE = (NodeEffect*)pNode;
02389 NodeBitmapEffect* pNewEffect = NULL;
02390 BOOL bChanged = DoEffectNodeOp(pLE, pParam, &pNewEffect);
02391
02392
02393 if (bChanged)
02394 {
02395 iChanges++;
02396
02397
02398
02399 if (!DoInvalidateNodeRegion(pNewEffect, TRUE, FALSE, FALSE, FALSE))
02400 {
02401 FailAndExecute();
02402 End();
02403 return FALSE;
02404 }
02405
02406
02407
02408 DocView* pDocView = GetWorkingDocView();
02409 if (pDocView)
02410 {
02411
02412 pDocView->FlushRedraw();
02413 GetApplication()->ServiceRendering();
02414 }
02415 }
02416 }
02417
02418 iCount++;
02419 pNode = pRange->FindNext(pNode);
02420 }
02421
02422
02423
02424 if (pNode)
02425 {
02426 FailAndExecute();
02427 End();
02428 return FALSE;
02429 }
02430
02431 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
02432 ObjChangeParam ObjChange(OBJCHANGE_FINISHED, cFlags, NULL, this);
02433 ok = UpdateChangedNodes(&ObjChange);
02434
02435
02436 if (iChanges==0)
02437 {
02438 SucceedAndDiscard();
02439 End();
02440 return FALSE;
02441 }
02442
02443 End();
02444 return FALSE;
02445 }
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464 void OpLiveEffect::Do(OpDescriptor* pOpDesc)
02465 {
02466
02467 DoWithParam(pOpDesc, NULL);
02468 }
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487 void OpLiveEffect::DoWithParam(OpDescriptor* pOpDesc, OpParam* pOpParam)
02488 {
02489 BOOL ok = FALSE;
02490
02491 OpLiveEffectParam* pLEOpParam = NULL;
02492 if (pOpParam && pOpParam->IsKindOf(CC_RUNTIME_CLASS(OpLiveEffectParam)))
02493 pLEOpParam = (OpLiveEffectParam*) pOpParam;
02494
02495 if (!CheckEffectOpParam(pLEOpParam))
02496 {
02497 End();
02498 return;
02499 }
02500
02501
02502 if (pLEOpParam)
02503 {
02504 m_strEffectID = pLEOpParam->strOpUnique;
02505 m_iStackPos = pLEOpParam->StackPosition;
02506 }
02507
02508
02509 Range Sel(*(GetApplication()->FindSelection()));
02510 RangeControl rc = Sel.GetRangeControlFlags();
02511 rc.PromoteToParent = TRUE;
02512 Sel.Range::SetRangeControl(rc);
02513
02514 if (!AllowEmptySelection() && Sel.FindFirst()==NULL)
02515 {
02516 End();
02517 return;
02518 }
02519
02520
02521 Tool* pTool = Tool::GetCurrent();
02522 Spread* pSpread = Document::GetSelectedSpread();
02523 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
02524 pTool->RenderToolBlobs(pSpread, NULL);
02525
02526
02527 if (!DoStartSelOp(FALSE, FALSE))
02528 {
02529 End();
02530 return;
02531 }
02532
02533
02534
02535 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
02536 ObjChangeParam ObjChange(OBJCHANGE_STARTING, cFlags, NULL, this);
02537 BOOL bOK = Sel.AllowOp(&ObjChange);
02538 if (!bOK)
02539 {
02540 End();
02541 return;
02542 }
02543
02544
02545 if (!DoInvalidateNodesRegions(Sel, TRUE, FALSE, FALSE, FALSE))
02546 {
02547 End();
02548 return;
02549 }
02550
02551
02552 ListRange* pLERange = NULL;
02553 if (pLEOpParam && pLEOpParam->pPPStack)
02554 {
02555 pLERange = pLEOpParam->pPPStack->GetLevelRange(&pLEOpParam->StackPosition);
02556
02557 if (pLERange)
02558 pLERange = new ListRange(pLERange);
02559 }
02560 m_bAppliedNewEffects = FALSE;
02561
02562
02563
02564 BOOL bEndNormally = DoEffectOp(pLERange, pLEOpParam);
02565
02566
02567 if (pLERange)
02568 {
02569 delete pLERange;
02570 pLERange = NULL;
02571 }
02572
02573 if (bEndNormally)
02574 {
02575
02576 if (!DoInvalidateNodesRegions(*(GetApplication()->FindSelection()), TRUE, FALSE, FALSE, FALSE))
02577 {
02578 End();
02579 return;
02580 }
02581
02582
02583 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
02584 pTool->RenderToolBlobs(pSpread, NULL);
02585
02586 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
02587 ObjChangeParam ObjChange(OBJCHANGE_FINISHED, cFlags, NULL, this);
02588 BOOL ok = UpdateChangedNodes(&ObjChange);
02589
02590 BROADCAST_TO_ALL(SelChangingMsg(SelChangingMsg::EFFECTSTACKCHANGED));
02591
02592
02593 GetApplication()->FindSelection()->Update();
02594
02595 End();
02596 }
02597 }
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615 BOOL OpLiveEffect::CheckEffectOpParam(OpLiveEffectParam* pLEOpParam)
02616 {
02617 if (pLEOpParam->StackPosition==-1)
02618 {
02619 ERROR3("OpLiveEffect must be given a valid position in the LiveEffects Stack");
02620 return FALSE;
02621 }
02622
02623
02624 if (pLEOpParam->pPPStack==NULL)
02625 return FALSE;
02626
02627 return TRUE;
02628 }
02629
02630
02631
02632
02634
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653 OpState OpApplyLiveEffect::GetParamState(String_256* pstrDescription, OpDescriptor* pOpDesc, OpParam* pOpParam)
02654 {
02655
02656 OpState OpSt;
02657 OpSt.Greyed = FALSE;
02658
02659 if (XPEHost::IsEditSessionRunning())
02660 {
02661 OpSt.Greyed = TRUE;
02662 *pstrDescription = String_256(_R(IDS_LE_EDIT_RUNNING));
02663 }
02664 else if (GetApplication()->FindSelection()->FindFirst()==NULL)
02665 {
02666 OpSt.Greyed = TRUE;
02667 *pstrDescription = String_256(_R(IDS_LE_NOTHING_SELECTED));
02668 }
02669
02670 return OpSt;
02671 }
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689 void OpApplyLiveEffect::GetOpName(String_256* pstrOpName)
02690 {
02691 *pstrOpName = String_256(_R(IDS_LE_OPAPPLY));
02692 }
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710 void OpApplyLiveEffect::DoWithParam(OpDescriptor* pOpDesc, OpParam* pOpParam)
02711 {
02712 BOOL ok = FALSE;
02713
02714 OpLiveEffectParam* pLEOpParam = NULL;
02715 if (pOpParam->IsKindOf(CC_RUNTIME_CLASS(OpLiveEffectParam)))
02716 pLEOpParam = (OpLiveEffectParam*) pOpParam;
02717
02718 INT32 InsertPos = pLEOpParam->StackPosition;
02719 if (pLEOpParam->StackPosition<STACKPOS_TOP)
02720 InsertPos = InsertPos - 1;
02721
02722
02723
02724 m_strEffectID = pLEOpParam->strOpUnique;
02725 m_iStackPos = InsertPos;
02726 if (m_strEffectID.IsEmpty())
02727 {
02728 End();
02729 return;
02730 }
02731
02732
02733 SelRange* pSelRange = GetApplication()->FindSelection();
02734
02735 Range* pInitialRange = NULL;
02736
02737
02738 Tool* pTool = Tool::GetCurrent();
02739 Spread* pSpread = Document::GetSelectedSpread();
02740 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
02741 pTool->RenderToolBlobs(pSpread, NULL);
02742
02743
02744 if (!DoStartSelOp(FALSE, FALSE))
02745 {
02746 End();
02747 return;
02748 }
02749
02750
02751
02752
02753 if (!(pLEOpParam->bReUseEditor && pSelRange->IsEmpty()))
02754 {
02755
02756
02757 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
02758 ObjChangeParam ObjChange(OBJCHANGE_STARTING, cFlags, NULL, this);
02759 BOOL bOK = pSelRange->AllowOp(&ObjChange);
02760 if (!bOK)
02761 {
02762 End();
02763 return;
02764 }
02765 }
02766
02767
02768 if (!DoInvalidateNodesRegions(*pSelRange, TRUE, FALSE, FALSE, FALSE))
02769 {
02770 End();
02771 return;
02772 }
02773
02774
02775 pSelRange->MakePartialSelectionWhole(FALSE, FALSE, TRUE);
02776
02777
02778 ENSURE(m_pLERange==NULL, "!");
02779 if (InsertPos==-1)
02780 {
02781
02782 pInitialRange = GetApplication()->FindSelection();
02783 m_iStackPos = 0;
02784 }
02785 else
02786 {
02787 ENSURE(pLEOpParam->pPPStack, "Can't find EffectsStack");
02788 pInitialRange = pLEOpParam->pPPStack->GetLevelRange(&InsertPos);
02789 m_iStackPos = InsertPos+1;
02790
02791 }
02792
02793
02794 if (pInitialRange==NULL)
02795 {
02796 ERROR3("If this happens, the UI logic disagrees with the Op about what the Op can do");
02797 FailAndExecute();
02798 End();
02799 return;
02800 }
02801
02802
02803
02804
02805 if (pLEOpParam && !pLEOpParam->bIsDestructive)
02806 {
02807 if (NodeBitmapEffect::DefaultLocked)
02808 m_pLERange = DoApplyLiveEffect(pInitialRange, pLEOpParam->strOpUnique, pLEOpParam->strMenuText, NodeBitmapEffect::DefaultLockedPixelsPerInch, pLEOpParam->pEditsList, TRUE, TRUE);
02809 else
02810 m_pLERange = DoApplyLiveEffect(pInitialRange, pLEOpParam->strOpUnique, pLEOpParam->strMenuText, NodeBitmapEffect::DefaultLivePixelsPerInch, pLEOpParam->pEditsList, FALSE, TRUE);
02811 }
02812 else
02813 {
02814
02815
02816 if (!IsTopOfStack(pLEOpParam->pPPStack, pLEOpParam->StackPosition))
02817 {
02818 InformWarning(_R(IDS_LE_DESTRUCTIVE_APPLY_TOP), _R(IDS_CONTINUE));
02819 FailAndExecute();
02820 End();
02821 return;
02822 }
02823 else
02824 {
02825 m_pLERange = DoApplyLockedEffect(pInitialRange, pLEOpParam->strOpUnique, pLEOpParam->strMenuText, NodeBitmapEffect::DefaultLockedPixelsPerInch, NULL, TRUE);
02826 }
02827 }
02828 m_bAppliedNewEffects = (m_pLERange!=NULL);
02829
02830
02831 if (pLEOpParam->pEditsList==NULL)
02832 {
02833
02834 SetChanged(FALSE);
02835
02836
02837 ok = EnsureLiveEffectOriginalBitmaps();
02838 if (!ok)
02839 {
02840 FailAndExecute();
02841 End();
02842 return;
02843 }
02844
02845
02846
02847
02848 NodeBitmapEffect* pLE = NULL;
02849 if (m_pLERange)
02850 {
02851 Node* pNode = m_pLERange->FindLast();
02852 while (pNode && !(pNode->IsBitmapEffect() && ((NodeBitmapEffect*)pNode)->CanGenerateBitmap()))
02853 pNode = m_pLERange->FindPrev(pNode);
02854
02855 if (pNode==NULL)
02856 {
02857 FailAndExecute();
02858 End();
02859 return;
02860 }
02861
02862 pLE = (NodeBitmapEffect*)pNode;
02863 }
02864
02865
02866
02867
02868
02869
02870
02871 ok = XPEHost::EditLiveEffect(this, pLE, pLEOpParam->strOpUnique, pLEOpParam->bReUseEditor);
02872 if (!ok)
02873 {
02874 FailAndExecute();
02875 End();
02876 return;
02877 }
02878
02879 GetApplication()->FindSelection()->Update();
02880
02881
02882
02883 }
02884 else
02885 {
02886
02887 DoInvalidateNodesRegions(*pSelRange, TRUE, FALSE, FALSE);
02888
02889
02890 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
02891 pTool->RenderToolBlobs(pSpread, NULL);
02892
02893 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
02894 ObjChangeParam ObjChange(OBJCHANGE_FINISHED, cFlags, NULL, this);
02895 BOOL ok = UpdateChangedNodes(&ObjChange);
02896
02897 BROADCAST_TO_ALL(SelChangingMsg(SelChangingMsg::EFFECTSTACKCHANGED));
02898
02899
02900 GetApplication()->FindSelection()->Update();
02901
02902 End();
02903 }
02904 }
02905
02906
02907
02909
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928 OpState OpEditLiveEffect::GetParamState(String_256* pstrDescription, OpDescriptor* pOpDesc, OpParam* pOpParam)
02929 {
02930
02931 OpState OpSt;
02932 OpSt.Greyed = FALSE;
02933
02934
02935
02936
02937
02938
02939 if (GetApplication()->FindSelection()->FindFirst()==NULL)
02940 {
02941 OpSt.Greyed = TRUE;
02942 *pstrDescription = String_256(_R(IDS_LE_NOTHING_SELECTED));
02943 }
02944
02945 return OpSt;
02946 }
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970
02971
02972
02973
02974
02975
02976
02977
02978
02979
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989
02990
02991
02992
02993
02994
02995
02996 void OpEditLiveEffect::GetOpName(String_256* pstrOpName)
02997 {
02998 *pstrOpName = String_256(_R(IDS_LE_OPEDIT));
02999 }
03000
03001
03002
03003
03004
03005
03006
03007
03008
03009
03010
03011
03012
03013
03014
03015
03016
03017
03018 BOOL OpEditLiveEffect::DoEffectOp(ListRange* pLevelRange, OpLiveEffectParam* pLEOpParam)
03019 {
03020 m_pLERange = new ListRange(pLevelRange);
03021 BOOL ok = FALSE;
03022
03023
03024 {
03025 Node* pNode = m_pLERange->FindFirst();
03026 INT32 count=0;
03027 BOOL bDestructive = FALSE;
03028 BOOL bLocked = FALSE;
03029 while (pNode)
03030 {
03031 if (pNode->IsBitmapEffect() && ((NodeBitmapEffect*)pNode)->IsLockedEffect())
03032 {
03033 bLocked = TRUE;
03034 if (!((NodeLockedEffect*)pNode)->CanBeUnlocked())
03035 bDestructive = TRUE;
03036 }
03037
03038 count++;
03039 pNode = m_pLERange->FindNext(pNode);
03040 }
03041 if (bDestructive)
03042 {
03043 ENSURE(count==1, "Shouldn't allow user to edit more than one destructive effects at a time - greying should prevent this");
03044
03045 INT32 butt = AskQuestion(_R(IDS_LE_DESTRUCTIVE_EDIT), _R(IDS_LE_RECREATEEFFECT), _R(IDS_CANCEL));
03046 if (butt==2)
03047 {
03048 FailAndExecute();
03049 End();
03050 return FALSE;
03051 }
03052
03053
03054
03055
03056
03057 ListRange* pRangeUnderDeletedEffect = new ListRange();
03058 if (pRangeUnderDeletedEffect==NULL)
03059 {
03060 FailAndExecute();
03061 End();
03062 return FALSE;
03063 }
03064 Node* pNode = m_pLERange->FindFirst();
03065 while (pNode)
03066 {
03067 if (pNode->IsBitmapEffect())
03068 {
03069 Node* pChild = ((NodeBitmapEffect*)pNode)->GetInkNodeFromController();
03070 if (pChild) pRangeUnderDeletedEffect->AddNode(pChild);
03071 }
03072 else
03073 ERROR3("Something's gone horribly wrong - non bitmap effect foudn in list of locked effects to be deleted\n");
03074
03075 pNode = m_pLERange->FindNext(pNode);
03076 }
03077 if (pRangeUnderDeletedEffect->IsEmpty())
03078 {
03079 ERROR3("List of nodes under locked effect unexpectedly empty\n");
03080 FailAndExecute();
03081 End();
03082 return FALSE;
03083 }
03084
03085
03086 ok = OpLiveEffect::DoDeletePostProcessor(this, m_pLERange);
03087 if (ok)
03088 {
03089
03090
03091 delete m_pLERange;
03092 m_pLERange = DoApplyLockedEffect(pRangeUnderDeletedEffect, pLEOpParam->strOpUnique, pLEOpParam->strMenuText, NodeBitmapEffect::DefaultLockedPixelsPerInch);
03093 m_bAppliedNewEffects = (m_pLERange!=NULL);
03094 }
03095 else
03096 {
03097 FailAndExecute();
03098 End();
03099 return FALSE;
03100 }
03101 if (pRangeUnderDeletedEffect)
03102 {
03103 delete pRangeUnderDeletedEffect;
03104 pRangeUnderDeletedEffect = NULL;
03105 }
03106 }
03107 else
03108 {
03109
03110
03111
03112 ActionCode ac = MarkEditListAction::DoMarkEditList(this, &UndoActions, pLEOpParam->pPPStack, pLEOpParam->StackPosition);
03113 }
03114 }
03115
03116
03117 SetChanged(FALSE);
03118
03119
03120 ok = EnsureLiveEffectOriginalBitmaps();
03121 if (!ok)
03122 {
03123 FailAndExecute();
03124 End();
03125 return FALSE;
03126 }
03127
03128
03129
03130
03131 NodeBitmapEffect* pLE = NULL;
03132 if (m_pLERange)
03133 {
03134 Node* pNode = m_pLERange->FindLast();
03135 while (pNode && !(pNode->IsBitmapEffect() && ((NodeBitmapEffect*)pNode)->CanGenerateBitmap()))
03136 pNode = m_pLERange->FindPrev(pNode);
03137
03138 if (pNode==NULL)
03139 {
03140 FailAndExecute();
03141 End();
03142 return FALSE;
03143 }
03144
03145 pLE = (NodeBitmapEffect*)pNode;
03146 }
03147
03148
03149
03150
03151
03152
03153
03154 ok = XPEHost::EditLiveEffect(this, pLE, pLEOpParam->strOpUnique, pLEOpParam->bReUseEditor);
03155 if (!ok)
03156 {
03157 FailAndExecute();
03158 End();
03159 return FALSE;
03160 }
03161
03162 GetApplication()->FindSelection()->Update();
03163
03164
03165
03166 return FALSE;
03167 }
03168
03169
03170
03171
03173
03175
03176
03177
03178
03179
03180
03181
03182
03183
03184
03185
03186
03187
03188
03189
03190 OpState OpEditLegacyEffect::GetParamState(String_256* pstrDescription, OpDescriptor* pOpDesc, OpParam* pOpParam)
03191 {
03192
03193 OpState OpSt;
03194 OpSt.Greyed = FALSE;
03195
03196 if (XPEHost::IsEditSessionRunning())
03197 {
03198 OpSt.Greyed = TRUE;
03199 *pstrDescription = String_256(_R(IDS_LE_EDIT_RUNNING));
03200 }
03201 else if (GetApplication()->FindSelection()->FindFirst()==NULL)
03202 {
03203 OpSt.Greyed = TRUE;
03204 *pstrDescription = String_256(_R(IDS_LE_NOTHING_SELECTED));
03205 }
03206
03207 return OpSt;
03208 }
03209
03210
03211
03212
03213
03214
03215
03216
03217
03218
03219
03220
03221
03222
03223
03224
03225
03226 void OpEditLegacyEffect::GetOpName(String_256* pstrOpName)
03227 {
03228 *pstrOpName = String_256(_R(IDS_LE_OPEDIT));
03229 }
03230
03231
03232
03233
03234
03235
03236
03237
03238
03239
03240
03241
03242
03243
03244
03245
03246
03247
03248 void OpEditLegacyEffect::Do(OpDescriptor* pOpDesc)
03249 {
03250
03251 DoWithParam(pOpDesc, NULL);
03252 }
03253
03254
03255
03256
03257
03258
03259
03260
03261
03262
03263
03264
03265
03266
03267
03268
03269
03270
03271 void OpEditLegacyEffect::DoWithParam(OpDescriptor* pOpDesc, OpParam* pOpParam)
03272 {
03273 BOOL ok = FALSE;
03274
03275 OpLiveEffectParam* pLEOpParam = NULL;
03276 if (pOpParam && pOpParam->IsKindOf(CC_RUNTIME_CLASS(OpLiveEffectParam)))
03277 pLEOpParam = (OpLiveEffectParam*) pOpParam;
03278
03279
03280 if (pLEOpParam)
03281 {
03282 if (pLEOpParam->strOpUnique==String_256(POSTPRO_ID_SHADOW))
03283 {
03284
03285 Tool* pShadowTool = Tool::FindTool(TOOLID_SOFTSHADOW);
03286 if (pShadowTool)
03287 {
03288 INT32 iStackPos = pLEOpParam->StackPosition;
03289 ListRange* pShadowRange = pLEOpParam->pPPStack->GetLevelRange(&iStackPos);
03290 if (pShadowRange)
03291 {
03292 ((SoftShadowTool*)pShadowTool)->SelectShadowRange(pShadowRange);
03293 }
03294
03295 pShadowTool->SetCurrent();
03296 End();
03297 return;
03298 }
03299 }
03300
03301 if (pLEOpParam->strOpUnique==String_256(POSTPRO_ID_FEATHER))
03302 {
03303 INT32 iStackPos = pLEOpParam->StackPosition;
03304 ListRange* pFeatherRange = pLEOpParam->pPPStack->GetLevelRange(&iStackPos);
03305 OpChangeFeatherSize::SetEditContext(iStackPos, pFeatherRange);
03306 End();
03307 return;
03308 }
03309 }
03310
03311 End();
03312 }
03313
03314
03315
03316
03318
03320
03321
03322
03323
03324
03325
03326
03327
03328
03329
03330
03331
03332
03333
03334
03335 OpState OpDeleteLiveEffect::GetState(String_256* pstrDescription, OpDescriptor* pOpDesc)
03336 {
03337
03338 OpState OpSt;
03339 OpSt.Greyed = FALSE;
03340 *pstrDescription = String_256(_R(IDS_DESCRIBE_LIVEEFFECT));
03341
03342 if (XPEHost::IsEditSessionRunning())
03343 {
03344 OpSt.Greyed = TRUE;
03345 *pstrDescription = String_256(_R(IDS_LE_EDIT_RUNNING));
03346 }
03347
03348 return OpSt;
03349 }
03350
03351
03352
03353
03354
03355
03356
03357
03358
03359
03360
03361
03362
03363
03364
03365
03366
03367 void OpDeleteLiveEffect::GetOpName(String_256* pstrOpName)
03368 {
03369 *pstrOpName = String_256(_R(IDS_LE_OPDELETE));
03370 }
03371
03372
03373
03374
03375
03376
03377
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388
03389 BOOL OpDeleteLiveEffect::DoEffectOp(ListRange* pLevelRange, OpLiveEffectParam* pLEOpParam)
03390 {
03391 OpLiveEffect::DoDeletePostProcessor(this, pLevelRange);
03392
03393 return TRUE;
03394 }
03395
03396
03397
03398
03400
03402
03403
03404
03405
03406
03407
03408
03409
03410
03411
03412
03413
03414
03415
03416
03417 OpState OpDeleteAllLiveEffect::GetState(String_256* pstrDescription, OpDescriptor* pOpDesc)
03418 {
03419
03420 OpState OpSt;
03421 OpSt.Greyed = FALSE;
03422
03423
03424 if (XPEHost::IsEditSessionRunning())
03425 {
03426 OpSt.Greyed = TRUE;
03427 *pstrDescription = String_256(_R(IDS_LE_EDIT_RUNNING));
03428 }
03429
03430 return OpSt;
03431 }
03432
03433
03434
03435
03436
03437
03438
03439
03440
03441
03442
03443
03444
03445
03446
03447
03448
03449 void OpDeleteAllLiveEffect::GetOpName(String_256* pstrOpName)
03450 {
03451 *pstrOpName = String_256(_R(IDS_LE_OPDELETE));
03452 }
03453
03454
03455
03456
03457
03458
03459
03460
03461
03462
03463
03464
03465
03466
03467
03468
03469
03470
03471 BOOL OpDeleteAllLiveEffect::DoEffectOp(ListRange* pLevelRange, OpLiveEffectParam* pLEOpParam)
03472 {
03473 Range* pSelRange = GetApplication()->FindSelection();
03474 ENSURE(pSelRange, "OpDeleteAllLiveEffect can't find selection\n");
03475
03476
03477
03478
03479
03480
03481
03482 Node* pNode = pSelRange->FindFirst();
03483 while (pNode)
03484 {
03485
03486 Node* pNextSel = pSelRange->FindNext(pNode);
03487
03488 if (pNode->IsAnObject())
03489 DoDeleteAllPostProcessors(this, (NodeRenderableInk*)pNode, FALSE, TRUE);
03490
03491 pNode = pNextSel;
03492 }
03493
03494 return TRUE;
03495 }
03496
03497
03498
03499
03500 BOOL OpDeleteAllLiveEffect::CheckEffectOpParam(OpLiveEffectParam* pLEOpParam)
03501 {
03502
03503
03504
03505
03506
03507
03508
03509
03510
03511 return TRUE;
03512 }
03513
03514
03515
03516
03518
03520
03521
03522
03523
03524
03525
03526
03527
03528
03529
03530
03531
03532
03533
03534
03535 OpState OpEffectRes::GetState(String_256* pstrDescription, OpDescriptor* pOpDesc)
03536 {
03537
03538 OpState OpSt;
03539 OpSt.Greyed = FALSE;
03540 *pstrDescription = String_256(_R(IDS_DESCRIBE_LIVEEFFECT));
03541
03542 if (XPEHost::IsEditSessionRunning())
03543 {
03544 OpSt.Greyed = TRUE;
03545 *pstrDescription = String_256(_R(IDS_LE_EDIT_RUNNING));
03546 }
03547
03548 return OpSt;
03549 }
03550
03551
03552
03553
03554
03555
03556
03557
03558
03559
03560
03561
03562
03563
03564
03565
03566
03567 void OpEffectRes::GetOpName(String_256* pstrOpName)
03568 {
03569 *pstrOpName = String_256(_R(IDS_LE_OPEFFECTRES));
03570 }
03571
03572
03573
03574
03575
03576
03577
03578
03579
03580
03581
03582
03583
03584
03585
03586
03587
03588
03589 BOOL OpEffectRes::DoEffectOp(ListRange* pLevelRange, OpLiveEffectParam* pLEOpParam)
03590 {
03591 BOOL bOK = FALSE;
03592
03593 bOK = DoEffectRangeOp(_R(IDS_LE_CHANGE_RES_PROGRESS), pLevelRange, pLEOpParam);
03594
03595 return bOK;
03596 }
03597
03598
03599
03600
03601
03602
03603
03604
03605
03606
03607
03608
03609
03610
03611
03612
03613
03614
03615 BOOL OpEffectRes::DoEffectNodeOp(NodeEffect* pLE, OpLiveEffectParam* pParam, NodeBitmapEffect** ppNewEffect)
03616 {
03617
03618 ERROR2IF(pLE==NULL, FALSE, "OpEffectRes::DoEffectNodeOp given NULL node");
03619 ERROR2IF(pParam==NULL, FALSE, "OpEffectRes::DoEffectNodeOp given NULL param");
03620
03621 if (pLE->IsLockedEffect())
03622 {
03623
03624 if (((NodeLockedEffect*)pLE)->CanBeUnlocked())
03625 {
03626 if (ChangeEffectResAction::CreateChangeEffectResAction(this, (NodeLockedEffect*)pLE, pParam->dResolution))
03627 {
03628 ((NodeLockedEffect*)pLE)->SetPixelsPerInch(pParam->dResolution);
03629
03630
03631
03632 ((NodeLockedEffect*)pLE)->SetProcessedBitmap(NULL, NULL, DocRect(), 0, 0, 0, 0);
03633 pLE->ReleaseCached(TRUE, FALSE);
03634
03635 *ppNewEffect = (NodeLockedEffect*)pLE;
03636
03637 return TRUE;
03638 }
03639 }
03640 }
03641 else
03642 if (pLE->IsBitmapEffect())
03643 {
03644 if (ChangeEffectResAction::CreateChangeEffectResAction(this, (NodeBitmapEffect*)pLE, pParam->dResolution))
03645 {
03646 ((NodeBitmapEffect*)pLE)->SetPixelsPerInch(pParam->dResolution);
03647 pLE->ReleaseCached();
03648 *ppNewEffect = (NodeBitmapEffect*)pLE;
03649
03650 return TRUE;
03651 }
03652 }
03653 else
03654 ERROR3("Unknown effect type in OpEffectRes::DoEffectNodeOp");
03655
03656 return FALSE;
03657 }
03658
03659
03660
03661
03663
03665
03666
03667
03668
03669
03670
03671
03672
03673
03674
03675
03676
03677
03678
03679
03680 OpState OpEffectLock::GetState(String_256* pstrDescription, OpDescriptor* pOpDesc)
03681 {
03682
03683 OpState OpSt;
03684 OpSt.Greyed = FALSE;
03685 *pstrDescription = String_256(_R(IDS_DESCRIBE_LIVEEFFECT));
03686
03687 return OpSt;
03688 }
03689
03690
03691
03692
03693
03694
03695
03696
03697
03698
03699
03700
03701
03702
03703
03704
03705
03706 void OpEffectLock::GetOpName(String_256* pstrOpName)
03707 {
03708 *pstrOpName = String_256(_R(IDS_LE_OPEFFECTLOCK));
03709 }
03710
03711
03712
03713
03714
03715
03716
03717
03718
03719
03720
03721
03722
03723
03724
03725
03726
03727
03728 BOOL OpEffectLock::DoEffectOp(ListRange* pLevelRange, OpLiveEffectParam* pParam)
03729 {
03730 BOOL bOK = FALSE;
03731
03732 UINT32 idsProgress = _R(IDS_LE_UNLOCK_PROGRESS);
03733 if (pParam->bForceLock) idsProgress = _R(IDS_LE_LOCK_PROGRESS);
03734 bOK = DoEffectRangeOp(idsProgress, pLevelRange, pParam);
03735
03736 return bOK;
03737 }
03738
03739
03740
03741
03742
03743
03744
03745
03746
03747
03748
03749
03750
03751
03752
03753
03754
03755
03756 BOOL OpEffectLock::DoEffectNodeOp(NodeEffect* pLE, OpLiveEffectParam* pParam, NodeBitmapEffect** ppNewEffect)
03757 {
03758
03759 ERROR2IF(pLE==NULL, FALSE, "OpEffectLock::DoEffectNodeOp given NULL node");
03760 ERROR2IF(pParam==NULL, FALSE, "OpEffectRes::DoEffectNodeOp given NULL param");
03761
03762 double dViewPPI = 96.0;
03763 View* pView = View::GetCurrent();
03764 if (pView) dViewPPI = 72000.0 / pView->GetPixelWidth().MakeDouble();
03765 BOOL bForceLock = pParam->bForceLock;
03766 NodeBitmapEffect* pNewEffect = NULL;
03767
03768 if (pLE->IsBitmapEffect() && !pLE->IsFeatherEffect())
03769 {
03770 NodeBitmapEffect* pBitmapEffect = (NodeBitmapEffect*)pLE;
03771 if (pBitmapEffect->IsLockedEffect())
03772 {
03773 if (((NodeLockedEffect*)pBitmapEffect)->CanBeUnlocked() && bForceLock==FALSE)
03774 {
03775
03776
03777 BOOL bWasSelected = pBitmapEffect->IsSelected();
03778
03779
03780
03781 double dNewRes = pBitmapEffect->GetPixelsPerInch();
03782 if (dNewRes==dViewPPI)
03783 dNewRes = 0;
03784
03785 pNewEffect = DoApplyLiveEffect(this,
03786 pBitmapEffect,
03787 pBitmapEffect->GetPostProcessorID(),
03788 pBitmapEffect->GetDisplayName(),
03789 dNewRes,
03790 pBitmapEffect->GetEditList()
03791 );
03792 CopyEffectAttrs(pBitmapEffect, pNewEffect);
03793 DoFactorOutCommonChildAttributes(pNewEffect);
03794 DoDeletePostProcessor(this, pBitmapEffect, TRUE);
03795
03796 if (bWasSelected)
03797 {
03798 pNewEffect->Select(FALSE);
03799 }
03800
03801 *ppNewEffect = pNewEffect;
03802 return TRUE;
03803 }
03804 }
03805 else
03806 {
03807 if (bForceLock==TRUE)
03808 {
03809
03810
03811 ERROR3IF(pBitmapEffect->IsLockedEffect(), "Unexpected type of BitmapEffect in OpEffectLock");
03812 NodeLiveEffect* pLiveEffect = (NodeLiveEffect*)pBitmapEffect;
03813 BOOL bWasSelected = pLiveEffect->IsParentOfSelected();
03814
03815 double dReqdResolution = pLiveEffect->GetPixelsPerInch();
03816 LPBITMAPINFO lpInfo = NULL;
03817 LPBYTE lpBits = NULL;
03818 DocRect rectBounds;
03819 double dRes = 0;
03820 Matrix matTransform;
03821
03822 if (bWasSelected)
03823 {
03824
03825 pLiveEffect->DeSelect(FALSE, TRUE);
03826 }
03827
03828 if (pLiveEffect->GetPixelsPerInch()==dReqdResolution)
03829 {
03830
03831
03832
03833
03834 BOOL bDirect = pLiveEffect->GetChildDirectBitmap(NULL, NULL, NULL, NULL, &matTransform, &dRes);
03835 if (dRes==0)
03836 dRes = pLiveEffect->GetPixelsPerInch();
03837
03838
03839
03840
03841
03842 bDirect = bDirect && !matTransform.IsIdentity();
03843 pLiveEffect->GetProcessedBitmap(bDirect, &lpInfo, &lpBits, &rectBounds);
03844
03845 pLiveEffect->RemoveBitmapFromCache();
03846 }
03847
03848
03849
03850
03851 pNewEffect = DoApplyLiveEffect(this,
03852 pLiveEffect,
03853 pLiveEffect->GetPostProcessorID(),
03854 pLiveEffect->GetDisplayName(),
03855 dReqdResolution,
03856 pLiveEffect->GetEditList(),
03857 TRUE
03858 );
03859 CopyEffectAttrs(pLiveEffect, pNewEffect);
03860 DoFactorOutCommonChildAttributes(pNewEffect);
03861
03862
03863 if (pNewEffect && lpInfo && lpBits && rectBounds.IsValid())
03864 {
03865 pNewEffect->SetProcessedBitmap(lpInfo, lpBits, rectBounds, 0, 0, 0, 0, 72000.0/dRes, &matTransform);
03866 }
03867
03868 DoDeletePostProcessor(this, pLiveEffect, TRUE);
03869
03870 if (bWasSelected)
03871 {
03872 pNewEffect->Select(FALSE);
03873 }
03874
03875 *ppNewEffect = pNewEffect;
03876 return TRUE;
03877 }
03878 }
03879 }
03880 else
03881 ERROR3("Unknown effect type in OpEffectLock::DoEffectNodeOp");
03882
03883 return FALSE;
03884 }
03885
03886
03887
03888
03889
03890
03891
03892
03893
03894
03895
03896
03897
03898
03899
03900
03901
03902
03903
03904 BOOL OpEffectLock::CopyEffectAttrs(NodeBitmapEffect* pSrcNode, NodeBitmapEffect* pDestNode)
03905 {
03906 NodeAttribute* pAttr = NodeAttribute::FindFirstAppliedAttr(pSrcNode);
03907 while (pAttr && pAttr->IsEffectAttribute() && pAttr->FindParent()==pSrcNode)
03908 {
03909 if (!pAttr->HasEquivalentDefaultValue(TRUE))
03910 {
03911 if (pDestNode->IsValidEffectAttr(pAttr))
03912 {
03913 NodeAttribute* pExistingAttr = pDestNode->FindAppliedAttribute(pAttr->GetRuntimeClass());
03914 if (pExistingAttr==NULL || pExistingAttr->FindParent()!=pDestNode)
03915 {
03916
03917
03918 NodeAttribute* pCopyAttr = NULL;
03919 BOOL bOK = FALSE;
03920 CALL_WITH_FAIL(pCopyAttr = (NodeAttribute*)pAttr->SimpleCopy(), this, bOK);
03921 if (!bOK) return FALSE;
03922
03923 pCopyAttr->AttachNode(pDestNode, LASTCHILD);
03924 }
03925 }
03926 }
03927
03928 pAttr = NodeAttribute::FindPrevAppliedAttr(pAttr);
03929 }
03930
03931 return TRUE;
03932 }
03933
03934
03935
03936
03938
03940
03941
03942
03943
03944
03945
03946
03947
03948
03949
03950
03951
03952
03953
03954
03955 OpState OpEffectLockAll::GetState(String_256* pstrDescription, OpDescriptor* pOpDesc)
03956 {
03957
03958 OpState OpSt;
03959 OpSt.Greyed = FALSE;
03960 *pstrDescription = String_256(_R(IDS_DESCRIBE_LIVEEFFECT));
03961
03962 if (XPEHost::IsEditSessionRunning())
03963 {
03964 OpSt.Greyed = TRUE;
03965 *pstrDescription = String_256(_R(IDS_LE_EDIT_RUNNING));
03966 }
03967
03968 return OpSt;
03969 }
03970
03971
03972
03973
03974
03975
03976
03977
03978
03979
03980
03981
03982
03983
03984
03985
03986
03987 void OpEffectLockAll::GetOpName(String_256* pstrOpName)
03988 {
03989 *pstrOpName = String_256(_R(IDS_LE_OPEFFECTLOCKALL));
03990 }
03991
03992
03993
03994
03995
03996
03997
03998
03999
04000
04001
04002
04003
04004
04005
04006
04007
04008
04009 BOOL OpEffectLockAll::DoEffectOp(ListRange* pLevelRange, OpLiveEffectParam* pLEOpParam)
04010 {
04011 SelRange Sel(*(GetApplication()->FindSelection()));
04012
04013 Sel.SetPromoteToParent(TRUE);
04014 Node* pNode = Sel.FindFirst();
04015 Node* pNextNode = NULL;
04016 NodeBitmapEffect* pNewEffect = NULL;
04017 BOOL bChangedSomething = FALSE;
04018 BOOL bChanged;
04019 while (pNode)
04020 {
04021 pNextNode = Sel.FindNext(pNode);
04022
04023
04024
04025 Node* pScanNode = pNode->FindFirstPreorder();
04026 while (pScanNode)
04027 {
04028 if (pScanNode->IsBitmapEffect() && !((NodeBitmapEffect*)pScanNode)->IsFeatherEffect())
04029 {
04030 pNewEffect = NULL;
04031 bChanged = OpEffectLock::DoEffectNodeOp((NodeBitmapEffect*)pScanNode, pLEOpParam, &pNewEffect);
04032 if (pNewEffect && bChanged)
04033 {
04034 if (pScanNode == pNode)
04035 pNode = pNewEffect;
04036 pScanNode = pNewEffect;
04037 }
04038 bChangedSomething = bChangedSomething || bChanged;
04039
04040
04041
04042
04043 pScanNode = pScanNode->FindNextPreorder(pNode, TRUE);
04044 }
04045 else
04046 pScanNode = pScanNode->FindNextPreorder(pNode);
04047 }
04048
04049 pNode = pNextNode;
04050 }
04051
04052 if (!bChangedSomething)
04053 SucceedAndDiscard();
04054
04055 return TRUE;
04056 }
04057
04058
04059
04060
04061 BOOL OpEffectLockAll::CheckEffectOpParam(OpLiveEffectParam* pLEOpParam)
04062 {
04063 return TRUE;
04064 }
04065
04066
04067
04068
04069 #ifdef FEATHER_EFFECT
04070
04071
04073
04074
04075
04076
04077
04078
04079
04080
04081
04082
04083
04084
04085
04086
04087
04088
04089
04090 OpState OpApplyFeatherEffect::GetParamState(String_256* pstrDescription, OpDescriptor* pOpDesc, OpParam* pOpParam)
04091 {
04092
04093 OpState OpSt;
04094 OpSt.Greyed = (GetApplication()->FindSelection()->FindFirst()==NULL);
04095
04096 return OpSt;
04097 }
04098
04099
04100
04101
04102
04103
04104
04105
04106
04107
04108
04109
04110
04111
04112
04113
04114
04115 void OpApplyFeatherEffect::GetOpName(String_256* pstrOpName)
04116 {
04117 *pstrOpName = String_256(_R(IDS_LE_OPAPPLYFEATHER));
04118 }
04119
04120
04121
04122
04123
04124
04125
04126
04127
04128
04129
04130
04131
04132
04133
04134
04135
04136 void OpApplyFeatherEffect::DoWithParam(OpDescriptor* pOpDesc, OpParam* pOpParam)
04137 {
04138 BOOL ok = FALSE;
04139
04140 OpFeatherEffectParam* pFeatherOpParam = NULL;
04141 if (pOpParam->IsKindOf(CC_RUNTIME_CLASS(OpFeatherEffectParam)))
04142 pFeatherOpParam = (OpFeatherEffectParam*) pOpParam;
04143
04144 INT32 InsertPos = pFeatherOpParam->StackPosition - 1;
04145
04146
04147
04148 m_strEffectID = pFeatherOpParam->strOpUnique;
04149 m_iStackPos = InsertPos;
04150
04151
04152 SelRange* pSelRange = GetApplication()->FindSelection();
04153
04154 if (pSelRange->FindFirst()==NULL)
04155 {
04156 End();
04157 return;
04158 }
04159
04160 Range* pInitialRange = NULL;
04161
04162
04163 Tool* pTool = Tool::GetCurrent();
04164 Spread* pSpread = Document::GetSelectedSpread();
04165 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
04166 pTool->RenderToolBlobs(pSpread, NULL);
04167
04168
04169 if (!DoStartSelOp(FALSE, FALSE))
04170 {
04171 End();
04172 return;
04173 }
04174
04175
04176
04177 ObjChangeFlags cFlags(NULL, TRUE, NULL, NULL, NULL, NULL, NULL, TRUE);
04178 ObjChangeParam ObjChange(OBJCHANGE_STARTING, cFlags, NULL, this);
04179 BOOL bOK = pSelRange->AllowOp(&ObjChange);
04180 if (!bOK)
04181 {
04182 End();
04183 return;
04184 }
04185
04186 if (!DoInvalidateNodesRegions(*pSelRange, TRUE, FALSE, FALSE, FALSE))
04187 {
04188 End();
04189 return;
04190 }
04191
04192
04193 pSelRange->MakePartialSelectionWhole(FALSE, FALSE, TRUE);
04194
04195
04196 ENSURE(m_pLERange==NULL, "!");
04197 if (InsertPos==-1)
04198 {
04199
04200 pInitialRange = GetApplication()->FindSelection();
04201 m_iStackPos = 0;
04202 }
04203 else
04204 {
04205 ENSURE(pFeatherOpParam->pPPStack, "Can't find EffectsStack");
04206 pInitialRange = pFeatherOpParam->pPPStack->GetLevelRange(&InsertPos);
04207 m_iStackPos = InsertPos+1;
04208
04209 }
04210
04211
04212 if (pInitialRange==NULL)
04213 {
04214 ERROR3("If this happens, the UI logic disagrees with the Op about what the Op can do");
04215 FailAndExecute();
04216 End();
04217 return;
04218 }
04219
04220 m_pLERange = DoApplyFeatherEffect(this, pInitialRange, pFeatherOpParam->strOpUnique, pFeatherOpParam->strMenuText, pFeatherOpParam->FeatherSize, pFeatherOpParam->Profile);
04221 m_bAppliedNewEffects = TRUE;
04222
04223
04224 if (m_pLERange==NULL)
04225 {
04226 FailAndExecute();
04227 End();
04228 return;
04229 }
04230
04231
04232
04233 OpChangeFeatherSize::SetEditContext(m_iStackPos, m_pLERange);
04234
04235
04236 if (pTool->GetID()==TOOLID_LIVEEFFECT)
04237 {
04238 ((LiveEffectsTool*)pTool)->SetCurrentEffectID(m_strEffectID);
04239 ((LiveEffectsTool*)pTool)->SetCurrentStackPos(m_iStackPos);
04240 }
04241
04242
04243 DoInvalidateNodesRegions(*pSelRange, TRUE, FALSE, FALSE);
04244
04245
04246 if (pSpread != NULL && pTool != NULL && !pTool->AreToolBlobsRenderedOnSelection())
04247 pTool->RenderToolBlobs(pSpread, NULL);
04248
04249 ObjChange.Define(OBJCHANGE_FINISHED, cFlags, NULL, this);
04250 ok = UpdateChangedNodes(&ObjChange);
04251
04252 BROADCAST_TO_ALL(SelChangingMsg(SelChangingMsg::EFFECTSTACKCHANGED));
04253
04254
04255 GetApplication()->FindSelection()->Update();
04256
04257 End();
04258 }
04259 #endif
04260
04261
04262
04263
04265
04267
04268
04269
04270
04271
04272
04273
04274
04275
04276
04277
04278
04279
04280
04281
04282 ChangeEffectResAction::ChangeEffectResAction()
04283 {
04284 m_dResolution = 0;
04285 m_pEffectNode = NULL;
04286 }
04287
04288
04289
04290
04291
04292
04293
04294
04295
04296
04297
04298
04299
04300
04301
04302
04303
04304
04305
04306
04307
04308
04309
04310
04311
04312
04313
04314 ActionCode ChangeEffectResAction::Init( Operation* pOp,
04315 ActionList* pActionList,
04316 Action** NewAction)
04317 {
04318 UINT32 ActSize = sizeof(ChangeEffectResAction);
04319
04320 ActionCode Ac = Action::Init( pOp, pActionList, ActSize, CC_RUNTIME_CLASS(ChangeEffectResAction), NewAction);
04321
04322 return Ac;
04323 }
04324
04325
04326
04327
04328
04329
04330
04331
04332
04333
04334
04335
04336
04337
04338
04339
04340
04341
04342
04343
04344
04345
04346 BOOL ChangeEffectResAction::CreateChangeEffectResAction(Operation* pOp,
04347 NodeBitmapEffect* pEffectNode,
04348 double dRes
04349 )
04350 {
04351 ERROR3IF(pOp==NULL, "CreateChangeEffectResAction given NULL op pointer");
04352 ERROR3IF(pEffectNode==NULL, "CreateChangeEffectResAction given NULL node pointer");
04353
04354 if (dRes == pEffectNode->GetPixelsPerInchValue())
04355 return FALSE;
04356
04357 ChangeEffectResAction* RecAction = NULL;
04358 ActionCode Act = ChangeEffectResAction::Init(pOp, pOp->GetUndoActionList(), (Action**)&RecAction);
04359 if ( (Act == AC_OK) && (RecAction != NULL) )
04360 {
04361 RecAction->m_dResolution = pEffectNode->GetPixelsPerInchValue();
04362 RecAction->m_pEffectNode = pEffectNode;
04363 }
04364 else if (Act==AC_FAIL)
04365 {
04366 pOp->FailAndExecute();
04367 pOp->End();
04368 }
04369
04370 return (Act != AC_FAIL);
04371 }
04372
04373
04374
04375
04376
04377
04378
04379
04380
04381
04382
04383
04384
04385
04386
04387
04388
04389
04390 ActionCode ChangeEffectResAction::Execute()
04391 {
04392 ChangeEffectResAction* ReAction = NULL;
04393 ActionCode Act = AC_FAIL;
04394
04395
04396 Act = ChangeEffectResAction::Init(pOperation,
04397 pOppositeActLst,
04398 (Action**)(&ReAction));
04399 if (Act == AC_FAIL)
04400 return AC_FAIL;
04401
04402
04403
04404 ReAction->m_pEffectNode = m_pEffectNode;
04405 ReAction->m_dResolution = m_pEffectNode->GetPixelsPerInchValue();;
04406
04407
04408
04409 if (m_pEffectNode->IsLockedEffect())
04410 {
04411 ((NodeLockedEffect*)m_pEffectNode)->SetPixelsPerInch(m_dResolution);
04412 }
04413 else
04414 if (m_pEffectNode->IsBitmapEffect())
04415 {
04416 ((NodeBitmapEffect*)m_pEffectNode)->SetPixelsPerInch(m_dResolution);
04417 m_pEffectNode->ReleaseCached();
04418 }
04419
04420 return Act;
04421 }
04422
04423 ChangeEffectResAction::~ChangeEffectResAction()
04424 {
04425 m_pEffectNode = NULL;
04426 }
04427
04428
04429
04430
04432
04434
04435
04436
04437
04438
04439
04440
04441
04442
04443
04444
04445
04446
04447
04448
04449
04450
04451
04452
04453
04454
04455
04456
04457
04458
04459
04460
04461
04462
04463
04464
04465
04466
04467
04468
04469
04470
04471
04472
04473
04474
04475
04476
04477
04478
04479
04480
04481
04482
04483
04484
04485
04486
04487
04488
04489
04490
04491
04492
04493
04494
04495
04496
04497
04498
04499
04500
04501
04502
04503
04504
04505
04506
04507
04508
04509
04510
04511
04512
04513
04514
04515
04516
04517
04518
04519
04520
04521
04522
04523
04524
04525
04526
04527
04528
04529
04530
04531
04532
04533
04534
04535
04536
04537
04538
04539
04540
04541
04542
04543
04544
04545
04546
04547
04548
04549
04550
04551
04552
04553
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565
04566
04567
04568
04569
04570
04571
04572
04573
04574
04575
04576
04577
04578
04579
04580
04581
04582
04583
04584
04585
04586
04587
04588
04590
04592
04593
04594
04595
04596
04597
04598
04599
04600
04601
04602
04603
04604
04605
04606
04607 MarkEditListAction::MarkEditListAction()
04608 {
04609 pEditList = NULL;
04610 iStackPos = -1;
04611 }
04612
04613
04614
04615
04616
04617
04618
04619
04620
04621
04622
04623
04624
04625
04626
04627
04628
04629
04630
04631
04632
04633
04634
04635
04636
04637
04638
04639 ActionCode MarkEditListAction::Init( Operation* pOp,
04640 ActionList* pActionList,
04641 Action** NewAction)
04642 {
04643 UINT32 ActSize = sizeof(MarkEditListAction);
04644
04645 ActionCode Ac = Action::Init( pOp, pActionList, ActSize, CC_RUNTIME_CLASS(MarkEditListAction), NewAction);
04646
04647 return Ac;
04648 }
04649
04650
04651
04652
04653
04654
04655
04656
04657
04658
04659
04660
04661
04662
04663
04664
04665
04666
04667
04668
04669
04670
04671
04672 ActionCode MarkEditListAction::DoMarkEditList(Operation* pOp,
04673 ActionList* pActionList,
04674 EffectsStack* pPPStack,
04675 INT32 iStackPos
04676 )
04677 {
04678 ERROR2IF(iStackPos<0, AC_FAIL, "Bad stack pos in DoMarkEditList");
04679
04680 MarkEditListAction* RecAction = NULL;
04681 ActionCode Act = MarkEditListAction::Init(pOp, pActionList, (Action**)&RecAction);
04682 if ( (Act == AC_OK) && (RecAction != NULL) )
04683 {
04684 PPStackLevel* pLevel = (PPStackLevel*)pPPStack->FindItem(iStackPos);
04685 if (pLevel && pLevel->pPPNode && pLevel->pPPNode->IsBitmapEffect())
04686 {
04687 RecAction->pEditList = CXMLUtils::NewDocument(((NodeBitmapEffect*)pLevel->pPPNode)->GetEditList());
04688 RecAction->iStackPos = iStackPos;
04689 }
04690 else
04691 return AC_FAIL;
04692 }
04693 return Act;
04694 }
04695
04696
04697
04698
04699
04700
04701
04702
04703
04704
04705
04706
04707
04708
04709
04710
04711
04712
04713 ActionCode MarkEditListAction::Execute()
04714 {
04715 ERROR2IF(this->iStackPos<0, AC_FAIL, "Bad stack pos in MarkEditListAction::Execute");
04716
04717 MarkEditListAction* ReAction = NULL;
04718 ActionCode Act = AC_FAIL;
04719
04720
04721 Act = MarkEditListAction::Init(pOperation,
04722 pOppositeActLst,
04723 (Action**)(&ReAction));
04724 if (Act == AC_FAIL)
04725 return AC_FAIL;
04726
04727
04728
04729 EffectsStack* pPPStack = EffectsStack::GetEffectsStackFromSelection();
04730 if (pPPStack==NULL)
04731 return AC_FAIL;
04732
04733 PPStackLevel* pLevel = (PPStackLevel*)pPPStack->FindItem(this->iStackPos);
04734 if (pLevel && pLevel->pPPNode && pLevel->pPPNode->IsBitmapEffect())
04735 {
04736 ReAction->pEditList = CXMLUtils::NewDocument(((NodeBitmapEffect*)pLevel->pPPNode)->GetEditList());
04737 ReAction->iStackPos = this->iStackPos;
04738 }
04739 else
04740 {
04741 ReAction->pEditList = CXMLUtils::NewDocument(this->pEditList);
04742 ReAction->iStackPos = this->iStackPos;
04743 }
04744
04745
04746
04747
04748 Node* pNode = NULL;
04749 if (pLevel) pNode = pLevel->listSelNodes.FindFirst();
04750 while (pNode)
04751 {
04752 if (pNode->IsBitmapEffect())
04753 {
04754 NodeBitmapEffect* pLE = (NodeBitmapEffect*)pNode;
04755 pLE->SetProcessedBitmap(NULL, NULL, DocRect(), 0, 0, 0, 0);
04756 pLE->SetEditList(CXMLUtils::NewDocument(this->pEditList));
04757 }
04758 else
04759 return AC_FAIL;
04760
04761 pNode = pLevel->listSelNodes.FindNext(pNode);
04762 }
04763
04764 delete pPPStack;
04765 pPPStack = NULL;
04766
04767 return Act;
04768 }
04769
04770 MarkEditListAction::~MarkEditListAction()
04771 {
04772 pEditList = NULL;
04773 }
04774
04775
04776
04777