]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/wxconfigtool.cpp
Fix so sound looping will stop, courtesy of Ryan Norton.
[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
16#include "wx/wx.h"
17
18#ifdef __BORLANDC__
19#pragma hdrstop
20#endif
21
22#include "wx/config.h"
23#include "wx/laywin.h"
24#include "wx/image.h"
25#include "wx/menuitem.h"
26#include "wx/tooltip.h"
27#include "wx/cshelp.h"
88ff9430 28#include "wx/helphtml.h"
d7463f75
JS
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"
36
37#include "wxconfigtool.h"
38#include "configtooldoc.h"
39#include "configtoolview.h"
40#include "mainframe.h"
41#include "utils.h"
42
43IMPLEMENT_APP(ctApp)
44
45BEGIN_EVENT_TABLE(ctApp, wxApp)
46END_EVENT_TABLE()
47
48ctApp::ctApp()
49{
50 m_helpController = NULL;
51 m_helpControllerReference = NULL;
52 m_docManager = NULL;
53}
54
55ctApp::~ctApp()
56{
57}
58
59bool ctApp::OnInit(void)
60{
453bacf4 61#if wxUSE_LOG
d7463f75 62 wxLog::SetTimestamp(NULL);
453bacf4 63#endif // wxUSE_LOG
d7463f75
JS
64
65 wxHelpProvider::Set(new wxSimpleHelpProvider);
66
67#if wxUSE_LIBPNG
68 wxImage::AddHandler( new wxPNGHandler );
69#endif
70
71#if wxUSE_LIBJPEG
72 wxImage::AddHandler( new wxJPEGHandler );
73#endif
74
75#if wxUSE_GIF
76 wxImage::AddHandler( new wxGIFHandler );
77#endif
78
88ff9430 79#if wxUSE_MS_HTML_HELP && !defined(__WXUNIVERSAL__)
d7463f75
JS
80 m_helpController = new wxCHMHelpController;
81 m_helpControllerReference = new wxCHMHelpController;
82#else
83 m_helpController = new wxHtmlHelpController;
84 m_helpControllerReference = new wxHtmlHelpController;
85#endif
86
87 // Required for HTML help
88#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
89 wxFileSystem::AddHandler(new wxZipFSHandler);
90#endif
91
92 wxString currentDir = wxGetCwd();
93
94 // Use argv to get current app directory
95 m_appDir = apFindAppPath(argv[0], currentDir, wxT("WXCONFIGTOOLDIR"));
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();
119
120 wxString helpFilePathReference(GetFullAppPath(_("wx")));
121 m_helpControllerReference->Initialize(helpFilePathReference);
122
123 wxString helpFilePath(GetFullAppPath(_("configtool")));
124 m_helpController->Initialize(helpFilePath);
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 }
189
4fe30bce 190 GetTopWindow()->Show(true);
d7463f75 191
4fe30bce 192 return true;
d7463f75
JS
193}
194
195int ctApp::OnExit(void)
196{
197 SaveConfig();
198
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;
207
208 return 0;
209}
210
211void ctApp::ClearHelpControllers()
212{
213 delete m_helpController;
214 m_helpController = NULL;
215
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;
228
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}