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
;
60 bool ctApp::OnInit(void)
64 wxLog::SetTimestamp(NULL
);
67 wxHelpProvider::Set(new wxSimpleHelpProvider
);
70 wxImage::AddHandler( new wxPNGHandler
);
74 wxImage::AddHandler( new wxJPEGHandler
);
78 wxImage::AddHandler( new wxGIFHandler
);
81 #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
82 m_helpController
= new wxCHMHelpController
;
83 m_helpControllerReference
= new wxCHMHelpController
;
85 m_helpController
= new wxHtmlHelpController
;
86 m_helpControllerReference
= new wxHtmlHelpController
;
89 // Required for HTML help
90 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
91 wxFileSystem::AddHandler(new wxZipFSHandler
);
94 wxString currentDir
= wxGetCwd();
96 // Use argv to get current app directory
97 wxString
argv0(argv
[0]);
98 wxString
appVariableName(wxT("WXCONFIGTOOLDIR"));
99 m_appDir
= apFindAppPath(argv0
, currentDir
, appVariableName
);
102 // If the development version, go up a directory.
103 if ((m_appDir
.Right(5).CmpNoCase(_T("DEBUG")) == 0) ||
104 (m_appDir
.Right(11).CmpNoCase(_T("DEBUGSTABLE")) == 0) ||
105 (m_appDir
.Right(7).CmpNoCase(_T("RELEASE")) == 0) ||
106 (m_appDir
.Right(13).CmpNoCase(_T("RELEASESTABLE")) == 0) ||
107 (m_appDir
.Right(10).CmpNoCase(_T("RELEASEDEV")) == 0) ||
108 (m_appDir
.Right(8).CmpNoCase(_T("DEBUGDEV")) == 0)
110 m_appDir
= wxPathOnly(m_appDir
);
113 m_docManager
= new wxDocManager
;
114 m_docManager
->SetMaxDocsOpen(1);
116 //// Create a template relating documents to their views
117 (void) new wxDocTemplate(m_docManager
, wxGetApp().GetSettings().GetShortAppName(), wxT("*.wxs"), wxT(""), wxT("wxs"), wxT("Doc"), wxT("View"),
118 CLASSINFO(ctConfigToolDoc
), CLASSINFO(ctConfigToolView
));
124 wxString
helpFilePathReference(GetFullAppPath(_("wx")));
125 m_helpControllerReference
->Initialize(helpFilePathReference
);
127 wxString
helpFilePath(GetFullAppPath(_("configtool")));
128 m_helpController
->Initialize(helpFilePath
);
130 ctMainFrame
* frame
= new ctMainFrame(m_docManager
, NULL
, wxID_ANY
, wxGetApp().GetSettings().GetAppName(),
131 GetSettings().m_frameSize
.GetPosition(), GetSettings().m_frameSize
.GetSize(),
132 wxDEFAULT_FRAME_STYLE
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
135 switch (wxGetApp().GetSettings().m_frameStatus
)
137 case ctSHOW_STATUS_MAXIMIZED
:
139 frame
->Maximize(true);
142 case ctSHOW_STATUS_MINIMIZED
:
144 frame
->Iconize(true);
148 case ctSHOW_STATUS_NORMAL
:
154 // Load the file history. This has to be done AFTER the
155 // main frame has been created, so that the items
156 // will get appended to the file menu.
158 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
159 GetFileHistory().Load(config
);
164 // Concatenate strings since it could have spaces (and quotes)
167 for (i
= 1; i
< argc
; i
++)
171 arg
+= wxString(wxT(" "));
175 if (arg
.Last() == '"')
176 arg
= arg
.Mid(0, arg
.Len() - 1);
179 wxDocument
* doc
= m_docManager
->CreateDocument(arg
, wxDOC_SILENT
);
181 doc
->SetDocumentSaved(true);
185 if (GetSettings().m_loadLastDocument
)
187 // Load the file that was last loaded
188 wxDocument
* doc
= m_docManager
->CreateDocument(GetSettings().m_lastFilename
, wxDOC_SILENT
);
190 doc
->SetDocumentSaved(true);
194 GetTopWindow()->Show(true);
199 int ctApp::OnExit(void)
203 // Save the file history
205 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
206 GetFileHistory().Save(config
);
215 void ctApp::ClearHelpControllers()
217 delete m_helpController
;
218 m_helpController
= NULL
;
220 delete m_helpControllerReference
;
221 m_helpControllerReference
= NULL
;
225 // Prepend the current program directory to the name
226 wxString
ctApp::GetFullAppPath(const wxString
& filename
) const
228 wxString
path(m_appDir
);
229 if (path
.Last() != wxFILE_SEP_PATH
&& filename
[0] != wxFILE_SEP_PATH
)
230 path
+= wxFILE_SEP_PATH
;
237 bool ctApp::LoadConfig()
239 return m_settings
.LoadConfig();
243 bool ctApp::SaveConfig()
245 return m_settings
.SaveConfig();
248 bool ctApp::UsingTooltips()
250 return GetSettings().m_useToolTips
;
253 /// Returns the main frame
254 ctMainFrame
* ctApp::GetMainFrame()
256 return wxDynamicCast(wxTheApp
->GetTopWindow(), ctMainFrame
);