app.cpp

Go to the documentation of this file.
00001 // $Id: app.cpp 1531 2006-07-25 16:05:48Z 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 #include "camtypes.h"
00100 
00101 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00102 #include "colormgr.h"
00103 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00104 //#include "rndrgn.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00105 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "prefs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 
00108 //#include "pump.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "ops.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "bars.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00112 //#include "opdesc.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "range.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 #include "objreg.h"
00115 #include "pen.h"
00116 #include "blobs.h"
00117 //#include "docview.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00118 //#include "clipint.h"
00119 //#include "doccomp.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 //#include "keypress.h"
00121 //#include "tool.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00122 //#include "keymsg.h"
00123 #include "hotkeys.h"
00124 #include "statline.h"
00125 #include "camelot.h"
00126 #include "dbugtree.h"
00127 //#include "atminfo.h"
00128 #include "fontman.h"
00129 #include "coldlog.h"
00130 //#include "xaracms.h"
00131 #include "prnmks.h"
00132 #include "camelot.h"
00133 //#include "ralphcri.h"
00134 #include "ralphdoc.h"
00135 //#include "registry.h"
00136 
00137 //#include "resimmap.h" //For _R(IDS_NEWTEMPLATES_RELATIVEPATH)
00138 
00139 #ifdef FREEHANDPLUGINS
00140 // Only add in if required - general plug-in removal at present
00141 #include "apiobj.h"     // APIObject
00142 #include "handman.h"    //  HandleManager
00143 #endif
00144 //#include "plugmngr.h" // Plug-in Manager
00145 #include "filtrmgr.h"   // Filter Manager
00146 #include "tmpltarg.h"   // WizOp(s)
00147 #include "tmplmngr.h"
00148 
00149 #include "noisebas.h"
00150 #ifdef AUTOMATION
00151 #include "ccc.h"        // ConcurrencyController
00152 #endif
00153 
00154 #include "objcache.h"   // the objectcache header
00155 #include "cachrand.h"   // ObjectCache (random)
00156 #include "cachfifo.h"   // ObjectCache (fifo)
00157 #include "cachweak.h"   //
00158 //#include "bitmapcache.h"
00159 
00160 #include "sgliboil.h"   // AppendSlashIfNotPresent
00161 
00162 DECLARE_SOURCE("$Revision: 1531 $");
00163 
00164 CC_IMPLEMENT_MEMDUMP(Application, CCObject)
00165 
00166 // Declare smart memory handling in Debug builds
00167 #define new CAM_DEBUG_NEW
00168 
00169 Application Camelot;
00170 
00171 /***********************************************************************************************
00172 
00173 >   Application::Application()
00174 
00175     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00176     Created:    20/5/93
00177     
00178     Inputs:     -
00179     Outputs:    -
00180     Returns:    -
00181                  
00182     Purpose:    Initialise the application.
00183                
00184     Errors:     None.
00185                                                                  
00186 ***********************************************************************************************/
00187 
00188 Application::Application() : m_pTemplateManager( new CTemplateManager )
00189 {
00190 // WEBSTER - markn 25/4/97
00191 // No pen stuff required in Webster
00192 // Now taken out via vector stroking code Neville 2/10/97
00193 #ifdef VECTOR_STROKING
00194     PressurePen = NULL;
00195     PenInitialised = FALSE;
00196 #endif // VECTOR_STROKING
00197 
00198     CamelotPrefs = NULL;
00199     Selection = NULL;
00200     TheColourManager = NULL;
00201     BlobMgr = NULL;
00202     DocComponentClasses = NULL;
00203     pATMIniCache = NULL;
00204 
00205     FontMgr                     = NULL;
00206     CMSManager                  = NULL;
00207     TheMarksManager             = NULL;
00208     ThePlugInManager            = NULL;
00209     TheFilterManager            = NULL;
00210     TheAPIObject                = NULL;
00211     TheHandleManager            = NULL;
00212     TheNoiseManager             = NULL;
00213     TheWizardOfOps              = NULL;
00214     DisabledRealDownload        = FALSE;
00215 PORTNOTE("other","Removed HKEY usage")
00216 #ifndef EXCLUDE_FROM_XARALX
00217     key                         = NULL;
00218     key2                        = NULL;
00219 #endif
00220 #ifdef AUTOMATION
00221     TheConcurrencyController    = NULL;
00222 #endif
00223 
00224     // This variable will get set to TRUE when Camelot starts to shut down
00225     CamelotShuttingDown = FALSE; 
00226     BgRendering = FALSE;
00227 
00228     // Temporary: Remove when Kernel StatusLine is actually created by Oil statusline
00229     m_pStatusLine = NULL;
00230 }
00231 
00232 /***********************************************************************************************
00233 
00234 >   Application::~Application()
00235 
00236     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00237     Created:    20/5/93
00238     
00239     Inputs:     - 
00240     Outputs:    -
00241     Returns:    -
00242                  
00243     Purpose:    Destroys any documents associated with this object.
00244                
00245     Errors:     None.
00246                                                                  
00247 ***********************************************************************************************/
00248 
00249 Application::~Application()
00250 {
00251     // Delete any documents still associated with this application
00252     Document *pDocument = (Document *) Documents.GetHead();
00253     
00254     while (pDocument != NULL)
00255     {
00256         delete Documents.RemoveItem(pDocument);
00257         pDocument = (Document *) Documents.GetHead();
00258     }
00259 
00260 //  ERROR3IF(DocComponentClasses != NULL,
00261 //              "Application was not properly de-initialised");
00262     if (DocComponentClasses != 0) TRACE( wxT("WARNING: Application was not properly de-initialised\n") );
00263 
00264     RegenList.DeleteAll();
00265 }
00266 
00267 #if _AFXDLL
00268 
00269 // these must be an out-of-line function in DLL builds
00270 
00271 Application *GetApplication()
00272 {
00273     return &Camelot;
00274 }
00275 
00276 #endif
00277 
00278 /***********************************************************************************************
00279 
00280 >   BOOL Application::Init()
00281 
00282     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00283     Created:    26/8/93
00284     
00285     Inputs:     -
00286     Outputs:    -
00287     Returns:    TRUE if the object initialised ok.
00288                  
00289     Purpose:    Initialise the application, including the user preferences system. This is
00290                 the earliest kernel-level code to be called - do NOT ADD THINGS HERE. Almost
00291                 everything that needs to be initialised should go in InitKernel, which gets
00292                 called after this and some OIL initialisation. If you think you qualify to
00293                 add something here, speak to Andy first.
00294                
00295     Errors:     None.
00296                                                                  
00297 ***********************************************************************************************/
00298 
00299 BOOL Application::Init()
00300 {
00301     
00302     // Initialise the message handler class groups
00303     if(!(
00304         MessageHandler::RegisterClassGroup(CC_RUNTIME_CLASS(MessageHandler)) && 
00305         MessageHandler::RegisterClassGroup(CC_RUNTIME_CLASS(Operation))     &&
00306         MessageHandler::RegisterClassGroup(CC_RUNTIME_CLASS(DialogOp))      &&
00307         MessageHandler::RegisterClassGroup(CC_RUNTIME_CLASS(OpDescriptor))  &&
00308         MessageHandler::RegisterClassGroup(CC_RUNTIME_CLASS(DialogBarOp))   &&
00309         MessageHandler::RegisterClassGroup(CC_RUNTIME_CLASS(SelRangeMessageHandler))
00310       ))
00311     {
00312         return FALSE; // Failed
00313     }
00314 
00315 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00316 PORTNOTE("colourmanager","Removed XaraCMS usage")
00317     // Create the Xara CMS manager - we have to get this in there
00318     // before a colour manager initialise otherwise there'll be trouble.
00319     // Note that if this fails in any way, we continue happily, simply disabling
00320     // the advanced colour management functions.
00321     CMSManager = new XaraCMS;
00322     if (CMSManager != NULL)
00323     {
00324         // We got one. Let's initialise it
00325         if (!CMSManager->Initialise(1))
00326         {
00327             delete CMSManager;
00328             CMSManager = NULL;
00329         }
00330     }
00331     CMSManager = NULL;
00332 #else 
00333     CMSManager = NULL;
00334 #endif
00335 
00336     // startup the noise system
00337     TheNoiseManager = new NoiseMan;
00338     if (TheNoiseManager == NULL)
00339         return FALSE;
00340 
00341     if (!TheNoiseManager->Initialise())
00342         return FALSE;
00343 
00344     // Initialise the colour system
00345     if (!ColourManager::Init())
00346         return FALSE;
00347 
00348     // Create and initialise the Camelot Selection object
00349     // This must be done AFTER registering the SelRangeMessageHandler class above,
00350     // as the Selection tries to register a message handler when it is constructed.
00351     // Thus it is necessary to defer creation of the object until the msg system
00352     // has been appropriately set up.
00353     Selection = new SelRange;
00354     if (Selection == NULL)
00355         return(FALSE);
00356 
00357     // startup the noise system
00358     // Create and initialise the colour manager
00359     // THis is done here for the same reasons as described for the SelRange, above.
00360     TheColourManager = new ColourManager;
00361     if (TheColourManager == NULL)
00362         return(FALSE);
00363 
00364     // create and initialise a new Blob Manager
00365     BlobMgr = new BlobManager;
00366     if (BlobMgr == NULL)
00367         return FALSE;
00368 
00369 PORTNOTE("other","Removed init of stuff that is not supported")
00370 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00371     // create the ATM ini cache.
00372     pATMIniCache = new ATMIniCache;
00373     if (pATMIniCache == NULL)
00374         return FALSE;
00375 #endif
00376 
00377     // Create the font mangler
00378     FontMgr = new FontManager;
00379     if (FontMgr == NULL)
00380         return FALSE;
00381 
00382     // And make sure its initialised;
00383     if (!FontMgr->Init())
00384         return FALSE;
00385 
00386 #if !defined(EXCLUDE_FROM_RALPH)
00387 #ifndef STANDALONE
00388 #ifndef WEBSTER
00389 // Do not do do on Webster as this conflicts with the CleanUpAfterExport code in BaseCamelotFilter
00390 
00391     // Create a print marks manager please
00392     TheMarksManager = new PrintMarksMan;
00393     if (TheMarksManager == NULL)
00394         return FALSE;
00395 #endif // WEBSTER
00396 #endif
00397 #endif
00398 
00399 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00400 #ifndef STANDALONE
00401 #ifdef FREEHANDPLUGINS
00402 // Only add in if required - general plug-in removal at present
00403     // Create the external (Freehand Xtra) API object
00404     TheAPIObject = new APIObject;
00405     if (TheAPIObject == NULL)
00406         return FALSE; // Actually we can probably run without this...
00407 #endif // FREEHANDPLUGINS
00408 
00409 #ifdef PLUGINSUPPORT
00410     // Create a plug-in manager please
00411     ThePlugInManager = new PlugInManager;
00412     if (ThePlugInManager == NULL)
00413         return FALSE;
00414 #endif // PLUGINSUPPORT
00415 
00416 #ifdef FREEHANDPLUGINS
00417     TRACEUSER( "claude", _T("new handlemanager\n"));
00418     TheHandleManager = new HandleManager;
00419     if (TheHandleManager == NULL)
00420         return FALSE;
00421 #endif // FREEHANDPLUGINS
00422 
00423     if (!InitFilterManager())
00424     {
00425         return FALSE;
00426     }
00427     
00428 #endif // STANDALONE
00429 #endif // EXCLUDE_FROM_RALPH, EXCLUDE_FROM_XARALX
00430 
00431 #ifndef EXCLUDE_FROM_XARALX
00432 #ifdef AUTOMATION
00433     if (!InitCCC())
00434     {
00435         return FALSE;
00436     }
00437 #endif
00438 #endif
00439 
00440     // Initialise the object registry. 
00441     if (!ObjectRegistry::Init())
00442     {
00443         // Error has been set
00444         return (FALSE);  
00445     }
00446 
00447     if (!InitWizOps())
00448     {
00449         return FALSE;
00450     }  
00451 
00452 #if !defined(EXCLUDE_FROM_RALPH)
00453     // Create and initialise the CamelotPrefs object.
00454     // This object is dynamically created rather than being embedded in the Appliation object
00455     // because the Application destructor is called after the SimpleCCObject::MemoryDump()
00456     // function is called.  Hence if the CamelotPrefs object were embedded, the MemoryDump
00457     // would list all the preference-related objects on application termination.
00458     CamelotPrefs = new Preferences;
00459 
00460     if (!((CamelotPrefs != NULL) && CamelotPrefs->Init()))
00461         return FALSE;
00462 #endif
00463 
00464 #ifdef VECTOR_STROKING // Neville 6/8/97
00465     m_pObjCache = new ObjectCacheFIFO(50);      // set a cache of 50 bytes
00466 
00467     if (m_pObjCache == NULL)
00468         return FALSE;
00469     // Set the cache size with an arbitrary value (in bytes)
00470     //m_ObjCache->SetMaxCacheSize(50);
00471 #endif // VECTOR_STROKING
00472 
00473     // Set up the Bitmap Cache...
00474     TheBitmapCache = new CBitmapCache();
00475     TheBitmapCache->Initialise();                   // Initialise with default settings
00476 
00477     // Get an empty list object to hold all the registered doc components
00478     DocComponentClasses = new List;
00479     if (DocComponentClasses == NULL)
00480         return FALSE;
00481 
00482     // Eveything worked (gasp!)
00483     return TRUE; 
00484 }
00485 
00486 
00487 /***********************************************************************************************
00488 
00489 >   BOOL Application::InitFilterManager()
00490 
00491     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00492     Created:    26/12/96
00493     Returns:    TRUE if OK, FALSE if failed
00494     Purpose:    Support function to initialize this Application's FilterManager
00495                                                                  
00496 ***********************************************************************************************/
00497 BOOL Application::InitFilterManager()
00498 {
00499     BOOL Success = FALSE;
00500 
00501     TheFilterManager = new FilterManager;
00502     if (TheFilterManager != NULL)
00503     {
00504         Success = TheFilterManager->Init();
00505     }
00506     else
00507     {
00508         Success = FALSE;
00509     }
00510 
00511     return Success;
00512 }
00513 
00514 
00515 /***********************************************************************************************
00516 
00517 >   BOOL Application::InitWizOps()
00518 
00519     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00520     Created:    26/12/96
00521 
00522     Purpose:    Support function to initialize this Application's WizardOfOps from the local
00523                 registry.
00524 
00525     Returns:    TRUE if OK, FALSE if failed
00526                                                                  
00527 ***********************************************************************************************/
00528 BOOL Application::InitWizOps()
00529 {
00530     BOOL Ok = TRUE;
00531 
00532     TheWizardOfOps = new WizOps;
00533     if (TheWizardOfOps != NULL)
00534     {
00535         Ok = TheWizardOfOps->InitializeFromRegistry();
00536     }
00537     else
00538     {
00539         Ok = FALSE;
00540     }
00541 
00542     return Ok;
00543 }
00544 
00545 
00546 #ifdef AUTOMATION
00547 /***********************************************************************************************
00548 
00549 >   BOOL Application::InitCCC()
00550 
00551     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00552     Created:    26/03/97
00553 
00554     Returns:    TRUE if OK, FALSE if failed
00555     Purpose:    Support function to initialize this Application's ConcurrencyController
00556                                                                  
00557 ***********************************************************************************************/
00558 BOOL Application::InitCCC()
00559 {
00560     BOOL Success = FALSE;
00561 
00562     TheConcurrencyController = new ConcurrencyController;
00563     if (TheConcurrencyController != NULL)
00564     {
00565         Success = TheConcurrencyController->Init();
00566     }
00567     else
00568     {
00569         Success = FALSE;
00570     }
00571 
00572     return Success;
00573 }
00574 #endif  // AUTOMATION
00575 
00576 
00577 /***********************************************************************************************
00578 
00579 >   BOOL Application:LateInit()
00580 
00581     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00582     Created:    26/9/94
00583     Returns:    TRUE if OK, FALSE if failed->SetError.
00584     Purpose:    Initialise the application object bits that require the preferences system
00585                 to be fully up & running. Currently that means the pen only.
00586     Errors:     None.
00587                                                                  
00588 ***********************************************************************************************/
00589 
00590 BOOL Application::LateInit()
00591 {
00592 #ifdef PLUGINSUPPORT
00593 // Only add in if required - general plug-in removal at present
00594     // We need the preferences system present so we must wait until here
00595     // before we ask the PlugInManager to initialise iteself;
00596     if (ThePlugInManager == NULL || !ThePlugInManager->Init())
00597         return FALSE;
00598 #endif // PLUGINSUPPORT
00599 
00600     m_pTemplateManager->Init();
00601 
00602     // Everything went ok
00603     return TRUE;
00604 }
00605 
00606 /********************************************************************************************
00607 
00608 >   void Application::Deinit()
00609 
00610     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00611     Created:    26/8/93
00612     Purpose:    Close down the kernel application object, including the user preferences 
00613                 system.
00614                                                                  
00615 ********************************************************************************************/
00616 
00617 void Application::Deinit()
00618 {
00619 #ifdef PLUGINSUPPORT
00620 // Only add in if required - general plug-in removal at present
00621     // We need to ask the plug-in manager to save out its list of pathnames.
00622     // So before the prefs system is vaped.
00623     PlugInManager * pPlugMan = GetApplication()->GetPlugInManager();
00624     if (pPlugMan)
00625         pPlugMan->WritePathNameList();
00626 #endif // PLUGINSUPPORT
00627 
00628 #ifdef FREEHANDPLUGINS
00629     //  clean up the memory used by MOA
00630     TRACEUSER( "claude", wxT("Free up frmo the handle manager\n") );
00631     HandleManager* pHandleCleaning = GetApplication()->GetHandleManager();
00632     if(pHandleCleaning)
00633         pHandleCleaning->FreeAll();
00634 #endif // FREEHANDPLUGINS
00635 
00636     if (CamelotPrefs!=NULL)
00637     {
00638         CamelotPrefs->Deinit();
00639         delete CamelotPrefs;
00640         CamelotPrefs = NULL;
00641     }
00642 
00643     if (Selection!=NULL)
00644     {
00645         delete Selection;
00646         Selection = NULL;
00647     }
00648         
00649     if (DocComponentClasses != NULL)
00650     {
00651         DocComponentClasses->DeleteAll();
00652         delete DocComponentClasses;
00653         DocComponentClasses = NULL;
00654     }
00655 
00656     if (TheColourManager!=NULL)
00657     {
00658         ColourManager::Deinit();
00659         delete TheColourManager;
00660         TheColourManager = NULL;
00661     }
00662 
00663     if (TheNoiseManager!=NULL)
00664     {
00665         TheNoiseManager->Destroy();
00666         delete TheNoiseManager;
00667         TheNoiseManager=NULL;
00668     }
00669 
00670 #if !defined(EXCLUDE_FROM_RALPH)
00671 #if !defined(EXCLUDE_FROM_XARALX)
00672 PORTNOTE("colourmanager","Removed XaraCMS usage")
00673     if (CMSManager!=NULL)
00674     {
00675         CMSManager->Finalise();
00676         delete CMSManager;
00677         CMSManager = NULL;
00678     }
00679 
00680 // VECTOR_STROKING - markn 25/4/97
00681 // No pen stuff required in Webster
00682 // Taken out by vector stroking code Neville 2/10/97
00683 #ifdef VECTOR_STROKING
00684     if (PressurePen != NULL)
00685     {
00686         delete PressurePen;
00687         PressurePen = NULL;
00688     }
00689 #endif // VECTOR_STROKING
00690 
00691 #endif  // EXCLUDE_FROM_XARALX
00692     // Get rid of the blob manager
00693     if (BlobMgr!=NULL)
00694     {
00695         delete BlobMgr;
00696         BlobMgr = NULL;
00697     }
00698 #endif // EXCLUDE_FROM_RALPH
00699 
00700 PORTNOTE("other","Removed un-=impl. stuff")
00701 #ifndef EXCLUDE_FROM_XARALX
00702     // Get rid of the ATM Ini cache object
00703     if (pATMIniCache!=NULL)
00704     {
00705         delete pATMIniCache;
00706         pATMIniCache = NULL;
00707     } */
00708 #endif
00709 
00710     // Get rid of the font manager
00711     if (FontMgr!=NULL)
00712     {
00713         delete FontMgr;
00714         FontMgr = NULL;
00715     }
00716 
00717 #if !defined(EXCLUDE_FROM_RALPH)
00718 #ifndef STANDALONE
00719 #ifndef WEBSTER
00720 // Do not do do on Webster as this conflicts with the CleanUpAfterExport code in BaseCamelotFilter
00721 
00722     // Toast the marks manager
00723     if (TheMarksManager!=NULL)
00724     {
00725         delete TheMarksManager;
00726         TheMarksManager = NULL;
00727     }
00728 #endif // WEBSTER
00729 #endif
00730 #endif
00731 
00732 #ifdef PLUGINSUPPORT
00733 // Only add in if required - general plug-in removal at present
00734     // Toast the plug-in manager
00735     if (ThePlugInManager != NULL)
00736     {
00737         delete ThePlugInManager;
00738         ThePlugInManager = NULL;
00739     }
00740 #endif // PLUGINSUPPORT
00741 
00742 #ifdef FREEHANDPLUGINS
00743     // Nuke the API interfaces (must be done after killing the plugin manager). Don't delete
00744     // it afterwards, it's all handled by the reference count...
00745     if(TheAPIObject != NULL)
00746         TheAPIObject->ShutDown();
00747 
00748     //  Delete the Moa handle manager
00749     if(TheHandleManager != NULL)
00750     {
00751         TRACEUSER( "claude", wxT("deleting the moa handle manager\n") );
00752         delete TheHandleManager;
00753         TheHandleManager = NULL;
00754     }
00755 #endif // FREEHANDPLUGINS
00756 
00757     DeinitFilterManager();
00758 
00759     if (m_pObjCache != NULL)
00760     {
00761         delete m_pObjCache;
00762         m_pObjCache = NULL;
00763     }
00764 
00765     if (TheBitmapCache)
00766     {
00767         TheBitmapCache->DeInitialise();
00768         delete TheBitmapCache;
00769         TheBitmapCache = NULL;
00770     }
00771 
00772     DeinitWizOps();
00773 
00774 #ifdef AUTOMATION
00775     DestroyCCC();
00776 #endif
00777 
00778     // DialogManager was deinitialized a while ago, but this bit needs to be done after
00779     // the pref system has gone. It merely frees some memory
00780     DialogManager::FreePaneInfoHash();
00781 
00782     ObjectRegistry::Delete();
00783 }
00784 
00785 
00786 /***********************************************************************************************
00787 
00788 >   BOOL Application::DeinitFilterManager()
00789 
00790     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00791     Created:    26/12/96
00792     Returns:    TRUE if OK, FALSE if failed
00793     Purpose:    Support function to deinitialize & destruct this Application's FilterManager
00794                                                                  
00795 ***********************************************************************************************/
00796 BOOL Application::DeinitFilterManager()
00797 {
00798     BOOL Success = FALSE;
00799 
00800     FilterManager* pFilterManager = GetFilterManager();
00801     if (pFilterManager != NULL)
00802     {
00803         Success = TheFilterManager->DeInit();
00804         // ...ignore any errors
00805         if (!Success)
00806         {
00807             TRACE( wxT("Deinit of FilterManager not successful") );
00808         }
00809         delete TheFilterManager;
00810         TheFilterManager = NULL;
00811         Success = TRUE;
00812     }
00813     else
00814     {
00815         TRACE( wxT("No Filter Manager") );
00816         Success = FALSE;
00817     }
00818 
00819     return Success;
00820 }
00821 
00822 
00823 /***********************************************************************************************
00824 
00825 >   BOOL Application::DeinitWizOps()
00826 
00827     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00828     Created:    26/12/96
00829 
00830     Purpose:    Support function to deinitialize & destruct this Application's WizOps
00831 
00832     Returns:    TRUE if OK, FALSE if failed
00833                                                                  
00834 ***********************************************************************************************/
00835 BOOL Application::DeinitWizOps()
00836 {
00837     BOOL Ok = TRUE;
00838 
00839     if (TheWizardOfOps != NULL)
00840     {
00841         delete TheWizardOfOps;
00842         TheWizardOfOps = NULL;
00843     }
00844     else
00845     {
00846         TRACE( wxT("No WizOps") );
00847         Ok = FALSE;
00848     }
00849 
00850     return Ok;
00851 }
00852 
00853 
00854 #ifdef AUTOMATION
00855 /***********************************************************************************************
00856 
00857 >   BOOL Application::DestroyCCC()
00858 
00859     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00860     Created:    26/12/96
00861     Returns:    TRUE if OK, FALSE if failed
00862     Purpose:    Support function to deinitialize & destruct this Application's 
00863                 ConcurrencyController.
00864                                                                  
00865 ***********************************************************************************************/
00866 BOOL Application::DestroyCCC()
00867 {
00868     BOOL Success = FALSE;
00869 
00870     if (TheConcurrencyController != NULL)
00871     {
00872         delete TheConcurrencyController;
00873         TheConcurrencyController = NULL;
00874         Success = TRUE;
00875     }
00876     else
00877     {
00878         TRACE( wxT("No ConcurrencyController") );
00879         Success = FALSE;
00880     }
00881 
00882     return Success;
00883 }
00884 #endif
00885 
00886 
00887 /***********************************************************************************************
00888 
00889 >   RenderRegionList* Application::GetRegionList()
00890 
00891     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
00892     Created:    9/6/95
00893     Purpose:    Gets a pointer to the Applications RenderRegion list.
00894 
00895 ***********************************************************************************************/
00896 
00897 RenderRegionList* Application::GetRegionList()
00898 {
00899     return &RenderList;
00900 }
00901 
00902 /***********************************************************************************************
00903 
00904 >   void Application::AddRenderRegion(RenderRegion *pRegion)
00905 
00906     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00907     Created:    27/5/93
00908     Inputs:     pRegion - pointer to the RenderRegion to add to the list.
00909     Returns:    Region - the render region to add.
00910     Purpose:    To add a RenderRegion object to the RenderList. Automatically sets a flag
00911                 to do immediate rendering if the render region is an immediate one.
00912     SeeAlso:    RenderRegion; List
00913 
00914 ***********************************************************************************************/
00915 
00916 void Application::AddRenderRegion(RenderRegion *pRegion)
00917 {
00918     // Is this render region an immediate one?
00919 
00920     View *pView = pRegion->GetRenderView();
00921     ENSURE(pView != NULL, "No View in AddRenderRegion!");
00922 
00923     if (!pView->GetForeBackMode())
00924     {
00925 //      TRACE(_T("ImmediateRender\n"));
00926         // Yes - set the flag to indicate we should do some immediate rendering on the
00927         // next redraw event.
00928         ImmediateRenderPending = TRUE;
00929     }
00930 
00931     // Add this render region to the list.
00932     RenderList.Merge(pRegion);
00933 }
00934 
00935 /***********************************************************************************************
00936 
00937 >   BOOL Application::DeleteRenderRegion(RenderRegion *Region)
00938 
00939     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00940     Created:    27/5/93
00941     Inputs:     Region - pointer to the RenderRegion to remove from the list.
00942     Returns:    TRUE if the region was in the list, FALSE otherwise.
00943     Purpose:    To remove a RenderRegion object from the RenderList.  If the
00944                 region in not in the list, no errors occur.  The RenderRegion object will
00945                 be destroyed (i.e. delete will be called on it).
00946     Errors:     -
00947     SeeAlso:    RenderRegion; List
00948 
00949 ***********************************************************************************************/
00950 
00951 BOOL Application::DeleteRenderRegion(RenderRegion *Region)
00952 {
00953 #ifdef RALPH
00954         // Wait until it's safe to enter
00955         CCamApp::EnterGDrawCriticalSection();
00956 #endif
00957     if (RenderList.FindPosition(Region) == NOT_IN_LIST)
00958     {
00959     #ifdef RALPH
00960         // Let another process have a go
00961         CCamApp::ExitGDrawCriticalSection();
00962     #endif
00963         ENSURE( FALSE, "Couldn't find Region in List" );
00964         return FALSE;
00965     }
00966     
00967     RenderList.Remove(Region);
00968     #ifdef RALPH
00969         // Let another process have a go
00970         CCamApp::ExitGDrawCriticalSection();
00971     #endif
00972     return TRUE;
00973 }
00974 
00975 
00976 /********************************************************************************************
00977 
00978 >   BOOL Application::ServiceRendering(BOOL bImmediate = FALSE)
00979 
00980     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00981     Created:    27/06/94
00982     Returns:    TRUE if more rendering needs to be done, FALSE if there are no more
00983                 regions left to render.
00984     Purpose:    Render some objects!  This function will either render any outstanding 
00985                 'immediate' render regions to completion, or render a background render
00986                 regions for one time-slice.
00987     SeeAlso:    RenderRegionList::ImmediateRender; RenderRegionList::BackgroundRender
00988 
00989 ********************************************************************************************/
00990 
00991 BOOL Application::ServiceRendering(BOOL bImmediate)
00992 { 
00993 #ifdef RALPH
00994 #ifdef _DEBUG
00995     if(::GetCurrentThreadId() == RalphDocument::GetImportingThreadID())
00996     {
00997         // If we get in here, it's extremely BAD !
00998         AfxDebugBreak();
00999     }
01000 #endif
01001 
01002     // Fixes splodgy text problems...
01003     RalphCriticalSection RCS;
01004 #endif
01005 
01006 #ifdef RALPH
01007         // Wait until it's safe to enter
01008         CCamApp::EnterGDrawCriticalSection();
01009 #endif
01010 
01011     // DMc - render the list of nodes to regenerate
01012     RegenerateNodesInList();
01013 
01014 //  TRACEUSER( "Gerry", _T("Service Rendering - Enter\n"));
01015     if (ImmediateRenderPending || bImmediate)
01016     {
01017         // Render all immediate render regions to completion, and then clear the
01018         // flag so we do some background rendering the next time around.
01019         RenderList.ImmediateRender(bImmediate);
01020         ImmediateRenderPending = FALSE;
01021 
01022     #ifdef RALPH
01023         // Let another process have a go
01024         CCamApp::ExitGDrawCriticalSection();
01025     #endif
01026 
01027         // Try background rendering next
01028 //      TRACEUSER( "Gerry", _T("Service Rendering - Exit - More\n"));
01029         return TRUE;
01030     }
01031     else
01032     {
01033         BOOL ok = RenderList.BackgroundRender();
01034     #ifdef RALPH
01035         // Let another process have a go
01036         CCamApp::ExitGDrawCriticalSection();
01037     #endif
01038 
01039 //      TRACEUSER( "Gerry", _T("Service Rendering - Exit - %s\n"), ok ? _T("More") : _T("Finished"));
01040         return ok;
01041     }
01042 
01043 //  TRACEUSER( "Gerry", _T("Service Rendering - Exit - More\n"));
01044     return TRUE;
01045 }
01046 
01047 
01048 /********************************************************************************************
01049 
01050 >   BOOL Application::IsBgRendering()
01051 
01052     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01053     Created:    10/5/95
01054     Returns:    TRUE if Background rendering is in progress.
01055     Purpose:    Find out if there is Background rendering in progress or not.
01056 
01057 ********************************************************************************************/
01058 
01059 BOOL Application::IsBgRendering()
01060 {
01061     return BgRendering;
01062 }
01063 
01064 
01065 
01066 /********************************************************************************************
01067 
01068 >   void Application::RegisterDocComponent(DocComponentClass *pClass)
01069 
01070     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01071     Created:    02/08/94
01072     Inputs:     pClass - pointer to the Document component class thatis to be added.
01073     Purpose:    Register a new Document Component class with the application.  This class
01074                 will be asked to add an instance to a document every time a new document
01075                 is created. 
01076     SeeAlso:    DocComponentClass; DocComponent
01077 
01078 ********************************************************************************************/
01079 
01080 void Application::RegisterDocComponent(DocComponentClass *pClass)
01081 {
01082     // Check for multiple registrations in debug build...
01083     #if _DEBUG
01084     DocComponentClass *pItem = (DocComponentClass *) DocComponentClasses->GetHead();
01085 
01086     while (pItem != NULL)
01087     {
01088         // Already registered?
01089         if (pItem->GetRuntimeClass() == pClass->GetRuntimeClass())
01090         {
01091             ENSURE(FALSE, "Document component registered more than once!");
01092             return;
01093         }
01094         // Try the next one
01095         pItem = (DocComponentClass *) DocComponentClasses->GetNext(pItem);
01096     }
01097     #endif
01098 
01099     // Simple - just add it to the list
01100     DocComponentClasses->AddTail(pClass);
01101 }
01102 
01103 
01104 /********************************************************************************************
01105 
01106 >   DocComponentClass *Application::EnumerateDocComponents(DocComponentClass *pContext)
01107 
01108     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01109     Created:    02/08/94
01110     Inputs:     pContext: NULL => Get the first document component
01111                       non-NULL => Get the next document component after the one pointed to
01112                                   by pContext.
01113     Returns:    Pointer to the required document component.
01114     Purpose:    Allow the caller to examine/use all the registered document components.
01115                 pContext should be NULL for the first call, which will return the first
01116                 registered document component.  After that, the returned pointer should
01117                 be passed back in to this function, which will return the next one, and
01118                 so on.
01119                 For example:
01120                 MonoOn
01121                     DocComponentClass *pDocComp = NULL;
01122                     do
01123                     {
01124                         pDocComp = Camelot.EnumerateDocComponents(pDocComp);
01125 
01126                         // Do something groovy with pDocComp...
01127                     }
01128                     while (pDocComp != NULL);
01129                 MonoOff
01130 
01131     SeeAlso:    Application::RegisterDocComponent;
01132                 DocComponent; 
01133                 DocComponentClass
01134 
01135 ********************************************************************************************/
01136 
01137 DocComponentClass *Application::EnumerateDocComponents(DocComponentClass *pContext)
01138 {
01139     if (pContext == NULL)
01140     {
01141         // Return the first item in the list...
01142         return (DocComponentClass *) (DocComponentClasses->GetHead());
01143     }
01144     else
01145     {
01146         // Return the next document component...
01147         return (DocComponentClass *) (DocComponentClasses->GetNext(pContext));
01148     }
01149 }
01150 
01151 
01152 /********************************************************************************************
01153 
01154 >   BOOL Application::ApplyDocComponents(Document *pDocument)
01155 
01156     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01157     Created:    02/08/94
01158     Inputs:     pDocument - the document to add the components to.
01159     Returns:    TRUE if all the components were added successfully;
01160                 FALSE if not.
01161     Purpose:    Given a document, apply all the currently registered document components
01162                 to it.  i.e., add a colour table, units information, etc.
01163     Errors:     Out of memory, or other errors depending on implementations of each
01164                 document component.
01165     SeeAlso:    DocComponent; 
01166                 DocComponentClass
01167 
01168 ********************************************************************************************/
01169 
01170 BOOL Application::ApplyDocComponents(BaseDocument *pDocument)
01171 {
01172     // Go through the registered components and add their virtual function to add an
01173     // instance of the class to the Document object...
01174     DocComponentClass *pItem = (DocComponentClass *) DocComponentClasses->GetHead();
01175 
01176     while (pItem != NULL)
01177     {
01178         if (!pItem->AddComponent(pDocument))
01179         {
01180             // Component could not be added - probably out of memory.
01181             return FALSE;
01182         }
01183         // Try the next one
01184         pItem = (DocComponentClass *) DocComponentClasses->GetNext(pItem);
01185     }
01186 
01187     // All the components were successfully added
01188     return TRUE;
01189 }
01190 
01191 /********************************************************************************************
01192 >   BOOL Application::OnKeyPress(KeyPress* pKeyPress)
01193 
01194     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com> (simplified by JustinF)
01195     Created:    26/8/94
01196     Inputs:     pKeyPress =Ptr to platform-indy key press object
01197     Returns:    TRUE  if the key press was processed, so do not pass on.
01198                 FALSE if not processed, so pass on to other interested parties
01199     Purpose:    This is where key presses are handled in Camelot. It does the following in this order -
01200 
01201                     1) Lets the current tool have a go
01202                     2) See if a temporary tool switch has occurred
01203                     3) Check for a hot-key combination
01204                     [ 4) Broadcast key press to all live ops - removed as it slows text typing by 20% ]
01205 
01206                 If at any of the stages the key is processed, this function exits immediately with TRUE,
01207                 i.e. it doesn't let the next stage try and deal with a key press that's been processed
01208                 
01209     Errors:     -
01210     SeeAlso:    KeyPress::TranslateMessage
01211 ********************************************************************************************/
01212 
01213 BOOL Application::OnKeyPress(KeyPress* pKeyPress)
01214 {
01215 #if !defined(EXCLUDE_FROM_RALPH)
01216 PORTNOTE("other","Removed XaraCMS usage")
01217     // First, pass the keypress to the Colour Editor.
01218     // This is used to stop keypresses while dragging in the editor, so must be done first
01219     if (ColourEditDlg::OnKeyPress(pKeyPress))
01220         return(TRUE);
01221 #endif
01222 
01223     // Pass this keypress on to selected DocView, if we have one, otherwise
01224     // pass on to tools, hotkeys etc.
01225     DocView* pDocView = DocView::GetSelected();
01226     return ( (pDocView != NULL && pDocView->HandleKeyPress(pKeyPress))
01227             || Tool::SwitchTool(pKeyPress)
01228             || HotKey::OnKeyPress(pKeyPress)
01229 // removed by Ed 27/4/95 - no-one uses this and it slows text typing by 20%!
01230 //          || (BROADCAST_TO_ALL(KeyMsg(KeyMsg::KEYPRESS, pKeyPress)) == EAT_MSG )
01231             );
01232 }
01233 
01234 
01235 
01236 /********************************************************************************************
01237 
01238 >   void Application::RegisterIdleProcessor(INT32 Priority, Operation* pOp)
01239 
01240     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01241     Created:    12/9/94
01242     Inputs:     Priority - either IDLEPRIORITY_HIGH or IDLEPRIORITY_LOW.
01243                 pOp - Pointer to an operation.
01244     Returns:    -
01245     Purpose:    If an operation wants to do processing on idle events then it must register
01246                 to receive them.  It registers by calling this function with a pointer to
01247                 itself.  On idle events the operations OnIdle function is called.
01248 
01249     Notes:      If the operator is already registered for idles of the given priority,
01250                 this call does nothing (i.e. registering twice will give you only one
01251                 entry in the list)
01252 
01253                 HIGH priority handlers are called on every Idle event. LOW priority
01254                 handlers will only be called on idle events if there were no high
01255                 priority handlers which returned TRUE from their OnIdle method. 
01256                 i.e. If any high priority handler is active, all low-priority idles
01257                 cease to occur.
01258