]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GView.C
Display accelerator (binding) labels in menus.
[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         top_box_.show_all();
80
81         // Define the components making up the window.
82         menubar_.reset(new GMenubar(this, menubackend));
83         getToolbars().init();
84         bufferview_.reset(new BufferView(this, 300, 300));
85         minibuffer_.reset(new GMiniBuffer(this, *controlcommand_));
86
87         focus_command_buffer.connect(
88                 boost::bind(&GMiniBuffer::editMode, minibuffer_.get()));
89         view_state_changed.connect(boost::bind(&GView::showViewState, this));
90         signal_focus_in_event().connect(sigc::mem_fun(*this, &GView::onFocusIn));
91         set_default_size(500, 550);
92         // Make sure the buttons are disabled if needed.
93         updateToolbars();
94         string const iconName =
95                 support::LibFileSearch("images", "lyx", "xpm");
96         if (!iconName.empty())
97                 set_icon_from_file(iconName);
98 }
99
100
101 GView::~GView()
102 {}
103
104
105 Gtk::Box & GView::getBox(Position pos)
106 {
107         return *box_map_[pos];
108 }
109
110
111 bool GView::on_delete_event(GdkEventAny * /*event*/)
112 {
113         QuitLyX();
114         return true;
115 }
116
117
118 bool GView::onFocusIn(GdkEventFocus * /*event*/)
119 {
120         workArea_->grab_focus();
121         return true;
122 }
123
124
125 void GView::prohibitInput() const
126 {
127         view()->hideCursor();
128         const_cast<GView*>(this)->set_sensitive(false);
129 }
130
131
132 void GView::allowInput() const
133 {
134         const_cast<GView*>(this)->set_sensitive(true);
135 }
136
137
138 void GView::message(string const & msg)
139 {
140         minibuffer_->message(msg);
141 }
142
143
144 void GView::showViewState()
145 {
146         message(getLyXFunc().viewStatusMessage());
147 }
148
149
150 void GView::setWindowTitle(string const & t, string const & /*it*/)
151 {
152         set_title(Glib::locale_to_utf8(t));
153 }
154
155
156 void GView::busy(bool yes) const
157 {
158         if (yes ) {
159                 view()->hideCursor();
160                 Gdk::Cursor cursor(Gdk::WATCH);
161                 const_cast<GView *>(this)->get_window()->set_cursor(cursor);
162                 const_cast<GView *>(this)->set_sensitive(false);
163         } else {
164                 const_cast<GView *>(this)->get_window()->set_cursor();
165                 const_cast<GView *>(this)->set_sensitive(true);
166         }
167 }
168
169
170 void GView::clearMessage()
171 {
172         message(getLyXFunc().viewStatusMessage());
173 }
174
175 } // namespace frontend
176 } // namespace lyx