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"
29 GView::Position getPosition(ToolbarBackend::Flags const & flags)
31 if (flags & ToolbarBackend::TOP)
33 if (flags & ToolbarBackend::BOTTOM)
35 if (flags & ToolbarBackend::LEFT)
37 if (flags & ToolbarBackend::RIGHT)
43 LyXTextClass const & getTextClass(LyXView const & lv)
45 return lv.buffer()->params().getLyXTextClass();
49 void comboClear(Gtk::Combo & combo)
51 std::vector<Glib::ustring> strings;
52 strings.push_back("");
53 combo.set_popdown_strings(strings);
57 bool comboIsEmpty(Gtk::Combo & combo)
59 std::vector<Glib::ustring> strings = combo.get_popdown_strings();
60 return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
63 char const * gToolData = "tool_data";
68 GLayoutBox::GLayoutBox(LyXView & owner,
69 Gtk::Toolbar & toolbar,
70 FuncRequest const & func)
74 combo_.set_value_in_list();
75 combo_.get_entry()->set_editable(false);
76 combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
77 combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
80 combo_.get_entry()->signal_changed().connect(
82 &GLayoutBox::selected));
85 toolbar.tools().push_back(Gtk::Toolbar_Helpers::Element(combo_));
86 toolbar.tools().back().get_widget()->set_data(
88 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
92 void GLayoutBox::set(string const & layout)
94 LyXTextClass const & tc = getTextClass(owner_);
97 combo_.get_entry()->set_text(tc[layout]->name());
102 void GLayoutBox::update()
104 LyXTextClass const & tc = getTextClass(owner_);
106 std::vector<Glib::ustring> strings;
108 LyXTextClass::const_iterator it = tc.begin();
109 LyXTextClass::const_iterator const end = tc.end();
110 for (; it != end; ++it)
111 if ((*it)->obsoleted_by().empty())
113 Glib::locale_to_utf8((*it)->name()));
115 combo_.set_popdown_strings(strings);
120 void GLayoutBox::clear()
128 void GLayoutBox::open()
130 combo_.get_list()->activate();
134 void GLayoutBox::setEnabled(bool sensitive)
136 combo_.set_sensitive(sensitive);
140 void GLayoutBox::selected()
145 string layoutGuiName = combo_.get_entry()->get_text();
146 // we get two signal, one of it is empty and useless
147 if (layoutGuiName.empty())
149 LyXTextClass const & tc = getTextClass(owner_);
151 LyXTextClass::const_iterator it = tc.begin();
152 LyXTextClass::const_iterator const end = tc.end();
153 for (; it != end; ++it) {
154 string const & name = (*it)->name();
155 if (name == layoutGuiName) {
156 owner_.getLyXFunc().dispatch(
157 FuncRequest(LFUN_LAYOUT, name),
162 lyxerr << "ERROR (GLayoutBox::selected): layout not found! name: "
163 << layoutGuiName << std::endl;
167 Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
170 return Toolbars::ToolbarPtr(new GToolbar(tbb, owner));
174 GToolbar::GToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
175 : owner_(dynamic_cast<GView &>(owner))
177 ToolbarBackend::item_iterator it = tbb.items.begin();
178 ToolbarBackend::item_iterator end = tbb.items.end();
179 for (; it != end; ++it)
180 add(it->first, it->second);
182 toolbar_.set_toolbar_style(Gtk::TOOLBAR_ICONS);
184 GView::Position const position = getPosition(tbb.flags);
186 if (position == GView::Left || position == GView::Right)
187 toolbar_.set_orientation(Gtk::ORIENTATION_VERTICAL);
189 owner_.getBox(position).children().push_back(
190 Gtk::Box_Helpers::Element(toolbar_, Gtk::PACK_SHRINK));
194 void GToolbar::add(FuncRequest const & func, string const & tooltip)
196 switch (func.action) {
197 case ToolbarBackend::SEPARATOR:
198 toolbar_.tools().push_back(Gtk::Toolbar_Helpers::Space());
200 case ToolbarBackend::MINIBUFFER:
201 // Not supported yet.
203 case ToolbarBackend::LAYOUTS:
205 layout_.reset(new GLayoutBox(owner_, toolbar_, func));
209 Glib::ustring xpmName =
210 Glib::locale_to_utf8(toolbarbackend.getIcon(func));
211 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
212 if (xpmName.size() == 0) {
213 toolbar_.tools().push_back(
214 Gtk::Toolbar_Helpers::ButtonElem(
216 SigC::bind(SigC::slot(*this, >oolbar::clicked),
221 Gtk::manage(new Gtk::Image(xpmName));
223 toolbar_.tools().push_back(
224 Gtk::Toolbar_Helpers::ButtonElem(
227 SigC::bind(SigC::slot(*this, >oolbar::clicked),
231 toolbar_.tools().back().get_content()->set_data(
233 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
239 void GToolbar::clicked(FuncRequest func)
241 owner_.getLyXFunc().dispatch(func, true);
245 void GToolbar::hide(bool)
251 void GToolbar::show(bool)
257 void GToolbar::update()
259 Gtk::Toolbar_Helpers::ToolList::iterator it =
260 toolbar_.tools().begin();
261 Gtk::Toolbar_Helpers::ToolList::iterator const end =
262 toolbar_.tools().end();
264 for (; it != end; ++it) {
265 Gtk::Widget * widget;
266 switch (it->get_type()) {
267 case Gtk::TOOLBAR_CHILD_WIDGET:
268 widget = it->get_widget();
270 case Gtk::TOOLBAR_CHILD_SPACE:
273 widget = it->get_content();
276 FuncRequest const & func = *reinterpret_cast<FuncRequest *>(
277 widget->get_data(gToolData));
279 if (func.action == int(ToolbarBackend::LAYOUTS))
282 FuncStatus const status = owner_.getLyXFunc().getStatus(func);
283 bool sensitive = status.enabled();
284 widget->set_sensitive(sensitive);
285 if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
287 if (status.onoff(true))
288 static_cast<Gtk::Button*>(widget)->
289 set_relief(Gtk::RELIEF_NORMAL);
290 if (status.onoff(false))
291 static_cast<Gtk::Button*>(widget)->
292 set_relief(Gtk::RELIEF_NONE);