00001 // $Id: nodedoc.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 // class NodeRenderableDocument which holds the whole document tree 00100 00101 00102 #include "camtypes.h" 00103 #include "nodedoc.h" 00104 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "mario.h" 00106 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "chapter.h" 00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 00110 CC_IMPLEMENT_DYNAMIC(NodeDocument, NodeRenderablePaper) 00111 00112 // Declare smart memory handling in Debug builds 00113 #define new CAM_DEBUG_NEW 00114 00115 /*********************************************************************************************** 00116 00117 > NodeDocument::NodeDocument() 00118 00119 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00120 Created: 13/5/93 00121 Inputs: - 00122 Outputs: 00123 Returns: - 00124 00125 Purpose: This constructor creates a NodeDocument linked to no other nodes, with all status 00126 flags false, and NULL bounding and pasteboard rectangles. 00127 00128 Errors: 00129 00130 ***********************************************************************************************/ 00131 00132 00133 NodeDocument::NodeDocument(): NodeRenderablePaper() 00134 { 00135 pParentDoc = NULL; 00136 } 00137 00138 00139 /*********************************************************************************************** 00140 00141 > NodeDocument::NodeDocument 00142 ( 00143 Node* ContextNode, 00144 AttachNodeDirection Direction, 00145 BOOL Locked = FALSE, 00146 BOOL Mangled = FALSE, 00147 BOOL Marked = FALSE, 00148 BOOL Selected = FALSE, 00149 ) 00150 00151 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00152 Created: 26/4/93 00153 00154 Inputs: ContextNode: Pointer to a node which this node is to be attached to. 00155 00156 Direction: 00157 00158 Specifies the direction in which this node is to be attached to the 00159 ContextNode. The values this variable can take are as follows: 00160 00161 PREV : Attach node as a previous sibling of the context node 00162 NEXT : Attach node as a next sibling of the context node 00163 FIRSTCHILD: Attach node as the first child of the context node 00164 LASTCHILD : Attach node as a last child of the context node 00165 00166 The remaining inputs specify the status of the node: 00167 00168 Locked: Is node locked ? 00169 Mangled: Is node mangled ? 00170 Marked: Is node marked ? 00171 Selected: Is node selected ? 00172 00173 Outputs: - 00174 Returns: - 00175 Purpose: This constructor initialises the node and links it to ContextNode in the 00176 direction specified by Direction. All neccesary tree links are 00177 updated. 00178 00179 Errors: An assertion error will occur if ContextNode is NULL 00180 00181 00182 ***********************************************************************************************/ 00183 00184 NodeDocument::NodeDocument(Node* ContextNode, 00185 AttachNodeDirection Direction, 00186 BOOL Locked, 00187 BOOL Mangled, 00188 BOOL Marked, 00189 BOOL Selected):NodeRenderablePaper(ContextNode, Direction, Locked, 00190 Mangled,Marked, Selected) 00191 { 00192 pParentDoc = NULL; 00193 } 00194 00195 00196 00197 /*********************************************************************************************** 00198 00199 > NodeDocument::~NodeDocument() 00200 00201 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00202 Created: 5/5/94 00203 Inputs: - 00204 Outputs: - 00205 Returns: - 00206 00207 Purpose: NodeDocument destructor. 00208 Errors: 00209 Notes: OK, so this does nothing. But it used to. I've just ripped out all 00210 the code again 3 months later... 00211 00212 ***********************************************************************************************/ 00213 00214 NodeDocument::~NodeDocument() 00215 { 00216 } 00217 00218 00219 /******************************************************************************************** 00220 00221 > void NodeDocument::SetParentDoc(BaseDocument *pNewDoc) 00222 00223 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00224 Created: 14/02/95 00225 Inputs: pNewDoc - the Document to attach to, or NULL if detaching. 00226 Purpose: Specify which Document object a NodeDocument object is attached to. 00227 This cannot be done again, unless this function is first called with 00228 NULL as the document to attachto. 00229 Errors: Already attached to a document => ERROR2 00230 SeeAlso: NodeDocument::GetParentDoc 00231 00232 ********************************************************************************************/ 00233 00234 void NodeDocument::SetParentDoc(BaseDocument *pNewDoc) 00235 { 00236 if (pParentDoc != NULL) 00237 { 00238 // Error 00239 ERROR2RAW("NodeDocument is already attached to a Document!"); 00240 } 00241 else 00242 { 00243 // Attach document. 00244 pParentDoc = pNewDoc; 00245 } 00246 } 00247 00248 /******************************************************************************************** 00249 00250 > BaseDocument *NodeDocument::GetParentDoc() 00251 00252 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00253 Created: 14/02/95 00254 Returns: The Document that this node is attached to, or NULL if not attached. 00255 Purpose: Find out which Document object a NodeDocument object is attached to. 00256 SeeAlso: NodeDocument::SetParentDoc 00257 00258 ********************************************************************************************/ 00259 00260 /******************************************************************************************** 00261 00262 > BOOL NodeDocument::IsNodeDocument() const 00263 00264 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00265 Created: 15/02/95 00266 Returns: TRUE - this is a NodeDocument. 00267 Purpose: Tell the caller that this is a NodeDocument. 00268 00269 ********************************************************************************************/ 00270 00271 BOOL NodeDocument::IsNodeDocument() const 00272 { 00273 // Yes, it's a NodeDocument 00274 return TRUE; 00275 } 00276 00277 00278 /*********************************************************************************************** 00279 > Node* NodeDocument::SimpleCopy() 00280 00281 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00282 Created: 28/5/93 00283 00284 Inputs: - 00285 Outputs: 00286 Returns: A copy of the node, or NULL if memory runs out 00287 00288 Purpose: This method returns a shallow copy of the node with all Node pointers NULL. 00289 The function is virtual, and must be defined for all derived classes. 00290 00291 Errors: If memory runs out when trying to copy, then ERROR is called with an out of memory 00292 error and the function returns NULL. 00293 00294 Scope: protected 00295 ***********************************************************************************************/ 00296 00297 Node* NodeDocument::SimpleCopy() 00298 { 00299 NodeDocument* NodeCopy; 00300 NodeCopy = new NodeDocument(); 00301 ERRORIF(NodeCopy == NULL, _R(IDE_NOMORE_MEMORY), NULL); 00302 CopyNodeContents(NodeCopy); 00303 return (NodeCopy); 00304 } 00305 00306 00307 /*********************************************************************************************** 00308 > void NodeDocument::CopyNodeContents(NodeDocument* NodeCopy) 00309 00310 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00311 Created: 07/6/93 00312 00313 Inputs: 00314 Outputs: A copy of this node 00315 00316 Returns: - 00317 00318 Purpose: This method copies the node's contents to the node pointed to by NodeCopy. 00319 00320 Errors: An assertion failure will occur if NodeCopy is NULL 00321 00322 scope: protected 00323 00324 ***********************************************************************************************/ 00325 00326 void NodeDocument::CopyNodeContents(NodeDocument* NodeCopy) 00327 { 00328 ENSURE(NodeCopy != NULL, "Trying to copy a node's contents to a NULL node"); 00329 NodeRenderablePaper::CopyNodeContents(NodeCopy); 00330 NodeCopy->LowExtent = LowExtent; 00331 NodeCopy->HighExtent = HighExtent; 00332 } 00333 00334 00335 /*********************************************************************************************** 00336 > void NodeDocument::PolyCopyNodeContents(NodeRenderable* pNodeCopy) 00337 00338 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00339 Created: 18/12/2003 00340 Outputs: - 00341 Purpose: Polymorphically copies the contents of this node to another 00342 Errors: An assertion failure will occur if NodeCopy is NULL 00343 Scope: protected 00344 00345 ***********************************************************************************************/ 00346 00347 void NodeDocument::PolyCopyNodeContents(NodeRenderable* pNodeCopy) 00348 { 00349 ENSURE(pNodeCopy, "Trying to copy a node's contents into a NULL node"); 00350 ENSURE(IS_A(pNodeCopy, NodeDocument), "PolyCopyNodeContents given wrong dest node type"); 00351 00352 if (IS_A(pNodeCopy, NodeDocument)) 00353 CopyNodeContents((NodeDocument*)pNodeCopy); 00354 } 00355 00356 00357 00358 /*********************************************************************************************** 00359 00360 > DocCoord NodeDocument::LoExtent() const 00361 00362 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00363 Created: 28/5/93 00364 Inputs: - 00365 Outputs: - 00366 Returns: The documents low extent i.e. the low corner of the final chapters 00367 pasteboard rectangle. 00368 00369 Purpose: For finding the low extent of the document 00370 Errors: - 00371 SeeAlso: - 00372 00373 ***********************************************************************************************/ 00374 00375 DocCoord NodeDocument::LoExtent() const 00376 { 00377 return (LowExtent); 00378 } 00379 00380 /*********************************************************************************************** 00381 00382 > DocCoord NodeDocument::HiExtent() const 00383 00384 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00385 Created: 28/5/93 00386 Inputs: - 00387 Outputs: - 00388 Returns: The documents high extent, i.e. the high corner of the first chapters 00389 pasteboard rectangle. 00390 00391 Purpose: For finding the high extent of the document 00392 Errors: - 00393 SeeAlso: - 00394 00395 ***********************************************************************************************/ 00396 00397 DocCoord NodeDocument::HiExtent() const 00398 { 00399 return (HighExtent); 00400 } 00401 00402 /*********************************************************************************************** 00403 00404 > DocCoord NodeDocument::DescribeExtents(DocCoord* LoExtent, DocCoord* HiExtent) const 00405 00406 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00407 Created: 02/06/93 00408 Outputs: LoExtent: The documents low extent i.e. the low corner of the final chapters 00409 pasteboard rectangle. 00410 HiExtent: The documents high extent i.e. the high corner of the first chapters 00411 pasteboard rectangle. 00412 Returns: - 00413 Purpose: For finding the extents of the document. 00414 Errors: - 00415 SeeAlso: - 00416 00417 ***********************************************************************************************/ 00418 00419 void NodeDocument::DescribeExtents(DocCoord* LoExtent, DocCoord* HiExtent) const 00420 { 00421 *LoExtent = LowExtent; 00422 *HiExtent = HighExtent; 00423 } 00424 00425 /*********************************************************************************************** 00426 00427 > DocCoord NodeDocument::SetExtents() 00428 00429 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00430 Created: 28/4/93 00431 Inputs: - 00432 Outputs: - 00433 Returns: - 00434 Purpose: For setting the document's extents in the NodeDocument, and then updating the 00435 extents in the current document. The NodeDocument finds its extents by 00436 looking at its first and last chapter's pasteboard rectangles. 00437 00438 This method relies on the current document having been set. 00439 00440 Errors: An assertion failure will occur if the document has no chapters 00441 00442 ***********************************************************************************************/ 00443 /* Technical notes: 00444 00445 The NodeDocuments LowExtent is set to the low corner of the final chapters pasteboard rectangle 00446 The NodeDocuments HighExtent is set to the high corner of the first chapters pasteboard rectangle 00447 00448 */ 00449 00450 void NodeDocument::SetExtents() 00451 { 00452 BOOL FoundChapter = FALSE; // Flag indicating if we have found a chapter beneath the doc 00453 00454 Node* CurrentNode = FindFirstChild(); 00455 00456 // Find the first chapter of a document 00457 while ((CurrentNode != NULL) && (!FoundChapter)) 00458 { 00459 if (CurrentNode->IsKindOf(CC_RUNTIME_CLASS(Chapter))) 00460 { 00461 FoundChapter = TRUE; 00462 HighExtent = ((NodeRenderablePaper*)CurrentNode)->GetPasteboardRect(FALSE).HighCorner(); 00463 // Low extent will change if we find another chapter 00464 LowExtent = ((NodeRenderablePaper*)CurrentNode)->GetPasteboardRect(FALSE).LowCorner(); 00465 } 00466 CurrentNode = CurrentNode->FindNext(); 00467 } 00468 00469 // A document should have at least one chapter when setting the extents 00470 ENSURE(FoundChapter,"Trying to set the extents of a document with no chapters"); 00471 00472 // Find the last chapter which may be the first 00473 while(CurrentNode != NULL) 00474 { 00475 if (CurrentNode->IsKindOf(CC_RUNTIME_CLASS(Chapter))) 00476 { 00477 LowExtent = ((NodeRenderablePaper*)CurrentNode)->GetPasteboardRect().LowCorner(); 00478 } 00479 CurrentNode = CurrentNode->FindNext(); 00480 } 00481 00482 // Inform the document that its extents have changed (only do it for 'real' documents, 00483 // and not e.g. the clipboard. 00484 if (IS_A(pParentDoc, Document)) 00485 ((Document *) pParentDoc)->UpdateExtents(LowExtent, HighExtent); 00486 } 00487 00488 #ifdef _DEBUG 00489 00490 void NodeDocument::ShowDebugTreeDetails() const 00491 { 00492 TRACE( _T("Node Document ") ); 00493 Node::ShowDebugTreeDetails(); 00494 } 00495 00496 #endif 00497 00498 /******************************************************************************************** 00499 00500 > void* NodeDocument::GetDebugDetails(StringBase* Str) 00501 00502 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00503 Created: 21/9/93 00504 Inputs: - 00505 Outputs: Str: String giving debug info about the node 00506 Returns: - 00507 Purpose: For obtaining debug information about the Node 00508 Errors: - 00509 SeeAlso: - 00510 00511 ********************************************************************************************/ 00512 00513 00514 void NodeDocument::GetDebugDetails(StringBase* Str) 00515 { 00516 #ifdef _DEBUG 00517 NodeRenderablePaper::GetDebugDetails(Str); 00518 String_256 TempStr; 00519 TempStr._MakeMsg(TEXT("\r\nLowExtent = (#1%ld, #2%ld)\r\nHighExtent = (#3%ld, #4%ld)\r\n"), 00520 LowExtent.x, LowExtent.y, HighExtent.x, HighExtent.y); 00521 (*Str)+=TempStr; 00522 #endif 00523 } 00524 00525 /******************************************************************************************** 00526 00527 > virtual UINT32 NodeDocument::GetNodeSize() const 00528 00529 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00530 Created: 6/10/93 00531 Inputs: - 00532 Outputs: - 00533 Returns: The size of the node in bytes 00534 Purpose: For finding the size of the node 00535 00536 SeeAlso: Node::GetSubtreeSize 00537 00538 ********************************************************************************************/ 00539 00540 UINT32 NodeDocument::GetNodeSize() const 00541 { 00542 return (sizeof(NodeDocument)); 00543 } 00544