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