00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
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
00119 static void DisableSystem(CWindowID WindowID=NULL);
00120 static void EnableSystem();
00121 static inline bool IsDisabled() {return s_bIsDisabled;}
00122
00123
00124 static void DoAboutBox();
00125
00126
00127 static DialogManager *GetDlgManager();
00128
00129
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 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
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;
00177 static String_256 m_strResourceDirPath;
00178 static String_256 m_strResourceDirPathOverride;
00179
00180 static String_256 m_strMediaApplication;
00181
00182 wxTimer m_Timer;
00183
00184 wxSingleInstanceChecker * m_pSingleInstanceChecker;
00185 wxServerBase * m_pServer;
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;
00194
00195 static BOOL InInitOrDeInit;
00196
00197 DECLARE_EVENT_TABLE()
00198
00199 public:
00200
00201 static BOOL MainWndMaximized;
00202 static BOOL MainWndMinimized;
00203 static String_256 MainWndPosString;
00204
00205 static BOOL bFirstRun;
00206
00207 BOOL allowRegistryWrite;
00208
00209
00210 static void NeedMoreIdles() { ::wxWakeUpIdle(); }
00211 };
00212
00213 DECLARE_APP( CCamApp )
00214
00215 #endif
00216
00217
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
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
00243
00244
00245
00246
00247
00248
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
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
00271 m_pNext = i->second;
00272 i->second = this;
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;
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;
00308
00309 if (Empty)
00310 {
00311
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
00334 wxWindowDeletionWatcher * pWDW = i->second;
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;
00340 pWDW->m_HasBeenDeleted = TRUE;
00341 pWDW->RemoveFromList();
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
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_