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(ControlButton & c, string const & glade_file, 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();
53 /// Build the dialog. Also connects signals and prepares it for work.
54 virtual void build() = 0;
57 /// Loads the glade file to memory.
60 /// The glade file name
63 const string widget_name_;
64 /// The XML representation of the dialogs.
65 mutable GladeXML * xml_;
67 /** The dialog we work with, since it is managed by libglade, we do not
68 * need to delete it or destroy it, it will be destroyed with the rest
69 * of the libglade GladeXML structure.
71 Gnome::Dialog * dialog_;
76 T* GnomeBase::getWidget(char const * name) const
80 return getWidgetPtr<T>(xml_, name);
84 * This class is used to provide a simple automatic casting of the controller.
85 * We chose not to make GnomeBase a template since it has some size and we
86 * have no reason to duplicate it by making it a template.
88 * Basically the FormCB<Controller> template instantiates GnomeBase and passes
89 * the parameters to it and it also adds the controller() method to give us
90 * a reference to the controller of the correct type (the type is set by the
91 * template parameter).
93 template <class Controller>
94 class FormCB : public GnomeBase {
96 FormCB(Controller & c, string const & file, string const & name);
98 Controller & controller();
101 template <class Controller>
102 FormCB<Controller>::FormCB(Controller & c, string const & file, string const & name)
103 : GnomeBase(c, file, name)
106 template <class Controller>
108 FormCB<Controller>::controller()
110 return static_cast<Controller &>(controller_);