35 #include <GG/adobe/adam.hpp>
37 #include <boost/signals.hpp>
45 class RadioButtonGroup;
51 template <
class AdobeValueType,
class GGValueType>
52 GGValueType AnyCast(
const adobe::any_regular_t& any);
54 template <
class AdobeValueType,
class GGValueType>
55 adobe::any_regular_t MakeAny(GGValueType x);
58 struct AdamCellGlueBase {};
68 struct AdamCellGlue<TextControl, adobe::string_t, std::string> :
69 public AdamCellGlueBase
71 AdamCellGlue(TextControl& text, adobe::sheet_t& sheet, adobe::name_t cell);
74 typedef AdamCellGlue<TextControl, adobe::string_t, std::string> ThisType;
76 void SheetChanged(
const adobe::any_regular_t &any);
82 struct AdamCellGlue<Button, adobe::string_t, std::string> :
83 public AdamCellGlueBase
85 AdamCellGlue(Button& button, adobe::sheet_t& sheet, adobe::name_t cell);
88 typedef AdamCellGlue<Button, adobe::string_t, std::string> ThisType;
90 void SheetChanged(
const adobe::any_regular_t &any);
94 adobe::sheet_t* m_sheet;
99 struct AdamCellGlue<StateButton, bool, bool> :
100 public AdamCellGlueBase
102 AdamCellGlue(StateButton& state_button, adobe::sheet_t& sheet, adobe::name_t cell);
105 typedef AdamCellGlue<StateButton, bool, bool> ThisType;
107 void SheetChanged(
const adobe::any_regular_t &any);
109 void ControlChanged(
bool checked);
111 StateButton* m_state_button;
112 adobe::sheet_t* m_sheet;
113 adobe::name_t m_cell;
117 struct AdamCellGlue<RadioButtonGroup, double, std::size_t> :
118 public AdamCellGlueBase
120 AdamCellGlue(RadioButtonGroup& radio_button_group, adobe::sheet_t& sheet, adobe::name_t cell);
123 typedef AdamCellGlue<RadioButtonGroup, double, std::size_t> ThisType;
125 void SheetChanged(
const adobe::any_regular_t &any);
127 void ControlChanged(std::size_t button);
129 RadioButtonGroup* m_radio_button_group;
130 adobe::sheet_t* m_sheet;
131 adobe::name_t m_cell;
134 template <
class AdamValueType,
class T>
135 struct AdamCellGlue<Edit, AdamValueType, T> :
136 public AdamCellGlueBase
138 AdamCellGlue(Edit& edit, adobe::sheet_t& sheet, adobe::name_t cell);
141 typedef AdamCellGlue<Edit, AdamValueType, T> ThisType;
143 void SheetChanged(
const adobe::any_regular_t &any);
145 void ControlChanged(
const std::string& str);
148 adobe::sheet_t* m_sheet;
149 adobe::name_t m_cell;
153 struct AdamCellGlue<MultiEdit, adobe::string_t, std::string> :
154 public AdamCellGlueBase
156 AdamCellGlue(MultiEdit& multi_edit, adobe::sheet_t& sheet, adobe::name_t cell);
159 typedef AdamCellGlue<MultiEdit, adobe::string_t, std::string> ThisType;
161 void SheetChanged(
const adobe::any_regular_t &any);
163 void ControlChanged(
const std::string& str);
165 MultiEdit* m_multi_edit;
166 adobe::sheet_t* m_sheet;
167 adobe::name_t m_cell;
171 struct AdamCellGlue<Spin<T>, double, T> :
172 public AdamCellGlueBase
174 AdamCellGlue(Spin<T>& spin, adobe::sheet_t& sheet, adobe::name_t cell);
177 typedef AdamCellGlue<Spin<T>, double, T> ThisType;
179 void SheetChanged(
const adobe::any_regular_t &any);
181 void ControlChanged(T t);
184 adobe::sheet_t* m_sheet;
185 adobe::name_t m_cell;
189 struct AdamCellGlue<DropDownList, double, std::size_t> :
190 public AdamCellGlueBase
192 AdamCellGlue(DropDownList& drop_list, adobe::sheet_t& sheet, adobe::name_t cell);
195 typedef AdamCellGlue<DropDownList, double, std::size_t> ThisType;
197 void SheetChanged(
const adobe::any_regular_t &any);
199 void ControlChanged(DropDownList::iterator it);
201 DropDownList* m_drop_list;
202 adobe::sheet_t* m_sheet;
203 adobe::name_t m_cell;
207 struct AdamCellGlue<Slider<int>, double, int> :
208 public AdamCellGlueBase
210 AdamCellGlue(Slider<int>& slider, adobe::sheet_t& sheet, adobe::name_t cell);
213 typedef AdamCellGlue<Slider<int>, double,
int> ThisType;
215 void SheetChanged(
const adobe::any_regular_t &any);
217 void ControlChanged(
int tab_posn,
int min,
int max);
219 Slider<int>* m_slider;
220 adobe::sheet_t* m_sheet;
221 adobe::name_t m_cell;
226 AdamSheetGlue(
const std::string& str);
227 AdamSheetGlue(std::istream& stream);
229 void SetCell(adobe::name_t cell,
const adobe::any_regular_t& value);
230 void SetCells(
const adobe::dictionary_t& dictionary);
237 void BindCell(ControlType& control, adobe::name_t cell);
239 adobe::any_regular_t Result();
242 void Init(std::istream& stream);
244 adobe::sheet_t m_sheet;
245 std::vector<boost::shared_ptr<AdamCellGlueBase> > m_cells;
252 template <
class AdobeValueType,
class GGValueType>
253 GGValueType AnyCast(
const adobe::any_regular_t& any)
254 {
return static_cast<GGValueType
>(any.cast<AdobeValueType>()); }
256 template <
class AdobeValueType,
class GGValueType>
257 adobe::any_regular_t MakeAny(GGValueType x)
258 {
return adobe::any_regular_t(static_cast<AdobeValueType>(x)); }
264 template <
class AdamValueType,
class T>
265 AdamCellGlue<Edit, AdamValueType, T>::AdamCellGlue(
267 adobe::sheet_t& sheet,
268 adobe::name_t cell) :
273 m_sheet->monitor_value(m_cell, boost::bind(&ThisType::SheetChanged,
this, _1));
274 m_sheet->monitor_enabled(m_cell, 0, 0, boost::bind(&ThisType::Enable,
this, _1));
275 m_edit->EditedSignal.connect(boost::bind(&ThisType::ControlChanged,
this, _1));
278 template <
class AdamValueType,
class T>
279 void AdamCellGlue<Edit, AdamValueType, T>::SheetChanged(
const adobe::any_regular_t &any)
280 { *m_edit << detail::AnyCast<AdamValueType, T>(any); }
282 template <
class AdamValueType,
class T>
283 void AdamCellGlue<Edit, AdamValueType, T>::Enable(
bool b)
284 { m_edit->Disable(!b); }
286 template <
class AdamValueType,
class T>
287 void AdamCellGlue<Edit, AdamValueType, T>::ControlChanged(
const std::string& str)
290 T x = boost::lexical_cast<T>(str);
291 m_sheet->set(m_cell, detail::MakeAny<AdamValueType, T>(x));
293 }
catch (
const boost::bad_lexical_cast&) {}
300 AdamCellGlue<Spin<T>, double, T>::AdamCellGlue(
302 adobe::sheet_t& sheet,
303 adobe::name_t cell) :
308 m_sheet->monitor_value(m_cell, boost::bind(&ThisType::SheetChanged,
this, _1));
309 m_sheet->monitor_enabled(m_cell, 0, 0, boost::bind(&ThisType::Enable,
this, _1));
310 m_spin->ValueChangedSignal.connect(boost::bind(&ThisType::ControlChanged,
this, _1));
314 void AdamCellGlue<Spin<T>, double, T>::SheetChanged(
const adobe::any_regular_t &any)
315 { m_spin->SetValue(detail::AnyCast<double, T>(any)); }
318 void AdamCellGlue<Spin<T>, double, T>::Enable(
bool b)
319 { m_spin->Disable(!b); }
322 void AdamCellGlue<Spin<T>, double, T>::ControlChanged(T t)
324 m_sheet->set(m_cell, detail::MakeAny<double, T>(t));