00001 // $Id: selop.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 /* 00099 //*/ 00100 00101 #include "camtypes.h" 00102 //#include "selop.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 #include "ophist.h" 00104 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "selstate.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 #include "blobs.h" 00109 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00110 00111 00112 DECLARE_SOURCE("$Revision: 1282 $"); 00113 00114 CC_IMPLEMENT_DYNCREATE(SelOperation, UndoableOperation) 00115 00116 #define new CAM_DEBUG_NEW 00117 00118 BOOL SelOperation::RenderEndSelStateBlobs; 00119 BOOL SelOperation::RenderStartSelStateBlobs; 00120 BOOL SelOperation::UndoRenderEndSelStateBlobs; 00121 BOOL SelOperation::UndoRenderStartSelStateBlobs; 00122 00123 /******************************************************************************************** 00124 00125 > SelOperation::SelOperation() 00126 00127 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00128 Created: 15/2/94 00129 Inputs: - 00130 Outputs: - 00131 Returns: - 00132 Purpose: SelOperation constructor, calls the constructor of the base class 00133 Errors: - 00134 SeeAlso: - 00135 00136 ********************************************************************************************/ 00137 00138 SelOperation::SelOperation(): UndoableOperation() 00139 { 00140 m_bStartCalled = FALSE; 00141 } 00142 00143 /******************************************************************************************** 00144 00145 > SelOperation::~SelOperation() 00146 00147 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00148 Created: 15/2/94 00149 Inputs: - 00150 Outputs: - 00151 Returns: - 00152 Purpose: SelOperation destructor 00153 Errors: - 00154 SeeAlso: - 00155 00156 ********************************************************************************************/ 00157 00158 SelOperation::~SelOperation() 00159 { 00160 } 00161 00162 /******************************************************************************************** 00163 00164 > BOOL SelOperation::DoStartSelOp(BOOL RenderEndSelStateBlobs, 00165 BOOL RenderStartSelBlobs = TRUE) 00166 00167 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00168 Created: 15/2/94 00169 Inputs: RenderEndSelStateBlobs: Flag indicating if the blobs should be drawn for 00170 the end selection state or not. 00171 00172 This flag should be set to TRUE if the bounds of 00173 all selected objects at the end of the operation 00174 are not invalidated. 00175 00176 RenderStartSelBlobs: Flag indicating if the blobs should be drawn for 00177 the start selection state or not. 00178 00179 This flag should be set to TRUE if the bounds of 00180 all selected objects at the start of an operation 00181 are not invalidated. 00182 00183 All operations which insert a new object 00184 into the tree will have RenderStartSelBlobs set 00185 to TRUE. 00186 00187 00188 Outputs: - 00189 Returns: TRUE if successful, FALSE if memory ran out (call End) 00190 00191 Purpose: This function must be called by all SelOperations. It does the following: 00192 00193 Records the current selection status 00194 00195 Errors: - 00196 SeeAlso: SelOperation::End() 00197 00198 ********************************************************************************************/ 00199 00200 00201 BOOL SelOperation::DoStartSelOp(BOOL renderEndSelStateBlobs, 00202 BOOL renderStartSelBlobs, 00203 BOOL UndorenderEndSelStateBlobs, 00204 BOOL UndorenderStartSelBlobs) 00205 { 00206 SelOperation::RenderStartSelStateBlobs = renderStartSelBlobs; 00207 SelOperation::RenderEndSelStateBlobs = renderEndSelStateBlobs; 00208 00209 if (UndorenderEndSelStateBlobs) 00210 SelOperation::UndoRenderEndSelStateBlobs = !renderEndSelStateBlobs; 00211 else 00212 SelOperation::UndoRenderEndSelStateBlobs = renderEndSelStateBlobs; 00213 00214 if (UndorenderStartSelBlobs) 00215 SelOperation::UndoRenderStartSelStateBlobs = !renderStartSelBlobs; 00216 else 00217 SelOperation::UndoRenderStartSelStateBlobs = renderStartSelBlobs; 00218 00219 // Create a SelectionState object 00220 ALLOC_WITH_FAIL(SelState, (new SelectionState()), this); 00221 if (SelState == NULL) 00222 { 00223 return FALSE; // Failure 00224 } 00225 00226 // We have managed to create a SelectionState instance, now lets try and 00227 // record the current selections 00228 00229 BOOL Success; 00230 00231 CALL_WITH_FAIL(SelState->Record(), this, Success) 00232 00233 if (!Success) // We failed to allocate enough memory to store the selection state 00234 { 00235 // There was insufficient memory to record the selections 00236 delete SelState; // Delete the selection state 00237 SelState = NULL; 00238 return FALSE; 00239 } 00240 00241 // We have successfully managed to create a Selection state, create an action 00242 // to restore the selections when executed 00243 00244 // Recorded the current selection state ok 00245 RestoreSelectionsAction* RestoreAct; 00246 ActionCode ActCode; 00247 00248 // Attempt to initialise the action 00249 ActCode = RestoreSelectionsAction::Init(this, 00250 &UndoActions, 00251 SelState, 00252 FALSE, // Don't Toggle 00253 FALSE, 00254 FALSE, // The SelState is not shared 00255 UndoRenderStartSelStateBlobs, // Render the start blobs ? 00256 UndoRenderEndSelStateBlobs, // Render the end blobs ? 00257 FALSE, // End restore 00258 ( Action**)(&RestoreAct)); 00259 00260 00261 #if !defined(EXCLUDE_FROM_RALPH) 00262 if (RenderEndSelStateBlobs) 00263 { 00264 // Remove all existing blobs 00265 ENSURE(Camelot.FindSelection() != NULL, "There is no SelRange"); 00266 Node* SelNd = Camelot.FindSelection()->FindFirst(); 00267 if (SelNd != NULL) 00268 { 00269 Spread* SelSpread = (Spread*) SelNd->FindParent(CC_RUNTIME_CLASS(Spread)); 00270 ENSURE(SelSpread != NULL, "Could not find spread of selected item"); 00271 00272 // Remove the blobs 00273 Camelot.GetBlobManager()->RenderOff(NULL, SelSpread); 00274 } 00275 } 00276 #endif 00277 00278 if (ActCode == AC_FAIL) 00279 { 00280 delete SelState; // We won't be needing this 00281 return FALSE; 00282 } 00283 m_bStartCalled = TRUE; 00284 return TRUE; 00285 } 00286 00287 /******************************************************************************************** 00288 00289 > BOOL SelOperation::DoEndSelOp() 00290 00291 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00292 Created: 15/2/94 00293 Inputs: - 00294 Outputs: - 00295 Returns: - 00296 Purpose: This function gets called automatically by End() 00297 00298 It Invalidates the rectangle covered by the selection and its blobs 00299 00300 Scope: protected 00301 Errors: - 00302 SeeAlso: - 00303 00304 ********************************************************************************************/ 00305 00306 BOOL SelOperation::DoEndSelOp() 00307 { 00308 // Create a SelectionState object 00309 ALLOC_WITH_FAIL(SelState, (new SelectionState()), this); 00310 if (SelState == NULL) 00311 { 00312 return FALSE; // Failure 00313 } 00314 00315 // We have managed to create a SelectionState instance, now lets try and 00316 // record the current selections 00317 00318 BOOL Success; 00319 00320 CALL_WITH_FAIL(SelState->Record(), this, Success) 00321 00322 if (!Success) // We failed to allocate enough memory to store the selection state 00323 { 00324 // There was insufficient memory to record the selections 00325 delete SelState; // Delete the selection state 00326 SelState = NULL; 00327 return FALSE; 00328 } 00329 00330 // We have successfully managed to create a Selection state, create an action 00331 // to restore the selections when executed 00332 00333 // Recorded the current selection state ok 00334 RestoreSelectionsAction* RestoreAct; 00335 ActionCode ActCode; 00336 00337 // Attempt to initialise the action 00338 ActCode = RestoreSelectionsAction::Init(this, 00339 &UndoActions, 00340 SelState, 00341 FALSE, // Don't Toggle 00342 FALSE, 00343 FALSE, // The SelState is not shared 00344 UndoRenderStartSelStateBlobs, 00345 UndoRenderEndSelStateBlobs, 00346 TRUE, // restore at start of undo 00347 ( Action**)(&RestoreAct)); 00348 if (ActCode == AC_FAIL) 00349 { 00350 delete SelState; // We won't be needing this 00351 return FALSE; 00352 } 00353 00354 // OK the operation should have finished playing with the selection states, so we can turn 00355 // the blob rendering back on. If the operation needs to render the end SelState blobs then 00356 // this is done. 00357 00358 // If the operation needs to restore the blobs then do so 00359 00360 #if !defined(EXCLUDE_FROM_RALPH) 00361 if (RenderEndSelStateBlobs) 00362 { 00363 ENSURE(Camelot.FindSelection() != NULL, "There is no SelRange"); 00364 Node* SelNd = Camelot.FindSelection()->FindFirst(); 00365 if (SelNd != NULL) 00366 { 00367 Spread* SelSpread = (Spread*) SelNd->FindParent(CC_RUNTIME_CLASS(Spread)); 00368 ENSURE(SelSpread != NULL, "Could not find spread of selected item"); 00369 00370 // Put the blobs back 00371 Camelot.GetBlobManager()->RenderOn(NULL, SelSpread); 00372 } 00373 } 00374 #endif 00375 00376 m_bStartCalled = FALSE; 00377 return TRUE; 00378 } 00379 00380 00381 /******************************************************************************************** 00382 00383 > virtual void SelOperation::End() 00384 00385 00386 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00387 Created: 15/2/94 00388 Inputs: - 00389 Outputs: - 00390 Returns: - 00391 Purpose: Calls DoEndSelOp(), then Operation::End() 00392 Errors: - 00393 SeeAlso: - 00394 00395 ********************************************************************************************/ 00396 00397 00398 void SelOperation::End() 00399 { 00400 if (OpStatus == DO && (!OpFlags.Failed)) 00401 { 00402 DoEndSelOp(); // We don't want to perform this if we are undoing or 00403 } 00404 Operation::End(); 00405 }