]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/wxconfigtool.cpp
Oops, I left an extra { in there.
[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
12#ifdef __GNUG__
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"
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"
35
36#include "wxconfigtool.h"
37#include "configtooldoc.h"
38#include "configtoolview.h"
39#include "mainframe.h"
40#include "utils.h"
41
42IMPLEMENT_APP(ctApp)
43
44BEGIN_EVENT_TABLE(ctApp, wxApp)
45END_EVENT_TABLE()
46
47ctApp::ctApp()
48{
49 m_helpController = NULL;
50 m_helpControllerReference = NULL;
51 m_docManager = NULL;
52}
53
54ctApp::~ctApp()
55{
56}
57
58bool ctApp::OnInit(void)
59{
60 wxLog::SetTimestamp(NULL);
61
62 wxHelpProvider::Set(new wxSimpleHelpProvider);
63
64#if wxUSE_LIBPNG
65 wxImage::AddHandler( new wxPNGHandler );
66#endif
67
68#if wxUSE_LIBJPEG
69 wxImage::AddHandler( new wxJPEGHandler );
70#endif
71
72#if wxUSE_GIF
73 wxImage::AddHandler( new wxGIFHandler );
74#endif
75
76#ifdef __WXMSW__
77 m_helpController = new wxCHMHelpController;
78 m_helpControllerReference = new wxCHMHelpController;
79#else
80 m_helpController = new wxHtmlHelpController;
81 m_helpControllerReference = new wxHtmlHelpController;
82#endif
83
84 // Required for HTML help
85#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
86 wxFileSystem::AddHandler(new wxZipFSHandler);
87#endif
88
89 wxString currentDir = wxGetCwd();
90
91 // Use argv to get current app directory
92 m_appDir = apFindAppPath(argv[0], currentDir, wxT("WXCONFIGTOOLDIR"));
93
94#ifdef __WXMSW__
95 // If the development version, go up a directory.
69da0d99
JS
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)
d7463f75
JS
102 )
103 m_appDir = wxPathOnly(m_appDir);
104#endif
105
106 m_docManager = new wxDocManager;
107 m_docManager->SetMaxDocsOpen(1);
108
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));
112
113 m_settings.Init();
114
115 LoadConfig();
116
117 wxString helpFilePathReference(GetFullAppPath(_("wx")));
118 m_helpControllerReference->Initialize(helpFilePathReference);
119
120 wxString helpFilePath(GetFullAppPath(_("configtool")));
121 m_helpController->Initialize(helpFilePath);
122
123 ctMainFrame* frame = new ctMainFrame(m_docManager, NULL, -1, wxGetApp().GetSettings().GetAppName(),
124 GetSettings().m_frameSize.GetPosition(), GetSettings().m_frameSize.GetSize(),
61775320 125 wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN);
d7463f75
JS
126 SetTopWindow(frame);
127
128 switch (wxGetApp().GetSettings().m_frameStatus)
129 {
130 case ctSHOW_STATUS_MAXIMIZED:
131 {
132 frame->Maximize(TRUE);
133 break;
134 }
135 case ctSHOW_STATUS_MINIMIZED:
136 {
137 frame->Iconize(TRUE);
138 break;
139 }
140 default:
141 case ctSHOW_STATUS_NORMAL:
142 {
143 break;
144 }
145 }
146
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.
150 {
151 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
152 GetFileHistory().Load(config);
153 }
154
155 if (argc > 1)
156 {
157 // Concatenate strings since it could have spaces (and quotes)
158 wxString arg;
159 int i;
160 for (i = 1; i < argc; i++)
161 {
162 arg += argv[i];
163 if (i < (argc - 1))
164 arg += wxString(wxT(" "));
165 }
166 if (arg[0u] == '"')
167 arg = arg.Mid(1);
168 if (arg.Last() == '"')
169 arg = arg.Mid(0, arg.Len() - 1);
170
171 // Load the file
172 wxDocument* doc = m_docManager->CreateDocument(arg, wxDOC_SILENT);
173 if (doc)
174 doc->SetDocumentSaved(TRUE);
175 }
176 else
177 {
178 if (GetSettings().m_loadLastDocument)
179 {
180 // Load the file that was last loaded
181 wxDocument* doc = m_docManager->CreateDocument(GetSettings().m_lastFilename, wxDOC_SILENT);
182 if (doc)
183 doc->SetDocumentSaved(TRUE);
184 }
185 }
186
187 GetTopWindow()->Show(TRUE);
188
189 return TRUE;
190}
191
192int ctApp::OnExit(void)
193{
194 SaveConfig();
195
196 // Save the file history
197 {
198 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("Generic Organisation"));
199 GetFileHistory().Save(config);
200 }
201
202 delete m_docManager;
203 m_docManager = NULL;
204
205 return 0;
206}
207
208void ctApp::ClearHelpControllers()
209{
210 delete m_helpController;
211 m_helpController = NULL;
212
213 delete m_helpControllerReference;
214 m_helpControllerReference = NULL;
215}
216
217
218// Prepend the current program directory to the name
219wxString ctApp::GetFullAppPath(const wxString& filename) const
220{
221 wxString path(m_appDir);
222 if (path.Last() != wxFILE_SEP_PATH && filename[0] != wxFILE_SEP_PATH)
223 path += wxFILE_SEP_PATH;
224 path += filename;
225
226 return path;
227}
228
229// Load config info
230bool ctApp::LoadConfig()
231{
232 return m_settings.LoadConfig();
233}
234
235// Save config info
236bool ctApp::SaveConfig()
237{
238 return m_settings.SaveConfig();
239}
240
241bool ctApp::UsingTooltips()
242{
243 return GetSettings().m_useToolTips;
244}
245
246/// Returns the main frame
247ctMainFrame* ctApp::GetMainFrame()
248{
249 return wxDynamicCast(wxTheApp->GetTopWindow(), ctMainFrame);
250}