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