]>
Commit | Line | Data |
---|---|---|
d7463f75 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wxconfigtool.cpp | |
3 | // Purpose: Generic application class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2002-09-04 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
71ada1a5 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
f8105809 | 13 | #pragma implementation "wxconfigtool.h" |
d7463f75 JS |
14 | #endif |
15 | ||
d9ab621e WS |
16 | // For compilers that support precompilation, includes "wx/wx.h". |
17 | #include "wx/wxprec.h" | |
d7463f75 JS |
18 | |
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
d9ab621e WS |
23 | #ifndef WX_PRECOMP |
24 | ||
d7463f75 | 25 | #include "wx/laywin.h" |
d7463f75 JS |
26 | #include "wx/menuitem.h" |
27 | #include "wx/tooltip.h" | |
d9ab621e WS |
28 | #include "wx/variant.h" |
29 | ||
30 | #endif | |
31 | ||
d7463f75 | 32 | #include "wx/cshelp.h" |
88ff9430 | 33 | #include "wx/helphtml.h" |
d7463f75 JS |
34 | #include "wx/html/htmprint.h" |
35 | #include "wx/html/htmlwin.h" | |
d9ab621e | 36 | #include "wx/image.h" |
d7463f75 JS |
37 | #include "wx/filesys.h" |
38 | #include "wx/fs_mem.h" | |
39 | #include "wx/fs_zip.h" | |
40 | #include "wx/wfstream.h" | |
d9ab621e | 41 | #include "wx/config.h" |
d7463f75 JS |
42 | #include "wxconfigtool.h" |
43 | #include "configtooldoc.h" | |
44 | #include "configtoolview.h" | |
45 | #include "mainframe.h" | |
46 | #include "utils.h" | |
47 | ||
48 | IMPLEMENT_APP(ctApp) | |
49 | ||
50 | BEGIN_EVENT_TABLE(ctApp, wxApp) | |
51 | END_EVENT_TABLE() | |
52 | ||
53 | ctApp::ctApp() | |
54 | { | |
55 | m_helpController = NULL; | |
56 | m_helpControllerReference = NULL; | |
57 | m_docManager = NULL; | |
58 | } | |
59 | ||
d7463f75 JS |
60 | bool ctApp::OnInit(void) |
61 | { | |
d9ab621e | 62 | |
453bacf4 | 63 | #if wxUSE_LOG |
d7463f75 | 64 | wxLog::SetTimestamp(NULL); |
453bacf4 | 65 | #endif // wxUSE_LOG |
254a2129 | 66 | |
d7463f75 JS |
67 | wxHelpProvider::Set(new wxSimpleHelpProvider); |
68 | ||
69 | #if wxUSE_LIBPNG | |
70 | wxImage::AddHandler( new wxPNGHandler ); | |
71 | #endif | |
254a2129 | 72 | |
d7463f75 JS |
73 | #if wxUSE_LIBJPEG |
74 | wxImage::AddHandler( new wxJPEGHandler ); | |
75 | #endif | |
254a2129 | 76 | |
d7463f75 JS |
77 | #if wxUSE_GIF |
78 | wxImage::AddHandler( new wxGIFHandler ); | |
79 | #endif | |
80 | ||
88ff9430 | 81 | #if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__) |
d7463f75 JS |
82 | m_helpController = new wxCHMHelpController; |
83 | m_helpControllerReference = new wxCHMHelpController; | |
84 | #else | |
85 | m_helpController = new wxHtmlHelpController; | |
86 | m_helpControllerReference = new wxHtmlHelpController; | |
87 | #endif | |
88 | ||
89 | // Required for HTML help | |
90 | #if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB | |
91 | wxFileSystem::AddHandler(new wxZipFSHandler); | |
92 | #endif | |
93 | ||
94 | wxString currentDir = wxGetCwd(); | |
95 | ||
96 | // Use argv to get current app directory | |
d9ab621e WS |
97 | wxString argv0(argv[0]); |
98 | wxString appVariableName(wxT("WXCONFIGTOOLDIR")); | |
99 | m_appDir = apFindAppPath(argv0, currentDir, appVariableName); | |
d7463f75 JS |
100 | |
101 | #ifdef __WXMSW__ | |
102 | // If the development version, go up a directory. | |
69da0d99 JS |
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) | |
d7463f75 JS |
109 | ) |
110 | m_appDir = wxPathOnly(m_appDir); | |
111 | #endif | |
112 | ||
113 | m_docManager = new wxDocManager; | |
114 | m_docManager->SetMaxDocsOpen(1); | |
115 | ||
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)); | |
119 | ||
120 | m_settings.Init(); | |
121 | ||
122 | LoadConfig(); | |
254a2129 | 123 | |
d7463f75 JS |
124 | wxString helpFilePathReference(GetFullAppPath(_("wx"))); |
125 | m_helpControllerReference->Initialize(helpFilePathReference); | |
254a2129 | 126 | |
d7463f75 JS |
127 | wxString helpFilePath(GetFullAppPath(_("configtool"))); |
128 | m_helpController->Initialize(helpFilePath); | |
254a2129 | 129 | |
4fe30bce | 130 | ctMainFrame* frame = new ctMainFrame(m_docManager, NULL, wxID_ANY, wxGetApp().GetSettings().GetAppName(), |
d7463f75 | 131 | GetSettings().m_frameSize.GetPosition(), GetSettings().m_frameSize.GetSize(), |
61775320 | 132 | wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN); |
d7463f75 JS |
133 | SetTopWindow(frame); |
134 | ||
135 | switch (wxGetApp().GetSettings().m_frameStatus) | |
136 | { | |
137 | case ctSHOW_STATUS_MAXIMIZED: | |
138 | { | |
4fe30bce | 139 | frame->Maximize(true); |
d7463f75 JS |
140 | break; |
141 | } | |
142 | case ctSHOW_STATUS_MINIMIZED: | |
143 | { | |
4fe30bce | 144 | frame->Iconize(true); |
d7463f75 JS |
145 | break; |
146 | } | |
147 | default: | |
148 | case ctSHOW_STATUS_NORMAL: | |
149 | { | |
150 | break; | |
151 | } | |
152 | } | |
153 | ||
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. | |
157 | { | |
158 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation")); | |
159 | GetFileHistory().Load(config); | |
160 | } | |
161 | ||
162 | if (argc > 1) | |
163 | { | |
164 | // Concatenate strings since it could have spaces (and quotes) | |
165 | wxString arg; | |
166 | int i; | |
167 | for (i = 1; i < argc; i++) | |
168 | { | |
169 | arg += argv[i]; | |
170 | if (i < (argc - 1)) | |
171 | arg += wxString(wxT(" ")); | |
172 | } | |
173 | if (arg[0u] == '"') | |
174 | arg = arg.Mid(1); | |
175 | if (arg.Last() == '"') | |
176 | arg = arg.Mid(0, arg.Len() - 1); | |
177 | ||
178 | // Load the file | |
179 | wxDocument* doc = m_docManager->CreateDocument(arg, wxDOC_SILENT); | |
180 | if (doc) | |
4fe30bce | 181 | doc->SetDocumentSaved(true); |
d7463f75 JS |
182 | } |
183 | else | |
184 | { | |
185 | if (GetSettings().m_loadLastDocument) | |
186 | { | |
187 | // Load the file that was last loaded | |
188 | wxDocument* doc = m_docManager->CreateDocument(GetSettings().m_lastFilename, wxDOC_SILENT); | |
189 | if (doc) | |
4fe30bce | 190 | doc->SetDocumentSaved(true); |
d7463f75 JS |
191 | } |
192 | } | |
254a2129 | 193 | |
4fe30bce | 194 | GetTopWindow()->Show(true); |
254a2129 | 195 | |
4fe30bce | 196 | return true; |
d7463f75 JS |
197 | } |
198 | ||
199 | int ctApp::OnExit(void) | |
200 | { | |
201 | SaveConfig(); | |
254a2129 | 202 | |
d7463f75 JS |
203 | // Save the file history |
204 | { | |
205 | wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation")); | |
206 | GetFileHistory().Save(config); | |
207 | } | |
208 | ||
209 | delete m_docManager; | |
210 | m_docManager = NULL; | |
254a2129 | 211 | |
d7463f75 JS |
212 | return 0; |
213 | } | |
214 | ||
215 | void ctApp::ClearHelpControllers() | |
216 | { | |
217 | delete m_helpController; | |
218 | m_helpController = NULL; | |
254a2129 | 219 | |
d7463f75 JS |
220 | delete m_helpControllerReference; |
221 | m_helpControllerReference = NULL; | |
222 | } | |
223 | ||
224 | ||
225 | // Prepend the current program directory to the name | |
226 | wxString ctApp::GetFullAppPath(const wxString& filename) const | |
227 | { | |
228 | wxString path(m_appDir); | |
229 | if (path.Last() != wxFILE_SEP_PATH && filename[0] != wxFILE_SEP_PATH) | |
230 | path += wxFILE_SEP_PATH; | |
231 | path += filename; | |
254a2129 | 232 | |
d7463f75 JS |
233 | return path; |
234 | } | |
235 | ||
236 | // Load config info | |
237 | bool ctApp::LoadConfig() | |
238 | { | |
239 | return m_settings.LoadConfig(); | |
240 | } | |
241 | ||
242 | // Save config info | |
243 | bool ctApp::SaveConfig() | |
244 | { | |
245 | return m_settings.SaveConfig(); | |
246 | } | |
247 | ||
248 | bool ctApp::UsingTooltips() | |
249 | { | |
250 | return GetSettings().m_useToolTips; | |
251 | } | |
252 | ||
253 | /// Returns the main frame | |
254 | ctMainFrame* ctApp::GetMainFrame() | |
255 | { | |
256 | return wxDynamicCast(wxTheApp->GetTopWindow(), ctMainFrame); | |
257 | } |