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