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.
17 #include "bufferparams.h"
19 #include "funcrequest.h"
20 #include "FuncStatus.h"
30 GView::Position getPosition(ToolbarBackend::Flags const & flags)
32 if (flags & ToolbarBackend::TOP)
34 if (flags & ToolbarBackend::BOTTOM)
36 if (flags & ToolbarBackend::LEFT)
38 if (flags & ToolbarBackend::RIGHT)
44 LyXTextClass const & getTextClass(LyXView const & lv)
46 return lv.buffer()->params().getLyXTextClass();
50 void comboClear(Gtk::Combo & combo)
52 std::vector<Glib::ustring> strings;
53 strings.push_back("");
54 combo.set_popdown_strings(strings);
58 bool comboIsEmpty(Gtk::Combo & combo)
60 std::vector<Glib::ustring> strings = combo.get_popdown_strings();
61 return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
64 char const * gToolData = "tool_data";
69 GLayoutBox::GLayoutBox(LyXView & owner,
70 Gtk::Toolbar & toolbar,
71 FuncRequest const & func)
75 combo_.set_value_in_list();
76 combo_.get_entry()->set_editable(false);
77 combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
78 combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
81 combo_.get_entry()->signal_changed().connect(
82 sigc::mem_fun(*this,&GLayoutBox::selected));
88 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
90 Gtk::ToolItem * toolitem = Gtk::manage(new Gtk::ToolItem);
91 toolitem->add(combo_);
92 toolbar.insert(*toolitem,-1);
95 void GLayoutBox::set(string const & layout)
97 LyXTextClass const & tc = getTextClass(owner_);
100 combo_.get_entry()->set_text(tc[layout]->name());
105 void GLayoutBox::update()
107 LyXTextClass const & tc = getTextClass(owner_);
109 std::vector<Glib::ustring> strings;
111 LyXTextClass::const_iterator it = tc.begin();
112 LyXTextClass::const_iterator const end = tc.end();
113 for (; it != end; ++it)
114 if ((*it)->obsoleted_by().empty())
116 Glib::locale_to_utf8((*it)->name()));
118 combo_.set_popdown_strings(strings);
123 void GLayoutBox::clear()
131 void GLayoutBox::open()
133 combo_.get_list()->activate();
137 void GLayoutBox::setEnabled(bool sensitive)
139 combo_.set_sensitive(sensitive);
143 void GLayoutBox::selected()
148 string layoutGuiName = combo_.get_entry()->get_text();
149 // we get two signal, one of it is empty and useless
150 if (layoutGuiName.empty())
152 LyXTextClass const & tc = getTextClass(owner_);
154 LyXTextClass::const_iterator it = tc.begin();
155 LyXTextClass::const_iterator const end = tc.end();
156 for (; it != end; ++it) {
157 string const & name = (*it)->name();
158 if (name == layoutGuiName) {
159 owner_.getLyXFunc().dispatch(
160 FuncRequest(LFUN_LAYOUT, name),
165 lyxerr << "ERROR (GLayoutBox::selected): layout not found! name: "
166 << layoutGuiName << std::endl;
169 } // namespace frontend
173 Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
176 using lyx::frontend::GToolbar;
177 return Toolbars::ToolbarPtr(new GToolbar(tbb, owner));
183 GToolbar::GToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
184 : owner_(dynamic_cast<GView &>(owner))
186 ToolbarBackend::item_iterator it = tbb.items.begin();
187 ToolbarBackend::item_iterator end = tbb.items.end();
188 for (; it != end; ++it)
189 add(it->first, it->second);
191 toolbar_.set_toolbar_style(Gtk::TOOLBAR_ICONS);
194 GView::Position const position = getPosition(tbb.flags);
196 if (position == GView::Left || position == GView::Right)
197 toolbar_.set_orientation(Gtk::ORIENTATION_VERTICAL);
199 owner_.getBox(position).children().push_back(
200 Gtk::Box_Helpers::Element(toolbar_, Gtk::PACK_SHRINK));
205 void GToolbar::add(FuncRequest const & func, string const & tooltip)
207 switch (func.action) {
208 case ToolbarBackend::SEPARATOR: {
209 Gtk::SeparatorToolItem * space =
210 Gtk::manage(new Gtk::SeparatorToolItem);
211 toolbar_.insert(*space,-1);
215 case ToolbarBackend::MINIBUFFER:
216 // Not supported yet.
219 case ToolbarBackend::LAYOUTS: {
220 layout_.reset(new GLayoutBox(owner_, toolbar_, func));
225 Glib::ustring xpmName =
226 Glib::locale_to_utf8(toolbarbackend.getIcon(func));
227 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
228 Gtk::ToolButton * toolbutton;
229 if (xpmName.size() == 0) {
230 toolbutton = Gtk::manage(new Gtk::ToolButton);
232 Gtk::Image * image = Gtk::manage(new Gtk::Image(xpmName));
234 toolbutton = Gtk::manage(new Gtk::ToolButton(*image));
236 // This code is putting a function reference into the GObject data field
237 // named gToolData. That's how we know how to update the status of the
239 toolbutton->set_data(gToolData,
240 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
241 tooltips_.set_tip(*toolbutton, tip, tip);
242 toolbutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
243 >oolbar::clicked), FuncRequest(func)));
244 toolbar_.insert(*toolbutton,-1);
252 void GToolbar::clicked(FuncRequest func)
254 owner_.getLyXFunc().dispatch(func, true);
258 void GToolbar::hide(bool)
264 void GToolbar::show(bool)
270 void GToolbar::update()
272 int const items = toolbar_.get_n_items();
274 for (int i = 0; i < items; ++i) {
275 Gtk::ToolItem * item = toolbar_.get_nth_item(i);
277 FuncRequest const * func = reinterpret_cast<FuncRequest *>(
278 item->get_data(gToolData));
280 FuncStatus const status = owner_.getLyXFunc().getStatus(*func);
281 item->set_sensitive(status.enabled());
286 } // namespace frontend