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