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