]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GViewBase.h
gtk-patch_2004_2_9.new
[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         void setCancel(Gtk::Button * cancel);
28         void setApply(Gtk::Button * apply);
29         void setOK(Gtk::Button * ok);
30         void setRestore(Gtk::Button * restore);
31 protected:
32         // Build the dialog
33         virtual void build();
34         virtual void doBuild() = 0;
35         // Hide the dialog
36         virtual void hide();
37         // Create the dialog if necessary, update it and display it.
38         virtual void show();
39         //
40         virtual bool isVisible() const;
41         GBC & bcview();
42         void onApply();
43         void onOK();
44         void onCancel();
45         void onRestore();
46         bool onDeleteEvent(GdkEventAny *);
47 private:
48         virtual Gtk::Window * window() = 0;
49         virtual Gtk::Window const * window() const = 0;
50         bool allowResize_;
51 };
52
53 template <class Dialog>
54 class GViewDB : public GViewBase
55 {
56 protected:
57         GViewDB(Dialog &, std::string const &, bool allowResize);
58         virtual const Gtk::Window * window() const;
59         virtual Gtk::Window * window();
60         boost::scoped_ptr<Dialog> dialog_;
61 };
62
63
64 template <class Dialog>
65 GViewDB<Dialog>::GViewDB(Dialog & parent, std::string const & t, bool allowResize) :
66         GViewBase(parent, t, allowResize)
67 {
68 }
69
70
71 template <class Dialog>
72 Gtk::Window * GViewDB<Dialog>::window()
73 {
74         return dialog_.get();
75 }
76
77
78 template <class Dialog>
79 const Gtk::Window * GViewDB<Dialog>::window() const
80 {
81         return dialog_.get();
82 }
83
84
85 class GViewGladeB : public GViewBase
86 {
87 protected:
88         GViewGladeB(Dialog & parent, std::string const & t, bool allowResize);
89         virtual const Gtk::Window * window() const;
90         virtual Gtk::Window * window();
91         Glib::RefPtr<Gnome::Glade::Xml> xml_;
92 };
93
94
95 template <class Controller, class Base>
96 class GViewCB : public Base
97 {
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 #endif