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