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"
22 #include "wx/config.h"
23 #include "wx/laywin.h"
25 #include "wx/menuitem.h"
26 #include "wx/tooltip.h"
27 #include "wx/cshelp.h"
28 #include "wx/helphtml.h"
29 #include "wx/html/htmprint.h"
30 #include "wx/html/htmlwin.h"
31 #include "wx/filesys.h"
32 #include "wx/fs_mem.h"
33 #include "wx/fs_zip.h"
34 #include "wx/wfstream.h"
35 #include "wx/variant.h"
37 #include "wxconfigtool.h"
38 #include "configtooldoc.h"
39 #include "configtoolview.h"
40 #include "mainframe.h"
45 BEGIN_EVENT_TABLE(ctApp
, wxApp
)
50 m_helpController
= NULL
;
51 m_helpControllerReference
= NULL
;
59 bool ctApp::OnInit(void)
61 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 m_appDir
= apFindAppPath(argv
[0], currentDir
, wxT("WXCONFIGTOOLDIR"));
96 // If the development version, go up a directory.
97 if ((m_appDir
.Right(5).CmpNoCase(_T("DEBUG")) == 0) ||
98 (m_appDir
.Right(11).CmpNoCase(_T("DEBUGSTABLE")) == 0) ||
99 (m_appDir
.Right(7).CmpNoCase(_T("RELEASE")) == 0) ||
100 (m_appDir
.Right(13).CmpNoCase(_T("RELEASESTABLE")) == 0) ||
101 (m_appDir
.Right(10).CmpNoCase(_T("RELEASEDEV")) == 0) ||
102 (m_appDir
.Right(8).CmpNoCase(_T("DEBUGDEV")) == 0)
104 m_appDir
= wxPathOnly(m_appDir
);
107 m_docManager
= new wxDocManager
;
108 m_docManager
->SetMaxDocsOpen(1);
110 //// Create a template relating documents to their views
111 (void) new wxDocTemplate(m_docManager
, wxGetApp().GetSettings().GetShortAppName(), wxT("*.wxs"), wxT(""), wxT("wxs"), wxT("Doc"), wxT("View"),
112 CLASSINFO(ctConfigToolDoc
), CLASSINFO(ctConfigToolView
));
118 wxString
helpFilePathReference(GetFullAppPath(_("wx")));
119 m_helpControllerReference
->Initialize(helpFilePathReference
);
121 wxString
helpFilePath(GetFullAppPath(_("configtool")));
122 m_helpController
->Initialize(helpFilePath
);
124 ctMainFrame
* frame
= new ctMainFrame(m_docManager
, NULL
, wxID_ANY
, wxGetApp().GetSettings().GetAppName(),
125 GetSettings().m_frameSize
.GetPosition(), GetSettings().m_frameSize
.GetSize(),
126 wxDEFAULT_FRAME_STYLE
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
129 switch (wxGetApp().GetSettings().m_frameStatus
)
131 case ctSHOW_STATUS_MAXIMIZED
:
133 frame
->Maximize(true);
136 case ctSHOW_STATUS_MINIMIZED
:
138 frame
->Iconize(true);
142 case ctSHOW_STATUS_NORMAL
:
148 // Load the file history. This has to be done AFTER the
149 // main frame has been created, so that the items
150 // will get appended to the file menu.
152 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
153 GetFileHistory().Load(config
);
158 // Concatenate strings since it could have spaces (and quotes)
161 for (i
= 1; i
< argc
; i
++)
165 arg
+= wxString(wxT(" "));
169 if (arg
.Last() == '"')
170 arg
= arg
.Mid(0, arg
.Len() - 1);
173 wxDocument
* doc
= m_docManager
->CreateDocument(arg
, wxDOC_SILENT
);
175 doc
->SetDocumentSaved(true);
179 if (GetSettings().m_loadLastDocument
)
181 // Load the file that was last loaded
182 wxDocument
* doc
= m_docManager
->CreateDocument(GetSettings().m_lastFilename
, wxDOC_SILENT
);
184 doc
->SetDocumentSaved(true);
188 GetTopWindow()->Show(true);
193 int ctApp::OnExit(void)
197 // Save the file history
199 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
200 GetFileHistory().Save(config
);
209 void ctApp::ClearHelpControllers()
211 delete m_helpController
;
212 m_helpController
= NULL
;
214 delete m_helpControllerReference
;
215 m_helpControllerReference
= NULL
;
219 // Prepend the current program directory to the name
220 wxString
ctApp::GetFullAppPath(const wxString
& filename
) const
222 wxString
path(m_appDir
);
223 if (path
.Last() != wxFILE_SEP_PATH
&& filename
[0] != wxFILE_SEP_PATH
)
224 path
+= wxFILE_SEP_PATH
;
231 bool ctApp::LoadConfig()
233 return m_settings
.LoadConfig();
237 bool ctApp::SaveConfig()
239 return m_settings
.SaveConfig();
242 bool ctApp::UsingTooltips()
244 return GetSettings().m_useToolTips
;
247 /// Returns the main frame
248 ctMainFrame
* ctApp::GetMainFrame()
250 return wxDynamicCast(wxTheApp
->GetTopWindow(), ctMainFrame
);