]> git.saurik.com Git - wxWidgets.git/blame_incremental - utils/configtool/src/appsettings.cpp
Miscellaneous compilation and warning fixes.
[wxWidgets.git] / utils / configtool / src / appsettings.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: appsettings.cpp
3// Purpose: Implements settings-related functionality
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 "appsettings.h"
14#endif
15
16// For compilers that support precompilation, includes "wx/wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
24
25#include "wx/datstrm.h"
26#include "wx/dir.h"
27#include "wx/colordlg.h"
28#include "wx/wxhtml.h"
29#include "wx/effects.h"
30#include "wx/spinctrl.h"
31#include "wx/tooltip.h"
32#include "wx/settings.h"
33
34#endif
35
36#include "wx/wfstream.h"
37#include "wx/config.h"
38#include "wx/fileconf.h"
39#include "wx/valgen.h"
40#include "utils.h"
41#include "wxconfigtool.h"
42#include "appsettings.h"
43#include "mainframe.h"
44#include "symbols.h"
45#include "settingsdialog.h"
46
47/*
48 * User-changeable settings
49 */
50
51IMPLEMENT_DYNAMIC_CLASS(ctSettings, wxObject)
52
53ctSettings::ctSettings()
54{
55 m_noUses = 0;
56 m_showToolBar = true;
57 m_showWelcomeDialog = true;
58 m_exportDir = wxEmptyString;
59
60 m_frameSize = wxRect(10, 10, 600, 500);
61 // m_backgroundColour = wxColour(140, 172, 179); // blue-grey
62 m_editWindowFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
63
64 m_appName = wxT("wxWidgets Configuration Tool");
65 m_appNameShort = wxT("Configuration Tool");
66 m_showSplashScreen = false;
67 m_userName = wxEmptyString;
68 m_frameStatus = ctSHOW_STATUS_NORMAL;
69 m_loadLastDocument = true;
70 m_firstTimeRun = true;
71 m_smallToolbar = true;
72 m_mainSashSize = 200;
73 m_useToolTips = true;
74 m_showTrayIcon = true;
75 m_trayIconIsShown = false;
76 m_useEnvironmentVariable = true;
77 m_frameworkDir = wxEmptyString;
78 m_matchWholeWord = false;
79 m_matchCase = false;
80 m_defaultFileKind = wxT("Setup file");
81}
82
83// Copy constructor
84ctSettings::ctSettings(const ctSettings& settings) : wxObject()
85{
86 Copy(settings);
87}
88
89
90void ctSettings::operator = (const ctSettings& settings)
91{
92 Copy(settings);
93}
94
95void ctSettings::Copy (const ctSettings& settings)
96{
97 m_lastSetupSaveDir = settings.m_lastSetupSaveDir;
98 m_lastDocument = settings.m_lastDocument;
99 m_showToolBar = settings.m_showToolBar;
100 m_frameSize = settings.m_frameSize;
101 m_editWindowFont = settings.m_editWindowFont;
102 m_showSplashScreen = settings.m_showSplashScreen;
103 m_userName = settings.m_userName;
104 m_loadLastDocument = settings.m_loadLastDocument;
105 m_exportDir = settings.m_exportDir;
106 m_firstTimeRun = settings.m_firstTimeRun;
107 m_noUses = settings.m_noUses;
108 m_smallToolbar = settings.m_smallToolbar;
109 m_useToolTips = settings.m_useToolTips;
110 m_showWelcomeDialog = settings.m_showWelcomeDialog;
111 m_mainSashSize = settings.m_mainSashSize;
112
113 m_showTrayIcon = settings.m_showTrayIcon;
114 m_trayIconIsShown = settings.m_trayIconIsShown;
115
116 m_useEnvironmentVariable = settings.m_useEnvironmentVariable;
117 m_frameworkDir = settings.m_frameworkDir;
118 m_matchWholeWord = settings.m_matchWholeWord;
119 m_matchCase = settings.m_matchCase;
120 m_defaultFileKind = settings.m_defaultFileKind ;
121}
122
123// Do some initialisation within stApp::OnInit
124bool ctSettings::Init()
125{
126 m_lastSetupSaveDir = wxEmptyString;
127 if (m_userName.empty())
128 m_userName = wxGetUserName();
129
130 return true;
131}
132
133// Create new filename
134wxString ctSettings::GenerateFilename(const wxString& rootName)
135{
136 wxString path;
137 if (!m_lastFilename.empty())
138 path = wxPathOnly(m_lastFilename);
139 else
140 path = wxGetApp().GetAppDir();
141
142 wxString filename(path);
143 if (filename.Last() != wxFILE_SEP_PATH )
144 filename += wxFILE_SEP_PATH;
145 filename += rootName;
146
147 wxString fullFilename = filename + wxT(".wxs");
148 int i = 0;
149 wxString postfixStr;
150 while (wxFileExists(fullFilename))
151 {
152 i ++;
153 postfixStr.Printf(_T("%d"), i);
154 fullFilename = filename + postfixStr + wxT(".wxs");
155 }
156
157 m_lastFilename = fullFilename;
158 return fullFilename;
159}
160
161// Load config info
162bool ctSettings::LoadConfig()
163{
164 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
165
166 config.Read(wxT("Files/LastFile"), & m_lastFilename);
167 config.Read(wxT("Files/LastSetupSaveDir"), & m_lastSetupSaveDir);
168 config.Read(wxT("Files/ExportDir"), & m_exportDir);
169 config.Read(wxT("Files/FrameworkDir"), & m_frameworkDir);
170 config.Read(wxT("Files/UseEnvironmentVariable"), (bool*) & m_useEnvironmentVariable);
171
172 config.Read(wxT("Misc/UserName"), & m_userName);
173 config.Read(wxT("Misc/FrameStatus"), & m_frameStatus);
174 config.Read(wxT("Misc/ShowToolTips"), (bool*) & m_useToolTips);
175 config.Read(wxT("Misc/LastDocument"), & m_lastDocument);
176 config.Read(wxT("Misc/LoadLastDocument"), (bool*) & m_loadLastDocument);
177 config.Read(wxT("Misc/ShowWelcomeDialog"), (bool*) & m_showWelcomeDialog);
178 config.Read(wxT("Misc/Ran"), & m_noUses);
179 config.Read(wxT("Misc/ShowTrayIcon"), (bool*) & m_showTrayIcon);
180 config.Read(wxT("Misc/MatchWholeWord"), (bool*) & m_matchWholeWord);
181 config.Read(wxT("Misc/MatchCase"), (bool*) & m_matchCase);
182 config.Read(wxT("Misc/BuildMode"), & m_defaultFileKind );
183
184 m_noUses ++;
185
186 config.Read(wxT("Windows/ShowToolBar"), (bool*) & m_showToolBar);
187
188 m_firstTimeRun = !(config.Read(wxT("Windows/WindowX"), & m_frameSize.x));
189 config.Read(wxT("Windows/WindowY"), & m_frameSize.y);
190 config.Read(wxT("Windows/WindowWidth"), & m_frameSize.width);
191 config.Read(wxT("Windows/WindowHeight"), & m_frameSize.height);
192 config.Read(wxT("Windows/ShowSplashScreen"), (bool*) & m_showSplashScreen);
193 config.Read(wxT("Windows/SmallToolbar"), (bool*) & m_smallToolbar);
194 config.Read(wxT("Windows/MainSashSize"), & m_mainSashSize);
195
196 wxString fontSpec;
197
198 fontSpec = wxEmptyString;
199 config.Read(wxT("Style/EditWindowFont"), & fontSpec);
200 if (!fontSpec.empty())
201 m_editWindowFont = apStringToFont(fontSpec);
202
203 // Crash-resistance
204 int runningProgram = 0;
205 config.Read(wxT("Misc/RunningProgram"), & runningProgram);
206
207#ifndef __WXDEBUG__
208 // runningProgram should be zero if all is well. If 1,
209 // it crashed during a run, so we should disable the auto-load
210 // facility just in case it's trying to load a damaged file.
211 if (runningProgram != 0)
212 {
213 m_loadLastDocument = false;
214 }
215#endif
216
217 config.Write(wxT("Misc/RunningProgram"), (long) 1);
218
219 return true;
220}
221
222// Save config info
223bool ctSettings::SaveConfig()
224{
225 wxConfig config(wxGetApp().GetSettings().GetAppName(), wxT("wxWidgets"));
226
227 config.Write(wxT("Files/LastFile"), m_lastFilename);
228 config.Write(wxT("Files/LastSetupSaveDir"), m_lastSetupSaveDir);
229 config.Write(wxT("Files/ExportDir"), m_exportDir);
230 config.Write(wxT("Files/FrameworkDir"), m_frameworkDir);
231 config.Write(wxT("Files/UseEnvironmentVariable"), m_useEnvironmentVariable);
232
233 config.Write(wxT("Misc/UserName"), m_userName);
234 config.Write(wxT("Misc/FrameStatus"), (long) m_frameStatus);
235 config.Write(wxT("Misc/ShowToolTips"), m_useToolTips);
236 config.Write(wxT("Misc/LastDocument"), m_lastDocument);
237 config.Write(wxT("Misc/LoadLastDocument"), (long) m_loadLastDocument);
238 config.Write(wxT("Misc/ShowWelcomeDialog"), (long) m_showWelcomeDialog);
239 config.Write(wxT("Misc/Ran"), m_noUses);
240 config.Write(wxT("Misc/ShowTrayIcon"), (long) m_showTrayIcon);
241 config.Write(wxT("Misc/MatchWholeWord"), (long) m_matchWholeWord);
242 config.Write(wxT("Misc/MatchCase"), (long) m_matchCase);
243 config.Write(wxT("Misc/BuildMode"), m_defaultFileKind);
244
245 config.Write(wxT("Windows/ShowToolBar"), m_showToolBar);
246 config.Write(wxT("Windows/WindowX"), (long) m_frameSize.x);
247 config.Write(wxT("Windows/WindowY"), (long) m_frameSize.y);
248 config.Write(wxT("Windows/WindowWidth"), (long) m_frameSize.width);
249 config.Write(wxT("Windows/WindowHeight"), (long) m_frameSize.height);
250
251 config.Write(wxT("Windows/ShowSplashScreen"), m_showSplashScreen);
252 config.Write(wxT("Windows/SmallToolbar"), (long) m_smallToolbar);
253 config.Write(wxT("Windows/MainSashSize"), (long) m_mainSashSize);
254
255 /*
256 wxString backgroundColour(apColourToHexString(m_backgroundColour));
257 config.Write(wxT("Style/BackgroundColour"), backgroundColour);
258 */
259
260 config.Write(wxT("Style/EditWindowFont"), apFontToString(m_editWindowFont));
261
262 // Indicate that we're no longer running, so we know if the program
263 // crashed last time around.
264 config.Write(wxT("Misc/RunningProgram"), (long) 0);
265
266 {
267 config.SetPath(wxT("FileHistory/"));
268 wxGetApp().GetDocManager()->FileHistorySave(config);
269 }
270
271 return true;
272}
273
274void ctSettings::ShowSettingsDialog(const wxString& WXUNUSED(page))
275{
276 ctSettingsDialog* dialog = new ctSettingsDialog(wxGetApp().GetTopWindow());
277// if (!page.IsEmpty())
278// dialog->GetNotebook()->SetSelection(apFindNotebookPage(dialog->GetNotebook(), page));
279
280 /* int ret = */ dialog->ShowModal();
281 dialog->Destroy();
282}