3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
18 #include "bufferparams.h"
20 #include "funcrequest.h"
21 #include "FuncStatus.h"
31 GView::Position getPosition(ToolbarBackend::Flags const & flags)
33 if (flags & ToolbarBackend::TOP)
35 if (flags & ToolbarBackend::BOTTOM)
37 if (flags & ToolbarBackend::LEFT)
39 if (flags & ToolbarBackend::RIGHT)
45 LyXTextClass const & getTextClass(LyXView const & lv)
47 return lv.buffer()->params().getLyXTextClass();
51 void comboClear(Gtk::Combo & combo)
53 std::vector<Glib::ustring> strings;
54 strings.push_back("");
55 combo.set_popdown_strings(strings);
59 bool comboIsEmpty(Gtk::Combo & combo)
61 std::vector<Glib::ustring> strings = combo.get_popdown_strings();
62 return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
65 char const * gToolData = "tool_data";
70 GLayoutBox::GLayoutBox(LyXView & owner,
71 Gtk::Toolbar & toolbar,
72 FuncRequest const & func)
76 combo_.set_value_in_list();
77 combo_.get_entry()->set_editable(false);
78 combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
79 combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
82 combo_.get_entry()->signal_changed().connect(
84 &GLayoutBox::selected));
87 toolbar.tools().push_back(Gtk::Toolbar_Helpers::Element(combo_));
88 toolbar.tools().back().get_widget()->set_data(
90 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
94 void GLayoutBox::set(string const & layout)
96 LyXTextClass const & tc = getTextClass(owner_);
99 combo_.get_entry()->set_text(tc[layout]->name());
104 void GLayoutBox::update()
106 LyXTextClass const & tc = getTextClass(owner_);
108 std::vector<Glib::ustring> strings;
110 LyXTextClass::const_iterator it = tc.begin();
111 LyXTextClass::const_iterator const end = tc.end();
112 for (; it != end; ++it)
113 if ((*it)->obsoleted_by().empty())
115 Glib::locale_to_utf8((*it)->name()));
117 combo_.set_popdown_strings(strings);
122 void GLayoutBox::clear()
130 void GLayoutBox::open()
132 combo_.get_list()->activate();
136 void GLayoutBox::setEnabled(bool sensitive)
138 combo_.set_sensitive(sensitive);
142 void GLayoutBox::selected()
147 string layoutGuiName = combo_.get_entry()->get_text();
148 // we get two signal, one of it is empty and useless
149 if (layoutGuiName.empty())
151 LyXTextClass const & tc = getTextClass(owner_);
153 LyXTextClass::const_iterator it = tc.begin();
154 LyXTextClass::const_iterator const end = tc.end();
155 for (; it != end; ++it) {
156 string const & name = (*it)->name();
157 if (name == layoutGuiName) {
158 owner_.getLyXFunc().dispatch(
159 FuncRequest(LFUN_LAYOUT, name),
164 lyxerr << "ERROR (GLayoutBox::selected): layout not found! name: "
165 << layoutGuiName << std::endl;
168 } // namespace frontend
172 Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
175 using lyx::frontend::GToolbar;
176 return Toolbars::ToolbarPtr(new GToolbar(tbb, owner));
182 GToolbar::GToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
183 : owner_(dynamic_cast<GView &>(owner))
185 ToolbarBackend::item_iterator it = tbb.items.begin();
186 ToolbarBackend::item_iterator end = tbb.items.end();
187 for (; it != end; ++it)
188 add(it->first, it->second);
190 toolbar_.set_toolbar_style(Gtk::TOOLBAR_ICONS);
192 GView::Position const position = getPosition(tbb.flags);
194 if (position == GView::Left || position == GView::Right)
195 toolbar_.set_orientation(Gtk::ORIENTATION_VERTICAL);
197 owner_.getBox(position).children().push_back(
198 Gtk::Box_Helpers::Element(toolbar_, Gtk::PACK_SHRINK));
202 void GToolbar::add(FuncRequest const & func, string const & tooltip)
204 switch (func.action) {
205 case ToolbarBackend::SEPARATOR:
206 toolbar_.tools().push_back(Gtk::Toolbar_Helpers::Space());
208 case ToolbarBackend::MINIBUFFER:
209 // Not supported yet.
211 case ToolbarBackend::LAYOUTS:
213 layout_.reset(new GLayoutBox(owner_, toolbar_, func));
217 Glib::ustring xpmName =
218 Glib::locale_to_utf8(toolbarbackend.getIcon(func));
219 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
220 if (xpmName.size() == 0) {
221 toolbar_.tools().push_back(
222 Gtk::Toolbar_Helpers::ButtonElem(
224 SigC::bind(SigC::slot(*this, >oolbar::clicked),
229 Gtk::manage(new Gtk::Image(xpmName));
231 toolbar_.tools().push_back(
232 Gtk::Toolbar_Helpers::ButtonElem(
235 SigC::bind(SigC::slot(*this, >oolbar::clicked),
239 toolbar_.tools().back().get_content()->set_data(
241 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
247 void GToolbar::clicked(FuncRequest func)
249 owner_.getLyXFunc().dispatch(func, true);
253 void GToolbar::hide(bool)
259 void GToolbar::show(bool)
265 void GToolbar::update()
267 Gtk::Toolbar_Helpers::ToolList::iterator it =
268 toolbar_.tools().begin();
269 Gtk::Toolbar_Helpers::ToolList::iterator const end =
270 toolbar_.tools().end();
272 for (; it != end; ++it) {
273 Gtk::Widget * widget;
274 switch (it->get_type()) {
275 case Gtk::TOOLBAR_CHILD_WIDGET:
276 widget = it->get_widget();
278 case Gtk::TOOLBAR_CHILD_SPACE:
281 widget = it->get_content();
284 FuncRequest const & func = *reinterpret_cast<FuncRequest *>(
285 widget->get_data(gToolData));
287 if (func.action == int(ToolbarBackend::LAYOUTS))
290 FuncStatus const status = owner_.getLyXFunc().getStatus(func);
291 bool sensitive = status.enabled();
292 widget->set_sensitive(sensitive);
293 if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
295 if (status.onoff(true))
296 static_cast<Gtk::Button*>(widget)->
297 set_relief(Gtk::RELIEF_NORMAL);
298 if (status.onoff(false))
299 static_cast<Gtk::Button*>(widget)->
300 set_relief(Gtk::RELIEF_NONE);
304 } // namespace frontend