3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 // Too hard to make concept checks work with this file
15 #ifdef _GLIBCPP_CONCEPT_CHECKS
16 #undef _GLIBCPP_CONCEPT_CHECKS
25 #include "bufferparams.h"
27 #include "funcrequest.h"
28 #include "FuncStatus.h"
38 GView::Position getPosition(ToolbarBackend::Flags const & flags)
40 if (flags & ToolbarBackend::TOP)
42 if (flags & ToolbarBackend::BOTTOM)
44 if (flags & ToolbarBackend::LEFT)
46 if (flags & ToolbarBackend::RIGHT)
52 LyXTextClass const & getTextClass(LyXView const & lv)
54 return lv.buffer()->params().getLyXTextClass();
57 char const * gToolData = "tool_data";
62 GLayoutBox::GLayoutBox(LyXView & owner,
63 Gtk::Toolbar & toolbar,
64 FuncRequest const & func)
68 combo_.signal_changed().connect(
69 sigc::mem_fun(*this,&GLayoutBox::selected));
71 model_ = Gtk::ListStore::create(cols_);
72 combo_.set_model(model_);
73 Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
74 combo_.pack_start(*cell, true);
75 combo_.add_attribute(*cell,"text",0);
76 combo_.set_wrap_width(2);
77 // Initially there's nothing in the liststore, so set the size
78 // to avoid it jumping too much when the user does something that
79 // causes the first update()
80 combo_.set_size_request(130,-1);
85 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
89 Gtk::ToolItem * toolitem = Gtk::manage(new Gtk::ToolItem);
90 toolitem->add(combo_);
91 toolbar.append(*toolitem);
94 void GLayoutBox::set(string const & layout)
96 LyXTextClass const & tc = getTextClass(owner_);
97 string const target = tc[layout]->name();
100 Gtk::TreeModel::iterator it = model_->children().begin();
101 Gtk::TreeModel::iterator end = model_->children().end();
102 for (; it != end; ++it) {
103 if ((*it)[cols_.name] == target){
104 combo_.set_active(it);
111 lyxerr << "ERROR (GLayoutBox::set): layout not found! name: "
112 << target << std::endl;
116 void GLayoutBox::update()
120 LyXTextClass const & tc = getTextClass(owner_);
122 LyXTextClass::const_iterator it = tc.begin();
123 LyXTextClass::const_iterator const end = tc.end();
126 for (; it != end; ++it)
127 if ((*it)->obsoleted_by().empty()) {
128 Gtk::TreeModel::iterator iter = model_->append();
129 Gtk::TreeModel::Row row = *iter;
130 row[cols_.name] = Glib::locale_to_utf8((*it)->name());
134 // now that we've loaded something into the combobox, forget
135 // the initial fixed size and let GTK decide.
136 combo_.set_size_request(-1,-1);
140 void GLayoutBox::clear()
148 void GLayoutBox::open()
154 void GLayoutBox::setEnabled(bool sensitive)
156 combo_.set_sensitive(sensitive);
160 void GLayoutBox::selected()
165 Glib::ustring layoutGuiName = (*(combo_.get_active()))[cols_.name];
167 // we get two signal, one of them is empty and useless
168 if (layoutGuiName.empty())
171 layoutSelected(owner_, layoutGuiName);
174 } // namespace frontend
178 Toolbars::ToolbarPtr make_toolbar(ToolbarBackend::Toolbar const & tbb,
181 using lyx::frontend::GToolbar;
182 return Toolbars::ToolbarPtr(new GToolbar(tbb, owner));
188 GToolbar::GToolbar(ToolbarBackend::Toolbar const & tbb, LyXView & owner)
189 : owner_(dynamic_cast<GView &>(owner))
191 ToolbarBackend::item_iterator it = tbb.items.begin();
192 ToolbarBackend::item_iterator end = tbb.items.end();
193 for (; it != end; ++it)
194 add(it->first, it->second);
196 toolbar_.set_toolbar_style(Gtk::TOOLBAR_ICONS);
199 GView::Position const position = getPosition(tbb.flags);
201 if (position == GView::Left || position == GView::Right)
202 toolbar_.set_orientation(Gtk::ORIENTATION_VERTICAL);
204 owner_.getBox(position).children().push_back(
205 Gtk::Box_Helpers::Element(toolbar_, Gtk::PACK_SHRINK));
207 toolbar_.set_tooltips(true);
210 void GToolbar::add(FuncRequest const & func, string const & tooltip)
212 switch (func.action) {
213 case ToolbarBackend::SEPARATOR: {
214 Gtk::SeparatorToolItem * space =
215 Gtk::manage(new Gtk::SeparatorToolItem);
216 toolbar_.append(*space);
220 case ToolbarBackend::MINIBUFFER:
221 // Not supported yet.
224 case ToolbarBackend::LAYOUTS: {
225 layout_.reset(new GLayoutBox(owner_, toolbar_, func));
230 // choose an icon from the funcrequest
231 Gtk::BuiltinStockID stockID = getGTKStockIcon(func);
233 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
235 Gtk::ToolButton * toolbutton;
236 if (stockID != Gtk::Stock::MISSING_IMAGE) {
237 // Prefer stock gtk graphics
238 Gtk::IconSize size(Gtk::ICON_SIZE_LARGE_TOOLBAR);
239 Gtk::Image * image = Gtk::manage(new Gtk::Image(stockID, size));
241 toolbutton = Gtk::manage(new Gtk::ToolButton(*image));
243 Glib::ustring xpmName =
244 Glib::locale_to_utf8(toolbarbackend.getIcon(func));
245 Gtk::Image * image = Gtk::manage(new Gtk::Image(xpmName));
247 toolbutton = Gtk::manage(new Gtk::ToolButton(*image));
250 // This code is putting a function reference into the GObject data field
251 // named gToolData. That's how we know how to update the status of the
253 toolbutton->set_data(gToolData,
254 reinterpret_cast<void*>(&const_cast<FuncRequest &>(func)));
256 toolbutton->set_tooltip(*toolbar_.get_tooltips_object(),tip);
258 toolbutton->signal_clicked().connect(sigc::bind(sigc::mem_fun(*this,
259 >oolbar::clicked), FuncRequest(func)));
260 toolbar_.append(*toolbutton);
268 void GToolbar::clicked(FuncRequest func)
270 owner_.getLyXFunc().dispatch(func);
274 void GToolbar::hide(bool)
280 void GToolbar::show(bool)
286 void GToolbar::update()
288 int const items = toolbar_.get_n_items();
290 for (int i = 0; i < items; ++i) {
291 Gtk::ToolItem * item = toolbar_.get_nth_item(i);
293 FuncRequest const * func = reinterpret_cast<FuncRequest *>(
294 item->get_data(gToolData));
296 FuncStatus const status = owner_.getLyXFunc().getStatus(*func);
297 item->set_sensitive(status.enabled());
302 } // namespace frontend