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.
16 #include "LyXAction.h"
18 #include "FuncStatus.h"
20 #include "bufferparams.h"
21 #include "funcrequest.h"
24 #include "support/filetools.h"
25 #include "support/lstrings.h"
33 char const * gToolData = "tool_data";
36 inline void comboClear(Gtk::Combo & combo)
38 std::vector<Glib::ustring> strings;
39 strings.push_back("");
40 combo.set_popdown_strings(strings);
44 inline bool comboIsEmpty(Gtk::Combo & combo)
46 std::vector<Glib::ustring> strings = combo.get_popdown_strings();
47 return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
54 GToolbar::GToolbar(LyXView * lyxView, int /*x*/, int /*y*/)
55 : view_(lyxView), internal_(false)
57 combo_.set_value_in_list();
58 combo_.get_entry()->set_editable(false);
59 combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
60 combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
62 combo_.get_entry()->signal_changed().connect(
64 >oolbar::onLayoutSelected));
65 GView * gview = static_cast<GView*>(lyxView);
67 Gtk::VBox & vbox = gview->getVBox();
68 vbox.children().push_back(Gtk::Box_Helpers::Element(vbox_,
78 void GToolbar::add(ToolbarBackend::Toolbar const & tb)
80 Gtk::Toolbar * toolbar = manage(new Gtk::Toolbar);
81 ToolbarBackend::item_iterator it = tb.items.begin();
82 ToolbarBackend::item_iterator end = tb.items.end();
83 for (; it != end; ++it)
85 toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS);
87 vbox_.children().push_back(
88 Gtk::Box_Helpers::Element(*toolbar,
90 toolbars_.push_back(toolbar);
94 void GToolbar::add(Gtk::Toolbar * toolbar,
95 ToolbarBackend::Item const & item)
97 FuncRequest const & func = item.first;
98 string const & tooltip = item.second;
99 switch (func.action) {
100 case ToolbarBackend::SEPARATOR:
101 toolbar->tools().push_back(Gtk::Toolbar_Helpers::Space());
103 case ToolbarBackend::MINIBUFFER:
104 // Not supported yet.
106 case ToolbarBackend::LAYOUTS:
109 toolbar->tools().push_back(
110 Gtk::Toolbar_Helpers::Element(combo_));
111 toolbar->tools().back().get_widget()->set_data(
113 reinterpret_cast<void*>(&const_cast<ToolbarBackend::Item&>(item)));
118 Glib::ustring xpmName =
119 Glib::locale_to_utf8(toolbarbackend.getIcon(func));
120 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
121 if (xpmName.size() == 0) {
122 toolbar->tools().push_back(
123 Gtk::Toolbar_Helpers::ButtonElem(
125 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
130 Gtk::manage(new Gtk::Image(xpmName));
132 toolbar->tools().push_back(
133 Gtk::Toolbar_Helpers::ButtonElem(
136 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
140 toolbar->tools().back().get_content()->set_data(
142 reinterpret_cast<void*>(&const_cast<ToolbarBackend::Item&>(item)));
149 void GToolbar::onButtonClicked(FuncRequest func)
151 view_->getLyXFunc().dispatch(func, true);
155 void GToolbar::onLayoutSelected()
159 string layoutGuiName = combo_.get_entry()->get_text();
160 // we get two signal, one of it is empty and useless
161 if (layoutGuiName.empty())
163 LyXTextClass const & tc =
164 view_->buffer()->params().getLyXTextClass();
166 LyXTextClass::const_iterator end = tc.end();
167 for (LyXTextClass::const_iterator cit = tc.begin();
169 if ((*cit)->name() == layoutGuiName) {
170 view_->getLyXFunc().dispatch(
171 FuncRequest(LFUN_LAYOUT, (*cit)->name()),
176 lyxerr << "ERROR (GToolbar::layoutSelected): layout not found! name : "
182 void GToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/, bool /*show*/)
187 void GToolbar::update()
189 std::vector<Gtk::Toolbar*>::iterator itToolbar;
190 for (itToolbar = toolbars_.begin();
191 itToolbar != toolbars_.end(); ++itToolbar) {
192 Gtk::Toolbar * toolbar = *itToolbar;
193 Gtk::Toolbar_Helpers::ToolList::iterator it;
194 for (it = toolbar->tools().begin();
195 it != toolbar->tools().end(); ++it) {
196 Gtk::Widget * widget;
197 switch (it->get_type()) {
198 case Gtk::TOOLBAR_CHILD_WIDGET:
199 widget = it->get_widget();
201 case Gtk::TOOLBAR_CHILD_SPACE:
204 widget = it->get_content();
206 ToolbarBackend::Item * item =
207 reinterpret_cast<ToolbarBackend::Item*>(
208 widget->get_data(gToolData));
209 FuncStatus const status = view_->
210 getLyXFunc().getStatus(item->first);
211 bool sensitive = !status.disabled();
212 widget->set_sensitive(sensitive);
213 if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
215 if (status.onoff(true))
216 static_cast<Gtk::Button*>(widget)->
217 set_relief(Gtk::RELIEF_NORMAL);
218 if (status.onoff(false))
219 static_cast<Gtk::Button*>(widget)->
220 set_relief(Gtk::RELIEF_NONE);
226 void GToolbar::setLayout(string const & layout)
228 LyXTextClass const & tc =
229 view_->buffer()->params().getLyXTextClass();
231 combo_.get_entry()->set_text(tc[layout]->name());
236 void GToolbar::updateLayoutList()
238 LyXTextClass const & tc =
239 view_->buffer()->params().getLyXTextClass();
240 LyXTextClass::const_iterator end = tc.end();
241 std::vector<Glib::ustring> strings;
242 for (LyXTextClass::const_iterator cit = tc.begin();
244 if ((*cit)->obsoleted_by().empty())
246 Glib::locale_to_utf8((*cit)->name()));
248 combo_.set_popdown_strings(strings);
253 void GToolbar::openLayoutList()
255 combo_.get_list()->activate();
259 void GToolbar::clearLayoutList()