]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GnomeBase.h
handle some tmpl files in a more sane way
[lyx.git] / src / frontends / gnome / GnomeBase.h
1 // -*- C++ -*-
2 /* This file is part of
3  * =================================================
4  *
5  *          LyX, The Document Processor
6  *          Copyright 1995-2000 The LyX Team.
7  *
8  * =================================================
9  *
10  * \author Baruch Even
11  **/
12
13 #ifndef GnomeBase_H
14 #define GnomeBase_H
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "gnome_helpers.h"
21
22 #include <sigc++/sigc++.h>
23 #include <libglademm/xml.h>
24
25 #include "ViewBase.h"
26 #include "gnomeBC.h"
27
28
29 namespace Gtk {
30         class Dialog;
31 };
32
33 /**
34  * This is a base class for Gnome dialogs. It handles all the common
35  * work that is needed for all dialogs.
36  */
37 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
38 public:
39         ///
40         GnomeBase(ControlButtons & c,  string const & name);
41         ///
42         virtual ~GnomeBase();
43
44 protected:
45         /// Get the widget named 'name' from the xml representation.
46         template <class T>
47         T* getWidget(const string & name) const;
48
49         /// Get the dialog we use.
50         Gtk::Dialog * dialog();
51
52         /// Show the dialog.
53         void show();
54         /// Hide the dialog.
55         void hide();
56         /// Build the dialog. Also connects signals and prepares it for work.
57         virtual void build() = 0;
58         /// Dialog is valid
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();
70
71 private:
72         /// Loads the glade file to memory.
73         void loadXML();
74
75         /// The glade file name
76         const string file_;
77         /// The widget name
78         const string widget_name_;
79         /// The XML representation of the dialogs.
80         Glib::RefPtr<Gnome::Glade::Xml>  xml_;
81
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.
85          */
86         Gtk::Dialog * dialog_;
87 };
88
89
90 template <class T>
91 T* GnomeBase::getWidget(const string & name) const
92 {
93         return dynamic_cast<T*>(xml_->get_widget(name));
94 }
95
96 /**
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.
100  *
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).
105 */
106 template <class Controller>
107 class FormCB : public GnomeBase {
108 public:
109         FormCB(Controller & c, string const & name);
110 protected:
111         Controller & controller();
112 };
113
114 template <class Controller>
115 FormCB<Controller>::FormCB(Controller & c,  string const & name)
116         : GnomeBase(c, name)
117 {}
118
119 template <class Controller>
120 Controller &
121 FormCB<Controller>::controller()
122 {
123         return static_cast<Controller &>(controller_);
124 }
125
126 #endif