00001 // $Id: opnudge.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 // Implementation of the nudge ops 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 #include "opnudge.h" 00105 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "markn.h" 00107 //#include "resource.h" 00108 //#include "range.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00110 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00111 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00112 #include "ophist.h" 00113 00114 00115 //Matt 11/11/00 - I only wanted a function from the next line... 00116 #include "slicehelper.h" //For helper functions 00117 00118 //But I had to include all of these to get it to work!!... 00119 //#include "cxfrech.h" //For CamelotRecordHandler - in camtypes.h [AUTOMATICALLY REMOVED] 00120 #include "userattr.h" //For UserAttr 00121 #include "tmpltatr.h" //For TemplateAttribute 00122 00123 00124 DECLARE_SOURCE("$Revision: 1282 $"); 00125 00126 CC_IMPLEMENT_DYNCREATE(OpNudge,OpTranslateTrans) 00127 00128 /********************************************************************************************* 00129 00130 Preference: StepSize 00131 Section: Nudge 00132 Range: 0 to UINT_MAX 00133 Purpose: This is the users nudge step size setting. It is the distance in millipoints 00134 that the nudge operation should move the object. Holding down the CTRL key 00135 multiplies the nudge distance by 5, SHIFT multiplies it by 10. 00136 SeeAlso: 00137 00138 **********************************************************************************************/ 00139 00140 #define new CAM_DEBUG_NEW 00141 00142 // WEBSTER - markn 6/12/96 00143 // Changed the default nudge size to a round number of pixels 00144 #ifndef WEBSTER 00145 MILLIPOINT OpNudge::NudgeStep = 2835; // The default size of a single nudge (1mm) 00146 #else 00147 MILLIPOINT OpNudge::NudgeStep = 3750; // The default size of a single nudge (5 pixels) 00148 #endif // WEBSTER 00149 00150 /******************************************************************************************** 00151 00152 > static BOOL OpNudge::Init() 00153 00154 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00155 Created: 7/9/94 00156 Inputs: - 00157 Outputs: - 00158 Returns: TRUE if the operation could be successfully initialised 00159 FALSE if no more memory could be allocated 00160 Purpose: OpNudge initialiser method. Inits all the nudge OpDescriptors and reads the 00161 NudgeStep from the preferences file. 00162 Errors: ERROR will be called if there was insufficient memory to allocate the 00163 operation. 00164 SeeAlso: - 00165 00166 ********************************************************************************************/ 00167 00168 // This macro gives a short-hand way of registering all the nudge opdescriptors 00169 // It may have to be updated if we every want to put nudging on buttons 00170 00171 #define REG_NUDGE_OP(NAME)\ 00172 {\ 00173 BOOL Blobby = RegisterOpDescriptor(\ 00174 0,\ 00175 _R(IDS_NUDGE),\ 00176 CC_RUNTIME_CLASS(OpNudge),\ 00177 OPTOKEN_ ## NAME,\ 00178 OpNudge::GetState,\ 00179 0,\ 00180 0,\ 00181 0,\ 00182 0,\ 00183 SYSTEMBAR_ILLEGAL,\ 00184 TRUE,\ 00185 FALSE,\ 00186 FALSE,\ 00187 0,\ 00188 0 \ 00189 );\ 00190 ERROR1IF(!Blobby, FALSE, _R(IDS_OUT_OF_MEMORY));\ 00191 }\ 00192 00193 // Finally, OpNudge::Init() 00194 00195 BOOL OpNudge::Init() 00196 { 00197 REG_NUDGE_OP(NUDGEUP1); 00198 REG_NUDGE_OP(NUDGEUP5); 00199 REG_NUDGE_OP(NUDGEUP10); 00200 REG_NUDGE_OP(NUDGEUPFIFTH); 00201 REG_NUDGE_OP(NUDGEUPPIXEL1); 00202 REG_NUDGE_OP(NUDGEUPPIXEL10); 00203 00204 REG_NUDGE_OP(NUDGEDOWN1); 00205 REG_NUDGE_OP(NUDGEDOWN5); 00206 REG_NUDGE_OP(NUDGEDOWN10); 00207 REG_NUDGE_OP(NUDGEDOWNFIFTH); 00208 REG_NUDGE_OP(NUDGEDOWNPIXEL1); 00209 REG_NUDGE_OP(NUDGEDOWNPIXEL10); 00210 00211 REG_NUDGE_OP(NUDGELEFT1); 00212 REG_NUDGE_OP(NUDGELEFT5); 00213 REG_NUDGE_OP(NUDGELEFT10); 00214 REG_NUDGE_OP(NUDGELEFTFIFTH); 00215 REG_NUDGE_OP(NUDGELEFTPIXEL1); 00216 REG_NUDGE_OP(NUDGELEFTPIXEL10); 00217 00218 REG_NUDGE_OP(NUDGERIGHT1); 00219 REG_NUDGE_OP(NUDGERIGHT5); 00220 REG_NUDGE_OP(NUDGERIGHT10); 00221 REG_NUDGE_OP(NUDGERIGHTFIFTH); 00222 REG_NUDGE_OP(NUDGERIGHTPIXEL1); 00223 REG_NUDGE_OP(NUDGERIGHTPIXEL10); 00224 00225 //Camelot.DeclareSection(TEXT("Nudge"), 1); 00226 //Camelot.DeclarePref(TEXT("Nudge"), TEXT("StepSize"), (UINT32*)&OpNudge::NudgeStep, 0, UINT_MAX); 00227 00228 ERROR2IF(OpNudge::NudgeStep<0, FALSE, "Preference nudge step was negative"); 00229 00230 return (TRUE); 00231 } 00232 00233 /******************************************************************************************** 00234 00235 > static OpState OpNudge::GetState(String_256*, OpDescriptor*) 00236 00237 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00238 Created: 7/9/94 00239 Inputs: ptr to a string to place a description of what went wrong (if it did!) 00240 Outputs: - 00241 Returns: The state of the OpNudge operation 00242 Purpose: For finding OpNudge's state. 00243 Errors: - 00244 SeeAlso: - 00245 00246 ********************************************************************************************/ 00247 00248 OpState OpNudge::GetState(String_256* UIDescription, OpDescriptor*) 00249 { 00250 OpState OpSt; 00251 00252 SelRange* pSelRange = GetApplication()->FindSelection(); 00253 if (pSelRange != NULL && pSelRange->FindFirst() != NULL) 00254 OpSt.Greyed = FALSE; 00255 else 00256 OpSt.Greyed = TRUE; 00257 00258 return (OpSt); 00259 } 00260 00261 /******************************************************************************************** 00262 00263 > void OpNudge::Do(OpDescriptor* pOpDesc) 00264 00265 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00266 Created: 7/9/94 00267 Inputs: pOpDesc = ptr to the op descriptor 00268 Outputs: - 00269 Returns: - 00270 Purpose: The nudge op's Do() function. 00271 Errors: - 00272 SeeAlso: - 00273 00274 ********************************************************************************************/ 00275 void OpNudge::Do(OpDescriptor* pOpDesc) 00276 { 00277 // Determine the nudge factors based on the OpDescriptor used to invoke the nudge operation 00278 String OpToken = pOpDesc->Token; 00279 00280 //Get scaled pixel size 00281 FIXED16 ScaledPixelWidth, ScaledPixelHeight; 00282 GetWorkingView()->GetScaledPixelSize(&ScaledPixelWidth, &ScaledPixelHeight) ; 00283 PixelNudge=ScaledPixelWidth.MakeDouble() ; 00284 00285 00286 if (OpToken == String(OPTOKEN_NUDGEUP1)) { X_NudgeFactor = 0; Y_NudgeFactor = 1; flag=TRUE; } 00287 else if (OpToken == String(OPTOKEN_NUDGEUP5)) { X_NudgeFactor = 0; Y_NudgeFactor = 5; flag=TRUE; } 00288 else if (OpToken == String(OPTOKEN_NUDGEUP10)) { X_NudgeFactor = 0; Y_NudgeFactor = 10; flag=TRUE; } 00289 else if (OpToken == String(OPTOKEN_NUDGEUPFIFTH)) { X_NudgeFactor = 0; Y_NudgeFactor = 0.2; flag=TRUE; } 00290 else if (OpToken == String(OPTOKEN_NUDGEDOWN1)) { X_NudgeFactor = 0; Y_NudgeFactor = -1; flag=TRUE; } 00291 else if (OpToken == String(OPTOKEN_NUDGEDOWN5)) { X_NudgeFactor = 0; Y_NudgeFactor = -5; flag=TRUE; } 00292 else if (OpToken == String(OPTOKEN_NUDGEDOWN10)) { X_NudgeFactor = 0; Y_NudgeFactor = -10; flag=TRUE; } 00293 else if (OpToken == String(OPTOKEN_NUDGEDOWNFIFTH)) { X_NudgeFactor = 0; Y_NudgeFactor = -0.2; flag=TRUE; } 00294 else if (OpToken == String(OPTOKEN_NUDGELEFT1)) { X_NudgeFactor = -1; Y_NudgeFactor = 0; flag=TRUE; } 00295 else if (OpToken == String(OPTOKEN_NUDGELEFT5)) { X_NudgeFactor = -5; Y_NudgeFactor = 0; flag=TRUE; } 00296 else if (OpToken == String(OPTOKEN_NUDGELEFT10)) { X_NudgeFactor = -10; Y_NudgeFactor = 0; flag=TRUE; } 00297 else if (OpToken == String(OPTOKEN_NUDGELEFTFIFTH)) { X_NudgeFactor = -0.2; Y_NudgeFactor = 0; flag=TRUE; } 00298 else if (OpToken == String(OPTOKEN_NUDGERIGHT1)) { X_NudgeFactor = 1; Y_NudgeFactor = 0; flag=TRUE; } 00299 else if (OpToken == String(OPTOKEN_NUDGERIGHT5)) { X_NudgeFactor = 5; Y_NudgeFactor = 0; flag=TRUE; } 00300 else if (OpToken == String(OPTOKEN_NUDGERIGHT10)) { X_NudgeFactor = 10; Y_NudgeFactor = 0; flag=TRUE; } 00301 else if (OpToken == String(OPTOKEN_NUDGERIGHTFIFTH)) { X_NudgeFactor = 0.2; Y_NudgeFactor = 0; flag=TRUE; } 00302 00303 else if (OpToken == String(OPTOKEN_NUDGEUPPIXEL1)) { X_NudgeFactor = 0; Y_NudgeFactor = 1; flag=FALSE; } 00304 else if (OpToken == String(OPTOKEN_NUDGEUPPIXEL10)) { X_NudgeFactor = 0; Y_NudgeFactor = 10; flag=FALSE; } 00305 else if (OpToken == String(OPTOKEN_NUDGEDOWNPIXEL1)) { X_NudgeFactor = 0; Y_NudgeFactor = -1; flag=FALSE; } 00306 else if (OpToken == String(OPTOKEN_NUDGEDOWNPIXEL10)) { X_NudgeFactor = 0; Y_NudgeFactor = -10; flag=FALSE; } 00307 else if (OpToken == String(OPTOKEN_NUDGELEFTPIXEL1)) { X_NudgeFactor = -1; Y_NudgeFactor = 0; flag=FALSE; } 00308 else if (OpToken == String(OPTOKEN_NUDGELEFTPIXEL10)) { X_NudgeFactor = -10; Y_NudgeFactor = 0; flag=FALSE; } 00309 else if (OpToken == String(OPTOKEN_NUDGERIGHTPIXEL1)) { X_NudgeFactor = 1; Y_NudgeFactor = 0; flag=FALSE; } 00310 else if (OpToken == String(OPTOKEN_NUDGERIGHTPIXEL10)) { X_NudgeFactor = 10; Y_NudgeFactor = 0; flag=FALSE; } 00311 00312 else 00313 { 00314 ERROR3("Unknown type of nudge"); 00315 } 00316 00317 00318 00319 Range* Selection = GetApplication()->FindSelection(); 00320 RangeControl TransFlags = Selection->GetRangeControlFlags(); 00321 TransFlags.IgnoreNoneRenderable=TRUE; 00322 TransFlags.IgnoreInvisibleLayers = TRUE; 00323 Selection->SetRangeControl(TransFlags); 00324 SliceHelper::ModifySelectionToContainWholeButtonElements(); 00325 00326 00327 00328 // Setup the Offset DocCoord to contain the X and Y translation values 00329 DocCoord Offset; 00330 00331 if (flag) 00332 { 00333 (Offset.x) = (INT32) GetXNudgeDisplacement(); 00334 (Offset.y) = (INT32) GetYNudgeDisplacement(); 00335 } 00336 else if (!flag) 00337 { 00338 (Offset.x) = (INT32)GetXPixelDisplacement(); 00339 (Offset.y) = (INT32)GetYPixelDisplacement(); 00340 } 00341 00342 // Will the nudge send the selection beyond the spread bounds? 00343 // If so, fail and return now 00344 if (!IsNudgeOK(Offset.x,Offset.y)) 00345 { 00346 SliceHelper::RestoreSelection(); 00347 InformWarning(_R(IDS_NUDGE_OUTOFBOUNDS)); 00348 FailAndExecute(); 00349 End(); 00350 return; 00351 } 00352 00353 TransformData TransData; 00354 00355 // Set up the transform data 00356 TransData.CentreOfTrans.x = 0; 00357 TransData.CentreOfTrans.y = 0; 00358 TransData.StartBlob = 0; 00359 TransData.LockAspect = TRUE; 00360 TransData.LeaveCopy = FALSE; 00361 TransData.ScaleLines = FALSE; 00362 TransData.TransFills = TRUE; 00363 TransData.pRange = 0; 00364 00365 // Call OpTranslateTrans::DoWithParams() with a ptr to the transform data and a ptr to a DocCoord 00366 // that specs the X and Y offsets of the translation 00367 OpParam param( &TransData, &Offset ); 00368 DoWithParam( pOpDesc, ¶m ); 00369 00370 SliceHelper::RestoreSelection(); 00371 } 00372 00373 /******************************************************************************************** 00374 00375 > BOOL OpNudge::IsNudgeOK(BOOL dx,BOOL dy) 00376 00377 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00378 Created: 26/1/96 00379 Inputs: dx = the amount to nudge in the X direction 00380 dy = the amount to nudge in the Y direction 00381 Outputs: - 00382 Returns: FALSE if nudge will send the selection out of bounds, TRUE if OK 00383 Purpose: A validity check function the tests to see if the nudge will send the nudge 00384 beyond the spread bounds 00385 Errors: - 00386 SeeAlso: - 00387 00388 ********************************************************************************************/ 00389 00390 BOOL OpNudge::IsNudgeOK(BOOL dx,BOOL dy) 00391 { 00392 // Get the selection 00393 SelRange* pSel = GetApplication()->FindSelection(); 00394 ERROR2IF(pSel == NULL,FALSE,"Awooga, NULL sel range"); 00395 00396 // Find out the bounding rectangle of the selection 00397 DocRect BoundingRect = pSel->GetBoundingRect(); 00398 00399 // Find out the Pasteboard rect 00400 DocRect PasteRect; 00401 Spread* pSpread = pOurDoc->GetSelectedSpread(); 00402 if (pSpread==NULL) 00403 PasteRect = BoundingRect; 00404 else 00405 { 00406 // Try to make the pasteboard grow if necessary to include the new object position 00407 // This is very quick if the pasteboard is large enough already. 00408 pSpread->ExpandPasteboardToInclude(BoundingRect); 00409 00410 // And re-read the bounding rectangle of the selection, as the pasteboard resize may have 00411 // caused the origin of our entire coordinate space to have moved! Argh! 00412 BoundingRect = pSel->GetBoundingRect(); 00413 // BoundingRect.Translate(dx,dy); 00414 00415 // This is in Document Coords, so we need to convert it 00416 PasteRect = pSpread->GetPasteboardRect(); 00417 pSpread->DocCoordToSpreadCoord(&PasteRect); 00418 } 00419 00420 // Assume the nudge will be OK. 00421 BOOL NudgeOK = TRUE; 00422 00423 if (PasteRect.ContainsRect(BoundingRect)) 00424 { 00425 // Untranslated bounds fit inside pasteboard rect, so we must complain if the bounds 00426 // do not fit *after* translation 00427 00428 // Translate the bounds by the nudge values 00429 BoundingRect.Translate(dx,dy); 00430 00431 // Do the translated bounds still fit entirely in the pasteboard rect? 00432 NudgeOK = PasteRect.ContainsRect(BoundingRect); 00433 } 00434 else 00435 { 00436 // The original bounds overlap the pasteboard rect, so we must complain if the user 00437 // nudges the bounds completely out of sight 00438 00439 if (PasteRect.IsIntersectedWith(BoundingRect)) 00440 { 00441 // The original bounds intersect with the pasteboard rect 00442 BoundingRect.Translate(dx,dy); 00443 00444 // Only allow the nudge if the translated bounds still overlap with the spread. 00445 NudgeOK = PasteRect.IsIntersectedWith(BoundingRect); 00446 } 00447 } 00448 00449 // If the nudge is OK, we may need to scroll the DocView? 00450 00451 /* Jim, 12/9/96 - removed this because we don't want to scroll to show opn nudges 00452 00453 if (NudgeOK) 00454 { 00455 DocCoord Coord(0,0); 00456 00457 // If nudging left or right, pick the min or max X coord 00458 if (dx != 0) 00459 { 00460 if (dx < 0) 00461 Coord.x = BoundingRect.lox; 00462 else 00463 Coord.x = BoundingRect.hix; 00464 } 00465 00466 // If nudging up or down, pick the max or min Y coord 00467 if (dy != 0) 00468 { 00469 if (dy < 0) 00470 Coord.y = BoundingRect.loy; 00471 else 00472 Coord.y = BoundingRect.hiy; 00473 } 00474 00475 // If we have picked a coord, ensure that this coord is visible in the selected spread 00476 // of the selected DocView 00477 if (Coord != DocCoord(0,0)) 00478 { 00479 DocView* pDocView = DocView::GetSelected(); 00480 if (pDocView != NULL) 00481 pDocView->ScrollToShow(&Coord); 00482 } 00483 } 00484 */ 00485 return NudgeOK; 00486 } 00487 00488 00489 /******************************************************************************************** 00490 00491 > void OpNudge::GetOpName(String_256* OpName) 00492 00493 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00494 Created: 8/9/94 00495 Inputs: - 00496 Outputs: The undo string for the operation 00497 Returns: 00498 Purpose: The GetOpName fn is overridden so that we return back a description 00499 appropriate to the type of attribute that the operation applies. 00500 00501 Errors: - 00502 SeeAlso: - 00503 00504 ********************************************************************************************/ 00505 00506 void OpNudge::GetOpName(String_256* OpName) 00507 { 00508 *OpName = String_256(_R(IDS_UNDO_NUDGE)); 00509 } 00510 00511 00512 /******************************************************************************************** 00513 00514 > virtual void OpNudge::PerformMergeProcessing() 00515 00516 00517 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00518 Created: 7/11/94 00519 Inputs: - 00520 Outputs: - 00521 Returns: - 00522 Purpose: This virtual function gets called to allow for the merging of nudge operations 00523 Errors: - 00524 SeeAlso: - 00525 00526 ********************************************************************************************/ 00527 00528 void OpNudge::PerformMergeProcessing() 00529 { 00530 // Obtain a pointer to the operation history for the current document 00531 OperationHistory* pOpHist = &pOurDoc->GetOpHistory(); 00532 00533 // Ensure that we are the last operation added to the operation history 00534 // Note cannot be an ERROR2 cos this function cannot fail. 00535 ERROR3IF(pOpHist->FindLastOp() != this, "Last Op should be this op"); 00536 00537 // OK lets see if the operation performed before this was an OpNudge operation 00538 Operation* pPrevOp = pOpHist->FindPrevToLastOp(); 00539 00540 if (pPrevOp != NULL) // Check if there was a previous op 00541 { 00542 00543 if (IS_A(pPrevOp, OpNudge)) 00544 { 00545 // Yes it was 00546 // We can merge this op with pPrevOp if they both apply to the same set of objects 00547 // This will be TRUE is their SelectionStates are the same. 00548 RestoreSelectionsAction* pRestoreSelAct = (RestoreSelectionsAction*) 00549 GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(RestoreSelectionsAction)); 00550 ERROR3IF(pRestoreSelAct == NULL, "This op should have a RestoreSelectionsAction"); 00551 SelectionState* ThisOpsSelection = pRestoreSelAct->GetSelState(); 00552 00553 pRestoreSelAct = (RestoreSelectionsAction*) 00554 pPrevOp->GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(RestoreSelectionsAction)); 00555 ERROR3IF(pRestoreSelAct == NULL, "OpNudge op should have a RestoreSelectionsAction"); 00556 SelectionState* LastOpsSelection = pRestoreSelAct->GetSelState(); 00557 00558 if ((*ThisOpsSelection) == (*LastOpsSelection)) 00559 { 00560 00561 // scan to see if either of these ops hides a node 00562 // if either do then we cannot merge them together 00563 // this can happen if perhaps the extending definitions 00564 // were changed by the nudge (sjk 27-7-00) 00565 if (DoesActionListHideNodes(pPrevOp) || DoesActionListHideNodes(this) ) 00566 return; 00567 00568 // this op can be merged into the previous op, we simply need to combine the 00569 // TransformNodeActions 00570 TransformNodeAction* pTransNdAct = (TransformNodeAction*) 00571 GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(TransformNodeAction)); 00572 ERROR3IF(pTransNdAct == NULL, "This op should have a TransformNodeAction"); 00573 00574 TransformNodeAction* pLastOpsTransNdAct = (TransformNodeAction*) 00575 pPrevOp->GetUndoActionList()->FindActionOfClass(CC_RUNTIME_CLASS(TransformNodeAction)); 00576 ERROR3IF(pLastOpsTransNdAct == NULL,"OpNudgeOp should have a TransformNodeAction"); 00577 00578 pLastOpsTransNdAct->CombineWith(pTransNdAct); 00579 00580 // This op is no longer required, so let's vape it 00581 pOpHist->DeleteLastOp(); 00582 } 00583 } 00584 } 00585 return; 00586 } 00587 00588 /******************************************************************************************** 00589 00590 > BOOL OpNudge::DoesActionListHideNodes(OpNudge * pOp) 00591 00592 Author: Simon_Knight (Xara Group Ltd) <camelotdev@xara.com> 00593 Created: 27/7/00 00594 Inputs: ptr to the (nudge) operation 00595 Outputs: - 00596 Returns: TRUE if the action list for the op does a HideNodesAction 00597 Purpose: To disallow the merging of nudge operations if a HideNodesAction was added 00598 to this nudge op, as this wouldn't then undo correctly. 00599 Errors: - 00600 SeeAlso: - 00601 00602 ********************************************************************************************/ 00603 BOOL OpNudge::DoesActionListHideNodes(Operation * pOp) 00604 { 00605 ActionList * pActions = pOp->GetUndoActionList(); 00606 ListItem* CurrentAction = pActions->GetHead(); 00607 00608 while (CurrentAction != NULL) // For each action in the list 00609 { 00610 if (IS_A(CurrentAction, HideNodeAction)) 00611 return TRUE; 00612 00613 // Get next action 00614 CurrentAction = pActions->GetNext(CurrentAction); 00615 } 00616 00617 return FALSE; 00618 } 00619