]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GnomeBase.h
Fixed compilation problems.
[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 Gtk {
26 class Button;
27 class Entry;
28 };
29
30 namespace Gnome {
31 class Dialog;
32 };
33
34 /**
35  * This is a base class for Gnome dialogs. Basically it handles all the common
36  * work that is needed for all dialogs.
37  */
38 class GnomeBase : public ViewBC<gnomeBC>, public SigC::Object {
39 public:
40         /// 
41         GnomeBase(ControlBase & c, string const & glade_file, string const & name);
42         ///
43         virtual ~GnomeBase();
44
45 protected:
46         template <class T>
47         T* getWidget(char const * name) const; 
48
49 private:
50         /// Loads the glade file to memory.
51         void loadXML() const;
52
53         /// The glade file name
54         string file_;
55         /// The widget name
56         string widget_name_;
57         /// The XML representation of the dialogs.
58         mutable GladeXML * xml_;
59 };
60
61
62 template <class T>
63 T* GnomeBase::getWidget(char const * name) const
64 {
65         if (xml_ == 0)
66                 loadXML();
67         return getWidgetPtr<T>(xml_, name);
68 }
69
70 /**
71  * This class is used to provide a simple automatic casting of the controller.
72  * We chose not to make GnomeBase a template since it has some size and we 
73  * have no reason to duplicate it by making it a template.
74  *
75  * Basically the FormCB<Controller> template instantiates GnomeBase and passes
76  * the parameters to it and it also adds the controller() method to give us
77  * a reference to the controller of the correct type (the type is set by the
78  * template parameter).
79 */
80 template <class Controller>
81 class FormCB : public GnomeBase {
82 public:
83         FormCB(Controller & c, string const & file, string const & name);
84         
85 protected:
86         Controller & controller();
87 };
88
89 template <class Controller>
90 FormCB<Controller>::FormCB(Controller & c, string const & file, string const & name)
91         : GnomeBase(c, file, name)
92 {}
93
94 template <class Controller>
95 Controller &
96 FormCB<Controller>::controller()
97 {
98         return static_cast<Controller &>(controller_);
99 }
100
101 #endif