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_DIALOG_H)
00023 #define INCLUDED_DIALOG_H
00024
00025 #include <list>
00026
00027 #include "gtkutil/dialog.h"
00028 #include "generic/callback.h"
00029 #include "string/string.h"
00030
00031 template<typename Environment, typename FirstArgument, void(*func) (Environment&, FirstArgument)>
00032 class ReferenceCaller1;
00033
00034 inline void BoolImport (bool& self, bool value)
00035 {
00036 self = value;
00037 }
00038 typedef ReferenceCaller1<bool, bool, BoolImport> BoolImportCaller;
00039
00040 inline void BoolExport (bool& self, const BoolImportCallback& importCallback)
00041 {
00042 importCallback(self);
00043 }
00044 typedef ReferenceCaller1<bool, const BoolImportCallback&, BoolExport> BoolExportCaller;
00045
00046 inline void IntImport (int& self, int value)
00047 {
00048 self = value;
00049 }
00050 typedef ReferenceCaller1<int, int, IntImport> IntImportCaller;
00051
00052 inline void IntExport (int& self, const IntImportCallback& importCallback)
00053 {
00054 importCallback(self);
00055 }
00056 typedef ReferenceCaller1<int, const IntImportCallback&, IntExport> IntExportCaller;
00057
00058 inline void SizeImport (std::size_t& self, std::size_t value)
00059 {
00060 self = value;
00061 }
00062 typedef ReferenceCaller1<std::size_t, std::size_t, SizeImport> SizeImportCaller;
00063
00064 inline void SizeExport (std::size_t& self, const SizeImportCallback& importCallback)
00065 {
00066 importCallback(self);
00067 }
00068 typedef ReferenceCaller1<std::size_t, const SizeImportCallback&, SizeExport> SizeExportCaller;
00069
00070 inline void FloatImport (float& self, float value)
00071 {
00072 self = value;
00073 }
00074 typedef ReferenceCaller1<float, float, FloatImport> FloatImportCaller;
00075
00076 inline void FloatExport (float& self, const FloatImportCallback& importCallback)
00077 {
00078 importCallback(self);
00079 }
00080 typedef ReferenceCaller1<float, const FloatImportCallback&, FloatExport> FloatExportCaller;
00081
00082 inline void StringImport (std::string& self, const char* value)
00083 {
00084 self = value;
00085 }
00086 typedef ReferenceCaller1<std::string, const char*, StringImport> StringImportCaller;
00087 inline void StringExport (std::string& self, const StringImportCallback& importCallback)
00088 {
00089 importCallback(self.c_str());
00090 }
00091 typedef ReferenceCaller1<std::string, const StringImportCallback&, StringExport> StringExportCaller;
00092
00093 struct DLG_DATA
00094 {
00095 virtual ~DLG_DATA ()
00096 {
00097 }
00098 virtual void importData () const = 0;
00099 virtual void exportData () const = 0;
00100 };
00101
00102 typedef struct _GtkWindow GtkWindow;
00103 typedef struct _GtkToggleButton GtkToggleButton;
00104 typedef struct _GtkRadioButton GtkRadioButton;
00105 typedef struct _GtkSpinButton GtkSpinButton;
00106 typedef struct _GtkComboBox GtkComboBox;
00107 typedef struct _GtkEntry GtkEntry;
00108 typedef struct _GtkAdjustment GtkAdjustment;
00109
00110 template<typename FirstArgument>
00111 class CallbackDialogData;
00112
00113 typedef std::list<DLG_DATA*> DialogDataList;
00114
00115 class Dialog
00116 {
00117 GtkWindow* m_window;
00118 DialogDataList m_data;
00119 public:
00120 ModalDialog m_modal;
00121 GtkWindow* m_parent;
00122
00123 Dialog ();
00124 virtual ~Dialog ();
00125
00130 EMessageBoxReturn DoModal ();
00131 void EndModal (EMessageBoxReturn code);
00132 virtual GtkWindow* BuildDialog () = 0;
00133 virtual void exportData ();
00134 virtual void importData ();
00135 virtual void PreModal ()
00136 {
00137 }
00138 virtual void PostModal (EMessageBoxReturn code)
00139 {
00140 }
00141 virtual void ShowDlg ();
00142 virtual void HideDlg ();
00143 void Create ();
00144 void Destroy ();
00145 GtkWindow* GetWidget ()
00146 {
00147 return m_window;
00148 }
00149 const GtkWindow* GetWidget () const
00150 {
00151 return m_window;
00152 }
00153
00154 GtkWidget* addCheckBox (GtkWidget* vbox, const char* name, const char* flag,
00155 const BoolImportCallback& importCallback, const BoolExportCallback& exportCallback);
00156 GtkWidget* addCheckBox (GtkWidget* vbox, const char* name, const char* flag, bool& data);
00157 void addCombo (GtkWidget* vbox, const char* name, StringArrayRange values,
00158 const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
00159 void addCombo (GtkWidget* vbox, const char* name, int& data, StringArrayRange values);
00160 void addSlider (GtkWidget* vbox, const char* name, int& data, gboolean draw_value, const char* low,
00161 const char* high, double value, double lower, double upper, double step_increment,
00162 double page_increment, double page_size);
00163 void addRadio (GtkWidget* vbox, const char* name, StringArrayRange names,
00164 const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
00165 void addRadio (GtkWidget* vbox, const char* name, int& data, StringArrayRange names);
00166 void addRadioIcons (GtkWidget* vbox, const char* name, StringArrayRange icons,
00167 const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
00168 void addRadioIcons (GtkWidget* vbox, const char* name, int& data, StringArrayRange icons);
00169 GtkWidget* addIntEntry (GtkWidget* vbox, const char* name, const IntImportCallback& importCallback,
00170 const IntExportCallback& exportCallback);
00171 GtkWidget* addEntry (GtkWidget* vbox, const char* name, int& data)
00172 {
00173 return addIntEntry(vbox, name, IntImportCaller(data), IntExportCaller(data));
00174 }
00175 GtkWidget* addSizeEntry (GtkWidget* vbox, const char* name, const SizeImportCallback& importCallback,
00176 const SizeExportCallback& exportCallback);
00177 GtkWidget* addEntry (GtkWidget* vbox, const char* name, std::size_t& data)
00178 {
00179 return addSizeEntry(vbox, name, SizeImportCaller(data), SizeExportCaller(data));
00180 }
00181 GtkWidget* addFloatEntry (GtkWidget* vbox, const char* name, const FloatImportCallback& importCallback,
00182 const FloatExportCallback& exportCallback);
00183 GtkWidget* addEntry (GtkWidget* vbox, const char* name, float& data)
00184 {
00185 return addFloatEntry(vbox, name, FloatImportCaller(data), FloatExportCaller(data));
00186 }
00187 GtkWidget* addPathEntry (GtkWidget* vbox, const char* name, bool browse_directory,
00188 const StringImportCallback& importCallback, const StringExportCallback& exportCallback);
00189 GtkWidget* addPathEntry (GtkWidget* vbox, const char* name, std::string& data, bool directory);
00190 GtkWidget* addSpinner (GtkWidget* vbox, const char* name, int& data, double value, double lower, double upper);
00191 GtkWidget* addSpinner (GtkWidget* vbox, const char* name, double value, double lower, double upper,
00192 const IntImportCallback& importCallback, const IntExportCallback& exportCallback);
00193 GtkWidget* addSpinner (GtkWidget* vbox, const char* name, double value, double lower, double upper,
00194 const FloatImportCallback& importCallback, const FloatExportCallback& exportCallback);
00195
00196 protected:
00197
00198 void AddBoolToggleData (GtkToggleButton& object, const BoolImportCallback& importCallback,
00199 const BoolExportCallback& exportCallback);
00200 void AddIntRadioData (GtkRadioButton& object, const IntImportCallback& importCallback,
00201 const IntExportCallback& exportCallback);
00202 void AddTextEntryData (GtkEntry& object, const StringImportCallback& importCallback,
00203 const StringExportCallback& exportCallback);
00204 void AddIntEntryData (GtkEntry& object, const IntImportCallback& importCallback,
00205 const IntExportCallback& exportCallback);
00206 void AddSizeEntryData (GtkEntry& object, const SizeImportCallback& importCallback,
00207 const SizeExportCallback& exportCallback);
00208 void AddFloatEntryData (GtkEntry& object, const FloatImportCallback& importCallback,
00209 const FloatExportCallback& exportCallback);
00210 void AddFloatSpinnerData (GtkSpinButton& object, const FloatImportCallback& importCallback,
00211 const FloatExportCallback& exportCallback);
00212 void AddIntSpinnerData (GtkSpinButton& object, const IntImportCallback& importCallback,
00213 const IntExportCallback& exportCallback);
00214 void AddIntAdjustmentData (GtkAdjustment& object, const IntImportCallback& importCallback,
00215 const IntExportCallback& exportCallback);
00216 void AddIntComboData (GtkComboBox& object, const IntImportCallback& importCallback,
00217 const IntExportCallback& exportCallback);
00218
00219 void AddDialogData (GtkToggleButton& object, bool& data);
00220 void AddDialogData (GtkRadioButton& object, int& data);
00221 void AddDialogData (GtkEntry& object, std::string& data);
00222 void AddDialogData (GtkEntry& object, int& data);
00223 void AddDialogData (GtkEntry& object, std::size_t& data);
00224 void AddDialogData (GtkEntry& object, float& data);
00225 void AddDialogData (GtkSpinButton& object, float& data);
00226 void AddDialogData (GtkSpinButton& object, int& data);
00227 void AddDialogData (GtkAdjustment& object, int& data);
00228 void AddDialogData (GtkComboBox& object, int& data);
00229 };
00230
00231 #endif