00001 // $Id: basedoc.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 BaseDocument class 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 00105 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 #include "camelot.h" 00107 //#include "basedoc.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 #include "colcomp.h" 00109 //#include "doccomp.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00110 #include "dumbnode.h" 00111 //#include "jason.h" 00112 #include "nodedoc.h" 00113 #include "progress.h" 00114 #include "fontlist.h" 00115 //#include "textinfo.h" 00116 //#include "mario.h" 00117 //#include "resource.h" 00118 #include "fontman.h" 00119 #include "collist.h" 00120 #include "camdoc.h" 00121 #include "exphint.h" 00122 #include "nodeliveeffect.h" 00123 //#include "xpehost.h" 00124 //#include "peter.h" 00125 //#include "simon.h" 00126 00127 #ifdef RALPH 00128 #include "ralphcri.h" 00129 #endif 00130 00131 DECLARE_SOURCE($Revision: 1282 $) 00132 CC_IMPLEMENT_DYNAMIC(BaseDocument, ListItem) 00133 00134 // Declare smart memory handling in Debug builds 00135 #define new CAM_DEBUG_NEW 00136 00137 00138 /******************************************************************************************** 00139 00140 > BaseDocument::BaseDocument(BOOL fHide = TRUE) 00141 00142 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00143 Created: 20/7/94 00144 Inputs: - 00145 Outputs: - 00146 Returns: - 00147 Purpose: BaseDocument constructor 00148 Errors: - 00149 SeeAlso: - 00150 00151 ********************************************************************************************/ 00152 00153 BaseDocument::BaseDocument(BOOL fHide) 00154 : IsHidden(fHide), 00155 m_pExportHint(NULL), 00156 TreeStart(0), 00157 DocComponents(0), 00158 TagCounter(1) 00159 { 00160 // Empty. 00161 } 00162 00163 00164 00165 /******************************************************************************************** 00166 00167 > BaseDocument::~BaseDocument() 00168 00169 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00170 Created: 20/7/94 00171 Purpose: The BaseDocument destructor deletes all nodes in the document. 00172 It also deletes all the document components. 00173 00174 ********************************************************************************************/ 00175 00176 BaseDocument::~BaseDocument() 00177 { 00178 // Destroy the tree if it exists. This routine deletes all nodes to the right of 00179 // the StartDocument node. This is done by continually deleting the node to the 00180 // right (which shuffles all the others left one) until there are no more nodes. 00181 // Then the StartDocument node itself is deleted. 00182 if (TreeStart != NULL) 00183 { 00184 for (Node* pn = TreeStart->FindNext(); pn != NULL; pn = TreeStart->FindNext()) 00185 { 00186 // Delete the node's children then delete the node. The TreeStart 00187 // variable will be updated to point to the new first node. 00188 pn->CascadeDelete(); 00189 delete pn; 00190 } 00191 // Tree has only one node left - waste it. 00192 delete TreeStart; 00193 TreeStart = NULL; 00194 } 00195 00196 // The SelRange might still contain cached indexed colours. We must delete these 00197 // before destroying the DocComponents. 00198 SelRange* Sel = GetApplication()->FindSelection(); 00199 if (Sel) 00200 Sel->AttrsHaveChanged(); 00201 00202 // Destroy doc components (colours, etc) 00203 // (this must be left until after all possible things in the document that could 00204 // contain references to components (such as IndexedColours) have been deleted) 00205 DestroyDocComponents(); 00206 00207 if (m_pExportHint) 00208 { 00209 delete m_pExportHint; 00210 m_pExportHint = NULL; 00211 } 00212 } 00213 00214 00215 00216 /******************************************************************************************** 00217 00218 > void BaseDocument::DestroyDocComponents(void) 00219 00220 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00221 Created: 25/4/95 00222 Purpose: Deletes all DocComponents and related junk from this document 00223 Used by the destructor, and also by the InternalClipboard document 00224 when it wipes the clipboard. 00225 00226 SeeAlso: BaseDocument::InitDocComponents 00227 00228 ********************************************************************************************/ 00229 00230 void BaseDocument::DestroyDocComponents(void) 00231 { 00232 // And delete all the document components 00233 if (DocComponents != NULL) 00234 { 00235 DocComponents->DeleteAll(); 00236 delete DocComponents; 00237 DocComponents = NULL; 00238 } 00239 } 00240 00241 00242 00243 /******************************************************************************************** 00244 00245 > BOOL BaseDocument::Init() 00246 00247 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00248 Created: 20/7/94 00249 Purpose: Creates StartDocument, NodeDocument, and EndDocument nodes. 00250 Initialises the doc components. 00251 00252 ********************************************************************************************/ 00253 00254 BOOL BaseDocument::Init() 00255 { 00256 NodeDocument *Doc; 00257 EndDocument *End; 00258 00259 // Get a new StartDocument node. 00260 TreeStart = new StartDocument; 00261 if (TreeStart == NULL) 00262 goto NoMemory; 00263 00264 // Add a NodeDocument 00265 Doc = new NodeDocument(TreeStart, NEXT); 00266 if (Doc == NULL) 00267 goto NoMemory; 00268 00269 // Tell the NodeDocument which document it is attached to. 00270 Doc->SetParentDoc(this); 00271 00272 // Join a new EndDocument node after it in the tree. 00273 End = new EndDocument(Doc, NEXT); 00274 if (End == NULL) 00275 goto NoMemory; 00276 00277 if (!InitDocComponents()) 00278 goto NoMemory; 00279 00280 // We don't really mind if this fails but check it anyway 00281 m_pExportHint = new ExportHint; 00282 if (m_pExportHint == NULL) 00283 goto NoMemory; 00284 00285 // All is well 00286 return TRUE; 00287 00288 NoMemory: 00289 00290 // Failed to initialise due to running out of memory. 00291 if (TreeStart != NULL) 00292 { 00293 TreeStart->CascadeDelete(); 00294 delete TreeStart; 00295 TreeStart = NULL; 00296 } 00297 00298 return FALSE; 00299 } 00300 00301 00302 00303 00304 /******************************************************************************************** 00305 00306 > BOOL BaseDocument::InitDocComponents(void) 00307 00308 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00309 Created: 25/4/95 00310 00311 Returns: TRUE if it succeeds 00312 00313 Purpose: Creates and initialises all doc components 00314 00315 This is a subroutine called by Init(), and is also used by the 00316 InternalClipboard document when clearing the clipboard in order to wipe 00317 all contents of the document. 00318 00319 SeeAlso: BaseDocument::DestroyDocComponents 00320 00321 ********************************************************************************************/ 00322 00323 BOOL BaseDocument::InitDocComponents(void) 00324 { 00325 // Get a new set of document components for this document... 00326 DocComponents = new List; 00327 if (DocComponents == NULL) 00328 return(FALSE); 00329 00330 // Get each of the registered document components to add themselves to the document. 00331 if (!GetApplication()->ApplyDocComponents(this)) 00332 return(FALSE); 00333 00334 return(TRUE); 00335 } 00336 00337 00338 00339 /*********************************************************************************************** 00340 00341 > TAG BaseDocument::NewTag() 00342 00343 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00344 Created: 19/5/93 00345 Purpose: Returns a new unique TAG for this Document. 00346 00347 ***********************************************************************************************/ 00348 00349 TAG BaseDocument::NewTag() 00350 { 00351 // Increment and check for loop around. 00352 if (TagCounter == TAG_LAST_VALID) 00353 TagCounter = 1; // NB 0 is not used (not sure why - Tim). 00354 else 00355 TagCounter++; 00356 00357 // Return a unique tag 00358 return TagCounter; 00359 } 00360 00361 00362 /******************************************************************************************** 00363 00364 > void BaseDocument::IncNodeCount() 00365 00366 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00367 Created: 15/02/95 00368 Purpose: Adds one to the NodesInTree counter of this Document object. 00369 Called by the constructors of class Node. 00370 SeeAlso: BaseDocument::DecCurrentNodeCount; BaseDocument::NodesInDocument 00371 00372 ********************************************************************************************/ 00373 00374 void BaseDocument::IncNodeCount() 00375 { 00376 NodesInTree++; 00377 } 00378 00379 00380 00381 /******************************************************************************************** 00382 00383 > void BaseDocument::DecNodeCount() 00384 00385 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> 00386 Created: 30/11/93 00387 Purpose: Decrements the node counter in this Document. 00388 Called by the destructor of class Node. 00389 SeeAlso: BaseDocument::IncNodeCount; BaseDocument::NodesInDocument 00390 00391 ********************************************************************************************/ 00392 00393 void BaseDocument::DecNodeCount() 00394 { 00395 NodesInTree--; 00396 } 00397 00398 00399 00400 /******************************************************************************************** 00401 00402 > INT32 BaseDocument::NodesInDocument() const 00403 00404 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> 00405 Created: 30/11/93 00406 Returns: The number of nodes in this Document's tree. 00407 Purpose: Returns the nodes in the document's tree, ho hum. 00408 SeeAlso: BaseDocument::IncNodeCount; BaseDocument::DecNodeCount 00409 00410 ********************************************************************************************/ 00411 00412 INT32 BaseDocument::NodesInDocument() const 00413 { 00414 return NodesInTree; 00415 } 00416 00417 00418 00419 /*********************************************************************************************** 00420 > Node* BaseDocument::GetFirstNode() const 00421 00422 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00423 Created: 19/5/93 00424 Inputs: - 00425 Outputs: - 00426 Returns: First node in the tree. 00427 Purpose: Get the first node in the document tree - this will always be a StartDocument 00428 node. 00429 00430 (* Moved from Document to BaseDocument by SimonM *) 00431 00432 Errors: None. 00433 ***********************************************************************************************/ 00434 00435 Node* BaseDocument::GetFirstNode() const 00436 { 00437 return TreeStart; 00438 } 00439 00440 00441 00442 /******************************************************************************************** 00443 00444 > void BaseDocument::AddDocComponent(DocComponent *pComponent) 00445 00446 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00447 Created: 02/08/94 00448 Inputs: pComponent - the document component to add. 00449 Purpose: Add the given document component to the document - no check is made to see 00450 if such a component is already in the document - the caller should ensure 00451 that they do not overwrite the existing component. 00452 Errors: ENSURE of no document component list exists in the document. 00453 SeeAlso: BaseDocument::GetDocComponent; BaseDocument::GetDocComponentKindOf 00454 00455 ********************************************************************************************/ 00456 00457 void BaseDocument::AddDocComponent(DocComponent *pComponent) 00458 { 00459 // Basic sanity/safety checks. 00460 ENSURE(DocComponents != NULL, "No document component list in the document!"); 00461 if (DocComponents == NULL) 00462 return; 00463 00464 // Just add the component to the document's list. 00465 DocComponents->AddTail(pComponent); 00466 } 00467 00468 00469 00470 /******************************************************************************************** 00471 00472 > DocComponent *BaseDocument::GetDocComponent(CCRuntimeClass *pClass) 00473 00474 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00475 Created: 02/08/94 00476 Inputs: pClass - the class of component to look for. 00477 Returns: A pointer to the required component, or NULL if no match was found. 00478 Purpose: Find a document component of a specific type in this document. 00479 SeeAlso: BaseDocument::GetDocComponentKindOf; 00480 DocComponent 00481 00482 ********************************************************************************************/ 00483 00484 DocComponent *BaseDocument::GetDocComponent(CCRuntimeClass *pClass) 00485 { 00486 DocComponent *pItem = (DocComponent *) DocComponents->GetHead(); 00487 00488 while (pItem != NULL) 00489 { 00490 // Is this an exact match to the given runtime class? 00491 if (pItem->GetRuntimeClass() == pClass) 00492 // Yes - return to caller. 00493 return pItem; 00494 00495 // Try the next component 00496 pItem = (DocComponent *) DocComponents->GetNext(pItem); 00497 } 00498 00499 // Didn't find the component - report this to caller 00500 return NULL; 00501 } 00502 00503 /******************************************************************************************** 00504 00505 > DocComponent *BaseDocument::GetDocComponentKindOf(CCRuntimeClass *pClass) 00506 00507 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00508 Created: 02/08/94 00509 Inputs: pClass - the base class of the component to look for. 00510 Returns: A pointer to the required component, or NULL if no match was found. 00511 Purpose: Find a kind of document component of in this document - it must be 00512 derived from the class described by pClass. 00513 SeeAlso: BaseDocument::GetDocComponent; 00514 DocComponent 00515 00516 ********************************************************************************************/ 00517 00518 DocComponent *BaseDocument::GetDocComponentKindOf(CCRuntimeClass *pClass) 00519 { 00520 DocComponent *pItem = (DocComponent *) DocComponents->GetHead(); 00521 00522 while (pItem != NULL) 00523 { 00524 // Is this derived from the base class specified? 00525 if (pItem->IsKindOf(pClass)) 00526 // Yes - return to caller. 00527 return pItem; 00528 00529 // Try the next component 00530 pItem = (DocComponent *) DocComponents->GetNext(pItem); 00531 } 00532 00533 // Didn't find the component - report this to caller 00534 return NULL; 00535 } 00536 00537 00538 00539 /******************************************************************************************** 00540 00541 > DocComponent *BaseDocument::EnumerateDocComponents(DocComponent *pContext) 00542 00543 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00544 Created: 02/08/94 00545 Inputs: pContext: NULL => Get the first document component 00546 non-NULL => Get the next document component after the one pointed to 00547 by pContext. 00548 Returns: Pointer to the required document component. 00549 Purpose: Allow the caller to examine/use all the document components attached to this 00550 document.. 00551 pContext should be NULL for the first call, which will return the first 00552 document component. After that, the returned pointer should be passed back 00553 in to this function, which will return the next one, and so on. 00554 For example: 00555 MonoOn 00556 DocComponent *pDocComp = NULL; 00557 do 00558 { 00559 pDocComp = pDoc->EnumerateDocComponents(pDocComp); 00560 00561 // Do something groovy with pDocComp... 00562 } 00563 while (pDocComp != NULL); 00564 MonoOff 00565 00566 SeeAlso: DocComponent 00567 00568 ********************************************************************************************/ 00569 00570 DocComponent *BaseDocument::EnumerateDocComponents(DocComponent *pContext) 00571 { 00572 if (pContext == NULL) 00573 { 00574 // Return the first item in the list... 00575 return (DocComponent *) (DocComponents->GetHead()); 00576 } 00577 else 00578 { 00579 // Return the next document component... 00580 return (DocComponent *) (DocComponents->GetNext(pContext)); 00581 } 00582 } 00583 00584 /******************************************************************************************** 00585 00586 > virtual BOOL BaseDocument::StartComponentCopy() 00587 00588 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00589 Created: 16/8/94 00590 Inputs: - 00591 Outputs: - 00592 Returns: FALSE if a call to DocComponent::StartComponentCopy fails. In this case 00593 AbortComponentCopy gets called. 00594 Purpose: This function traverses the documents list of DocComponents and calls 00595 the virtual StartComponentCopy method on them. It calls AbortComponent copy 00596 on all DocComponents if we fail. 00597 Errors: - 00598 SeeAlso: DocComponent::StartComponentCopy 00599 00600 ********************************************************************************************/ 00601 00602 BOOL BaseDocument::StartComponentCopy() 00603 { 00604 DocComponent* Current = (DocComponent*) DocComponents->GetHead(); 00605 DocComponent* Next; 00606 while (Current != NULL) 00607 { 00608 Next = (DocComponent*) DocComponents->GetNext(Current); 00609 if (!Current->StartComponentCopy()) 00610 { 00611 AbortComponentCopy(); 00612 return FALSE; 00613 } 00614 Current = Next; 00615 } 00616 return TRUE; 00617 } 00618 00619 00620 /******************************************************************************************** 00621 00622 > virtual BOOL BaseDocument::EndComponentCopy() 00623 00624 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00625 Created: 16/8/94 00626 Inputs: - 00627 Outputs: - 00628 Returns: FALSE if a call to DocComponent::EndComponentCopy fails. In this situation 00629 Abort component copy is called. 00630 Purpose: This function traverses the documents list of DocComponents and calls 00631 the virtual EndComponentCopy method on them 00632 Errors: - 00633 SeeAlso: DocComponent::EndComponentCopy 00634 00635 ********************************************************************************************/ 00636 00637 BOOL BaseDocument::EndComponentCopy() 00638 { 00639 DocComponent* Current = (DocComponent*) DocComponents->GetHead(); 00640 DocComponent* Next; 00641 while (Current != NULL) 00642 { 00643 Next = (DocComponent*) DocComponents->GetNext(Current); 00644 if (!Current->EndComponentCopy()) 00645 { 00646 AbortComponentCopy(); 00647 return FALSE; 00648 } 00649 Current = Next; 00650 } 00651 return TRUE; 00652 } 00653 00654 /******************************************************************************************** 00655 00656 > virtual void BaseDocument::AbortComponentCopy() 00657 00658 Author: Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com> 00659 Created: 16/8/94 00660 Inputs: - 00661 Outputs: - 00662 Returns: - 00663 Purpose: This function traverses the documents list of DocComponents and calls 00664 the virtual AbortComponentCopy method on them 00665 Errors: - 00666 SeeAlso: DocComponent::AbortComponentCopy 00667 00668 ********************************************************************************************/ 00669 00670 void BaseDocument::AbortComponentCopy() 00671 { 00672 DocComponent* Current = (DocComponent*) DocComponents->GetHead(); 00673 DocComponent* Next; 00674 while (Current != NULL) 00675 { 00676 Next = (DocComponent*) DocComponents->GetNext(Current); 00677 Current->AbortComponentCopy(); 00678 Current = Next; 00679 } 00680 00681 } 00682 00683 00684 /******************************************************************************************** 00685 00686 > ColourList *BaseDocument::GetIndexedColours(void) 00687 00688 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00689 Created: 05/05/94 (Moved here from NodeDocument 1/8/94) 00690 Inputs: - 00691 Outputs: - 00692 Returns: A pointer to this documents list of IndexedColours 00693 Purpose: Returns a pointer to a list of the IndexedColours available to the 00694 user within this document. 00695 Scope: Private (intended only for colour manager to access) 00696 Errors: - 00697 SeeAlso: class IndexedColour; class ColourList 00698 00699 ********************************************************************************************/ 00700 00701 ColourList *BaseDocument::GetIndexedColours(void) 00702 { 00703 // Get the colour list component 00704 ColourListComponent *pComponent = 00705 (ColourListComponent *) GetDocComponent(CC_RUNTIME_CLASS(ColourListComponent)); 00706 00707 if(pComponent == NULL) 00708 return NULL; 00709 00710 // Extract the colour list 00711 return pComponent->GetColourList(); 00712 } 00713 00714 00715 /******************************************************************************************** 00716 00717 > ColourContextArray *BaseDocument::GetDefaultColourContexts(void) 00718 00719 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> 00720 Created: 18/04/94 00721 Inputs: - 00722 Outputs: - 00723 Returns: A pointer to this documents array of default colour contexts. 00724 Purpose: Gives access to the Documents array of default colour contexts 00725 This is used internally by the DocColour system, and I shouldn't 00726 think it will be of much interest to anyone else. 00727 Errors: - 00728 SeeAlso: ColourContext 00729 00730 ********************************************************************************************/ 00731 00732 ColourContextArray *BaseDocument::GetDefaultColourContexts(void) 00733 { 00734 return(&DefaultColourContexts); 00735 } 00736 00737 00738 00739 /******************************************************************************************** 00740 > BOOL BaseDocument::CheckReferences() 00741 00742 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00743 Created: 31/01/2005 00744 Inputs: - 00745 Outputs: - 00746 Returns: TRUE/FALSE for Success/Failure 00747 Purpose: Checks for references to resources outside the document that may be dangling 00748 because the resources are not present. 00749 00750 Errors: - 00751 SeeAlso: - 00752 ********************************************************************************************/ 00753 00754 BOOL BaseDocument::CheckReferences() 00755 { 00756 // URGH! This should be implemented in Document, not BaseDocument! 00757 CCamDoc* pOilDoc = NULL; 00758 if (IS_KIND_OF(Document)) 00759 pOilDoc = ((Document*) this)->GetOilDoc(); 00760 if (pOilDoc && pOilDoc->IsVisible()) 00761 { 00762 // We don't want to show the user a sequence of boxes so collapse all reference 00763 // checks into a single warning... 00764 // (Argh but it's too much trouble at the mo...) 00765 PORTNOTETRACE("text","BaseDocument::CheckReferences - removed CheckFontSubstitution call"); 00766 #ifndef EXCLUDE_FROM_XARALX 00767 BOOL bFontsOK = CheckFontSubstitution(); 00768 #endif 00769 BOOL bFontsOK = true; 00770 BOOL bEffectsOK = CheckEffects(); 00771 00772 #ifndef EXCLUDE_FROM_XARALX 00773 BOOL bFontsOK = CheckFontSubstitution(FALSE); 00774 BOOL bEffectsOK = CheckEffects(FALSE); 00775 00776 if (!bFontsOK || !bEffectsOK) 00777 { 00778 ErrorInfo warning; 00779 String_256 strWarning; 00780 strWarning.MakeMsg(_R(IDS_MISSINGREFERENCES), strFontsWarning, strEffectsWarning); 00781 warning.ErrorMsg = strWarning; 00782 warning.Title = String(_R(IDS_MISSINGREFS_TITLE)); 00783 warning.Button[0] = _R(IDB_CONTINUE); 00784 InformWarning(warning); 00785 } 00786 #endif 00787 return (bFontsOK && bEffectsOK); 00788 } 00789 00790 return FALSE; 00791 } 00792 00793 00794 00795 00796 /******************************************************************************************** 00797 > BOOL BaseDocument::CheckFontSubstitution() 00798 00799 Author: Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> 00800 Created: 31/7/96 00801 Inputs: - 00802 Outputs: - 00803 Returns: TRUE/FALSE for Success/Failure 00804 Purpose: Checks for substituted fonts, and if it finds any, in warns the user. 00805 00806 (This code has been separated from PostImport() so it can be called independantly) 00807 00808 Errors: - 00809 SeeAlso: - 00810 ********************************************************************************************/ 00811 00812 BOOL BaseDocument::CheckFontSubstitution() 00813 { 00814 // check whether any fonts have been substituted 00815 BOOL FontSubstitution = FALSE; 00816 FontList DocFonts; 00817 DocFonts.Build((Document*)this); 00818 FontListItem* FontItem = DocFonts.GetFirstItem(); 00819 if (FontItem!=NULL) 00820 { 00821 // fill up the list 00822 while (FontItem) 00823 { 00824 // get the name 00825 String_64 Name = FontItem->GetFontName(); 00826 FontClass Class = FontItem->GetFontClass(); 00827 if (FONTMANAGER->IsFontReplaced(&Name, Class)) 00828 { 00829 FontSubstitution=TRUE; 00830 break; 00831 } 00832 FontItem = DocFonts.GetNextItem(FontItem); 00833 } 00834 } 00835 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX) 00836 if (FontSubstitution) 00837 { 00838 #if (_OLE_VER >= 0x200) 00839 // Only warn about this if the document is visible to the user. 00840 CCamDoc* pOilDoc = 0; 00841 if (IS_KIND_OF(Document)) pOilDoc = ((Document*) this)->GetOilDoc(); 00842 if (pOilDoc && pOilDoc->IsVisible()) 00843 #endif 00844 // Inform the user that some fonts are not installed 00845 Operation::SetQuickRender(TRUE); // Prevent cacheing while this warning is on screen 00846 InformWarning(_R(IDS_FONTSSUBSTITUTED), _R(IDS_CONTINUE)); 00847 Operation::SetQuickRender(FALSE); 00848 } 00849 #endif 00850 00851 return TRUE; 00852 } 00853 00854 00855 00856 00857 /******************************************************************************************** 00858 > BOOL BaseDocument::CheckEffects() 00859 00860 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00861 Created: 31/01/2005 00862 Inputs: - 00863 Outputs: - 00864 Returns: TRUE/FALSE for Success/Failure 00865 Purpose: Checks for missing effects, and warn the user. 00866 00867 Errors: - 00868 SeeAlso: - 00869 ********************************************************************************************/ 00870 00871 BOOL BaseDocument::CheckEffects() 00872 { 00873 ListRange* pEffectList = GetEffectsList(500000); // Arbitrary large number 00874 BOOL bFound = TRUE; 00875 00876 if (pEffectList) 00877 { 00878 Node* pNode = pEffectList->FindFirst(); 00879 while (pNode) 00880 { 00881 if (pNode->IsBitmapEffect()) 00882 { 00883 NodeBitmapEffect* pEffect = (NodeBitmapEffect*)pNode; 00884 00885 if (!pEffect->IsLockedEffect()) 00886 { 00887 00888 PORTNOTE("other","Removed XPEHost usage") 00889 #ifndef EXCLUDE_FROM_XARALX 00890 // Live effects need to regenerate their bitmaps so we must 00891 // test whether the handler is present and warn the user if not 00892 String_64 strDisplayName; 00893 bFound = XPEHost::GetEffectDetails(pEffect->GetPostProcessorID(), &strDisplayName); 00894 if (!bFound) 00895 { 00896 break; 00897 } 00898 #endif 00899 } 00900 } 00901 00902 pNode = pEffectList->FindNext(pNode); 00903 } 00904 00905 delete pEffectList; 00906 } 00907 00908 if (!bFound) 00909 { 00910 Operation::SetQuickRender(TRUE); // Prevent cacheing while this warning is on screen 00911 InformWarning(_R(IDS_FINFO_MISSINGEFFECTS), _R(IDS_CONTINUE)); 00912 Operation::SetQuickRender(FALSE); 00913 } 00914 00915 return TRUE; 00916 } 00917 00918 00919 00920 00921 /******************************************************************************************* 00922 00923 > ListRange* BaseDocument::GetEffectsList(UINT32 iMaxItems) 00924 00925 Author: Phil_Martin (Xara Group Ltd) <camelotdev@xara.com> 00926 Created: 31/01/2005 00927 Inputs: - 00928 Outputs: - 00929 Returns: True if completed ok, False otherwise. 00930 Purpose: Updates the effects list showing referred and missing effects 00931 Errors: - 00932 SeeAlso: SetDocInfo; FontDropDown; DocumentFontDropDown; 00933 00934 *******************************************************************************************/ 00935 00936 ListRange* BaseDocument::GetEffectsList(UINT32 iMaxItems) 00937 { 00938 // Make a list of all unique effects used in the doc 00939 // Add each list item to the listbox, marking it if the referred effect can not 00940 // be found in the installed effect list 00941 00942 ListRange* pEffectList = new ListRange(); 00943 Node* pNode = GetFirstNode(); 00944 UINT32 i = 0; 00945 while (pNode && i<iMaxItems) 00946 { 00947 if (pNode->IsBitmapEffect()) 00948 { 00949 NodeBitmapEffect* pEffect = (NodeBitmapEffect*)pNode; 00950 00951 // Search for this type of effect in the list already 00952 Node* pListNode = pEffectList->FindFirst(); 00953 while (pListNode) 00954 { 00955 if (((NodeBitmapEffect*)pListNode)->GetPostProcessorID() == pEffect->GetPostProcessorID()) 00956 break; 00957 00958 pListNode = pEffectList->FindNext(pListNode); 00959 } 00960 00961 // If this effect type is not already in the list, add it 00962 if (pListNode==NULL) 00963 { 00964 pEffectList->AddNode(pNode); 00965 i++; 00966 } 00967 } 00968 00969 pNode = pNode->FindNextDepthFirst(NULL); 00970 } 00971 00972 return pEffectList; 00973 } 00974 00975 00976 00977 00978 /******************************************************************************************** 00979 > void BaseDocument::PostImport() 00980 00981 Author: Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com> 00982 Created: 04/04/95 00983 Inputs: - 00984 Outputs: - 00985 Returns: TRUE/FALSE for Success/Failure (you what? Surely some mistake? Sack the programmer) 00986 Purpose: Scans the entire tree, calling all nodes PostImport function. If any of 00987 functions returns FALSE the error is reported and the scan continues. 00988 Errors: - 00989 SeeAlso: - 00990 ********************************************************************************************/ 00991 00992 void BaseDocument::PostImport() 00993 { 00994 #ifdef RALPH 00995 // We don't want to be rendering at the same time as doing this, because we get 00996 // blobby text problems - fun, but bad ! 00997 RalphCriticalSection RalphCS; 00998 #endif 00999 01000 BeginSlowJob(); 01001 01002 // Get a pointer to the StartDocument node 01003 Node* pStartNode = GetFirstNode(); 01004 ERROR3IF(pStartNode == NULL, "(BaseDocument::PostImport) TreeStart was NULL"); 01005 01006 // Get a pointer to the NodeDocument node 01007 if (pStartNode != NULL) 01008 { 01009 pStartNode = pStartNode->FindNext(); 01010 ERROR3IF(pStartNode == NULL, "(BaseDocument::PostImport) No NodeDocument after StartDocument"); 01011 } 01012 01013 // Scan through the tree, calling all PostImport functions 01014 if (pStartNode != NULL) 01015 { 01016 Node* pCurrentNode = pStartNode->FindFirstDepthFirst(); 01017 01018 while (pCurrentNode != NULL) 01019 { 01020 if (!pCurrentNode->PostImport()) 01021 { 01022 InformError(); 01023 } 01024 pCurrentNode = pCurrentNode->FindNextDepthFirst(pStartNode); 01025 } 01026 } 01027 01028 // check whether any fonts have been substituted, and warn the user if they have 01029 // CheckFontSubstitution(); 01030 CheckReferences(); 01031 01032 EndSlowJob(); 01033 } 01034