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)
84 add(toolbar, it->first, it->second);
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,
96 string const & tooltip)
99 case ToolbarBackend::SEPARATOR:
100 toolbar->tools().push_back(Gtk::Toolbar_Helpers::Space());
102 case ToolbarBackend::MINIBUFFER:
103 // Not supported yet.
105 case ToolbarBackend::LAYOUTS:
108 toolbar->tools().push_back(
109 Gtk::Toolbar_Helpers::Element(combo_));
110 toolbar->tools().back().get_widget()->set_data(
112 reinterpret_cast<void*>(LFUN_LAYOUT));
117 Glib::ustring xpmName =
118 Glib::locale_to_utf8(toolbarbackend.getIcon(action));
119 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
120 if (xpmName.size() == 0) {
121 toolbar->tools().push_back(
122 Gtk::Toolbar_Helpers::ButtonElem(
124 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
129 Gtk::manage(new Gtk::Image(xpmName));
131 toolbar->tools().push_back(
132 Gtk::Toolbar_Helpers::ButtonElem(
135 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
139 toolbar->tools().back().get_content()->set_data(
141 reinterpret_cast<void*>(action));
148 void GToolbar::onButtonClicked(int action)
150 view_->getLyXFunc().dispatch(action, true);
154 void GToolbar::onLayoutSelected()
158 string layoutGuiName = combo_.get_entry()->get_text();
159 // we get two signal, one of it is empty and useless
160 if (layoutGuiName.empty())
162 LyXTextClass const & tc =
163 view_->buffer()->params.getLyXTextClass();
165 LyXTextClass::const_iterator end = tc.end();
166 for (LyXTextClass::const_iterator cit = tc.begin();
168 if ((*cit)->name() == layoutGuiName) {
169 view_->getLyXFunc().dispatch(
170 FuncRequest(LFUN_LAYOUT, (*cit)->name()),
175 lyxerr << "ERROR (GToolbar::layoutSelected): layout not found! name : "
181 void GToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/, bool /*show*/)
186 void GToolbar::update()
188 std::vector<Gtk::Toolbar*>::iterator itToolbar;
189 for (itToolbar = toolbars_.begin();
190 itToolbar != toolbars_.end(); ++itToolbar) {
191 Gtk::Toolbar * toolbar = *itToolbar;
192 Gtk::Toolbar_Helpers::ToolList::iterator it;
193 for (it = toolbar->tools().begin();
194 it != toolbar->tools().end(); ++it) {
195 Gtk::Widget * widget;
196 switch (it->get_type()) {
197 case Gtk::TOOLBAR_CHILD_WIDGET:
198 widget = it->get_widget();
200 case Gtk::TOOLBAR_CHILD_SPACE:
203 widget = it->get_content();
205 int action = reinterpret_cast<int>(
206 widget->get_data(gToolData));
207 FuncStatus const status = view_->
208 getLyXFunc().getStatus(action);
209 bool sensitive = !status.disabled();
210 widget->set_sensitive(sensitive);
211 if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
213 if (status.onoff(true))
214 static_cast<Gtk::Button*>(widget)->
215 set_relief(Gtk::RELIEF_NORMAL);
216 if (status.onoff(false))
217 static_cast<Gtk::Button*>(widget)->
218 set_relief(Gtk::RELIEF_NONE);
224 void GToolbar::setLayout(string const & layout)
226 LyXTextClass const & tc =
227 view_->buffer()->params.getLyXTextClass();
229 combo_.get_entry()->set_text(tc[layout]->name());
234 void GToolbar::updateLayoutList()
236 LyXTextClass const & tc =
237 view_->buffer()->params.getLyXTextClass();
238 LyXTextClass::const_iterator end = tc.end();
239 std::vector<Glib::ustring> strings;
240 for (LyXTextClass::const_iterator cit = tc.begin();
242 if ((*cit)->obsoleted_by().empty())
244 Glib::locale_to_utf8((*cit)->name()));
246 combo_.set_popdown_strings(strings);
251 void GToolbar::openLayoutList()
253 combo_.get_list()->activate();
257 void GToolbar::clearLayoutList()