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