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