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