]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GView.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[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 #include <gtkmm.h>
13
14 #include "GView.h"
15 #include "GMenubar.h"
16 #include "GMiniBuffer.h"
17
18 #include "BufferView.h"
19 #include "lyx_cb.h"
20 #include "lyxfunc.h"
21 #include "MenuBackend.h"
22
23 #include "frontends/Toolbars.h"
24
25 #include "support/filetools.h"
26
27 #include <boost/bind.hpp>
28
29 #include <vector>
30
31 using std::string;
32
33 namespace lyx {
34 namespace frontend {
35
36 namespace {
37
38 void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink)
39 {
40         Gtk::PackOptions const packing =
41                 shrink ? Gtk::PACK_SHRINK : Gtk::PACK_EXPAND_WIDGET;
42         list.push_back(Gtk::Box_Helpers::Element(box, packing));
43 }
44
45 } // namespace anon
46
47
48 GView::GView()
49 {
50         // The physical store for the boxes making up the layout.
51         box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::VBox));
52         box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
53         box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::VBox));
54         box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
55         box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
56         box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
57
58         // Lay them out correctly.
59         add(top_box_);
60
61         Gtk::Box::BoxList & layout1 = top_box_.children();
62         add_el(layout1, *box_store_[0], true);
63         add_el(layout1, *box_store_[1], true);
64         add_el(layout1, *box_store_[2], true);
65
66         Gtk::Box::BoxList & layout2 = box_store_[1]->children();
67         add_el(layout2, *box_store_[3], true);
68         add_el(layout2, *box_store_[4], false);
69         add_el(layout2, *box_store_[5], true);
70
71         // Define accessors to the various Boxes.
72         box_map_[Top]    = box_store_[0];
73         box_map_[Bottom] = box_store_[2];
74         box_map_[Left]   = box_store_[3];
75         box_map_[Center] = box_store_[4];
76         box_map_[Right]  = box_store_[5];
77
78         // Make all Boxes visible.
79         top_box_.show();
80         BoxStore::iterator it = box_store_.begin();
81         BoxStore::iterator const end = box_store_.end();
82         for (; it != end; ++it)
83                 (*it)->show();
84
85         // Define the components making up the window.
86         menubar_.reset(new GMenubar(this, menubackend));
87         getToolbars().init();
88         bufferview_.reset(new BufferView(this, 300, 300));
89         minibuffer_.reset(new GMiniBuffer(this, *controlcommand_));
90
91         focus_command_buffer.connect(
92                 boost::bind(&GMiniBuffer::editMode, minibuffer_.get()));
93         view_state_changed.connect(boost::bind(&GView::showViewState, this));
94         signal_focus_in_event().connect(SigC::slot(*this, &GView::onFocusIn));
95         set_default_size(500, 550);
96         // Make sure the buttons are disabled if needed.
97         updateToolbars();
98         string const iconName =
99                 support::LibFileSearch("images", "lyx", "xpm");
100         if (!iconName.empty())
101                 set_icon_from_file(iconName);
102 }
103
104
105 GView::~GView()
106 {}
107
108
109 Gtk::Box & GView::getBox(Position pos)
110 {
111         return *box_map_[pos];
112 }
113
114
115 bool GView::on_delete_event(GdkEventAny * /*event*/)
116 {
117         QuitLyX();
118         return true;
119 }
120
121
122 bool GView::onFocusIn(GdkEventFocus * /*event*/)
123 {
124         workArea_->grab_focus();
125         return true;
126 }
127
128
129 void GView::prohibitInput() const
130 {
131         view()->hideCursor();
132         const_cast<GView*>(this)->set_sensitive(false);
133 }
134
135
136 void GView::allowInput() const
137 {
138         const_cast<GView*>(this)->set_sensitive(true);
139 }
140
141
142 void GView::message(string const & msg)
143 {
144         minibuffer_->message(msg);
145 }
146
147
148 void GView::showViewState()
149 {
150         message(getLyXFunc().viewStatusMessage());
151 }
152
153
154 void GView::setWindowTitle(string const & t, string const & /*it*/)
155 {
156         set_title(Glib::locale_to_utf8(t));
157 }
158
159
160 void GView::busy(bool yes) const
161 {
162         if (yes ) {
163                 view()->hideCursor();
164                 Gdk::Cursor cursor(Gdk::WATCH);
165                 const_cast<GView *>(this)->get_window()->set_cursor(cursor);
166                 const_cast<GView *>(this)->set_sensitive(false);
167         } else {
168                 const_cast<GView *>(this)->get_window()->set_cursor();
169                 const_cast<GView *>(this)->set_sensitive(true);
170         }
171 }
172
173
174 void GView::clearMessage()
175 {
176         message(getLyXFunc().viewStatusMessage());
177 }
178
179 } // namespace frontend
180 } // namespace lyx