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