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
00099
00100
00101
00102
00103
00104 #include "camtypes.h"
00105
00106 #include "camdoc.h"
00107
00108 #include "camview.h"
00109 #include "camframe.h"
00110
00111 #include "kernel.h"
00112 #include "grndrgn.h"
00113 #include "oilmenus.h"
00114
00115 #if !defined(__WXMSW__)
00116 #include "gdraw.h"
00117 #endif
00118
00119 #include "cversion.h"
00120 #include "camelot.h"
00121 #include "camdoctp.h"
00122
00123 #include "keypress.h"
00124 #include "ccdc.h"
00125 #include "camprofile.h"
00126 #include "dlgevt.h"
00127 #include "cartprov.h"
00128 #include "ctrllist.h"
00129 #include "cartctl.h"
00130 #include "xmlutils.h"
00131 #include "camplatform.h"
00132 #include "filedlgs.h"
00133 #include "progress.h"
00134 #include "prdlgctl.h"
00135 #include "prncamvw.h"
00136 #include "gbrush.h"
00137 #include "selmedia.h"
00138 #include "filedlgs.h"
00139 #include "rendwnd.h"
00140
00141 #include "camprocess.h"
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 #define XARA_MENUGEN
00157
00158
00159 BOOL CCamApp::InInitOrDeInit = TRUE;
00160 IMPLEMENT_DYNAMIC_CLASS( wxWindowDeletionWatcher, wxObject);
00161 WindowToWindowDeletionWatcher * wxWindowDeletionWatcher::s_UndeletedWindowHash = NULL;
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 BOOL CCamApp::MainWndMaximized = FALSE;
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 BOOL CCamApp::MainWndMinimized = FALSE;
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 String_256 CCamApp::MainWndPosString;
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 BOOL CCamApp::bFirstRun = TRUE;
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 #define CAM_TIMER_ID 42
00224 #define CAM_TIMER_FREQUENCY 100
00225
00226
00227
00228 IMPLEMENT_APP( CCamApp )
00229 BEGIN_EVENT_TABLE( CCamApp, wxApp )
00230 EVT_IDLE( CCamApp::OnIdle )
00231
00232 END_EVENT_TABLE()
00233
00234 DialogManager CCamApp::m_DlgMgr;
00235 bool CCamApp::s_bIsDisabled = false;
00236 wxString CCamApp::m_strResourcePath;
00237 String_256 CCamApp::m_strResourceDirPath;
00238 String_256 CCamApp::m_strResourceDirPathOverride;
00239 String_256 CCamApp::m_strMediaApplication;
00240
00241
00242
00243 CCamApp::CCamApp()
00244 {
00245 }
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 int CCamApp::FilterEvent( wxEvent& event )
00267 {
00268 static long lLastTimeStamp = 0;
00269
00270 wxObject* pEventObject = event.GetEventObject();
00271
00272 if (( event.GetEventType() == wxEVT_DESTROY ) && pEventObject->IsKindOf(CLASSINFO(wxWindow)))
00273 {
00274
00275 wxWindowDeletionWatcher::RegisterWindowDeletion((wxWindow *)pEventObject);
00276 }
00277
00278 if (PrintMonitor::IsPrintingNow())
00279 {
00280
00281
00282 if (event.IsKindOf(CLASSINFO(wxPaintEvent)))
00283 {
00284 if (!pEventObject->IsKindOf(CLASSINFO(wxCamArtControl)))
00285 {
00286
00287 return false;
00288 }
00289 }
00290 }
00291
00292 if( event.GetEventType() == wxEVT_ACTIVATE )
00293 {
00294 TRACEUSER("luke", _T("CCamApp::FilterEvent activate to %s"), pEventObject->GetClassInfo()->GetClassName());
00295
00296 if( pEventObject->IsKindOf( CLASSINFO(wxAuiFloatingFrame) ) )
00297 {
00298 wxClassInfo* pClassInfo = pEventObject->GetClassInfo();
00299 while( NULL != pClassInfo )
00300 {
00301 TRACEUSER( "luke", _T("Class = %s"), (PCTSTR)pClassInfo->GetClassName() );
00302
00303 const wxChar* pszBaseClass = pClassInfo->GetBaseClassName1();
00304 pClassInfo = NULL == pszBaseClass ? NULL : wxClassInfo::FindClass( pszBaseClass );
00305 }
00306 TRACEUSER( "luke", _T("Parent = %x, %x"), ((wxWindow*)pEventObject)->GetParent(), m_pMainFrame );
00307 TRACEUSER( "luke", _T("Active = %x"), ((wxTopLevelWindow*)pEventObject)->IsActive() );
00308
00309 GiveActiveCanvasFocus();
00310 return 1;
00311 }
00312 }
00313
00314
00315
00316 if ( event.GetEventType() == wxEVT_SET_FOCUS )
00317 {
00318 TRACEUSER("luke", _T("CCamApp::FilterEvent focus to %s"), pEventObject->GetClassInfo()->GetClassName());
00319
00320
00321
00322
00323 }
00324
00325 if ( event.GetEventType() == wxEVT_KILL_FOCUS )
00326 {
00327 #if defined(_DEBUG)
00328 wxFocusEvent& FocusEvent = (wxFocusEvent&)event;
00329 TRACEUSER( "luke", _T("CCamApp::FilterEvent kill focus to %016x from 0x%016x"), FocusEvent.GetWindow(),
00330 FocusEvent.GetEventObject() );
00331 #endif
00332
00333
00334 wxSetCursor( *wxSTANDARD_CURSOR );
00335 }
00336
00337 if (( event.GetEventType() == wxEVT_CREATE )
00338 && pEventObject
00339 && (pEventObject->IsKindOf(CLASSINFO(wxTopLevelWindow)))
00340 && !(pEventObject->IsKindOf(CLASSINFO(wxAdvSplashScreen)))
00341 && !(pEventObject->IsKindOf(CLASSINFO(wxSplashScreen)))
00342 )
00343 {
00344
00345 CamResource::DoneInit(FALSE);
00346 }
00347
00348 #if defined(_DEBUG)
00349 if( event.GetEventType() == wxEVT_CHAR )
00350 {
00351 if (pEventObject)
00352 {
00353 TRACEUSER( "jlh92", _T("KeyEvent 4 %s CH\n"),
00354 ((wxWindow*)pEventObject)->GetClassInfo()->GetClassName() );
00355 }
00356 }
00357 #endif
00358
00359 if( event.GetEventType() == wxEVT_KEY_DOWN ||
00360 event.GetEventType() == wxEVT_KEY_UP )
00361 {
00362
00363
00364 if( lLastTimeStamp == event.GetTimestamp() )
00365 return -1;
00366 lLastTimeStamp = event.GetTimestamp();
00367
00368 TRACEUSER( "jlh92", _T("KeyEvent 4 %s %s\n"),
00369 ((wxWindow*)pEventObject)->GetClassInfo()->GetClassName(),
00370 event.GetEventType() == wxEVT_KEY_DOWN ? _T("KD") : _T("KU") );
00371
00372
00373
00374
00375 wxWindow* pScanObj = (wxWindow*)pEventObject;
00376 while( NULL != pScanObj )
00377 {
00378 wxClassInfo* pClassInfo = pScanObj->GetClassInfo();
00379 #if defined(DEBUG_KEYPRESS_SPEW)
00380 {
00381 wxClassInfo *pTmpInfo = pClassInfo;
00382 while( NULL != pTmpInfo )
00383 {
00384 TRACEUSER( "jlh92", _T("Class %s\n"), PCTSTR(pTmpInfo->GetClassName()) );
00385
00386 PCTSTR pszName = pTmpInfo->GetBaseClassName1();
00387 pTmpInfo = NULL == pszName ? NULL : wxClassInfo::FindClass( pszName );
00388 }
00389 TRACEUSER( "jlh92", _T("----------------------\n") );
00390 }
00391 #endif
00392 TRACEUSER("amb", _T("CCamApp::FilterEvent key for %s"), pClassInfo->GetClassName());
00393
00394 if( pClassInfo->IsKindOf( CLASSINFO(wxTextCtrl) ) ||
00395 pClassInfo->IsKindOf( CLASSINFO(wxComboBox) ) ||
00396 pClassInfo->IsKindOf( CLASSINFO(wxSliderCombo) ) ||
00397 pClassInfo->IsKindOf( CLASSINFO(wxOwnerDrawnComboBox) ) ||
00398 pClassInfo->IsKindOf( CLASSINFO(wxComboCtrl) )
00399 )
00400 {
00401 TRACEUSER("amb", _T("CCamApp::FilterEvent gets keys as special"));
00402 TRACEUSER( "jlh92", _T("Control gets keys") );
00403
00404 return -1;
00405 }
00406
00407 pScanObj = pScanObj->GetParent();
00408 }
00409
00410
00411
00412 wxWindow *pWnd = (wxWindow*)pEventObject;
00413 while( NULL != pWnd && !pWnd->IsKindOf( CLASSINFO(wxPanel) ) )
00414 {
00415
00416 if( pWnd->IsKindOf( CLASSINFO(wxDialog) ) )
00417 {
00418
00419 if( ((wxDialog*)pWnd)->IsModal() )
00420 {
00421 TRACEUSER( "jlh92", _T("Modal dialog\n") );
00422 TRACEUSER("amb", _T("CCamApp::FilterEvent gets keys as modal"));
00423 return -1;
00424 }
00425
00426
00427 break;
00428 }
00429
00430 pWnd = pWnd->GetParent();
00431 }
00432
00433 TRACEUSER("amb", _T("CCamApp::FilterEvent handle"));
00434 TRACEUSER( "jlh92", _T("Handled!\n") );
00435
00436
00437 wxWindowDeletionWatcher * wd = NULL;
00438 if (pEventObject->IsKindOf(CLASSINFO(wxWindow)))
00439 {
00440 wd = new wxWindowDeletionWatcher((wxWindow*)pEventObject);
00441 if (!wd)
00442 return -1;
00443 }
00444
00445
00446 if( HandleKeyPress( (wxKeyEvent&)event ) )
00447 {
00448 BOOL deleted = wd && wd->HasBeenDeleted();
00449 if (wd)
00450 delete wd;
00451 if (deleted)
00452 return 1;
00453
00454 else
00455 return -1;
00456 }
00457 if (wd)
00458 delete wd;
00459 }
00460
00461 return -1;
00462 }
00463
00464 static bool GiveFocusToFocusableOffspring( wxWindow* pWnd )
00465 {
00466 TRACEUSER( "jlh92", _T("GF2FO class %s\n"), pWnd->GetClassInfo()->GetClassName() );
00467
00468
00469
00470 if( pWnd->AcceptsFocus() )
00471 {
00472 TRACEUSER( "jlh92", _T("Focused!\n") );
00473 pWnd->SetFocus();
00474 return true;
00475 }
00476
00477
00478 wxWindowList& lstChild = pWnd->GetChildren();
00479 wxWindowListNode* pNode = lstChild.GetFirst();
00480 while( NULL != pNode )
00481 {
00482 if( GiveFocusToFocusableOffspring( pNode->GetData() ) )
00483 return true;
00484
00485 pNode = pNode->GetNext();
00486 }
00487
00488 return false;
00489 }
00490
00491
00492
00493
00494
00495
00496
00497 const wxString camIPC_START = _T("StartOther");
00498
00499 class CamIPCConnection : public wxConnection
00500 {
00501
00502 public:
00503 CamIPCConnection() : wxConnection(m_pBuffer, WXSIZEOF(m_pBuffer)) {}
00504
00505 virtual bool OnExecute (const wxString& WXUNUSED(topic),
00506 wxChar *data,
00507 int size,
00508 wxIPCFormat WXUNUSED(format))
00509 {
00510
00511 INT32 argc = 0;
00512
00513 INT32 i;
00514 for (i=0; i<size; i++)
00515 {
00516
00517 if (!data[i] && i && !data[i-1])
00518 break;
00519
00520 if (!data[i])
00521 argc++;
00522 }
00523
00524 wxChar ** argv = new wxChar*[argc];
00525
00526 wxChar* p = data;
00527 for (i=0; i<argc; i++)
00528 {
00529 argv[i] = camStrdup(p);
00530 p+=wxStrlen(argv[i])+1;
00531 }
00532
00533 BOOL result = wxGetApp().OnSecondInstance(argv, argc);
00534
00535
00536 for (i=0; i<argc; i++)
00537 {
00538 free(argv[i]);
00539 }
00540 delete [] argv;
00541
00542
00543 return result;
00544 }
00545
00546 private:
00547 wxChar m_pBuffer[4096];
00548
00549 };
00550
00551 class CamIPCServer : public wxServer
00552 {
00553 public:
00554 virtual wxConnectionBase *OnAcceptConnection (const wxString& topic)
00555 {
00556 if (topic != camIPC_START)
00557 return NULL;
00558 else
00559 return new CamIPCConnection;
00560 }
00561 };
00562
00563
00564 static const wxCmdLineEntryDesc cmdLineDesc[] =
00565 {
00566 #if defined(_DEBUG)
00567 { wxCMD_LINE_OPTION, _T("u"), _T("user"), _T("set username for debug tracing") },
00568 { wxCMD_LINE_SWITCH, _T("m"), _T("memorycheck"), _T("check memory") },
00569 { wxCMD_LINE_OPTION, _T("l"), _T("listdebug"), _T("list debug level") , wxCMD_LINE_VAL_NUMBER },
00570 #endif
00571 { wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("Display this help"), wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
00572 { wxCMD_LINE_SWITCH, _T("v"), _T("version"), _T("Display the version information") },
00573 { wxCMD_LINE_OPTION, _T("r"), _T("resource"), _T("resource directory") },
00574 { wxCMD_LINE_SWITCH, _T("x"), _T("xrccheckgen"), _T("generate xrc.check file") },
00575 { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"), wxCMD_LINE_VAL_STRING,
00576 wxCMD_LINE_PARAM_OPTIONAL|wxCMD_LINE_PARAM_MULTIPLE },
00577 { wxCMD_LINE_NONE }
00578 };
00579
00580 BOOL CCamApp::OnSecondInstance(wxChar** argv, INT32 argc)
00581 {
00582
00583
00584
00585 wxCmdLineParser parser(argc,argv);
00586 parser.SetDesc(cmdLineDesc);
00587 if (parser.Parse())
00588 {
00589 return FALSE;
00590 }
00591 if (parser.GetParamCount()>=1)
00592 {
00593 for ( UINT32 i=0 ; i<parser.GetParamCount() ; i++ )
00594 m_docManager->CreateDocument(parser.GetParam(i),wxDOC_SILENT);
00595 }
00596 m_pMainFrame->Raise();
00597 return TRUE;
00598 }
00599
00600 bool CCamApp::OnInit()
00601 {
00602 InInitOrDeInit = TRUE;
00603 ::wxHandleFatalExceptions(TRUE);
00604
00605
00606
00607
00608
00609 wxCmdLineParser parser(argc,argv);
00610 parser.SetDesc(cmdLineDesc);
00611 if (parser.Parse())
00612 {
00613 return FALSE;
00614 }
00615
00616 wxString ResourceDir = _T("");
00617 if (parser.Found(_T("r"), &ResourceDir))
00618 {
00619 if (!ResourceDir.IsEmpty())
00620 {
00621 CamResource::SetResourceFilePath(ResourceDir);
00622 }
00623
00624 if ( parser.Found( _T("x") ) )
00625 {
00626 CamResource::SetGenerateXRCCheck(TRUE);
00627 }
00628 }
00629
00630 if( parser.Found( _T("v") ) )
00631 {
00632 wxString strMessage;
00633
00634 #if defined(__WXMSW__)
00635 strMessage = wxString::Format( wxT("Xara Xtreme\nVersion: %s\nCDraw Version: %d.%03d\n"),
00636 g_pszAppVersion, HIWORD(GDraw_GetVersion()), LOWORD(GDraw_GetVersion()) );
00637 #else
00638 #if FALSE == wxUSE_UNICODE
00639 TCHAR* pszCDrawVer = GDraw_GetSvnVersion();
00640 #else
00641 TCHAR pszCDrawVer[32];
00642 camMbstowcs( pszCDrawVer, GDraw_GetSvnVersion(), 31 );
00643 #endif
00644 strMessage = wxString::Format( wxT("Xara Xtreme\nVersion: %s (%s)\nCDraw Version: %d.%03d (%s)\nBuild date: %s\n"),
00645 g_pszAppVersion, g_pszSvnVersion, HIWORD(GDraw_GetVersion()), LOWORD(GDraw_GetVersion()), pszCDrawVer, CAMELOT_BUILD_DATE );
00646 #endif
00647
00648 camPrintf( strMessage.c_str() );
00649
00650 return FALSE;
00651 }
00652
00653 #if defined(_DEBUG)
00654 if (parser.Found(_T("m"))) SimpleCCObject::CheckMemoryFlag=1;
00655
00656 long listlevel;
00657 if (parser.Found(_T("l"), &listlevel))
00658 {
00659 List::ListDebugLevel = listlevel;
00660 }
00661
00662
00663
00664 wxString Username = _T("");
00665
00666
00667 wxGetEnv(_T("LOGNAME"), &Username);
00668
00669
00670 parser.Found(_T("u"), &Username);
00671
00672 Error::SetUserName(Username);
00673
00674 if (Username==_T(""))
00675 {
00676 TRACEUSER("ALL", _T("No user specific trace output\n"));
00677 }
00678 else
00679 {
00680
00681 TRACEUSER("ALL",_T("Tracing output where user is %s\n"),(const TCHAR *)Username.c_str());
00682 }
00683
00684 TRACEUSER("ALL",_T("Memory debugging %d, List debugging %d\n"), SimpleCCObject::CheckMemoryFlag, List::ListDebugLevel);
00685
00686 #endif
00687
00688
00689
00690
00691
00692 wxString SIname = wxString(_T(".XARA-XTREME-WX-")) +GetAppName()+wxString::Format(_T("-%s"), wxGetUserId().c_str());
00693 wxFileName IPCfn(wxGetHomeDir(),SIname+_T(".ipc"));
00694 wxString IPCname = IPCfn.GetFullPath();
00695
00696 m_pSingleInstanceChecker = NULL;
00697 m_pServer = NULL;
00698
00699 #ifdef _DEBUG
00700 BOOL SingleInstanceCheck = FALSE;
00701 #else
00702 BOOL SingleInstanceCheck = TRUE;
00703 #endif
00704
00705 if (SingleInstanceCheck)
00706 {
00707
00708 m_pSingleInstanceChecker = new wxSingleInstanceChecker(SIname);
00709 if (!m_pSingleInstanceChecker)
00710 {
00711 ERROR2(FALSE, "Failed to create single instance checker");
00712 }
00713
00714
00715 if (m_pSingleInstanceChecker->IsAnotherRunning())
00716 {
00717 wxClient Client;
00718 wxConnectionBase * Connection = Client.MakeConnection(wxEmptyString, IPCname, camIPC_START);
00719
00720
00721 if (Connection)
00722 {
00723 INT32 len=1;
00724 INT32 i;
00725
00726 wxArrayString docs;
00727 INT32 doccount = parser.GetParamCount()+1;
00728
00729
00730 for ( i=0 ; i<doccount; i++ )
00731 {
00732 wxString docname;
00733 if (i)
00734 {
00735 docname = parser.GetParam(i-1);
00736 wxFileName fn(docname);
00737 fn.Normalize(wxPATH_NORM_ALL);
00738 docname=fn.GetFullPath();
00739 }
00740 else
00741 {
00742 docname=argv[0];
00743 }
00744 len+=docname.length()+1;
00745 docs.Add(docname);
00746 }
00747
00748 wxChar * Data = new wxChar[len];
00749 if (!Data)
00750 {
00751 ERROR2(FALSE, "Failed to create single instance checker data");
00752 }
00753
00754
00755 wxChar * p = Data;
00756 for (i = 0; i < doccount; i++)
00757 {
00758 wxStrcpy(p, docs[i]);
00759 p+=docs[i].length()+1;
00760 }
00761 *p = _T('\0');
00762
00763
00764 if (Connection->Execute (Data, len*sizeof(wxChar)))
00765 {
00766 delete [] Data;
00767 delete Connection;
00768
00769
00770 delete m_pSingleInstanceChecker;
00771 m_pSingleInstanceChecker = NULL;
00772
00773
00774 return FALSE;
00775 }
00776
00777
00778 delete [] Data;
00779 delete Connection;
00780 }
00781 }
00782 }
00783
00784
00785 ::wxRemoveFile(IPCname);
00786
00787
00788 wxImage::AddHandler( new wxCURHandler );
00789
00790
00791 wxImage::AddHandler( new wxPNGHandler );
00792
00793
00794
00795 BrInitError error;
00796 br_init( &error );
00797
00798
00799
00800
00801
00802
00803 MonotonicTime::Init();
00804
00805
00806 CamProfile::Init();
00807
00808 CamProfile::ActivateProfiling(TRUE);
00809
00810 CamProfile::AtBase(CAMPROFILE_OTHER);
00811
00812 TRACET(_T("CCamApp::OnInit first available time to trace"));
00813
00814
00815 if (!CamResource::Init()) return FALSE;
00816
00817 wxPlatformDependent::Init(CLASSINFO(CamPlatformDependent));
00818 if (!CamArtProvider::Init()) return FALSE;
00819
00820 if (!DialogEventHandler::Init()) return FALSE;
00821 if (!ControlList::Init()) return FALSE;
00822
00823 TRACET(_T("CCamApp::Calling Camelot.Init"));
00824
00825
00826 if( !Camelot.Init() )
00827 return false;
00828
00829
00830
00831 if (Camelot.DeclareSection(TEXT("Preferences"), 10))
00832 {
00833 Camelot.DeclarePref(NULL, TEXT("FirstRun"), &bFirstRun, 0, 1);
00834 }
00835
00836
00837 Camelot.DeclarePref( NULL, TEXT("ResourceDirOverride"), &m_strResourceDirPathOverride );
00838 m_strResourceDirPath = m_strResourceDirPathOverride;
00839 if( m_strResourceDirPath == _T("") || !wxDir::Exists( (PCTSTR)m_strResourceDirPath ) )
00840 {
00841 #if !defined(RESOURCE_DIR)
00842
00843 char * pszDataPath = br_find_data_dir( "/usr/share" );
00844 if (pszDataPath)
00845 {
00846 m_strResourceDirPath = wxString( pszDataPath, wxConvFile );
00847 free(pszDataPath);
00848 m_strResourceDirPath += _T("/xaralx");
00849 TRACEUSER( "luke", _T("Using resource directory \"%s\"\n"), PCTSTR(m_strResourceDirPath) );
00850 #if defined(_DEBUG)
00851 if( !wxDir::Exists( PCTSTR(m_strResourceDirPath) ) )
00852 {
00853
00854 m_strResourceDirPath = _T("/usr/share/xaralx");
00855 TRACEUSER( "luke", _T("Try = \"%s\"\n"), PCTSTR(m_strResourceDirPath) );
00856 }
00857 #endif
00858 }
00859 #else
00860
00861 m_strResourceDirPath = _T(""RESOURCE_DIR);
00862 #endif
00863 }
00864 TRACEUSER( "luke", _T("ResDir = %s\n"), PCTSTR(m_strResourceDirPath) );
00865
00866
00867 Camelot.DeclarePref( NULL, TEXT("MediaApplication"), &m_strMediaApplication );
00868
00869 TRACET(_T("CCamApp::Calling InitKernel"));
00870
00871 if( !InitKernel() )
00872 return false;
00873
00874 if( !Camelot.LateInit() )
00875 return false;
00876
00877 TRACET(_T("CCamApp::Calling GRenderRegion::Init"));
00878 if (!GRenderRegion::Init(true))
00879 return false;
00880
00881
00882 if (Camelot.DeclareSection(TEXT("Windows"), 10))
00883 {
00884 Camelot.DeclarePref(NULL, TEXT("MainWndMax"), &MainWndMaximized, 0, 1);
00885 Camelot.DeclarePref(NULL, TEXT("MainWndMin"), &MainWndMinimized, 0, 1);
00886 Camelot.DeclarePref(NULL, TEXT("MainWndPos"), &MainWndPosString);
00887 }
00888
00889 TRACET(_T("CCamApp::Making Doc Manager"));
00890
00891
00892 m_docManager = std::auto_ptr<wxDocManager>( new wxDocManager() );
00893
00894 wxDocTemplate *pDocTemplate;
00895 pDocTemplate = new CCamDocTemplate(
00896 m_docManager.get(), wxT("Xara"), wxT("*.xar;*.web"), wxT(""), wxT("xar"), wxT("Xara document"),
00897 wxT("Text View"),
00898 CLASSINFO(CCamDoc),
00899 CLASSINFO(CCamView) );
00900
00901
00902
00903
00904
00905
00906
00907 wxFileHistory* pFileHist = m_docManager->GetFileHistory();
00908 for( UINT32 ord = 0; ord < 9; ++ord )
00909 {
00910
00911 TCHAR pszTag[8];
00912 camSprintf( pszTag, _T("File%d"), ord );
00913
00914 String_256 strFileName;
00915 Camelot.GetPrefDirect( _T("Recent File list"), pszTag, &strFileName );
00916
00917 if( strFileName != _T("") )
00918 pFileHist->AddFileToHistory( PCTSTR(strFileName) );
00919 }
00920
00921 if (bFirstRun)
00922 {
00923
00924 wxString strConfigPath( (TCHAR*)m_strResourceDirPath );
00925 strConfigPath += _T("/Examples");
00926
00927 #if defined(_DEBUG)
00928
00929 if (!wxDir::Exists(strConfigPath))
00930 strConfigPath = _T("/usr/share/xaralx/Examples");
00931 #endif
00932
00933 if (wxDir::Exists(strConfigPath))
00934 BaseFileDialog::DefaultOpenFilePath = strConfigPath;
00935 }
00936
00937
00938
00939
00940
00941 wxIdleEvent::SetMode(wxIDLE_PROCESS_SPECIFIED);
00942
00943
00944
00945
00946 wxSize ScreenSize = ::wxGetDisplaySize();
00947 wxRect WndRect;
00948 wxSize OldScreenSize;
00949 if ((camSscanf(MainWndPosString, _T("%d %d %d %d %d %d"),
00950 &WndRect.x, &WndRect.y, &WndRect.width, &WndRect.height, &OldScreenSize.x, &OldScreenSize.y) == 6) &&
00951 (WndRect.width > 0) && (WndRect.height > 0))
00952 {
00953
00954 if (OldScreenSize.x != ScreenSize.x)
00955 {
00956
00957 WndRect.x = MulDiv(WndRect.x, ScreenSize.x, OldScreenSize.x);
00958 WndRect.width = MulDiv(WndRect.width, ScreenSize.x, OldScreenSize.x);
00959 }
00960 if (OldScreenSize.y != ScreenSize.y)
00961 {
00962 WndRect.y = MulDiv(WndRect.y, ScreenSize.y, OldScreenSize.y);
00963 WndRect.height = MulDiv(WndRect.height, ScreenSize.y, OldScreenSize.y);
00964 }
00965 }
00966 else
00967 {
00968
00969
00970 WndRect.x = ScreenSize.x / 20;
00971 WndRect.width = ScreenSize.x - WndRect.x * 2;
00972 WndRect.y = ScreenSize.y / 10;
00973 WndRect.height = ScreenSize.y - WndRect.y * 2;
00974 }
00975
00976 TRACET(_T("CCamApp::Making Frame Window"));
00977 m_pMainFrame = new CCamFrame( m_docManager.get(), (wxFrame *)NULL, wxT("Xara Xtreme"),
00978 WndRect.GetPosition(), WndRect.GetSize(), wxDEFAULT_FRAME_STYLE);
00979
00980 m_pMainFrame->Show(FALSE);
00981
00982 #if !defined(XARA_MENUGEN)
00983 TRACET(_T("CCamApp::Making Menu structure"));
00984
00985
00986
00987
00988
00989 wxMenu* pFileMenu = new wxMenu;
00990
00991 pFileMenu->Append( wxID_NEW, wxT("&New...") );
00992 pFileMenu->Append( wxID_OPEN, wxT("&Open...") );
00993
00994 #if defined(FILELIST)
00995 wxMenu* pRecentFilesMenu = new wxMenu;
00996 m_docManager->FileHistoryUseMenu(pRecentFilesMenu);
00997 m_docManager->FileHistoryAddFilesToMenu(pRecentFilesMenu);
00998
00999 pFileMenu->AppendSeparator();
01000 pFileMenu->Append( -1, wxT("&Recent files"),pRecentFilesMenu );
01001 #endif //defiend(FILELIST)
01002
01003 pFileMenu->AppendSeparator();
01004 pFileMenu->Append( wxID_EXIT, wxT("E&xit") );
01005
01006
01007 wxMenu *pHelpMenu = new wxMenu;
01008 pHelpMenu->Append( _R(DOCVIEW_ABOUT), wxT("&About...") );
01009
01010
01011 wxMenuBar *pMenuBar = new wxMenuBar;
01012 pMenuBar->Append( pFileMenu, wxT("File") );
01013 pMenuBar->Append( pHelpMenu, wxT("Help") );
01014
01015 #ifdef __WXMAC__
01016 wxMenuBar::MacSetCommonMenuBar( pMenuBar );
01017 #endif //def __WXMAC__
01018
01019
01020 m_pMainFrame->SetMenuBar( pMenuBar );
01021
01022 #else
01023
01024 #ifdef __WXMAC__
01025 wxMenuBar::MacSetCommonMenuBar( WinMDIMenu );
01026 #endif //def __WXMAC__
01027
01028
01029 m_pMainFrame->SetMenuBar( WinMDIMenu );
01030 WinMDIMenu->ClearAccelTable();
01031
01032 #endif
01033
01034
01035
01036
01037
01038
01039 TRACET(_T("CCamApp::Init Setting mainframe as top window"));
01040
01041 m_pMainFrame->CreateToolbars();
01042 m_pMainFrame->UpdateFrameManager();
01043
01044
01045
01046 if (MainWndMaximized)
01047 {
01048 m_pMainFrame->Maximize();
01049 }
01050 if (MainWndMinimized)
01051 {
01052 m_pMainFrame->Iconize();
01053 }
01054 SetTopWindow( m_pMainFrame );
01055 ::wxYield();
01056 m_pMainFrame->Show( true );
01057 ::wxYield();
01058 wxPlatformDependent::Get()->FixUpdate(m_pMainFrame);
01059 ::wxYield();
01060
01061 #ifndef EXCLUDE_FROM_XARALX
01062 m_pMainFrame->CacheNormalPlaceMode();
01063 m_pMainFrame->CheckFullScreenMode();
01064
01065
01066
01067 if (AfxOleGetUserCtrl())
01068 {
01069 if (m_nCmdShow == SW_SHOWMINIMIZED || m_nCmdShow == SW_SHOWMINNOACTIVE)
01070 {
01071 pMainFrame->ShowWindow(SW_SHOWMINNOACTIVE);
01072 }
01073 else
01074 {
01075 if (m_nCmdShow == SW_SHOWMAXIMIZED)
01076 m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
01077 else
01078 pMainFrame->ShowWindow(SW_SHOWNOACTIVATE);
01079
01080
01081
01082 pSplashbox->SetActiveWindow();
01083 }
01084 }
01085 #endif
01086
01087 Tool::SelectFirstTool();
01088
01089
01090 TRACET(_T("CCamApp::Init Loading docs (if any) from command line"));
01091
01092 if( 0 == parser.GetParamCount() )
01093 m_docManager->CreateDocument( _T(""), wxDOC_NEW );
01094 else
01095 {
01096 for ( UINT32 i=0 ; i<parser.GetParamCount() ; i++ )
01097 m_docManager->CreateDocument(parser.GetParam(i),wxDOC_SILENT);
01098 }
01099
01100
01101 CamResource::DoneInit();
01102
01103 CXMLUtils::Initialise();
01104
01105 if (SingleInstanceCheck)
01106 {
01107
01108 m_pServer = new CamIPCServer();
01109 if (!m_pServer)
01110 {
01111 delete (m_pSingleInstanceChecker);
01112 m_pSingleInstanceChecker = NULL;
01113 ERROR2(FALSE, "Failed to create IPC server");
01114 }
01115
01116
01117 if (!(m_pServer->Create(IPCname)))
01118 {
01119 delete m_pServer;
01120 m_pServer = NULL;
01121
01122 delete (m_pSingleInstanceChecker);
01123 m_pSingleInstanceChecker = NULL;
01124 ERROR2(FALSE, "Failed to init IPC server");
01125 }
01126 }
01127
01128
01129
01130 GiveFocusToFocusableOffspring( m_pMainFrame );
01131
01132
01133
01134
01135
01136 InInitOrDeInit = FALSE;
01137
01138 return true;
01139 }
01140
01141
01142
01143
01144
01145
01146 INT32 CCamApp::OnExit( void )
01147 {
01148 InInitOrDeInit = TRUE;
01149
01150 Camelot.ShuttingDown(TRUE);
01151
01152
01153 wxFileHistory* pFileHist = m_docManager->GetFileHistory();
01154 UINT32 cRecent = UINT32(pFileHist->GetCount());
01155 for( UINT32 ord = 0; ord < 9; ++ord )
01156 {
01157
01158 TCHAR pszTag[8];
01159 camSprintf( pszTag, _T("File%d"), ord );
01160
01161 if( ord < cRecent )
01162 {
01163 wxString strFileName( pFileHist->GetHistoryFile( ord ) );
01164 Camelot.SetPrefDirect( _T("Recent File list"), pszTag, PCTSTR(strFileName), TRUE );
01165 }
01166 else
01167 Camelot.SetPrefDirect( _T("Recent File list"), pszTag, _T(""), TRUE );
01168 }
01169
01170
01171 if (m_pServer)
01172 {
01173 delete m_pServer;
01174 m_pServer = NULL;
01175 }
01176
01177
01178 if (m_pSingleInstanceChecker)
01179 {
01180 delete m_pSingleInstanceChecker;
01181 m_pSingleInstanceChecker = NULL;
01182 }
01183
01184
01185
01186
01187 #if defined(FILELIST)
01188 {
01189 m_docManager->FileHistorySave(Preferences::GetOilPrefs());
01190 }
01191 #endif
01192 m_docManager = std::auto_ptr<wxDocManager>( NULL );
01193
01194 bFirstRun = FALSE;
01195
01196
01197
01198 CXMLUtils::DeInitialise();
01199
01200 DeinitKernel();
01201
01202 #if CUSTOM_INONE == 2
01203 DLLControlClass::DeinitAllControls();
01204 #endif
01205
01206 GRenderRegion::DeInit();
01207
01208 PORTNOTE("other","Removed GDI+, filelist and profilename support")
01209 #ifndef EXCLUDE_FROM_XARALX
01210 Gdiplus::GdiplusShutdown(gdiplusToken);
01211
01212
01213 if (m_pszProfileName != NULL)
01214 {
01215 free((void *) m_pszProfileName);
01216 m_pszProfileName = NULL;
01217 }
01218 #endif
01219
01220 ControlList::DeInit();
01221 DialogEventHandler::DeInit();
01222
01223 CamArtProvider::DeInit();
01224 wxPlatformDependent::DeInit();
01225
01226 CamResource::DeInit();
01227
01228
01229 CamProfile::ActivateProfiling(FALSE);
01230
01231 #if DUMP_MEM_AT_END
01232 MemoryState.DumpAllObjectsSince();
01233 #endif
01234
01235
01236 #ifdef _DEBUG
01237 SimpleCCObject::MemoryDump();
01238 DumpCCMallocTrace();
01239 #endif
01240
01241 PORTNOTE("other","Removed 3D, Extras and UserHelp support")
01242 #ifndef EXCLUDE_FROM_XARALX
01243
01244 if (Is3dWanted())
01245 pCtl3dUnregister(AfxGetInstanceHandle());
01246
01247 OILModule::DeinitExtras();
01248
01249
01250 DeInitUserHelp();
01251 #endif
01252
01253
01254 wxWindowDeletionWatcher::DeInit();
01255
01256 ::wxHandleFatalExceptions(FALSE);
01257 return wxApp::OnExit();
01258 }
01259
01260
01261 #ifndef WEBSTER
01262 void CCamApp::OnFilePrintSetup()
01263 {
01264 #ifndef STANDALONE
01265 Document *pDoc = Document::GetSelected();
01266 DocView *pDocView = DocView::GetSelected();
01267
01268 if (pDoc && pDocView && pDocView->GetConnectionToOilView())
01269 {
01270
01271
01272 CCPrintDialog::InformResetToDefaultPrinter(FALSE);
01273
01274
01275
01276
01277
01278
01279 CCPrintInfo printinfo(pDoc, pDocView->GetConnectionToOilView());
01280 printinfo.OnPreparePrinting(TRUE);
01281 }
01282
01283 #endif
01284 }
01285 #endif
01286
01287 void CCamApp::OnAppExit()
01288 {
01289 PORTNOTE("other","Removed multi-instance flag stuff")
01290 #ifndef EXCLUDE_FROM_XARALX
01291
01292
01293
01294 HWND mainWindow = m_pMainWnd->m_hWnd;
01295
01296 if (mainWindow)
01297 {
01298 BOOL* ret = (BOOL*) RemoveProp (m_pMainWnd->m_hWnd, "Xara X sfs");
01299
01300 if (ret) delete (ret);
01301 }
01302 #endi