]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GnomeBase.h
A lean, clean and working start to the new, improved gnome frontend.
[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 "ViewBase.h"
21 #include "gnomeBC.h"
22 #include <sigc++/signal_system.h>
23 #include "gnome_helpers.h"
24
25 namespace Gnome {
26 class Dialog;
27 };
28
29 /**
30  * This is a base class for Gnome dialogs. It handles all the common
31  * work that is needed for all dialogs.
32  */
33 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
34 public:
35         ///
36         GnomeBase(ControlButtons & c,  string const & name);
37         ///
38         virtual ~GnomeBase();
39
40 protected:
41         /// Get the widget named 'name' from the xml representation.
42         template <class T>
43         T* getWidget(char const * name) const;
44
45         /// Get the dialog we use.
46         Gnome::Dialog * dialog();
47
48         /// Show the dialog.
49         void show();
50         /// Hide the dialog.
51         void hide();
52         /// Build the dialog. Also connects signals and prepares it for work.
53         virtual void build() = 0;
54         /// Dialog is valid
55         virtual bool validate();
56         /// Default OK behaviour
57         virtual void OKClicked();
58         /// Default Cancel behaviour
59         virtual void CancelClicked();
60         /// Default Restore behaviour
61         virtual void RestoreClicked();
62         /// Default apply behaviour
63         virtual void ApplyClicked();
64         /// Default changed input behaviour
65         virtual void InputChanged();
66
67 private:
68         /// Loads the glade file to memory.
69         void loadXML() const;
70
71         /// The glade file name
72         const string file_;
73         /// The widget name
74         const string widget_name_;
75         /// The XML representation of the dialogs.
76         mutable GladeXML * xml_;
77
78         /** The dialog we work with, since it is managed by libglade, we do not
79          *  need to delete it or destroy it, it will be destroyed with the rest
80          *  of the libglade GladeXML structure.
81          */
82         Gnome::Dialog * dialog_;
83 };
84
85
86 template <class T>
87 T* GnomeBase::getWidget(char const * name) const
88 {
89         if (xml_ == 0)
90                 loadXML();
91         return getWidgetPtr<T>(xml_, name);
92 }
93
94 /**
95  * This class is used to provide a simple automatic casting of the controller.
96  * We chose not to make GnomeBase a template since it has some size and we
97  * have no reason to duplicate it by making it a template.
98  *
99  * Basically the FormCB<Controller> template instantiates GnomeBase and passes
100  * the parameters to it and it also adds the controller() method to give us
101  * a reference to the controller of the correct type (the type is set by the
102  * template parameter).
103 */
104 template <class Controller>
105 class FormCB : public GnomeBase {
106 public:
107         FormCB(Controller & c, string const & name);
108 protected:
109         Controller & controller();
110 };
111
112 template <class Controller>
113 FormCB<Controller>::FormCB(Controller & c,  string const & name)
114         : GnomeBase(c, name)
115 {}
116
117 template <class Controller>
118 Controller &
119 FormCB<Controller>::controller()
120 {
121         return static_cast<Controller &>(controller_);
122 }
123
124 #endif