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 "ToolbarDefaults.h"
30 #include "LyXAction.h"
32 #include "support/LAssert.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
39 const int standardspacing = 2; // the usual space between items
40 const int sepspace = 6; // extra space
41 const int buttonwidth = 30; // the standard button width
42 const int height = 30; // the height of all items in the toolbar
44 Toolbar::Pimpl::toolbarItem::toolbarItem()
45 : action(LFUN_NOACTION), icon(0)
49 Toolbar::Pimpl::toolbarItem::~toolbarItem()
51 // Lars said here that ~XFormsView() dealt with the icons.
52 // This is not true. But enabling this causes crashes,
53 // because somehow we kill the same icon twice :(
59 void Toolbar::Pimpl::toolbarItem::kill_icon()
62 fl_delete_object(icon);
69 Toolbar::Pimpl::toolbarItem &
70 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
75 // If we already have an icon, release it.
76 // But we don't copy the icon from ti
86 Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
87 : owner_(static_cast<XFormsView *>(o)), xpos(x), ypos(y)
90 tooltip_ = new Tooltips();
94 Toolbar::Pimpl::~Pimpl()
96 fl_freeze_form(owner_->getForm());
98 // G++ vector does not have clear defined
100 toollist_.erase(toollist_.begin(), toollist_.end());
104 fl_unfreeze_form(owner_->getForm());
109 void Toolbar::Pimpl::update()
111 ToolbarList::const_iterator p = toollist_.begin();
112 ToolbarList::const_iterator end = toollist_.end();
113 for (; p != end; ++p) {
114 if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
115 if (owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled())
116 combox_->deactivate();
125 FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
126 if (status.onoff(true)) {
127 // I'd like to use a different color
128 // here, but then the problem is to
129 // know how to use transparency with
130 // Xpm library. It seems pretty
131 // complicated to me (JMarc)
132 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
133 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
135 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
136 fl_set_object_boxtype(p->icon, FL_UP_BOX);
138 if (status.disabled()) {
139 // Is there a way here to specify a
140 // mask in order to show that the
141 // button is disabled? (JMarc)
142 fl_deactivate_object(p->icon);
145 fl_activate_object(p->icon);
150 // this one is not "C" because combox callbacks are really C++ %-|
151 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
153 reinterpret_cast<Toolbar::Pimpl *>(arg)->layoutSelected();
157 void Toolbar::Pimpl::layoutSelected()
159 string const & layoutguiname = combox_->getline();
160 LyXTextClass const & tc =
161 owner_->buffer()->params.getLyXTextClass();
163 LyXTextClass::const_iterator end = tc.end();
164 for (LyXTextClass::const_iterator cit = tc.begin();
166 if (_((*cit)->name()) == layoutguiname) {
167 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
171 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
176 void Toolbar::Pimpl::setLayout(string const & layout)
179 LyXTextClass const & tc =
180 owner_->buffer()->params.getLyXTextClass();
181 combox_->select(_(tc[layout]->name()));
186 void Toolbar::Pimpl::updateLayoutList(bool force)
188 // Update the layout display
189 if (!combox_) return;
191 // If textclass is different, we need to update the list
192 if (combox_->empty() || force) {
194 LyXTextClass const & tc =
195 owner_->buffer()->params.getLyXTextClass();
196 LyXTextClass::const_iterator end = tc.end();
197 for (LyXTextClass::const_iterator cit = tc.begin();
199 // ignore obsolete entries
200 if ((*cit)->obsoleted_by().empty())
201 combox_->addline(_((*cit)->name()));
204 // we need to do this.
209 void Toolbar::Pimpl::clearLayoutList()
218 void Toolbar::Pimpl::openLayoutList()
227 void ToolbarCB(FL_OBJECT * ob, long ac)
229 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
231 owner->getLyXFunc().dispatch(int(ac), true);
238 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
246 void setPixmap(FL_OBJECT * obj, int action)
249 FuncRequest ev = lyxaction.retrieveActionArg(action);
251 string const name = lyxaction.getActionName(ev.action);
252 if (!ev.argument.empty())
253 xpm_name = subst(name + ' ' + ev.argument, ' ','_');
257 string fullname = LibFileSearch("images", xpm_name, "xpm");
259 if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
260 string arg = ev.argument.substr(1);
261 fullname = LibFileSearch("images/math/", arg, "xpm");
264 if (!fullname.empty()) {
265 lyxerr[Debug::GUI] << "Full icon name is `"
266 << fullname << '\'' << endl;
267 fl_set_pixmapbutton_file(obj, fullname.c_str());
271 lyxerr << "Unable to find icon `" << xpm_name << '\'' << endl;
272 fullname = LibFileSearch("images", "unknown", "xpm");
273 if (!fullname.empty()) {
274 lyxerr[Debug::GUI] << "Using default `unknown' icon"
276 fl_set_pixmapbutton_file(obj, fullname.c_str());
283 void Toolbar::Pimpl::add(int action)
288 item.action = action;
291 case ToolbarDefaults::SEPARATOR:
294 case ToolbarDefaults::NEWLINE:
295 // Not supported yet.
297 case ToolbarDefaults::LAYOUTS:
298 xpos += standardspacing;
300 combox_ = new Combox(FL_COMBOX_DROPLIST);
301 combox_->add(xpos, ypos, 135, height, 400);
302 combox_->setcallback(layoutSelectedCB, this);
303 combox_->resize(FL_RESIZE_ALL);
304 combox_->gravity(NorthWestGravity, NorthWestGravity);
308 xpos += standardspacing;
310 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
314 fl_set_object_resize(obj, FL_RESIZE_ALL);
315 fl_set_object_gravity(obj,
318 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
319 static_cast<long>(action));
320 // Remove the blue feedback rectangle
321 fl_set_pixmapbutton_focus_outline(obj, 0);
323 // initialise the tooltip
324 string const tip = _(lyxaction.helpText(obj->argument));
325 tooltip_->init(obj, tip);
327 // The view that this object belongs to.
328 obj->u_vdata = owner_;
330 setPixmap(obj, action);
331 // we must remember to update the positions
334 /* Here will come a check to see if the new
335 * pos is within the bounds of the main frame,
336 * and perhaps wrap the toolbar if not.
341 toollist_.push_back(item);