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