2 * \file xforms/Toolbar_pimpl.C
3 * Copyright 1995 Matthias Ettrich
4 * Copyright 1996-1998 Lars Gullik Bjønnes
5 * This file is part of LyX, the document processor.
6 * Licence details can be found in the file COPYING.
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS
13 // Added pseudo-action handling, asierra 180296
18 #include "Toolbar_pimpl.h"
20 #include "XFormsView.h"
22 #include "FuncStatus.h"
24 #include "funcrequest.h"
27 #include FORMS_H_LOCATION
29 #include "xforms_helpers.h"
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)), combox_(0), xpos(x), ypos(y)
91 tooltip_ = new Tooltips();
95 Toolbar::Pimpl::~Pimpl()
97 fl_freeze_form(owner_->getForm());
99 // G++ vector does not have clear defined
101 toollist_.erase(toollist_.begin(), toollist_.end());
103 fl_unfreeze_form(owner_->getForm());
108 void Toolbar::Pimpl::update()
110 ToolbarList::const_iterator p = toollist_.begin();
111 ToolbarList::const_iterator end = toollist_.end();
112 for (; p != end; ++p) {
113 if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
114 LyXFunc const & lf = owner_->getLyXFunc();
116 lf.getStatus(LFUN_LAYOUT).disabled();
117 setEnabled(combox_, !disable);
124 FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
125 if (status.onoff(true)) {
126 // I'd like to use a different color
127 // here, but then the problem is to
128 // know how to use transparency with
129 // Xpm library. It seems pretty
130 // complicated to me (JMarc)
131 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
132 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
134 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
135 fl_set_object_boxtype(p->icon, FL_UP_BOX);
137 if (status.disabled()) {
138 // Is there a way here to specify a
139 // mask in order to show that the
140 // button is disabled? (JMarc)
141 fl_deactivate_object(p->icon);
144 fl_activate_object(p->icon);
151 void C_layoutSelectedCB(FL_OBJECT * ob, long)
153 if (!ob || !ob->u_vdata)
155 Toolbar::Pimpl * ptr = static_cast<Toolbar::Pimpl *>(ob->u_vdata);
156 ptr->layoutSelected();
162 void Toolbar::Pimpl::layoutSelected()
167 string const & layoutguiname = getString(combox_);
168 LyXTextClass const & tc =
169 owner_->buffer()->params.getLyXTextClass();
171 LyXTextClass::const_iterator end = tc.end();
172 for (LyXTextClass::const_iterator cit = tc.begin();
174 if (_((*cit)->name()) == layoutguiname) {
175 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
179 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
184 void Toolbar::Pimpl::setLayout(string const & layout)
189 LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
190 string const layoutname = _(tc[layout]->name());
192 int const nnames = fl_get_combox_maxitems(combox_);
193 for (int i = 1; i <= nnames; ++i) {
194 string const name = fl_get_combox_line(combox_, i);
195 if (name == layoutname) {
196 fl_set_combox(combox_, i);
203 void Toolbar::Pimpl::updateLayoutList(bool force)
208 // If textclass is different, we need to update the list
209 if (fl_get_combox_maxitems(combox_) == 0 || force) {
210 fl_clear_combox(combox_);
211 LyXTextClass const & tc =
212 owner_->buffer()->params.getLyXTextClass();
213 LyXTextClass::const_iterator end = tc.end();
214 for (LyXTextClass::const_iterator cit = tc.begin();
216 // ignore obsolete entries
217 if ((*cit)->obsoleted_by().empty()) {
218 string const & name = _((*cit)->name());
219 fl_addto_combox(combox_, name.c_str());
223 // we need to do this.
224 fl_redraw_object(combox_);
228 void Toolbar::Pimpl::clearLayoutList()
233 fl_clear_combox(combox_);
234 fl_redraw_object(combox_);
238 void Toolbar::Pimpl::openLayoutList()
243 fl_show_combox_browser(combox_);
249 void ToolbarCB(FL_OBJECT * ob, long ac)
251 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
253 owner->getLyXFunc().dispatch(int(ac), true);
259 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
267 void setPixmap(FL_OBJECT * obj, int action)
270 FuncRequest ev = lyxaction.retrieveActionArg(action);
272 string const name = lyxaction.getActionName(ev.action);
273 if (!ev.argument.empty())
274 xpm_name = subst(name + ' ' + ev.argument, ' ','_');
278 string fullname = LibFileSearch("images", xpm_name, "xpm");
280 if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
281 string arg = ev.argument.substr(1);
282 fullname = LibFileSearch("images/math/", arg, "xpm");
285 if (!fullname.empty()) {
286 lyxerr[Debug::GUI] << "Full icon name is `"
287 << fullname << '\'' << endl;
288 fl_set_pixmapbutton_file(obj, fullname.c_str());
292 lyxerr << "Unable to find icon `" << xpm_name << '\'' << endl;
293 fullname = LibFileSearch("images", "unknown", "xpm");
294 if (!fullname.empty()) {
295 lyxerr[Debug::GUI] << "Using default `unknown' icon"
297 fl_set_pixmapbutton_file(obj, fullname.c_str());
304 void Toolbar::Pimpl::add(int action)
307 item.action = action;
310 case ToolbarDefaults::SEPARATOR:
313 case ToolbarDefaults::NEWLINE:
314 // Not supported yet.
316 case ToolbarDefaults::LAYOUTS:
317 xpos += standardspacing;
321 combox_ = fl_add_combox(FL_DROPLIST_COMBOX,
322 xpos, ypos, 135, height, "");
323 fl_set_combox_browser_height(combox_, 400);
324 fl_set_object_boxtype(combox_, FL_DOWN_BOX);
325 fl_set_object_color(combox_, FL_MCOL, FL_MCOL);
326 fl_set_object_gravity(combox_, FL_NorthWest, FL_NorthWest);
327 fl_set_object_resize(combox_, FL_RESIZE_ALL);
329 combox_->u_vdata = this;
330 fl_set_object_callback(combox_, C_layoutSelectedCB, 0);
336 xpos += standardspacing;
338 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
342 fl_set_object_resize(obj, FL_RESIZE_ALL);
343 fl_set_object_gravity(obj,
346 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
347 static_cast<long>(action));
348 // Remove the blue feedback rectangle
349 fl_set_pixmapbutton_focus_outline(obj, 0);
351 // initialise the tooltip
352 string const tip = _(lyxaction.helpText(obj->argument));
353 tooltip_->init(obj, tip);
355 // The view that this object belongs to.
356 obj->u_vdata = owner_;
358 setPixmap(obj, action);
359 // we must remember to update the positions
362 /* Here will come a check to see if the new
363 * pos is within the bounds of the main frame,
364 * and perhaps wrap the toolbar if not.
370 toollist_.push_back(item);