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