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