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>
32 * This is a base class for Gnome dialogs. It handles all the common
33 * work that is needed for all dialogs.
35 class GnomeBase : public ViewBase, public SigC::Object {
38 GnomeBase(string const & name);
43 /// Get the widget named 'name' from the xml representation.
45 T* getWidget(const string & name) const;
47 /// Get the dialog we use.
48 Gtk::Dialog * dialog();
54 /// Build the dialog. Also connects signals and prepares it for work.
55 virtual void build() = 0;
57 virtual bool isValid();
59 virtual bool isVisible() const;
60 /// Default OK behaviour
61 virtual void OKClicked();
62 /// Default Cancel behaviour
63 virtual void CancelClicked();
64 /// Default Restore behaviour
65 virtual void RestoreClicked();
66 /// Default apply behaviour
67 virtual void ApplyClicked();
68 /// Default changed input behaviour
69 virtual void InputChanged();
77 /// Loads the glade file to memory.
80 /// The glade file name
83 const string widget_name_;
84 /// The XML representation of the dialogs.
85 Glib::RefPtr<Gnome::Glade::Xml> xml_;
87 /** The dialog we work with, since it is managed by libglade, we do not
88 * need to delete it or destroy it, it will be destroyed with the rest
89 * of the libglade GladeXML structure.
91 Gtk::Dialog * dialog_;
93 /// dialog title, displayed by WM.
99 T* GnomeBase::getWidget(const string & name) const
101 return dynamic_cast<T*>(xml_->get_widget(name));
105 * This class is used to provide a simple automatic casting of the controller.
106 * We chose not to make GnomeBase a template since it has some size and we
107 * have no reason to duplicate it by making it a template.
109 * Basically the GnomeCB<Controller> template instantiates GnomeBase and passes
110 * the parameters to it and it also adds the controller() method to give us
111 * a reference to the controller of the correct type (the type is set by the
112 * template parameter).
114 template <class Controller>
115 class GnomeCB : public GnomeBase {
117 GnomeCB(string const & name);
119 Controller & controller();
122 template <class Controller>
123 GnomeCB<Controller>::GnomeCB(string const & name)
127 template <class Controller>
129 GnomeCB<Controller>::controller()
131 return static_cast<Controller &>(getController());