1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxconfigtool.cpp
3 // Purpose: Generic application class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "wxconfigtool.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/laywin.h"
26 #include "wx/menuitem.h"
27 #include "wx/tooltip.h"
28 #include "wx/variant.h"
32 #include "wx/cshelp.h"
33 #include "wx/helphtml.h"
34 #include "wx/html/htmprint.h"
35 #include "wx/html/htmlwin.h"
37 #include "wx/filesys.h"
38 #include "wx/fs_mem.h"
39 #include "wx/fs_zip.h"
40 #include "wx/wfstream.h"
41 #include "wx/config.h"
42 #include "wxconfigtool.h"
43 #include "configtooldoc.h"
44 #include "configtoolview.h"
45 #include "mainframe.h"
50 BEGIN_EVENT_TABLE(ctApp
, wxApp
)
55 m_helpController
= NULL
;
56 m_helpControllerReference
= NULL
;
64 bool ctApp::OnInit(void)
68 wxLog::SetTimestamp(NULL
);
71 wxHelpProvider::Set(new wxSimpleHelpProvider
);
74 wxImage::AddHandler( new wxPNGHandler
);
78 wxImage::AddHandler( new wxJPEGHandler
);
82 wxImage::AddHandler( new wxGIFHandler
);
85 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
86 m_helpController
= new wxCHMHelpController
;
87 m_helpControllerReference
= new wxCHMHelpController
;
89 m_helpController
= new wxHtmlHelpController
;
90 m_helpControllerReference
= new wxHtmlHelpController
;
93 // Required for HTML help
94 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
95 wxFileSystem::AddHandler(new wxZipFSHandler
);
98 wxString currentDir
= wxGetCwd();
100 // Use argv to get current app directory
101 wxString
argv0(argv
[0]);
102 wxString
appVariableName(wxT("WXCONFIGTOOLDIR"));
103 m_appDir
= apFindAppPath(argv0
, currentDir
, appVariableName
);
106 // If the development version, go up a directory.
107 if ((m_appDir
.Right(5).CmpNoCase(_T("DEBUG")) == 0) ||
108 (m_appDir
.Right(11).CmpNoCase(_T("DEBUGSTABLE")) == 0) ||
109 (m_appDir
.Right(7).CmpNoCase(_T("RELEASE")) == 0) ||
110 (m_appDir
.Right(13).CmpNoCase(_T("RELEASESTABLE")) == 0) ||
111 (m_appDir
.Right(10).CmpNoCase(_T("RELEASEDEV")) == 0) ||
112 (m_appDir
.Right(8).CmpNoCase(_T("DEBUGDEV")) == 0)
114 m_appDir
= wxPathOnly(m_appDir
);
117 m_docManager
= new wxDocManager
;
118 m_docManager
->SetMaxDocsOpen(1);
120 //// Create a template relating documents to their views
121 (void) new wxDocTemplate(m_docManager
, wxGetApp().GetSettings().GetShortAppName(), wxT("*.wxs"), wxT(""), wxT("wxs"), wxT("Doc"), wxT("View"),
122 CLASSINFO(ctConfigToolDoc
), CLASSINFO(ctConfigToolView
));
128 wxString
helpFilePathReference(GetFullAppPath(_("wx")));
129 m_helpControllerReference
->Initialize(helpFilePathReference
);
131 wxString
helpFilePath(GetFullAppPath(_("configtool")));
132 m_helpController
->Initialize(helpFilePath
);
134 ctMainFrame
* frame
= new ctMainFrame(m_docManager
, NULL
, wxID_ANY
, wxGetApp().GetSettings().GetAppName(),
135 GetSettings().m_frameSize
.GetPosition(), GetSettings().m_frameSize
.GetSize(),
136 wxDEFAULT_FRAME_STYLE
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
139 switch (wxGetApp().GetSettings().m_frameStatus
)
141 case ctSHOW_STATUS_MAXIMIZED
:
143 frame
->Maximize(true);
146 case ctSHOW_STATUS_MINIMIZED
:
148 frame
->Iconize(true);
152 case ctSHOW_STATUS_NORMAL
:
158 // Load the file history. This has to be done AFTER the
159 // main frame has been created, so that the items
160 // will get appended to the file menu.
162 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
163 GetFileHistory().Load(config
);
168 // Concatenate strings since it could have spaces (and quotes)
171 for (i
= 1; i
< argc
; i
++)
175 arg
+= wxString(wxT(" "));
179 if (arg
.Last() == '"')
180 arg
= arg
.Mid(0, arg
.Len() - 1);
183 wxDocument
* doc
= m_docManager
->CreateDocument(arg
, wxDOC_SILENT
);
185 doc
->SetDocumentSaved(true);
189 if (GetSettings().m_loadLastDocument
)
191 // Load the file that was last loaded
192 wxDocument
* doc
= m_docManager
->CreateDocument(GetSettings().m_lastFilename
, wxDOC_SILENT
);
194 doc
->SetDocumentSaved(true);
198 GetTopWindow()->Show(true);
203 int ctApp::OnExit(void)
207 // Save the file history
209 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
210 GetFileHistory().Save(config
);
219 void ctApp::ClearHelpControllers()
221 delete m_helpController
;
222 m_helpController
= NULL
;
224 delete m_helpControllerReference
;
225 m_helpControllerReference
= NULL
;
229 // Prepend the current program directory to the name
230 wxString
ctApp::GetFullAppPath(const wxString
& filename
) const
232 wxString
path(m_appDir
);
233 if (path
.Last() != wxFILE_SEP_PATH
&& filename
[0] != wxFILE_SEP_PATH
)
234 path
+= wxFILE_SEP_PATH
;
241 bool ctApp::LoadConfig()
243 return m_settings
.LoadConfig();
247 bool ctApp::SaveConfig()
249 return m_settings
.SaveConfig();
252 bool ctApp::UsingTooltips()
254 return GetSettings().m_useToolTips
;
257 /// Returns the main frame
258 ctMainFrame
* ctApp::GetMainFrame()
260 return wxDynamicCast(wxTheApp
->GetTopWindow(), ctMainFrame
);