4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
19 #include "gnome_helpers.h"
21 #include <sigc++/sigc++.h>
22 #include <libglademm/xml.h>
33 * This is a base class for Gnome dialogs. It handles all the common
34 * work that is needed for all dialogs.
36 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
39 GnomeBase(ControlButtons & c, string const & name);
44 /// Get the widget named 'name' from the xml representation.
46 T* getWidget(const string & name) const;
48 /// Get the dialog we use.
49 Gtk::Dialog * dialog();
55 /// Build the dialog. Also connects signals and prepares it for work.
56 virtual void build() = 0;
58 virtual bool validate();
59 /// Default OK behaviour
60 virtual void OKClicked();
61 /// Default Cancel behaviour
62 virtual void CancelClicked();
63 /// Default Restore behaviour
64 virtual void RestoreClicked();
65 /// Default apply behaviour
66 virtual void ApplyClicked();
67 /// Default changed input behaviour
68 virtual void InputChanged();
71 /// Loads the glade file to memory.
74 /// The glade file name
77 const string widget_name_;
78 /// The XML representation of the dialogs.
79 Glib::RefPtr<Gnome::Glade::Xml> xml_;
81 /** The dialog we work with, since it is managed by libglade, we do not
82 * need to delete it or destroy it, it will be destroyed with the rest
83 * of the libglade GladeXML structure.
85 Gtk::Dialog * dialog_;
90 T* GnomeBase::getWidget(const string & name) const
92 return dynamic_cast<T*>(xml_->get_widget(name));
96 * This class is used to provide a simple automatic casting of the controller.
97 * We chose not to make GnomeBase a template since it has some size and we
98 * have no reason to duplicate it by making it a template.
100 * Basically the GnomeCB<Controller> template instantiates GnomeBase and passes
101 * the parameters to it and it also adds the controller() method to give us
102 * a reference to the controller of the correct type (the type is set by the
103 * template parameter).
105 template <class Controller>
106 class GnomeCB : public GnomeBase {
108 GnomeCB(Controller & c, string const & name);
110 Controller & controller();
113 template <class Controller>
114 GnomeCB<Controller>::GnomeCB(Controller & c, string const & name)
118 template <class Controller>
120 GnomeCB<Controller>::controller()
122 return static_cast<Controller &>(controller_);