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