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"
25 #include "funcrequest.h"
26 #include "MathsSymbols.h"
29 #include FORMS_H_LOCATION
31 #include "ToolbarDefaults.h"
32 #include "LyXAction.h"
34 #include "support/LAssert.h"
35 #include "support/filetools.h"
36 #include "support/lstrings.h"
41 const int standardspacing = 2; // the usual space between items
42 const int sepspace = 6; // extra space
43 const int buttonwidth = 30; // the standard button width
44 const int height = 30; // the height of all items in the toolbar
46 Toolbar::Pimpl::toolbarItem::toolbarItem()
47 : action(LFUN_NOACTION), icon(0)
51 Toolbar::Pimpl::toolbarItem::~toolbarItem()
53 // Lars said here that ~XFormsView() dealt with the icons.
54 // This is not true. But enabling this causes crashes,
55 // because somehow we kill the same icon twice :(
61 void Toolbar::Pimpl::toolbarItem::kill_icon()
64 fl_delete_object(icon);
71 Toolbar::Pimpl::toolbarItem &
72 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
77 // If we already have an icon, release it.
78 // But we don't copy the icon from ti
88 Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
89 : owner_(static_cast<XFormsView *>(o)), xpos(x), ypos(y)
92 tooltip_ = new Tooltips();
96 Toolbar::Pimpl::~Pimpl()
98 fl_freeze_form(owner_->getForm());
100 // G++ vector does not have clear defined
102 toollist_.erase(toollist_.begin(), toollist_.end());
106 fl_unfreeze_form(owner_->getForm());
111 void Toolbar::Pimpl::update()
113 ToolbarList::const_iterator p = toollist_.begin();
114 ToolbarList::const_iterator end = toollist_.end();
115 for (; p != end; ++p) {
116 if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
117 if (owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled())
118 combox_->deactivate();
127 FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
128 if (status.onoff(true)) {
129 // I'd like to use a different color
130 // here, but then the problem is to
131 // know how to use transparency with
132 // Xpm library. It seems pretty
133 // complicated to me (JMarc)
134 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
135 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
137 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
138 fl_set_object_boxtype(p->icon, FL_UP_BOX);
140 if (status.disabled()) {
141 // Is there a way here to specify a
142 // mask in order to show that the
143 // button is disabled? (JMarc)
144 fl_deactivate_object(p->icon);
147 fl_activate_object(p->icon);
152 // this one is not "C" because combox callbacks are really C++ %-|
153 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
155 reinterpret_cast<Toolbar::Pimpl *>(arg)->layoutSelected();
159 void Toolbar::Pimpl::layoutSelected()
161 string const & layoutguiname = combox_->getline();
162 LyXTextClass const & tc =
163 owner_->buffer()->params.getLyXTextClass();
165 LyXTextClass::const_iterator end = tc.end();
166 for (LyXTextClass::const_iterator cit = tc.begin();
168 if (_((*cit)->name()) == layoutguiname) {
169 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()));
173 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
178 void Toolbar::Pimpl::setLayout(string const & layout)
181 LyXTextClass const & tc =
182 owner_->buffer()->params.getLyXTextClass();
183 combox_->select(_(tc[layout]->name()));
188 void Toolbar::Pimpl::updateLayoutList(bool force)
190 // Update the layout display
191 if (!combox_) return;
193 // If textclass is different, we need to update the list
194 if (combox_->empty() || force) {
196 LyXTextClass const & tc =
197 owner_->buffer()->params.getLyXTextClass();
198 LyXTextClass::const_iterator end = tc.end();
199 for (LyXTextClass::const_iterator cit = tc.begin();
201 // ignore obsolete entries
202 if ((*cit)->obsoleted_by().empty())
203 combox_->addline(_((*cit)->name()));
206 // we need to do this.
211 void Toolbar::Pimpl::clearLayoutList()
220 void Toolbar::Pimpl::openLayoutList()
229 void ToolbarCB(FL_OBJECT * ob, long ac)
231 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
233 owner->getLyXFunc().dispatch(int(ac), true);
240 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
248 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
251 FuncRequest ev = lyxaction.retrieveActionArg(action);
253 string const name = lyxaction.getActionName(ev.action);
254 if (!ev.argument.empty())
255 xpm_name = subst(name + ' ' + ev.argument, ' ','_');
259 string fullname = LibFileSearch("images", xpm_name, "xpm");
261 if (!fullname.empty()) {
262 lyxerr[Debug::GUI] << "Full icon name is `"
263 << fullname << "'" << endl;
264 fl_set_pixmapbutton_file(obj, fullname.c_str());
268 if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
269 char const ** pixmap = get_pixmap_from_symbol(ev.argument.c_str(),
273 lyxerr[Debug::GUI] << "Using mathed-provided icon"
275 fl_set_pixmapbutton_data(obj,
276 const_cast<char **>(pixmap));
281 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
282 fullname = LibFileSearch("images", "unknown", "xpm");
283 if (!fullname.empty()) {
284 lyxerr[Debug::GUI] << "Using default `unknown' icon"
286 fl_set_pixmapbutton_file(obj, fullname.c_str());
293 void Toolbar::Pimpl::add(int action)
298 item.action = action;
301 case ToolbarDefaults::SEPARATOR:
304 case ToolbarDefaults::NEWLINE:
305 // Not supported yet.
307 case ToolbarDefaults::LAYOUTS:
308 xpos += standardspacing;
310 combox_ = new Combox(FL_COMBOX_DROPLIST);
311 combox_->add(xpos, ypos, 135, height, 400);
312 combox_->setcallback(layoutSelectedCB, this);
313 combox_->resize(FL_RESIZE_ALL);
314 combox_->gravity(NorthWestGravity, NorthWestGravity);
318 xpos += standardspacing;
320 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
324 fl_set_object_resize(obj, FL_RESIZE_ALL);
325 fl_set_object_gravity(obj,
328 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
329 static_cast<long>(action));
330 // Remove the blue feedback rectangle
331 fl_set_pixmapbutton_focus_outline(obj, 0);
333 // initialise the tooltip
334 string const tip = _(lyxaction.helpText(obj->argument));
335 tooltip_->init(obj, tip);
337 // The view that this object belongs to.
338 obj->u_vdata = owner_;
340 setPixmap(obj, action, buttonwidth, height);
341 // we must remember to update the positions
344 /* Here will come a check to see if the new
345 * pos is within the bounds of the main frame,
346 * and perhaps wrap the toolbar if not.
351 toollist_.push_back(item);