2 * \file Toolbar_pimpl.C
3 * Copyright 1995 Matthias Ettrich
4 * Copyright 1995-2001 The LyX Team.
5 * Copyright 1996-1998 Lars Gullik Bjønnes
6 * See the file COPYING.
8 * \author Lars Gullik Bjønnes, larsbj@lyx.org
11 // Added pseudo-action handling, asierra 180296
16 #pragma implementation
19 #include "Toolbar_pimpl.h"
21 #include "XFormsView.h"
23 #include "FuncStatus.h"
24 #include "BufferView.h"
26 #include "funcrequest.h"
27 #include "MathsSymbols.h"
30 #include FORMS_H_LOCATION
32 #include "ToolbarDefaults.h"
33 #include "LyXAction.h"
35 #include "support/LAssert.h"
36 #include "support/filetools.h"
37 #include "support/lstrings.h"
39 #include <boost/tuple/tuple.hpp>
44 const int standardspacing = 2; // the usual space between items
45 const int sepspace = 6; // extra space
46 const int buttonwidth = 30; // the standard button width
47 const int height = 30; // the height of all items in the toolbar
49 Toolbar::Pimpl::toolbarItem::toolbarItem()
50 : action(LFUN_NOACTION), icon(0)
55 Toolbar::Pimpl::toolbarItem::~toolbarItem()
57 // Lars said here that ~XFormsView() dealt with the icons.
58 // This is not true. But enabling this causes crashes,
59 // because somehow we kill the same icon twice :(
65 void Toolbar::Pimpl::toolbarItem::kill_icon()
68 fl_delete_object(icon);
75 Toolbar::Pimpl::toolbarItem &
76 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
81 // If we already have an icon, release it.
82 // But we don't copy the icon from ti
92 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs & d, int x, int y)
93 : owner_(static_cast<XFormsView *>(o)), xpos(x), ypos(y)
96 tooltip_ = new Tooltips(d);
100 Toolbar::Pimpl::~Pimpl()
102 fl_freeze_form(owner_->getForm());
104 // G++ vector does not have clear defined
106 toollist_.erase(toollist_.begin(), toollist_.end());
110 fl_unfreeze_form(owner_->getForm());
115 void Toolbar::Pimpl::update()
117 ToolbarList::const_iterator p = toollist_.begin();
118 ToolbarList::const_iterator end = toollist_.end();
119 for (; p != end; ++p) {
120 if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
121 if (owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled())
122 combox_->deactivate();
131 FuncStatus const status = owner_->getLyXFunc()->getStatus(p->action);
132 if (status.onoff(true)) {
133 // I'd like to use a different color
134 // here, but then the problem is to
135 // know how to use transparency with
136 // Xpm library. It seems pretty
137 // complicated to me (JMarc)
138 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
139 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
141 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
142 fl_set_object_boxtype(p->icon, FL_UP_BOX);
144 if (status.disabled()) {
145 // Is there a way here to specify a
146 // mask in order to show that the
147 // button is disabled? (JMarc)
148 fl_deactivate_object(p->icon);
151 fl_activate_object(p->icon);
156 // this one is not "C" because combox callbacks are really C++ %-|
157 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
159 reinterpret_cast<Toolbar::Pimpl *>(arg)->layoutSelected();
163 void Toolbar::Pimpl::layoutSelected()
165 string const & layoutguiname = combox_->getline();
166 LyXTextClass const & tc =
167 owner_->buffer()->params.getLyXTextClass();
169 LyXTextClass::const_iterator end = tc.end();
170 for (LyXTextClass::const_iterator cit = tc.begin();
172 if (_((*cit)->name()) == layoutguiname) {
173 owner_->getLyXFunc()->dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()));
177 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
182 void Toolbar::Pimpl::setLayout(string const & layout)
185 LyXTextClass const & tc =
186 owner_->buffer()->params.getLyXTextClass();
187 combox_->select(_(tc[layout]->name()));
192 void Toolbar::Pimpl::updateLayoutList(bool force)
194 // Update the layout display
195 if (!combox_) return;
197 // If textclass is different, we need to update the list
198 if (combox_->empty() || force) {
200 LyXTextClass const & tc =
201 owner_->buffer()->params.getLyXTextClass();
202 LyXTextClass::const_iterator end = tc.end();
203 for (LyXTextClass::const_iterator cit = tc.begin();
205 // ignore obsolete entries
206 if ((*cit)->obsoleted_by().empty())
207 combox_->addline(_((*cit)->name()));
210 // we need to do this.
215 void Toolbar::Pimpl::clearLayoutList()
224 void Toolbar::Pimpl::openLayoutList()
233 void ToolbarCB(FL_OBJECT * ob, long ac)
235 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
237 owner->getLyXFunc()->dispatch(int(ac), true);
244 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
252 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
258 boost::tie(act, arg) = lyxaction.retrieveActionArg(action);
260 string const name = lyxaction.getActionName(act);
262 xpm_name = subst(name + ' ' + arg, ' ','_');
266 string fullname = LibFileSearch("images", xpm_name, "xpm");
268 if (!fullname.empty()) {
269 lyxerr[Debug::GUI] << "Full icon name is `"
270 << fullname << "'" << endl;
271 fl_set_pixmapbutton_file(obj, fullname.c_str());
275 if (act == LFUN_INSERT_MATH && !arg.empty()) {
276 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
280 lyxerr[Debug::GUI] << "Using mathed-provided icon"
282 fl_set_pixmapbutton_data(obj,
283 const_cast<char **>(pixmap));
288 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
289 fullname = LibFileSearch("images", "unknown", "xpm");
290 if (!fullname.empty()) {
291 lyxerr[Debug::GUI] << "Using default `unknown' icon"
293 fl_set_pixmapbutton_file(obj, fullname.c_str());
300 void Toolbar::Pimpl::add(int action)
305 item.action = action;
308 case ToolbarDefaults::SEPARATOR:
311 case ToolbarDefaults::NEWLINE:
312 // Not supported yet.
314 case ToolbarDefaults::LAYOUTS:
315 xpos += standardspacing;
317 combox_ = new Combox(FL_COMBOX_DROPLIST);
318 combox_->add(xpos, ypos, 135, height, 400);
319 combox_->setcallback(layoutSelectedCB, this);
320 combox_->resize(FL_RESIZE_ALL);
321 combox_->gravity(NorthWestGravity, NorthWestGravity);
325 xpos += standardspacing;
327 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
331 fl_set_object_resize(obj, FL_RESIZE_ALL);
332 fl_set_object_gravity(obj,
335 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
336 static_cast<long>(action));
337 // Remove the blue feedback rectangle
338 fl_set_pixmapbutton_focus_outline(obj, 0);
340 // initialise the tooltip
341 string const tip = _(lyxaction.helpText(obj->argument));
342 tooltip_->init(obj, tip);
344 // The view that this object belongs to.
345 obj->u_vdata = owner_;
347 setPixmap(obj, action, buttonwidth, height);
348 // we must remember to update the positions
351 /* Here will come a check to see if the new
352 * pos is within the bounds of the main frame,
353 * and perhaps wrap the toolbar if not.
358 toollist_.push_back(item);