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"
35 char const * gToolData = "tool_data";
38 inline void comboClear(Gtk::Combo & combo)
40 std::vector<Glib::ustring> strings;
41 strings.push_back("");
42 combo.set_popdown_strings(strings);
46 inline bool comboIsEmpty(Gtk::Combo & combo)
48 std::vector<Glib::ustring> strings = combo.get_popdown_strings();
49 return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
56 GToolbar::GToolbar(LyXView * lyxView, int /*x*/, int /*y*/)
57 : view_(lyxView), internal_(false)
59 combo_.set_value_in_list();
60 combo_.get_entry()->set_editable(false);
61 combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
62 combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
64 combo_.get_entry()->signal_changed().connect(
66 >oolbar::onLayoutSelected));
67 GView * gview = static_cast<GView*>(lyxView);
69 Gtk::VBox & vbox = gview->getVBox();
70 vbox.children().push_back(Gtk::Box_Helpers::Element(vbox_,
80 void GToolbar::add(ToolbarBackend::Toolbar const & tb)
82 Gtk::Toolbar * toolbar = manage(new Gtk::Toolbar);
83 ToolbarBackend::item_iterator it = tb.items.begin();
84 ToolbarBackend::item_iterator end = tb.items.end();
85 for (; it != end; ++it)
87 toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS);
89 vbox_.children().push_back(
90 Gtk::Box_Helpers::Element(*toolbar,
92 toolbars_.push_back(toolbar);
96 void GToolbar::add(Gtk::Toolbar * toolbar,
97 ToolbarBackend::Item const & item)
99 FuncRequest const & func = item.first;
100 string const & tooltip = item.second;
101 switch (func.action) {
102 case ToolbarBackend::SEPARATOR:
103 toolbar->tools().push_back(Gtk::Toolbar_Helpers::Space());
105 case ToolbarBackend::MINIBUFFER:
106 // Not supported yet.
108 case ToolbarBackend::LAYOUTS:
111 toolbar->tools().push_back(
112 Gtk::Toolbar_Helpers::Element(combo_));
113 toolbar->tools().back().get_widget()->set_data(
115 reinterpret_cast<void*>(&const_cast<ToolbarBackend::Item&>(item)));
120 Glib::ustring xpmName =
121 Glib::locale_to_utf8(toolbarbackend.getIcon(func));
122 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
123 if (xpmName.size() == 0) {
124 toolbar->tools().push_back(
125 Gtk::Toolbar_Helpers::ButtonElem(
127 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
132 Gtk::manage(new Gtk::Image(xpmName));
134 toolbar->tools().push_back(
135 Gtk::Toolbar_Helpers::ButtonElem(
138 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
142 toolbar->tools().back().get_content()->set_data(
144 reinterpret_cast<void*>(&const_cast<ToolbarBackend::Item&>(item)));
151 void GToolbar::onButtonClicked(FuncRequest func)
153 view_->getLyXFunc().dispatch(func, true);
157 void GToolbar::onLayoutSelected()
161 string layoutGuiName = combo_.get_entry()->get_text();
162 // we get two signal, one of it is empty and useless
163 if (layoutGuiName.empty())
165 LyXTextClass const & tc =
166 view_->buffer()->params().getLyXTextClass();
168 LyXTextClass::const_iterator end = tc.end();
169 for (LyXTextClass::const_iterator cit = tc.begin();
171 if ((*cit)->name() == layoutGuiName) {
172 view_->getLyXFunc().dispatch(
173 FuncRequest(LFUN_LAYOUT, (*cit)->name()),
178 lyxerr << "ERROR (GToolbar::layoutSelected): layout not found! name : "
184 void GToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/, bool /*show*/)
189 void GToolbar::update()
191 std::vector<Gtk::Toolbar*>::iterator itToolbar;
192 for (itToolbar = toolbars_.begin();
193 itToolbar != toolbars_.end(); ++itToolbar) {
194 Gtk::Toolbar * toolbar = *itToolbar;
195 Gtk::Toolbar_Helpers::ToolList::iterator it;
196 for (it = toolbar->tools().begin();
197 it != toolbar->tools().end(); ++it) {
198 Gtk::Widget * widget;
199 switch (it->get_type()) {
200 case Gtk::TOOLBAR_CHILD_WIDGET:
201 widget = it->get_widget();
203 case Gtk::TOOLBAR_CHILD_SPACE:
206 widget = it->get_content();
208 ToolbarBackend::Item * item =
209 reinterpret_cast<ToolbarBackend::Item*>(
210 widget->get_data(gToolData));
211 FuncStatus const status = view_->
212 getLyXFunc().getStatus(item->first);
213 bool sensitive = !status.disabled();
214 widget->set_sensitive(sensitive);
215 if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
217 if (status.onoff(true))
218 static_cast<Gtk::Button*>(widget)->
219 set_relief(Gtk::RELIEF_NORMAL);
220 if (status.onoff(false))
221 static_cast<Gtk::Button*>(widget)->
222 set_relief(Gtk::RELIEF_NONE);
228 void GToolbar::setLayout(string const & layout)
230 LyXTextClass const & tc =
231 view_->buffer()->params().getLyXTextClass();
233 combo_.get_entry()->set_text(tc[layout]->name());
238 void GToolbar::updateLayoutList()
240 LyXTextClass const & tc =
241 view_->buffer()->params().getLyXTextClass();
242 LyXTextClass::const_iterator end = tc.end();
243 std::vector<Glib::ustring> strings;
244 for (LyXTextClass::const_iterator cit = tc.begin();
246 if ((*cit)->obsoleted_by().empty())
248 Glib::locale_to_utf8((*cit)->name()));
250 combo_.set_popdown_strings(strings);
255 void GToolbar::openLayoutList()
257 combo_.get_list()->activate();
261 void GToolbar::clearLayoutList()