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