]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GnomeBase.h
259d32bc10596e85d3aac1f45b165e84bdf09dc3
[lyx.git] / src / frontends / gnome / GnomeBase.h
1 // -*- C++ -*-
2 /**
3  * \file GnomeBase.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Baruch Even
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef GnomeBase_H
13 #define GnomeBase_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "gnome_helpers.h"
20
21 #include <sigc++/sigc++.h>
22 #include <libglademm/xml.h>
23
24 #include "ViewBase.h"
25 #include "gnomeBC.h"
26
27
28 namespace Gtk {
29         class Dialog;
30 };
31
32 /**
33  * This is a base class for Gnome dialogs. It handles all the common
34  * work that is needed for all dialogs.
35  */
36 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
37 public:
38         ///
39         GnomeBase(ControlButtons & c,  string const & name);
40         ///
41         virtual ~GnomeBase();
42
43 protected:
44         /// Get the widget named 'name' from the xml representation.
45         template <class T>
46         T* getWidget(const string & name) const;
47
48         /// Get the dialog we use.
49         Gtk::Dialog * dialog();
50
51         /// Show the dialog.
52         void show();
53         /// Hide the dialog.
54         void hide();
55         /// Build the dialog. Also connects signals and prepares it for work.
56         virtual void build() = 0;
57         /// Dialog is valid
58         virtual bool validate();
59         /// Default OK behaviour
60         virtual void OKClicked();
61         /// Default Cancel behaviour
62         virtual void CancelClicked();
63         /// Default Restore behaviour
64         virtual void RestoreClicked();
65         /// Default apply behaviour
66         virtual void ApplyClicked();
67         /// Default changed input behaviour
68         virtual void InputChanged();
69
70 private:
71         /// Loads the glade file to memory.
72         void loadXML();
73
74         /// The glade file name
75         const string file_;
76         /// The widget name
77         const string widget_name_;
78         /// The XML representation of the dialogs.
79         Glib::RefPtr<Gnome::Glade::Xml>  xml_;
80
81         /** The dialog we work with, since it is managed by libglade, we do not
82          *  need to delete it or destroy it, it will be destroyed with the rest
83          *  of the libglade GladeXML structure.
84          */
85         Gtk::Dialog * dialog_;
86 };
87
88
89 template <class T>
90 T* GnomeBase::getWidget(const string & name) const
91 {
92         return dynamic_cast<T*>(xml_->get_widget(name));
93 }
94
95 /**
96  * This class is used to provide a simple automatic casting of the controller.
97  * We chose not to make GnomeBase a template since it has some size and we
98  * have no reason to duplicate it by making it a template.
99  *
100  * Basically the GnomeCB<Controller> template instantiates GnomeBase and passes
101  * the parameters to it and it also adds the controller() method to give us
102  * a reference to the controller of the correct type (the type is set by the
103  * template parameter).
104 */
105 template <class Controller>
106 class GnomeCB : public GnomeBase {
107 public:
108         GnomeCB(Controller & c, string const & name);
109 protected:
110         Controller & controller();
111 };
112
113 template <class Controller>
114 GnomeCB<Controller>::GnomeCB(Controller & c,  string const & name)
115         : GnomeBase(c, name)
116 {}
117
118 template <class Controller>
119 Controller &
120 GnomeCB<Controller>::controller()
121 {
122         return static_cast<Controller &>(controller_);
123 }
124
125 #endif