]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GView.C
compile fix
[lyx.git] / src / frontends / gtk / GView.C
1 /**
2  * \file gtk/GView.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 "GView.h"
22 #include "GMenubar.h"
23 #include "GMiniBuffer.h"
24
25 #include "BufferView.h"
26 #include "lyx_cb.h"
27 #include "lyxrc.h"
28 #include "lyx_main.h"
29 #include "session.h"
30 #include "lyxfunc.h"
31 #include "MenuBackend.h"
32 #include "funcrequest.h"
33
34 #include "frontends/Toolbars.h"
35 #include "frontends/WorkArea.h"
36
37 #include "support/filetools.h"
38 #include "support/convert.h"
39
40 #include <boost/bind.hpp>
41
42 #include <vector>
43
44 using std::string;
45
46 namespace lyx {
47 namespace frontend {
48
49 namespace {
50
51 void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink)
52 {
53         Gtk::PackOptions const packing =
54                 shrink ? Gtk::PACK_SHRINK : Gtk::PACK_EXPAND_WIDGET;
55         list.push_back(Gtk::Box_Helpers::Element(box, packing));
56 }
57
58 } // namespace anon
59
60
61 GView::GView(Gui & owner) : LyXView(owner)
62 {
63         // The physical store for the boxes making up the layout.
64         box_store_.push_back(BoxPtr(new Gtk::VBox));
65         box_store_.push_back(BoxPtr(new Gtk::HBox));
66         box_store_.push_back(BoxPtr(new Gtk::VBox));
67         box_store_.push_back(BoxPtr(new Gtk::HBox));
68         box_store_.push_back(BoxPtr(new Gtk::HBox));
69         box_store_.push_back(BoxPtr(new Gtk::HBox));
70
71         // Lay them out correctly.
72         add(top_box_);
73
74         Gtk::Box::BoxList & layout1 = top_box_.children();
75         add_el(layout1, *box_store_[0], true);
76         add_el(layout1, *box_store_[1], false);
77         add_el(layout1, *box_store_[2], true);
78
79         Gtk::Box::BoxList & layout2 = box_store_[1]->children();
80         add_el(layout2, *box_store_[3], true);
81         add_el(layout2, *box_store_[4], false);
82         add_el(layout2, *box_store_[5], true);
83
84         // Define accessors to the various Boxes.
85         box_map_[Top]    = box_store_[0];
86         box_map_[Bottom] = box_store_[2];
87         box_map_[Left]   = box_store_[3];
88         box_map_[Center] = box_store_[4];
89         box_map_[Right]  = box_store_[5];
90
91         // Make all Boxes visible.
92         top_box_.show_all();
93
94         // Define the components making up the window.
95         menubar_.reset(new GMenubar(this, menubackend));
96         getToolbars().init();
97         minibuffer_.reset(new GMiniBuffer(this, *controlcommand_));
98
99         focus_command_buffer.connect(
100                 boost::bind(&GMiniBuffer::editMode, minibuffer_.get()));
101         signal_focus_in_event().connect(sigc::mem_fun(*this, &GView::onFocusIn));
102         //
103         int width = 750;
104         int height = 550;
105         // first try lyxrc
106         if (lyxrc.geometry_width != 0 && lyxrc.geometry_height != 0 ) {
107                 width = lyxrc.geometry_width;
108                 height = lyxrc.geometry_height;
109         }
110         // if lyxrc returns (0,0), then use session info
111         else {
112                 string val = LyX::ref().session().loadSessionInfo("WindowWidth");
113                 if (val != "")
114                         width = convert<unsigned int>(val);
115                 val = LyX::ref().session().loadSessionInfo("WindowHeight");
116                 if (val != "")
117                         height = convert<unsigned int>(val);
118         }
119         set_default_size(width, height);
120         // Make sure the buttons are disabled if needed.
121         //updateToolbars();
122         string const iconName =
123                 support::libFileSearch("images", "lyx", "xpm");
124         if (!iconName.empty())
125                 set_icon_from_file(iconName);
126 }
127
128
129 GView::~GView()
130 {}
131
132
133 Gtk::Box & GView::getBox(Position pos)
134 {
135         return *box_map_[pos];
136 }
137
138
139 bool GView::on_delete_event(GdkEventAny * /*event*/)
140 {
141         // save windows size and position
142         Gtk::Requisition req = workArea_->size_request();
143         LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(req.width));
144         LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(req.height));
145         // trigger LFUN_LYX_QUIT instead of quit directly
146         // since LFUN_LYX_QUIT may have more cleanup stuff
147         //
148         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
149         return true;
150 }
151
152
153 bool GView::onFocusIn(GdkEventFocus * /*event*/)
154 {
155         workArea_->grab_focus();
156         return true;
157 }
158
159
160 void GView::prohibitInput() const
161 {
162         // FIXME: Why is prohibitInput const?
163         // FIXME: hideCursor is protected
164         //const_cast<GView*>(this)->workArea()->hideCursor();
165         const_cast<GView*>(this)->set_sensitive(false);
166 }
167
168
169 void GView::allowInput() const
170 {
171         const_cast<GView*>(this)->set_sensitive(true);
172 }
173
174
175 void GView::message(string const & msg)
176 {
177         minibuffer_->message(msg);
178 }
179
180
181 void GView::updateStatusBar()
182 {
183         message(getLyXFunc().viewStatusMessage());
184 }
185
186
187 void GView::setWindowTitle(string const & t, string const & /*it*/)
188 {
189         set_title(Glib::locale_to_utf8(t));
190 }
191
192
193 void GView::busy(bool yes) const
194 {
195         // FIXME: Why is busy const?
196         if (yes) {
197                 // FIXME: hideCursor is protected
198                 //const_cast<GView*>(this)->workArea()->hideCursor();
199                 Gdk::Cursor cursor(Gdk::WATCH);
200                 const_cast<GView *>(this)->get_window()->set_cursor(cursor);
201                 const_cast<GView *>(this)->set_sensitive(false);
202         } else {
203                 const_cast<GView *>(this)->get_window()->set_cursor();
204                 const_cast<GView *>(this)->set_sensitive(true);
205         }
206 }
207
208
209 void GView::clearMessage()
210 {
211         message(getLyXFunc().viewStatusMessage());
212 }
213
214
215 bool GView::hasFocus() const
216 {
217         // No real implementation needed for now
218         return true;
219 }
220
221
222 } // namespace frontend
223 } // namespace lyx