00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(INCLUDED_PREFERENCES_H)
00023 #define INCLUDED_PREFERENCES_H
00024
00025 #include <libxml/parser.h>
00026 #include "../dialog.h"
00027 #include <list>
00028 #include <map>
00029
00030 void Widget_connectToggleDependency (GtkWidget* self, GtkWidget* toggleButton);
00031
00032 class PreferencesPage
00033 {
00034 Dialog& m_dialog;
00035 GtkWidget* m_vbox;
00036 public:
00037 PreferencesPage (Dialog& dialog, GtkWidget* vbox) :
00038 m_dialog(dialog), m_vbox(vbox)
00039 {
00040 }
00041 GtkWidget* appendCheckBox (const char* name, const char* flag, bool& data)
00042 {
00043 return m_dialog.addCheckBox(m_vbox, name, flag, data);
00044 }
00045 GtkWidget* appendCheckBox (const char* name, const char* flag, const BoolImportCallback& importCallback,
00046 const BoolExportCallback& exportCallback)
00047 {
00048 return m_dialog.addCheckBox(m_vbox, name, flag, importCallback, exportCallback);
00049 }
00050 void appendCombo (const char* name, StringArrayRange values, const IntImportCallback& importCallback,
00051 const IntExportCallback& exportCallback)
00052 {
00053 m_dialog.addCombo(m_vbox, name, values, importCallback, exportCallback);
00054 }
00055 void appendCombo (const char* name, int& data, StringArrayRange values)
00056 {
00057 m_dialog.addCombo(m_vbox, name, data, values);
00058 }
00059 void appendSlider (const char* name, int& data, gboolean draw_value, const char* low, const char* high,
00060 double value, double lower, double upper, double step_increment, double page_increment,
00061 double page_size)
00062 {
00063 m_dialog.addSlider(m_vbox, name, data, draw_value, low, high, value, lower, upper, step_increment,
00064 page_increment, page_size);
00065 }
00066 void appendRadio (const char* name, StringArrayRange names, const IntImportCallback& importCallback,
00067 const IntExportCallback& exportCallback)
00068 {
00069 m_dialog.addRadio(m_vbox, name, names, importCallback, exportCallback);
00070 }
00071 void appendRadio (const char* name, int& data, StringArrayRange names)
00072 {
00073 m_dialog.addRadio(m_vbox, name, data, names);
00074 }
00075 void appendRadioIcons (const char* name, StringArrayRange icons, const IntImportCallback& importCallback,
00076 const IntExportCallback& exportCallback)
00077 {
00078 m_dialog.addRadioIcons(m_vbox, name, icons, importCallback, exportCallback);
00079 }
00080 void appendRadioIcons (const char* name, int& data, StringArrayRange icons)
00081 {
00082 m_dialog.addRadioIcons(m_vbox, name, data, icons);
00083 }
00084 GtkWidget* appendEntry (const char* name, const IntImportCallback& importCallback,
00085 const IntExportCallback& exportCallback)
00086 {
00087 return m_dialog.addIntEntry(m_vbox, name, importCallback, exportCallback);
00088 }
00089 GtkWidget* appendEntry (const char* name, int& data)
00090 {
00091 return m_dialog.addEntry(m_vbox, name, data);
00092 }
00093 GtkWidget* appendEntry (const char* name, const SizeImportCallback& importCallback,
00094 const SizeExportCallback& exportCallback)
00095 {
00096 return m_dialog.addSizeEntry(m_vbox, name, importCallback, exportCallback);
00097 }
00098 GtkWidget* appendEntry (const char* name, std::size_t& data)
00099 {
00100 return m_dialog.addEntry(m_vbox, name, data);
00101 }
00102 GtkWidget* appendEntry (const char* name, const FloatImportCallback& importCallback,
00103 const FloatExportCallback& exportCallback)
00104 {
00105 return m_dialog.addFloatEntry(m_vbox, name, importCallback, exportCallback);
00106 }
00107 GtkWidget* appendEntry (const char* name, float& data)
00108 {
00109 return m_dialog.addEntry(m_vbox, name, data);
00110 }
00111 GtkWidget* appendPathEntry (const char* name, bool browse_directory,
00112 const StringImportCallback& importCallback, const StringExportCallback& exportCallback)
00113 {
00114 return m_dialog.addPathEntry(m_vbox, name, browse_directory, importCallback, exportCallback);
00115 }
00116 GtkWidget* appendPathEntry (const char* name, std::string& data, bool directory)
00117 {
00118 return m_dialog.addPathEntry(m_vbox, name, data, directory);
00119 }
00120 GtkWidget* appendSpinner (const char* name, int& data, double value, double lower, double upper)
00121 {
00122 return m_dialog.addSpinner(m_vbox, name, data, value, lower, upper);
00123 }
00124 GtkWidget* appendSpinner (const char* name, double value, double lower, double upper,
00125 const IntImportCallback& importCallback, const IntExportCallback& exportCallback)
00126 {
00127 return m_dialog.addSpinner(m_vbox, name, value, lower, upper, importCallback, exportCallback);
00128 }
00129 GtkWidget* appendSpinner (const char* name, double value, double lower, double upper,
00130 const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback)
00131 {
00132 return m_dialog.addSpinner(m_vbox, name, value, lower, upper, importCallback, exportCallback);
00133 }
00134 };
00135
00136 typedef Callback1<PreferencesPage&> PreferencesPageCallback;
00137
00138 class PreferenceGroup
00139 {
00140 public:
00141 virtual ~PreferenceGroup ()
00142 {
00143 }
00144 virtual PreferencesPage createPage (const char* treeName, const char* frameName) = 0;
00145 };
00146
00147 typedef Callback1<PreferenceGroup&> PreferenceGroupCallback;
00148
00149 void PreferencesDialog_addInterfacePreferences (const PreferencesPageCallback& callback);
00150 void PreferencesDialog_addInterfacePage (const PreferenceGroupCallback& callback);
00151 void PreferencesDialog_addSettingsPreferences (const PreferencesPageCallback& callback);
00152 void PreferencesDialog_addSettingsPage (const PreferenceGroupCallback& callback);
00153
00154 void PreferencesDialog_restartRequired (const std::string& staticName);
00155
00156 template<typename Value>
00157 class LatchedValue
00158 {
00159 public:
00160 Value m_value;
00161 Value m_latched;
00162 const std::string m_description;
00163
00164 LatchedValue (Value value, const std::string& description) :
00165 m_latched(value), m_description(description)
00166 {
00167 }
00168 void useLatched ()
00169 {
00170 m_value = m_latched;
00171 }
00172 void import (Value value)
00173 {
00174 m_latched = value;
00175 if (m_latched != m_value) {
00176 PreferencesDialog_restartRequired(m_description);
00177 }
00178 }
00179 };
00180
00181 typedef LatchedValue<bool> LatchedBool;
00182 typedef MemberCaller1<LatchedBool, bool, &LatchedBool::import> LatchedBoolImportCaller;
00183
00184 typedef LatchedValue<int> LatchedInt;
00185 typedef MemberCaller1<LatchedInt, int, &LatchedInt::import> LatchedIntImportCaller;
00186
00197 class CGameDescription
00198 {
00199 private:
00200 typedef std::map<std::string, std::string> GameDescription;
00201
00202 public:
00203 std::string mGameFile;
00204 const std::string emptyString;
00205 GameDescription m_gameDescription;
00206
00207 const std::string& getKeyValue (const std::string& key) const
00208 {
00209 GameDescription::const_iterator i = m_gameDescription.find(key);
00210 if (i != m_gameDescription.end()) {
00211 return (*i).second;
00212 }
00213 return CGameDescription::emptyString;
00214 }
00215 const std::string& getRequiredKeyValue (const std::string& key) const
00216 {
00217 GameDescription::const_iterator i = m_gameDescription.find(key);
00218 if (i != m_gameDescription.end()) {
00219 return (*i).second;
00220 }
00221 ERROR_MESSAGE("game attribute " << makeQuoted(key) << " not found in " << makeQuoted(mGameFile));
00222 return CGameDescription::emptyString;
00223 }
00224
00225 CGameDescription (xmlDocPtr pDoc, const std::string &GameFile);
00226 };
00227
00228 extern CGameDescription *g_pGameDescription;
00229
00230 typedef struct _GtkWidget GtkWidget;
00231 class PrefsDlg;
00232
00233 class PreferencesPage;
00234
00235 class StringOutputStream;
00236
00240 class CGameDialog: public Dialog
00241 {
00242 protected:
00243
00244 mutable int m_nComboSelect;
00245
00246 public:
00247
00259 bool m_bForceLogConsole;
00262 CGameDialog () :
00263 m_bForceLogConsole(false)
00264 {
00265 }
00266 virtual ~CGameDialog ();
00267
00268 void Init ();
00269
00273 void Reset ();
00274
00279 GtkWindow* BuildDialog ();
00280
00288 void CreateGlobalFrame (PreferencesPage& page);
00289
00290 private:
00291
00295 CGameDescription *GameDescriptionForComboItem ();
00296 };
00297
00301 extern CGameDialog g_GamesDialog;
00302
00303 class texdef_t;
00304
00305 class PrefsDlg: public Dialog
00306 {
00307 public:
00308
00309 GtkWidget *m_notebook;
00310
00311 virtual ~PrefsDlg ()
00312 {
00313 }
00314
00315
00316 void Init ();
00317
00319 void showPrefPage (GtkWidget* prefpage);
00320
00321 protected:
00322
00324 GtkWindow* BuildDialog ();
00325 void PostModal (EMessageBoxReturn code);
00326 };
00327
00328 extern PrefsDlg g_Preferences;
00329
00330 struct preferences_globals_t
00331 {
00332
00333 bool disable_ini;
00334 preferences_globals_t () :
00335 disable_ini(false)
00336 {
00337 }
00338 };
00339 extern preferences_globals_t g_preferences_globals;
00340
00341 typedef struct _GtkWindow GtkWindow;
00342 void PreferencesDialog_constructWindow (GtkWindow* main_window);
00343 void PreferencesDialog_destroyWindow ();
00344
00345 void PreferencesDialog_showDialog ();
00346
00347 void Preferences_Init ();
00348
00349 void Preferences_Load ();
00350 void Preferences_Save ();
00351
00352 void Preferences_Reset ();
00353
00354 #endif