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 "funcrequest.h"
23 #include "support/filetools.h"
24 #include "support/lstrings.h"
32 char const * gToolData = "tool_data";
35 inline void comboClear(Gtk::Combo & combo)
37 std::vector<Glib::ustring> strings;
38 strings.push_back("");
39 combo.set_popdown_strings(strings);
43 inline bool comboIsEmpty(Gtk::Combo & combo)
45 std::vector<Glib::ustring> strings = combo.get_popdown_strings();
46 return (strings.empty() || (strings.size() == 1 && strings[0] == ""));
53 GToolbar::GToolbar(LyXView * lyxView, int /*x*/, int /*y*/)
54 : view_(lyxView), internal_(false)
56 combo_.set_value_in_list();
57 combo_.get_entry()->set_editable(false);
58 combo_.unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
59 combo_.get_entry()->unset_flags(Gtk::CAN_FOCUS | Gtk::CAN_DEFAULT);
61 combo_.get_entry()->signal_changed().connect(
63 >oolbar::onLayoutSelected));
64 GView * gview = static_cast<GView*>(lyxView);
66 Gtk::VBox & vbox = gview->getVBox();
67 vbox.children().push_back(Gtk::Box_Helpers::Element(vbox_,
77 void GToolbar::add(ToolbarBackend::Toolbar const & tb)
79 Gtk::Toolbar * toolbar = manage(new Gtk::Toolbar());
80 ToolbarBackend::item_iterator it = tb.items.begin();
81 ToolbarBackend::item_iterator end = tb.items.end();
82 for (; it != end; ++it)
83 add(toolbar, it->first, it->second);
84 toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS);
86 vbox_.children().push_back(
87 Gtk::Box_Helpers::Element(*toolbar,
89 toolbars_.push_back(toolbar);
93 void GToolbar::add(Gtk::Toolbar * toolbar,
95 string const & tooltip)
98 case ToolbarBackend::SEPARATOR:
99 toolbar->tools().push_back(Gtk::Toolbar_Helpers::Space());
101 case ToolbarBackend::MINIBUFFER:
102 // Not supported yet.
104 case ToolbarBackend::LAYOUTS:
107 toolbar->tools().push_back(
108 Gtk::Toolbar_Helpers::Element(combo_));
109 toolbar->tools().back().get_widget()->set_data(
111 reinterpret_cast<void*>(LFUN_LAYOUT));
116 Glib::ustring xpmName =
117 Glib::locale_to_utf8(toolbarbackend.getIcon(action));
118 Glib::ustring tip = Glib::locale_to_utf8(tooltip);
119 if (xpmName.size() == 0) {
120 toolbar->tools().push_back(
121 Gtk::Toolbar_Helpers::ButtonElem(
123 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
128 Gtk::manage(new Gtk::Image(xpmName));
130 toolbar->tools().push_back(
131 Gtk::Toolbar_Helpers::ButtonElem(
134 SigC::bind(SigC::slot(*this, >oolbar::onButtonClicked),
138 toolbar->tools().back().get_content()->set_data(
140 reinterpret_cast<void*>(action));
147 void GToolbar::onButtonClicked(int action)
149 view_->getLyXFunc().dispatch(action, true);
153 void GToolbar::onLayoutSelected()
157 string layoutGuiName = combo_.get_entry()->get_text();
158 // we get two signal, one of it is empty and useless
159 if (layoutGuiName.empty())
161 LyXTextClass const & tc =
162 view_->buffer()->params.getLyXTextClass();
164 LyXTextClass::const_iterator end = tc.end();
165 for (LyXTextClass::const_iterator cit = tc.begin();
167 if ((*cit)->name() == layoutGuiName) {
168 view_->getLyXFunc().dispatch(
169 FuncRequest(LFUN_LAYOUT, (*cit)->name()),
174 lyxerr << "ERROR (GToolbar::layoutSelected): layout not found! name : "
180 void GToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/, bool /*show*/)
185 void GToolbar::update()
187 std::vector<Gtk::Toolbar*>::iterator itToolbar;
188 for (itToolbar = toolbars_.begin();
189 itToolbar != toolbars_.end(); ++itToolbar) {
190 Gtk::Toolbar * toolbar = *itToolbar;
191 Gtk::Toolbar_Helpers::ToolList::iterator it;
192 for (it = toolbar->tools().begin();
193 it != toolbar->tools().end(); ++it) {
194 Gtk::Widget * widget;
195 switch (it->get_type()) {
196 case Gtk::TOOLBAR_CHILD_WIDGET:
197 widget = it->get_widget();
199 case Gtk::TOOLBAR_CHILD_SPACE:
202 widget = it->get_content();
204 int action = reinterpret_cast<int>(
205 widget->get_data(gToolData));
206 FuncStatus const status = view_->
207 getLyXFunc().getStatus(action);
208 bool sensitive = !status.disabled();
209 widget->set_sensitive(sensitive);
210 if (it->get_type() != Gtk::TOOLBAR_CHILD_BUTTON)
212 if (status.onoff(true))
213 static_cast<Gtk::Button*>(widget)->
214 set_relief(Gtk::RELIEF_NORMAL);
215 if (status.onoff(false))
216 static_cast<Gtk::Button*>(widget)->
217 set_relief(Gtk::RELIEF_NONE);
223 void GToolbar::setLayout(string const & layout)
225 LyXTextClass const & tc =
226 view_->buffer()->params.getLyXTextClass();
228 combo_.get_entry()->set_text(tc[layout]->name());
233 void GToolbar::updateLayoutList()
235 LyXTextClass const & tc =
236 view_->buffer()->params.getLyXTextClass();
237 LyXTextClass::const_iterator end = tc.end();
238 std::vector<Glib::ustring> strings;
239 for (LyXTextClass::const_iterator cit = tc.begin();
241 if ((*cit)->obsoleted_by().empty())
243 Glib::locale_to_utf8((*cit)->name()));
245 combo_.set_popdown_strings(strings);
250 void GToolbar::openLayoutList()
252 combo_.get_list()->activate();
256 void GToolbar::clearLayoutList()