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 "LyXAction.h"
27 #include "MathsSymbols.h"
30 #include FORMS_H_LOCATION
32 #include "ToolbarDefaults.h"
34 #include "support/LAssert.h"
35 #include "support/filetools.h"
36 #include "support/lstrings.h"
40 extern LyXAction lyxaction;
43 const int standardspacing = 2; // the usual space between items
44 const int sepspace = 6; // extra space
45 const int buttonwidth = 30; // the standard button width
46 const int height = 30; // the height of all items in the toolbar
48 Toolbar::Pimpl::toolbarItem::toolbarItem()
49 : action(LFUN_NOACTION), icon(0)
54 Toolbar::Pimpl::toolbarItem::~toolbarItem()
56 // Lars said here that ~XFormsView() dealt with the icons.
57 // This is not true. But enabling this causes crashes,
58 // because somehow we kill the same icon twice :(
64 void Toolbar::Pimpl::toolbarItem::kill_icon()
67 fl_delete_object(icon);
74 Toolbar::Pimpl::toolbarItem &
75 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
80 // If we already have an icon, release it.
81 // But we don't copy the icon from ti
91 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs & d, int x, int y)
92 : owner_(static_cast<XFormsView *>(o)), xpos(x), ypos(y)
95 tooltip_ = new Tooltips(d);
99 Toolbar::Pimpl::~Pimpl()
101 fl_freeze_form(owner_->getForm());
103 // G++ vector does not have clear defined
105 toollist_.erase(toollist_.begin(), toollist_.end());
109 fl_unfreeze_form(owner_->getForm());
114 void Toolbar::Pimpl::update()
116 ToolbarList::const_iterator p = toollist_.begin();
117 ToolbarList::const_iterator end = toollist_.end();
118 for (; p != end; ++p) {
119 if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
120 if (owner_->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled())
121 combox_->deactivate();
130 FuncStatus const status = owner_->getLyXFunc()->getStatus(p->action);
131 if (status.onoff(true)) {
132 // I'd like to use a different color
133 // here, but then the problem is to
134 // know how to use transparency with
135 // Xpm library. It seems pretty
136 // complicated to me (JMarc)
137 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
138 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
140 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
141 fl_set_object_boxtype(p->icon, FL_UP_BOX);
143 if (status.disabled()) {
144 // Is there a way here to specify a
145 // mask in order to show that the
146 // button is disabled? (JMarc)
147 fl_deactivate_object(p->icon);
150 fl_activate_object(p->icon);
155 // this one is not "C" because combox callbacks are really C++ %-|
156 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
158 Toolbar::Pimpl * tb = reinterpret_cast<Toolbar::Pimpl *>(arg);
160 tb->layoutSelected();
164 void Toolbar::Pimpl::layoutSelected()
166 string const & layoutguiname = combox_->getline();
167 LyXTextClass const & tc =
168 owner_->buffer()->params.getLyXTextClass();
170 LyXTextClass::const_iterator end = tc.end();
171 for (LyXTextClass::const_iterator cit = tc.begin();
173 if (_((*cit)->name()) == layoutguiname) {
174 owner_->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
178 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
183 void Toolbar::Pimpl::setLayout(string const & layout)
186 LyXTextClass const & tc =
187 owner_->buffer()->params.getLyXTextClass();
188 combox_->select(_(tc[layout]->name()));
193 void Toolbar::Pimpl::updateLayoutList(bool force)
195 // Update the layout display
196 if (!combox_) return;
198 // If textclass is different, we need to update the list
199 if (combox_->empty() || force) {
201 LyXTextClass const & tc =
202 owner_->buffer()->params.getLyXTextClass();
203 LyXTextClass::const_iterator end = tc.end();
204 for (LyXTextClass::const_iterator cit = tc.begin();
206 // ignore obsolete entries
207 if ((*cit)->obsoleted_by().empty())
208 combox_->addline(_((*cit)->name()));
211 // we need to do this.
216 void Toolbar::Pimpl::clearLayoutList()
225 void Toolbar::Pimpl::openLayoutList()
234 void ToolbarCB(FL_OBJECT * ob, long ac)
236 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
238 owner->getLyXFunc()->dispatch(int(ac), true);
245 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
253 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
258 const kb_action act = lyxaction.retrieveActionArg(action, arg);
259 string const name = lyxaction.getActionName(act);
261 xpm_name = subst(name + ' ' + arg, ' ','_');
265 string fullname = LibFileSearch("images", xpm_name, "xpm");
267 if (!fullname.empty()) {
268 lyxerr[Debug::GUI] << "Full icon name is `"
269 << fullname << "'" << endl;
270 fl_set_pixmapbutton_file(obj, fullname.c_str());
274 if (act == LFUN_INSERT_MATH && !arg.empty()) {
275 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
279 lyxerr[Debug::GUI] << "Using mathed-provided icon"
281 fl_set_pixmapbutton_data(obj,
282 const_cast<char **>(pixmap));
287 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
288 fullname = LibFileSearch("images", "unknown", "xpm");
289 if (!fullname.empty()) {
290 lyxerr[Debug::GUI] << "Using default `unknown' icon"
292 fl_set_pixmapbutton_file(obj, fullname.c_str());
299 void Toolbar::Pimpl::add(int action)
304 item.action = action;
307 case ToolbarDefaults::SEPARATOR:
310 case ToolbarDefaults::NEWLINE:
311 // Not supported yet.
313 case ToolbarDefaults::LAYOUTS:
314 xpos += standardspacing;
316 combox_ = new Combox(FL_COMBOX_DROPLIST);
317 combox_->add(xpos, ypos, 135, height, 400);
318 combox_->setcallback(layoutSelectedCB, this);
319 combox_->resize(FL_RESIZE_ALL);
320 combox_->gravity(NorthWestGravity, NorthWestGravity);
324 xpos += standardspacing;
326 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
330 fl_set_object_resize(obj, FL_RESIZE_ALL);
331 fl_set_object_gravity(obj,
334 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
335 static_cast<long>(action));
336 // Remove the blue feedback rectangle
337 fl_set_pixmapbutton_focus_outline(obj, 0);
339 // initialise the tooltip
340 string const tip = _(lyxaction.helpText(obj->argument));
341 tooltip_->init(obj, tip);
343 // The view that this object belongs to.
344 obj->u_vdata = owner_;
346 setPixmap(obj, action, buttonwidth, height);
347 // we must remember to update the positions
350 /* Here will come a check to see if the new
351 * pos is within the bounds of the main frame,
352 * and perhaps wrap the toolbar if not.
357 toollist_.push_back(item);