1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxconfigtool.cpp
3 // Purpose: Generic application class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
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/html/htmprint.h"
29 #include "wx/html/htmlwin.h"
30 #include "wx/filesys.h"
31 #include "wx/fs_mem.h"
32 #include "wx/fs_zip.h"
33 #include "wx/wfstream.h"
34 #include "wx/variant.h"
36 #include "wxconfigtool.h"
37 #include "configtooldoc.h"
38 #include "configtoolview.h"
39 #include "mainframe.h"
44 BEGIN_EVENT_TABLE(ctApp
, wxApp
)
49 m_helpController
= NULL
;
50 m_helpControllerReference
= NULL
;
58 bool ctApp::OnInit(void)
60 wxLog::SetTimestamp(NULL
);
62 wxHelpProvider::Set(new wxSimpleHelpProvider
);
65 wxImage::AddHandler( new wxPNGHandler
);
69 wxImage::AddHandler( new wxJPEGHandler
);
73 wxImage::AddHandler( new wxGIFHandler
);
77 m_helpController
= new wxCHMHelpController
;
78 m_helpControllerReference
= new wxCHMHelpController
;
80 m_helpController
= new wxHtmlHelpController
;
81 m_helpControllerReference
= new wxHtmlHelpController
;
84 // Required for HTML help
85 #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
86 wxFileSystem::AddHandler(new wxZipFSHandler
);
89 wxString currentDir
= wxGetCwd();
91 // Use argv to get current app directory
92 m_appDir
= apFindAppPath(argv
[0], currentDir
, wxT("WXCONFIGTOOLDIR"));
95 // If the development version, go up a directory.
96 if ((m_appDir
.Right(5).CmpNoCase(_T("DEBUG")) == 0) ||
97 (m_appDir
.Right(11).CmpNoCase(_T("DEBUGSTABLE")) == 0) ||
98 (m_appDir
.Right(7).CmpNoCase(_T("RELEASE")) == 0) ||
99 (m_appDir
.Right(13).CmpNoCase(_T("RELEASESTABLE")) == 0) ||
100 (m_appDir
.Right(10).CmpNoCase(_T("RELEASEDEV")) == 0) ||
101 (m_appDir
.Right(8).CmpNoCase(_T("DEBUGDEV")) == 0)
103 m_appDir
= wxPathOnly(m_appDir
);
106 m_docManager
= new wxDocManager
;
107 m_docManager
->SetMaxDocsOpen(1);
109 //// Create a template relating documents to their views
110 (void) new wxDocTemplate(m_docManager
, wxGetApp().GetSettings().GetShortAppName(), wxT("*.wxs"), wxT(""), wxT("wxs"), wxT("Doc"), wxT("View"),
111 CLASSINFO(ctConfigToolDoc
), CLASSINFO(ctConfigToolView
));
117 wxString
helpFilePathReference(GetFullAppPath(_("wx")));
118 m_helpControllerReference
->Initialize(helpFilePathReference
);
120 wxString
helpFilePath(GetFullAppPath(_("configtool")));
121 m_helpController
->Initialize(helpFilePath
);
123 ctMainFrame
* frame
= new ctMainFrame(m_docManager
, NULL
, -1, wxGetApp().GetSettings().GetAppName(),
124 GetSettings().m_frameSize
.GetPosition(), GetSettings().m_frameSize
.GetSize(),
125 wxDEFAULT_FRAME_STYLE
|wxNO_FULL_REPAINT_ON_RESIZE
|wxCLIP_CHILDREN
);
128 switch (wxGetApp().GetSettings().m_frameStatus
)
130 case ctSHOW_STATUS_MAXIMIZED
:
132 frame
->Maximize(TRUE
);
135 case ctSHOW_STATUS_MINIMIZED
:
137 frame
->Iconize(TRUE
);
141 case ctSHOW_STATUS_NORMAL
:
147 // Load the file history. This has to be done AFTER the
148 // main frame has been created, so that the items
149 // will get appended to the file menu.
151 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
152 GetFileHistory().Load(config
);
157 // Concatenate strings since it could have spaces (and quotes)
160 for (i
= 1; i
< argc
; i
++)
164 arg
+= wxString(wxT(" "));
168 if (arg
.Last() == '"')
169 arg
= arg
.Mid(0, arg
.Len() - 1);
172 wxDocument
* doc
= m_docManager
->CreateDocument(arg
, wxDOC_SILENT
);
174 doc
->SetDocumentSaved(TRUE
);
178 if (GetSettings().m_loadLastDocument
)
180 // Load the file that was last loaded
181 wxDocument
* doc
= m_docManager
->CreateDocument(GetSettings().m_lastFilename
, wxDOC_SILENT
);
183 doc
->SetDocumentSaved(TRUE
);
187 GetTopWindow()->Show(TRUE
);
192 int ctApp::OnExit(void)
196 // Save the file history
198 wxConfig
config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
199 GetFileHistory().Save(config
);
208 void ctApp::ClearHelpControllers()
210 delete m_helpController
;
211 m_helpController
= NULL
;
213 delete m_helpControllerReference
;
214 m_helpControllerReference
= NULL
;
218 // Prepend the current program directory to the name
219 wxString
ctApp::GetFullAppPath(const wxString
& filename
) const
221 wxString
path(m_appDir
);
222 if (path
.Last() != wxFILE_SEP_PATH
&& filename
[0] != wxFILE_SEP_PATH
)
223 path
+= wxFILE_SEP_PATH
;
230 bool ctApp::LoadConfig()
232 return m_settings
.LoadConfig();
236 bool ctApp::SaveConfig()
238 return m_settings
.SaveConfig();
241 bool ctApp::UsingTooltips()
243 return GetSettings().m_useToolTips
;
246 /// Returns the main frame
247 ctMainFrame
* ctApp::GetMainFrame()
249 return wxDynamicCast(wxTheApp
->GetTopWindow(), ctMainFrame
);