camelot.h

Go to the documentation of this file.
00001 // $Id: camelot.h 1714 2006-08-23 14:52:52Z luke $
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 #if !defined(_CAMELOT_H_)
00099 #define _CAMELOT_H_
00100 
00101 #if !defined(EXCLUDE_FROM_XARLIB)
00102 
00103 #include "dlgmgr.h"     
00104 
00105 class CCamFrame;
00106 
00107 class CCamApp : public wxApp
00108 {
00109 public:
00110     CCamApp();
00111 
00112     bool OnInit();
00113     INT32 OnExit();
00114     void OnAppExit();
00115 
00116     wxMDIChildFrame *CreateChildFrame( wxDocument *doc, wxView *view );
00117 
00118     // Functions required to enable/disable the systems functionality.   
00119     static void DisableSystem(CWindowID WindowID=NULL); 
00120     static void EnableSystem();
00121     static inline bool IsDisabled() {return s_bIsDisabled;}
00122 
00123     // Display our about box             
00124     static void DoAboutBox();
00125     
00126     // Used to access the dialog manager             
00127     static DialogManager *GetDlgManager();
00128 
00129     // Access the DocManager for templates
00130     wxDocManager *GetDocumentManager() const
00131     {
00132         return m_docManager.get();
00133     }
00134     
00135     bool OnRecentFile( INT32 RecentFileNumber );
00136     bool GetRecentFileText( INT32 Index, String_256* pszText );
00137 
00138     void OnIdle     ( wxIdleEvent  &event );
00139     void OnTimer    ( wxTimerEvent &event );
00140 
00141     bool HandleKeyPress( wxKeyEvent &event );
00142 
00143     void OnHelpIndex();
00144 
00145     void GiveActiveCanvasFocus();
00146     
00147     int /*TYPENOTE: Correct*/ FilterEvent( wxEvent& event );
00148 
00149     void OnFatalException();
00150 
00151     void OnFileOpen();
00152 
00153     void OnFilePrintSetup();
00154 
00155     static BOOL LaunchWebBrowser(const wxString& strUrl);
00156 
00157     static bool LaunchMediaApp( const wxString& strUrl );
00158     static bool SelectMediaApp();
00159     
00160     // Get the path to the root of the resource directory structure
00161     static StringBase& GetResourceDirectory();
00162 
00163 private:
00164     INT32 RunFalseMainLoop();
00165 
00166     wxDocument* OpenDocumentFile( PCTSTR lpcszFileName );
00167     void AddToRecentFileList( LPCTSTR pPathName );
00168     BOOL MakeDocumentNative(wxDocument* pDoc, PathName* Path);
00169 
00170 protected:
00171     std::auto_ptr<wxDocManager> m_docManager;
00172     CCamFrame              *m_pMainFrame;
00173 
00174     static bool         s_bIsDisabled;
00175 
00176     static wxString     m_strResourcePath;      // The usually bound in resources
00177     static String_256   m_strResourceDirPath;   // External resources (i.e. help files)
00178     static String_256   m_strResourceDirPathOverride;   // Version in preference file
00179 
00180     static String_256   m_strMediaApplication;  // The media replay application the user chose
00181 
00182     wxTimer             m_Timer;
00183 
00184     wxSingleInstanceChecker * m_pSingleInstanceChecker;
00185     wxServerBase * m_pServer; // IPC server
00186 
00187 public:
00188     BOOL OnSecondInstance(wxChar** argv, INT32 argc = 0);
00189 
00190 private:
00191     static BOOL LaunchBrowserApp(const wxString& strAppName, wxString strCommand);
00192 
00193     static DialogManager m_DlgMgr;      // The dialog manager handles all oily dialog functions
00194 
00195     static BOOL InInitOrDeInit;
00196 
00197     DECLARE_EVENT_TABLE()
00198 
00199 public:
00200     // Window
00201     static BOOL MainWndMaximized;                   // user maximized preference
00202     static BOOL MainWndMinimized;                   // user maximized preference
00203     static String_256 MainWndPosString;             // user window position
00204 
00205     static BOOL bFirstRun;                          // TRUE if this is the first time the app has been run
00206                                                     // (first time with this set of preferences)
00207     BOOL allowRegistryWrite;                        // if a copy of camelot is open, and we try do load another one,
00208                                                     // and exit (we prevent this), then we don't wan't to write to
00209                                                     // the registry !!!!
00210     static void NeedMoreIdles() { ::wxWakeUpIdle(); }
00211 };
00212 
00213 DECLARE_APP( CCamApp )
00214 
00215 #endif
00216 
00217 // Used to determine target platform at runtime.
00218 #if defined(__WXMSW__)
00219 extern BOOL WinArray[];
00220 enum Winver { Winver32s=0, Winver32c=1 };
00221 inline BOOL IsWin32s()  {   return WinArray[Winver32s];     }
00222 inline BOOL IsWin32c()  {   return WinArray[Winver32c];     }
00223 inline BOOL IsWin32NT() {   return !WinArray[Winver32s];    }
00224 
00225 inline BOOL IsWindows95() { return IsWin32s() && IsWin32c();        }
00226 inline BOOL IsWindows31() { return IsWin32s() && !IsWin32c();       }
00227 inline BOOL IsWindowsNT() { return !IsWindows95() && !IsWindows31(); }
00228 
00229 // Matt 16/01/2001 - Added so that we can detect NT5/Win2000
00230 inline BOOL IsWindows2000()
00231 {
00232     DWORD dwVersion = GetVersion();
00233     return ((dwVersion < 0x80000000) && ((DWORD)(LOBYTE(LOWORD(dwVersion))) == 5));
00234 }
00235 
00236 #endif
00237 
00238 
00239 
00240 /*******************************************************************************************
00241 
00242 >   class wxWindowDeletionWatcher : public wxObject
00243 
00244     Author:     Alex_Bligh <alex@alex.org.uk>
00245     Created:    02/07/2006
00246     Purpose:    A derived event to watch for the deletion of windows
00247     Notes:      In the OIL
00248     See Also:   
00249 
00250 ********************************************************************************************/
00251 
00252 class wxWindowDeletionWatcher;
00253 WX_DECLARE_HASH_MAP( wxWindow *, wxWindowDeletionWatcher *, wxPointerHash, wxPointerEqual, WindowToWindowDeletionWatcher );
00254 
00255 class wxWindowDeletionWatcher : public wxObject
00256 {
00257 public:
00258     wxWindowDeletionWatcher(wxWindow * pWatchedWindow = NULL) : m_HasBeenDeleted(FALSE), m_pWatchedWindow(pWatchedWindow), m_pNext(NULL), m_pPrev(NULL)
00259     {
00260         WindowToWindowDeletionWatcher::iterator i = GetHashEntry(m_pWatchedWindow);
00261 
00262         // If there is no list, create a new hash entry, and we are done
00263         if (i == s_UndeletedWindowHash->end() || !(i->second))
00264         {
00265             ERROR3IF(i != s_UndeletedWindowHash->end(), "wxWindowDeletionWatcher list non-empty but has NULL pointer");
00266             (*s_UndeletedWindowHash)[m_pWatchedWindow]=this;
00267         }
00268         else
00269         {
00270             // we are going to stick it on the front of the list
00271             m_pNext = i->second; // save the current list (may be NULL).
00272             i->second = this; // stick us on the list
00273 
00274             m_pPrev = NULL;
00275             m_pNext->m_pPrev=this;
00276         }
00277         if (m_pWatchedWindow->IsBeingDeleted())
00278             RegisterWindowDeletion(m_pWatchedWindow);
00279     }
00280 
00281     ~wxWindowDeletionWatcher()
00282     {
00283         RemoveFromList();
00284     }
00285 
00286     void RemoveFromList()
00287     {
00288         if (m_HasBeenDeleted)
00289         {
00290             ERROR3IF(m_pNext || m_pPrev, "a deleted window appears to still be on the wxWindowDeletionWatcher list");
00291             return; // it's not on a list anyway
00292         }
00293 
00294         BOOL Empty = TRUE;
00295         if (m_pNext)
00296         {
00297             ERROR3IF(m_pNext->m_pPrev != this, "bad wxWindowDeletionWatcher next pointer");
00298             m_pNext->m_pPrev = m_pPrev;
00299             Empty = FALSE;
00300         }
00301         if (m_pPrev)
00302         {
00303             ERROR3IF(m_pPrev->m_pNext != this, "bad wxWindowDeletionWatcher prev pointer");
00304             m_pPrev->m_pNext = m_pNext;
00305             Empty = FALSE;
00306         }
00307         m_pPrev = m_pNext = NULL; // disconnect
00308 
00309         if (Empty)
00310         {
00311             // Delete the hash table entry
00312             WindowToWindowDeletionWatcher::iterator i = GetHashEntry(m_pWatchedWindow);
00313             if (i->second != this)
00314             {
00315                 ERROR3("wxWindowWatcher list appeared to be newly emptied but I wasn't the first item on it");
00316             }
00317             if (i != s_UndeletedWindowHash->end())
00318                 s_UndeletedWindowHash->erase(i);
00319             else
00320             {
00321                 ERROR3("Can't find wxWindowDeletionWatcher list");
00322             }
00323         }
00324     }
00325 
00326     BOOL HasBeenDeleted() const {return m_HasBeenDeleted;}
00327 
00328     static void RegisterWindowDeletion(wxWindow * pWindow)
00329     {
00330         WindowToWindowDeletionWatcher::iterator i = GetHashEntry(pWindow);
00331         if (i != s_UndeletedWindowHash->end())
00332         {
00333             // OK, there's an entry there
00334             wxWindowDeletionWatcher * pWDW = i->second; // as "i" may become invalid
00335             ERROR3IF(!pWDW, "Empty list in wxWindowDeletionWatcher::RegisterWindowDeletion");
00336             while (pWDW)
00337             {
00338                 ERROR3IF(pWDW->m_pWatchedWindow != pWindow, "Window on the wrong list in wxWindowDeletionWatcher::RegisterWindowDeletion");
00339                 wxWindowDeletionWatcher * next = pWDW->m_pNext; // as removing from the list erases the next pointer
00340                 pWDW->m_HasBeenDeleted = TRUE;
00341                 pWDW->RemoveFromList(); // note we don't delete the WDW object
00342                 pWDW = next;            
00343             }
00344         }
00345     }
00346 
00347     static void DeInit()
00348     {
00349         if (s_UndeletedWindowHash)
00350         {
00351             ERROR3IF(!s_UndeletedWindowHash->empty(), "wxWindowDeletionWatcher::DeInit() found hash of watched windows was non-empty; someone leaked a wxWindowDeletionWatcher");
00352             s_UndeletedWindowHash->clear();
00353             delete s_UndeletedWindowHash;
00354             s_UndeletedWindowHash = NULL;
00355         }
00356     }
00357 
00358 private:
00359     static WindowToWindowDeletionWatcher::iterator GetHashEntry(wxWindow * pWindow) {EnsureHash(); return s_UndeletedWindowHash->find(pWindow);}
00360 
00361     static BOOL EnsureHash() {if (!s_UndeletedWindowHash) s_UndeletedWindowHash = new WindowToWindowDeletionWatcher; return s_UndeletedWindowHash!=NULL;}
00362 
00363     BOOL m_HasBeenDeleted;
00364     wxWindow * m_pWatchedWindow;
00365 
00366     // whilst the windows remain undeleted, they sit on this list
00367     wxWindowDeletionWatcher * m_pNext;
00368     wxWindowDeletionWatcher * m_pPrev;
00369 
00370     static WindowToWindowDeletionWatcher * s_UndeletedWindowHash;
00371 
00372     DECLARE_DYNAMIC_CLASS(wxWindowDeletionWatcher);
00373 };
00374 
00375 #endif //_CAMELOT_H_

Generated on Sat Nov 10 03:48:08 2007 for Camelot by  doxygen 1.4.4