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.
16 #include "gnome_helpers.h"
18 #include <sigc++/sigc++.h>
19 #include <libglademm/xml.h>
29 * This is a base class for Gnome dialogs. It handles all the common
30 * work that is needed for all dialogs.
32 class GView : public ViewBase, public SigC::Object {
35 GView(string const & name);
40 /// Get the widget named 'name' from the xml representation.
42 T* getWidget(const string & name) const;
44 /// Get the dialog we use.
45 Gtk::Dialog * dialog();
51 /// Build the dialog. Also connects signals and prepares it for work.
52 virtual void build() = 0;
54 virtual bool isValid();
56 virtual bool isVisible() const;
57 /// Default OK behaviour
58 virtual void OKClicked();
59 /// Default Cancel behaviour
60 virtual void CancelClicked();
61 /// Default Restore behaviour
62 virtual void RestoreClicked();
63 /// Default apply behaviour
64 virtual void ApplyClicked();
65 /// Default changed input behaviour
66 virtual void InputChanged();
74 /// Loads the glade file to memory.
77 /// The glade file name
80 const string widget_name_;
81 /// The XML representation of the dialogs.
82 Glib::RefPtr<Gnome::Glade::Xml> xml_;
84 /** The dialog we work with, since it is managed by libglade, we do not
85 * need to delete it or destroy it, it will be destroyed with the rest
86 * of the libglade GladeXML structure.
88 Gtk::Dialog * dialog_;
90 /// dialog title, displayed by WM.
96 T* GView::getWidget(const string & name) const
98 return dynamic_cast<T*>(xml_->get_widget(name));
102 * This class is used to provide a simple automatic casting of the controller.
103 * We chose not to make GView a template since it has some size and we
104 * have no reason to duplicate it by making it a template.
106 * Basically the GControlledView<Controller> template instantiates GView and
107 * passes the parameters to it and it also adds the controller() method to
108 * give us a reference to the controller of the correct type (the type is
109 * set by the template parameter).
111 template <class Controller>
112 class GControlledView : public GView {
114 GControlledView(string const & name);
116 Controller & controller();
119 template <class Controller>
120 GControlledView<Controller>::GControlledView(string const & name)
124 template <class Controller>
126 GControlledView<Controller>::controller()
128 return static_cast<Controller &>(getController());