]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GViewBase.C
205bb8246ce3c61305a01dd0bae1962f314c3252
[lyx.git] / src / frontends / gtk / GViewBase.C
1 /**
2  * \file GViewBase.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GViewBase.h"
22 #include "support/filetools.h"
23
24 using lyx::docstring;
25
26 using std::string;
27
28 namespace lyx {
29 namespace frontend {
30
31 GViewBase::GViewBase(Dialog & parent, docstring const & t, bool allowResize) :
32         Dialog::View(parent, t), allowResize_(allowResize)
33 {
34 }
35
36
37 GViewBase::~GViewBase()
38 {
39 }
40
41
42 void GViewBase::hide()
43 {
44         window()->hide();
45 }
46
47
48 void GViewBase::build()
49 {
50         doBuild();
51         string const iconName =
52                 support::libFileSearch("images", "lyx", "xpm");
53         if (!iconName.empty())
54                 window()->set_icon_from_file(iconName);
55         window()->signal_delete_event().connect(
56                 sigc::mem_fun(*this, &GViewBase::onDeleteEvent));
57         window()->set_title(Glib::locale_to_utf8(getTitle()));
58 }
59
60
61 void GViewBase::show()
62 {
63         if (!window()) {
64                 build();
65         }
66
67         update();
68
69         if (dialog().controller().exitEarly())
70                 return;
71
72         window()->show();
73 }
74
75
76 bool GViewBase::isVisible() const
77 {
78         return window() && window()->is_visible();
79 }
80
81
82 GBC & GViewBase::bcview()
83 {
84         return static_cast<GBC &>(dialog().bc().view());
85 }
86
87
88 void GViewBase::setCancel(Gtk::Button * cancel)
89 {
90         bcview().setCancel(cancel);
91         cancel->signal_clicked().connect(
92                 sigc::mem_fun(*this, &GViewBase::onCancel));
93 }
94
95
96 void GViewBase::setApply(Gtk::Button * apply)
97 {
98         bcview().setApply(apply);
99         apply->signal_clicked().connect(
100                 sigc::mem_fun(*this, &GViewBase::onApply));
101 }
102
103
104 void GViewBase::setOK(Gtk::Button * ok)
105 {
106         bcview().setOK(ok);
107         ok->signal_clicked().connect(
108                 sigc::mem_fun(*this, &GViewBase::onOK));
109 }
110
111
112 void GViewBase::setRestore(Gtk::Button * restore)
113 {
114         bcview().setRestore(restore);
115         restore->signal_clicked().connect(
116                 sigc::mem_fun(*this, &GViewBase::onRestore));
117 }
118
119
120 void GViewBase::setTitle(lyx::docstring const & title)
121 {
122         Dialog::View::setTitle(title);
123         window()->set_title(title);
124 }
125
126
127 bool GViewBase::readOnly() const
128 {
129         return kernel().isBufferReadonly();
130 }
131
132
133 void GViewBase::onApply()
134 {
135         dialog().ApplyButton();
136 }
137
138
139 void GViewBase::onOK()
140 {
141         dialog().OKButton();
142 }
143
144
145 void GViewBase::onCancel()
146 {
147         dialog().CancelButton();
148 }
149
150
151 void GViewBase::onRestore()
152 {
153         dialog().RestoreButton();
154 }
155
156
157 bool GViewBase::onDeleteEvent(GdkEventAny *)
158 {
159         dialog().CancelButton();
160         return false;
161 }
162
163
164 GViewGladeB::GViewGladeB(Dialog & parent, string const & t, bool allowResize) :
165         GViewBase(parent, t, allowResize)
166 {
167 }
168
169
170 Gtk::Window * GViewGladeB::window()
171 {
172         Gtk::Window * win;
173         if (!xml_)
174                 return 0;
175         xml_->get_widget("dialog", win);
176         return win;
177 }
178
179
180 Gtk::Window const * GViewGladeB::window() const
181 {
182         Gtk::Window * win;
183         if (!xml_)
184                 return 0;
185         xml_->get_widget("dialog", win);
186         return win;
187 }
188
189 } // namespace frontend
190 } // namespace lyx