1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxconfigtool.cpp
3 // Purpose: Generic application class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/laywin.h"
22 #include "wx/menuitem.h"
23 #include "wx/tooltip.h"
24 #include "wx/variant.h"
28 #include "wx/cshelp.h"
29 #include "wx/helphtml.h"
30 #include "wx/html/htmprint.h"
31 #include "wx/html/htmlwin.h"
33 #include "wx/filesys.h"
34 #include "wx/fs_mem.h"
35 #include "wx/fs_zip.h"
36 #include "wx/wfstream.h"
37 #include "wx/config.h"
38 #include "wxconfigtool.h"
39 #include "configtooldoc.h"
40 #include "configtoolview.h"
41 #include "mainframe.h"
46 BEGIN_EVENT_TABLE(ctApp
, wxApp
)
51 m_helpController
= NULL
;
52 m_helpControllerReference
= NULL
;
56 bool ctApp::OnInit(void)
60 wxLog::SetTimestamp(NULL
);
63 wxHelpProvider::Set(new wxSimpleHelpProvider
);
66 wxImage::AddHandler( new wxPNGHandler
);
70 wxImage::AddHandler( new wxJPEGHandler
);
74 wxImage::AddHandler( new wxGIFHandler
);
77 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
78 m_helpController
= new wxCHMHelpController
;
79 m_helpControllerReference
= new wxCHMHelpController
;
81 m_helpController
= new wxHtmlHelpController
;
82 m_helpControllerReference
= new wxHtmlHelpController
;
85 // Required for HTML help
86 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
87 wxFileSystem::AddHandler(new wxZipFSHandler
);
90 wxString currentDir
= wxGetCwd();
92 // Use argv to get current app directory
93 wxString
argv0(argv
[0]);
94 wxString
appVariableName(wxT("WXCONFIGTOOLDIR"));
95 m_appDir
= apFindAppPath(argv0
, currentDir
, appVariableName
);
98 // If the development version, go up a directory.
99 if ((m_appDir
.Right(5).CmpNoCase(_T("DEBUG")) == 0) ||
100 (m_appDir
.Right(11).CmpNoCase(_T("DEBUGSTABLE")) == 0) ||
101 (m_appDir
.Right(7).CmpNoCase(_T("RELEASE")) == 0) ||
102 (m_appDir
.Right(13).CmpNoCase(_T("RELEASESTABLE")) == 0) ||
103 (m_appDir
.Right(10).CmpNoCase(_T("RELEASEDEV")) == 0) ||
104 (m_appDir
.Right(8).CmpNoCase(_T("DEBUGDEV")) == 0)
106 m_appDir
= wxPathOnly(m_appDir
);
109 m_docManager
= new wxDocManager
;
110 m_docManager
->SetMaxDocsOpen(1);
112 //// Create a template relating documents to their views
113 (void) new wxDocTemplate(m_docManager
, wxGetApp().GetSettings().GetShortAppName(), wxT("*.wxs"), wxT(""), wxT("wxs"), wxT("Doc"), wxT("View"),
114 CLASSINFO(ctConfigToolDoc
), CLASSINFO(ctConfigToolView
));
120 wxString
helpFilePathReference(GetFullAppPath(_("wx")));
121 m_helpControllerReference
->Initialize(helpFilePathReference
);
123 wxString
helpFilePath(GetFullAppPath(_("configtool")));
124 m_helpController
->Initialize(helpFilePath
);
126 ctMainFrame
* frame
= new ctMainFrame(m_docManager
, NULL
, wxID_ANY
, wxGetApp().GetSettings().GetAppName(),
127 GetSettings().m_frameSize
.GetPosition(), GetSettings().m_frameSize
.GetSize(),
128 wxDEFAULT_FRAME_STYLE
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
131 switch (wxGetApp().GetSettings().m_frameStatus
)
133 case ctSHOW_STATUS_MAXIMIZED
:
135 frame
->Maximize(true);
138 case ctSHOW_STATUS_MINIMIZED
:
140 frame
->Iconize(true);
144 case ctSHOW_STATUS_NORMAL
:
150 // Load the file history. This has to be done AFTER the
151 // main frame has been created, so that the items
152 // will get appended to the file menu.
154 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
155 GetFileHistory().Load(config
);
160 // Concatenate strings since it could have spaces (and quotes)
163 for (i
= 1; i
< argc
; i
++)
167 arg
+= wxString(wxT(" "));
171 if (arg
.Last() == '"')
172 arg
= arg
.Mid(0, arg
.Len() - 1);
175 wxDocument
* doc
= m_docManager
->CreateDocument(arg
, wxDOC_SILENT
);
177 doc
->SetDocumentSaved(true);
181 if (GetSettings().m_loadLastDocument
)
183 // Load the file that was last loaded
184 wxDocument
* doc
= m_docManager
->CreateDocument(GetSettings().m_lastFilename
, wxDOC_SILENT
);
186 doc
->SetDocumentSaved(true);
190 GetTopWindow()->Show(true);
195 int ctApp::OnExit(void)
199 // Save the file history
201 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
202 GetFileHistory().Save(config
);
211 void ctApp::ClearHelpControllers()
213 delete m_helpController
;
214 m_helpController
= NULL
;
216 delete m_helpControllerReference
;
217 m_helpControllerReference
= NULL
;
221 // Prepend the current program directory to the name
222 wxString
ctApp::GetFullAppPath(const wxString
& filename
) const
224 wxString
path(m_appDir
);
225 if (path
.Last() != wxFILE_SEP_PATH
&& filename
[0] != wxFILE_SEP_PATH
)
226 path
+= wxFILE_SEP_PATH
;
233 bool ctApp::LoadConfig()
235 return m_settings
.LoadConfig();
239 bool ctApp::SaveConfig()
241 return m_settings
.SaveConfig();
244 bool ctApp::UsingTooltips()
246 return GetSettings().m_useToolTips
;
249 /// Returns the main frame
250 ctMainFrame
* ctApp::GetMainFrame()
252 return wxDynamicCast(wxTheApp
->GetTopWindow(), ctMainFrame
);