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