]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GViewBase.h
Move to gtk 2.4
[lyx.git] / src / frontends / gtk / GViewBase.h
1 // -*- C++ -*-
2 /**
3  * \file GViewBase.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Huang Ying
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef GVIEWBASE_H
13 #define GVIEWBASE_H
14
15 #include <gtkmm.h>
16 #include <libglademm.h>
17 #include <boost/scoped_ptr.hpp>
18 #include "Dialog.h"
19 #include "ButtonPolicies.h"
20 #include "GBC.h"
21
22 namespace lyx {
23 namespace frontend {
24
25 class GViewBase : public Dialog::View, public sigc::trackable {
26 public:
27         GViewBase(Dialog &, std::string const &, bool allowResize);
28         virtual ~GViewBase();
29         void setCancel(Gtk::Button * cancel);
30         void setApply(Gtk::Button * apply);
31         void setOK(Gtk::Button * ok);
32         void setRestore(Gtk::Button * restore);
33 protected:
34         // Build the dialog
35         virtual void build();
36         virtual void doBuild() = 0;
37         // Hide the dialog
38         virtual void hide();
39         // Create the dialog if necessary, update it and display it.
40         virtual void show();
41         //
42         virtual bool isVisible() const;
43         GBC & bcview();
44         void onApply();
45         void onOK();
46         void onCancel();
47         void onRestore();
48         bool onDeleteEvent(GdkEventAny *);
49 private:
50         virtual Gtk::Window * window() = 0;
51         virtual Gtk::Window const * window() const = 0;
52         bool allowResize_;
53 };
54
55
56 template <class Dialog>
57 class GViewDB : public GViewBase {
58 protected:
59         GViewDB(Dialog &, std::string const &, bool allowResize);
60         virtual const Gtk::Window * window() const;
61         virtual Gtk::Window * window();
62         boost::scoped_ptr<Dialog> dialog_;
63 };
64
65
66 template <class Dialog>
67 GViewDB<Dialog>::GViewDB(Dialog & parent, std::string const & t, bool allowResize) :
68         GViewBase(parent, t, allowResize)
69 {
70 }
71
72
73 template <class Dialog>
74 Gtk::Window * GViewDB<Dialog>::window()
75 {
76         return dialog_.get();
77 }
78
79
80 template <class Dialog>
81 const Gtk::Window * GViewDB<Dialog>::window() const
82 {
83         return dialog_.get();
84 }
85
86
87 class GViewGladeB : public GViewBase {
88 protected:
89         GViewGladeB(Dialog & parent, std::string const & t, bool allowResize);
90         virtual Gtk::Window const * window() const;
91         virtual Gtk::Window * window();
92         Glib::RefPtr<Gnome::Glade::Xml> xml_;
93 };
94
95
96 template <class Controller, class Base>
97 class GViewCB : public Base {
98 public:
99         Controller & controller();
100         Controller const & controller() const;
101 protected:
102         GViewCB(Dialog & parent, std::string const & t, bool allowResize = false);
103 };
104
105
106 template <class Controller, class Base>
107 GViewCB<Controller, Base>::GViewCB(Dialog & parent, std::string const & t,
108                                    bool allowResize) :
109         Base(parent, t, allowResize)
110 {
111 }
112
113
114 template <class Controller, class Base>
115 Controller & GViewCB<Controller, Base>::controller()
116 {
117         return static_cast<Controller &>(getController());
118 }
119
120
121 template <class Controller, class Base>
122 Controller const & GViewCB<Controller, Base>::controller() const
123 {
124         return static_cast<Controller const &>(getController());
125 }
126
127 } // namespace frontend
128 } // namespace lyx
129
130 #endif