]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GnomeBase.h
fix problem with nroff detection, remove dead code with old floats, bogus message...
[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 & glade_file, 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         
53         /// Build the dialog. Also connects signals and prepares it for work.
54         virtual void build() = 0;
55
56 private:
57         /// Loads the glade file to memory.
58         void loadXML() const;
59
60         /// The glade file name
61         const string file_;
62         /// The widget name
63         const string widget_name_;
64         /// The XML representation of the dialogs.
65         mutable GladeXML * xml_;
66
67         /** The dialog we work with, since it is managed by libglade, we do not
68          *  need to delete it or destroy it, it will be destroyed with the rest
69          *  of the libglade GladeXML structure.
70          */
71         Gnome::Dialog * dialog_;
72 };
73
74
75 template <class T>
76 T* GnomeBase::getWidget(char const * name) const
77 {
78         if (xml_ == 0)
79                 loadXML();
80         return getWidgetPtr<T>(xml_, name);
81 }
82
83 /**
84  * This class is used to provide a simple automatic casting of the controller.
85  * We chose not to make GnomeBase a template since it has some size and we 
86  * have no reason to duplicate it by making it a template.
87  *
88  * Basically the FormCB<Controller> template instantiates GnomeBase and passes
89  * the parameters to it and it also adds the controller() method to give us
90  * a reference to the controller of the correct type (the type is set by the
91  * template parameter).
92 */
93 template <class Controller>
94 class FormCB : public GnomeBase {
95 public:
96         FormCB(Controller & c, string const & file, string const & name);
97 protected:
98         Controller & controller();
99 };
100
101 template <class Controller>
102 FormCB<Controller>::FormCB(Controller & c, string const & file, string const & name)
103         : GnomeBase(c, file, name)
104 {}
105
106 template <class Controller>
107 Controller &
108 FormCB<Controller>::controller()
109 {
110         return static_cast<Controller &>(controller_);
111 }
112
113 #endif