]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GView.C
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[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
36 #include "support/filetools.h"
37 #include "support/convert.h"
38
39 #include <boost/bind.hpp>
40
41 #include <vector>
42
43 using std::string;
44
45 namespace lyx {
46 namespace frontend {
47
48 namespace {
49
50 void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink)
51 {
52         Gtk::PackOptions const packing =
53                 shrink ? Gtk::PACK_SHRINK : Gtk::PACK_EXPAND_WIDGET;
54         list.push_back(Gtk::Box_Helpers::Element(box, packing));
55 }
56
57 } // namespace anon
58
59
60 GView::GView() : frontend_(*this)
61 {
62         // The physical store for the boxes making up the layout.
63         box_store_.push_back(BoxPtr(new Gtk::VBox));
64         box_store_.push_back(BoxPtr(new Gtk::HBox));
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::HBox));
68         box_store_.push_back(BoxPtr(new Gtk::HBox));
69
70         // Lay them out correctly.
71         add(top_box_);
72
73         Gtk::Box::BoxList & layout1 = top_box_.children();
74         add_el(layout1, *box_store_[0], true);
75         add_el(layout1, *box_store_[1], false);
76         add_el(layout1, *box_store_[2], true);
77
78         Gtk::Box::BoxList & layout2 = box_store_[1]->children();
79         add_el(layout2, *box_store_[3], true);
80         add_el(layout2, *box_store_[4], false);
81         add_el(layout2, *box_store_[5], true);
82
83         // Define accessors to the various Boxes.
84         box_map_[Top]    = box_store_[0];
85         box_map_[Bottom] = box_store_[2];
86         box_map_[Left]   = box_store_[3];
87         box_map_[Center] = box_store_[4];
88         box_map_[Right]  = box_store_[5];
89
90         // Make all Boxes visible.
91         top_box_.show_all();
92
93         // Define the components making up the window.
94         menubar_.reset(new GMenubar(this, menubackend));
95         getToolbars().init();
96         bufferview_.reset(new BufferView(this, 300, 300));
97         minibuffer_.reset(new GMiniBuffer(this, *controlcommand_));
98
99         focus_command_buffer.connect(
100                 boost::bind(&GMiniBuffer::editMode, minibuffer_.get()));
101         view_state_changed.connect(boost::bind(&GView::showViewState, this));
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 Gtk::Box & GView::getBox(Position pos)
135 {
136         return *box_map_[pos];
137 }
138
139
140 bool GView::on_delete_event(GdkEventAny * /*event*/)
141 {
142         // save windows size and position
143         Gtk::Requisition req = workArea_->size_request();
144         LyX::ref().session().saveSessionInfo("WindowWidth", convert<string>(req.width));
145         LyX::ref().session().saveSessionInfo("WindowHeight", convert<string>(req.height));
146         // trigger LFUN_LYX_QUIT instead of quit directly
147         // since LFUN_LYX_QUIT may have more cleanup stuff
148         //
149         getLyXFunc().dispatch(FuncRequest(LFUN_LYX_QUIT));
150         return true;
151 }
152
153
154 bool GView::onFocusIn(GdkEventFocus * /*event*/)
155 {
156         workArea_->grab_focus();
157         return true;
158 }
159
160
161 void GView::prohibitInput() const
162 {
163         view()->hideCursor();
164         const_cast<GView*>(this)->set_sensitive(false);
165 }
166
167
168 void GView::allowInput() const
169 {
170         const_cast<GView*>(this)->set_sensitive(true);
171 }
172
173
174 void GView::message(string const & msg)
175 {
176         minibuffer_->message(msg);
177 }
178
179
180 void GView::showViewState()
181 {
182         message(getLyXFunc().viewStatusMessage());
183 }
184
185
186 void GView::setWindowTitle(string const & t, string const & /*it*/)
187 {
188         set_title(Glib::locale_to_utf8(t));
189 }
190
191
192 void GView::busy(bool yes) const
193 {
194         if (yes ) {
195                 view()->hideCursor();
196                 Gdk::Cursor cursor(Gdk::WATCH);
197                 const_cast<GView *>(this)->get_window()->set_cursor(cursor);
198                 const_cast<GView *>(this)->set_sensitive(false);
199         } else {
200                 const_cast<GView *>(this)->get_window()->set_cursor();
201                 const_cast<GView *>(this)->set_sensitive(true);
202         }
203 }
204
205
206 void GView::clearMessage()
207 {
208         message(getLyXFunc().viewStatusMessage());
209 }
210
211
212 bool GView::hasFocus() const
213 {
214         // No real implementation needed for now
215         return true;
216 }
217
218
219 } // namespace frontend
220 } // namespace lyx