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