2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995-2000 The LyX Team.
8 * =================================================
20 #include "gnome_helpers.h"
22 #include <sigc++/sigc++.h>
23 #include <libglademm/xml.h>
34 * This is a base class for Gnome dialogs. It handles all the common
35 * work that is needed for all dialogs.
37 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
40 GnomeBase(ControlButtons & c, string const & name);
45 /// Get the widget named 'name' from the xml representation.
47 T* getWidget(const string & name) const;
49 /// Get the dialog we use.
50 Gtk::Dialog * dialog();
56 /// Build the dialog. Also connects signals and prepares it for work.
57 virtual void build() = 0;
59 virtual bool validate();
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();
72 /// Loads the glade file to memory.
75 /// The glade file name
78 const string widget_name_;
79 /// The XML representation of the dialogs.
80 Glib::RefPtr<Gnome::Glade::Xml> xml_;
82 /** The dialog we work with, since it is managed by libglade, we do not
83 * need to delete it or destroy it, it will be destroyed with the rest
84 * of the libglade GladeXML structure.
86 Gtk::Dialog * dialog_;
91 T* GnomeBase::getWidget(const string & name) const
93 return dynamic_cast<T*>(xml_->get_widget(name));
97 * This class is used to provide a simple automatic casting of the controller.
98 * We chose not to make GnomeBase a template since it has some size and we
99 * have no reason to duplicate it by making it a template.
101 * Basically the FormCB<Controller> template instantiates GnomeBase and passes
102 * the parameters to it and it also adds the controller() method to give us
103 * a reference to the controller of the correct type (the type is set by the
104 * template parameter).
106 template <class Controller>
107 class FormCB : public GnomeBase {
109 FormCB(Controller & c, string const & name);
111 Controller & controller();
114 template <class Controller>
115 FormCB<Controller>::FormCB(Controller & c, string const & name)
119 template <class Controller>
121 FormCB<Controller>::controller()
123 return static_cast<Controller &>(controller_);