1 /* variablesmap.h 2 * 3 * Copyright (C) 2002 The libglademm Development Team 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public 16 * License along with this library; if not, write to the Free 17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 20 #ifndef _LIBGLADEMM_VARIABLESMAP_H 21 #define _LIBGLADEMM_VARIABLESMAP_H 22 23 #include <libglademm/xml.h> 24 #include <map> 25 26 namespace Gnome 27 { 28 29 namespace Glade 30 { 31 32 /** Associates named Glade widgets with member variables. 33 * Use connect_widget() to link the widgets with variables that will contain their data. 34 * Then use transfer_widgets_to_variables() and transfer_variables_to_widgets() to get or set all of the variables at once. 35 * 36 * This is meant to be a bit like MFC's "Dialog Data Exchange and Validation". 37 * 38 * The association of widget and member varables follow this mapping: 39 * 40 * Gtk::Entry --> Glib::ustring 41 * Gtk::SpinBox --> Glib::ustring 42 * Gtk::ComboBoxEntry --> Glib::ustring 43 * Gtk::Scale --> double 44 * Gtk::Calendar --> Glib::Date 45 * Gtk::CheckBox --> bool 46 * Gtk::RadioButton --> bool 47 * 48 */ 49 class VariablesMap 50 { 51 public: 52 explicit VariablesMap(const Glib::RefPtr<Glade::Xml>& glade); 53 virtual ~VariablesMap(); 54 55 ///For ToggleButton (CheckBox and RadioButton) 56 virtual void connect_widget(const Glib::ustring& widget_name, bool& variable); 57 58 ///For Entry, ComboBoxEntry and SpinBox 59 virtual void connect_widget(const Glib::ustring& widget_name, Glib::ustring& variable); 60 61 ///For Scale (HScale and VScale) 62 virtual void connect_widget(const Glib::ustring& widget_name, double& variable); 63 64 ///For Calendar 65 virtual void connect_widget(const Glib::ustring& widget_name, Glib::Date& variable); 66 67 ///Transfer data from the widget to the variable. 68 virtual void transfer_widgets_to_variables(); 69 70 ///Transfer data from the variable to the widget. 71 virtual void transfer_variables_to_widgets(); 72 73 protected: 74 75 /** Override this to validate the data that the user enters into the widgets. 76 * The return value indicates whether the widgets' data is valid. 77 */ 78 virtual bool validate_widgets(); 79 80 virtual void transfer_one_widget(Gtk::Widget* pWidget, bool to_variable); 81 82 typedef std::map<Gtk::Widget*, void*> type_mapWidgetsToVariables; 83 type_mapWidgetsToVariables m_mapWidgetsToVariables; 84 85 Glib::RefPtr<Glade::Xml> m_refGlade; 86 }; 87 88 } /* namespace Glade */ 89 } /* namespace Gnome */ 90 91 92 93 94 #endif /* _LIBGLADEMM_VARIABLESMAP_H */ 95 96 97