2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995-2000 The LyX Team.
8 * =================================================
22 #include <sigc++/signal_system.h>
23 #include "gnome_helpers.h"
30 * This is a base class for Gnome dialogs. It handles all the common
31 * work that is needed for all dialogs.
33 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
36 GnomeBase(ControlButtons & c, string const & name);
41 /// Get the widget named 'name' from the xml representation.
43 T* getWidget(char const * name) const;
45 /// Get the dialog we use.
46 Gnome::Dialog * dialog();
52 /// Build the dialog. Also connects signals and prepares it for work.
53 virtual void build() = 0;
55 virtual bool validate();
56 /// Default OK behaviour
57 virtual void OKClicked();
58 /// Default Cancel behaviour
59 virtual void CancelClicked();
60 /// Default Restore behaviour
61 virtual void RestoreClicked();
62 /// Default apply behaviour
63 virtual void ApplyClicked();
64 /// Default changed input behaviour
65 virtual void InputChanged();
68 /// Loads the glade file to memory.
71 /// The glade file name
74 const string widget_name_;
75 /// The XML representation of the dialogs.
76 mutable GladeXML * xml_;
78 /** The dialog we work with, since it is managed by libglade, we do not
79 * need to delete it or destroy it, it will be destroyed with the rest
80 * of the libglade GladeXML structure.
82 Gnome::Dialog * dialog_;
87 T* GnomeBase::getWidget(char const * name) const
91 return getWidgetPtr<T>(xml_, name);
95 * This class is used to provide a simple automatic casting of the controller.
96 * We chose not to make GnomeBase a template since it has some size and we
97 * have no reason to duplicate it by making it a template.
99 * Basically the FormCB<Controller> template instantiates GnomeBase and passes
100 * the parameters to it and it also adds the controller() method to give us
101 * a reference to the controller of the correct type (the type is set by the
102 * template parameter).
104 template <class Controller>
105 class FormCB : public GnomeBase {
107 FormCB(Controller & c, string const & name);
109 Controller & controller();
112 template <class Controller>
113 FormCB<Controller>::FormCB(Controller & c, string const & name)
117 template <class Controller>
119 FormCB<Controller>::controller()
121 return static_cast<Controller &>(controller_);