]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GnomeBase.h
applying Martin Craig's gnome patch. Upgrading to gtkmm-2.0+ from the 1.3 developmen...
[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 namespace Gtk {
28         class Dialog;
29 };
30
31 /**
32  * This is a base class for Gnome dialogs. It handles all the common
33  * work that is needed for all dialogs.
34  */
35 class GnomeBase : public ViewBase, public SigC::Object {
36 public:
37         ///
38         GnomeBase(string const & name);
39         ///
40         virtual ~GnomeBase();
41
42 protected:
43         /// Get the widget named 'name' from the xml representation.
44         template <class T>
45         T* getWidget(const string & name) const;
46
47         /// Get the dialog we use.
48         Gtk::Dialog * dialog();
49
50         /// Show the dialog.
51         void show();
52         /// Hide the dialog.
53         void hide();
54         /// Build the dialog. Also connects signals and prepares it for work.
55         virtual void build() = 0;
56         /// Dialog is valid
57         virtual bool isValid();
58         /// dialog is visible
59         virtual bool isVisible() const;
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         ///
72         gnomeBC & bc();
73
74         /// are we updating ?
75         bool updating_;
76 private:
77         /// Loads the glade file to memory.
78         void loadXML();
79
80         /// The glade file name
81         const string file_;
82         /// The widget name
83         const string widget_name_;
84         /// The XML representation of the dialogs.
85         Glib::RefPtr<Gnome::Glade::Xml>  xml_;
86
87         /** The dialog we work with, since it is managed by libglade, we do not
88          *  need to delete it or destroy it, it will be destroyed with the rest
89          *  of the libglade GladeXML structure.
90          */
91         Gtk::Dialog * dialog_;
92
93         /// dialog title, displayed by WM.
94         string title_;
95 };
96
97
98 template <class T>
99 T* GnomeBase::getWidget(const string & name) const
100 {
101         return dynamic_cast<T*>(xml_->get_widget(name));
102 }
103
104 /**
105  * This class is used to provide a simple automatic casting of the controller.
106  * We chose not to make GnomeBase a template since it has some size and we
107  * have no reason to duplicate it by making it a template.
108  *
109  * Basically the GnomeCB<Controller> template instantiates GnomeBase and passes
110  * the parameters to it and it also adds the controller() method to give us
111  * a reference to the controller of the correct type (the type is set by the
112  * template parameter).
113 */
114 template <class Controller>
115 class GnomeCB : public GnomeBase {
116 public:
117         GnomeCB(string const & name);
118 protected:
119         Controller & controller();
120 };
121
122 template <class Controller>
123 GnomeCB<Controller>::GnomeCB(string const & name)
124         : GnomeBase(name)
125 {}
126
127 template <class Controller>
128 Controller &
129 GnomeCB<Controller>::controller()
130 {
131         return static_cast<Controller &>(getController());
132 }
133
134 #endif