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()
50 action = LFUN_NOACTION;
55 Toolbar::Pimpl::toolbarItem::~toolbarItem()
57 // It seems that now this is taken care of
58 // in the XFormsView destructor. (Lgb)
63 void Toolbar::Pimpl::toolbarItem::clean()
66 fl_delete_object(icon);
73 Toolbar::Pimpl::toolbarItem &
74 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
76 // Are we assigning the object onto itself?
80 // If we already have an icon, release it.
83 // do we have to check icon too?
85 icon = 0; // locally we need to get the icon anew
92 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs & d, int x, int y)
93 : owner(static_cast<XFormsView *>(o)), sxpos(x), sypos(y)
96 tooltip_ = new Tooltips(d);
100 Toolbar::Pimpl::~Pimpl()
107 void Toolbar::Pimpl::update()
109 ToolbarList::const_iterator p = toollist.begin();
110 ToolbarList::const_iterator end = toollist.end();
111 for (; p != end; ++p) {
113 FuncStatus status = owner->getLyXFunc()->getStatus(p->action);
114 if (status.onoff(true)) {
115 // I'd like to use a different color
116 // here, but then the problem is to
117 // know how to use transparency with
118 // Xpm library. It seems pretty
119 // complicated to me (JMarc)
120 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
121 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
123 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
124 fl_set_object_boxtype(p->icon, FL_UP_BOX);
126 if (status.disabled()) {
127 // Is there a way here to specify a
128 // mask in order to show that the
129 // button is disabled? (JMarc)
130 fl_deactivate_object(p->icon);
133 fl_activate_object(p->icon);
134 } else if (p->action == ToolbarDefaults::LAYOUTS && combox) {
135 if (owner->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled())
136 combox->deactivate();
144 // this one is not "C" because combox callbacks are really C++ %-|
145 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
147 Toolbar::Pimpl * tb = reinterpret_cast<Toolbar::Pimpl *>(arg);
149 tb->layoutSelected();
153 void Toolbar::Pimpl::layoutSelected()
155 string const & layoutguiname = combox->getline();
156 LyXTextClass const & tc =
157 owner->buffer()->params.getLyXTextClass();
159 LyXTextClass::const_iterator end = tc.end();
160 for (LyXTextClass::const_iterator cit = tc.begin();
162 if (_((*cit)->name()) == layoutguiname) {
163 owner->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
167 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
172 void Toolbar::Pimpl::setLayout(string const & layout)
175 LyXTextClass const & tc =
176 owner->buffer()->params.getLyXTextClass();
177 combox->select(_(tc[layout]->name()));
182 void Toolbar::Pimpl::updateLayoutList(bool force)
184 // Update the layout display
187 // If textclass is different, we need to update the list
188 if (combox->empty() || force) {
190 LyXTextClass const & tc =
191 owner->buffer()->params.getLyXTextClass();
192 LyXTextClass::const_iterator end = tc.end();
193 for (LyXTextClass::const_iterator cit = tc.begin();
195 // ignore obsolete entries
196 if ((*cit)->obsoleted_by().empty())
197 combox->addline(_((*cit)->name()));
200 // we need to do this.
205 void Toolbar::Pimpl::clearLayoutList()
214 void Toolbar::Pimpl::openLayoutList()
223 void ToolbarCB(FL_OBJECT * ob, long ac)
225 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
227 owner->getLyXFunc()->dispatch(int(ac), true);
234 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
242 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
247 const kb_action act = lyxaction.retrieveActionArg(action, arg);
248 string const name = lyxaction.getActionName(act);
250 xpm_name = subst(name + ' ' + arg, ' ','_');
254 string fullname = LibFileSearch("images", xpm_name, "xpm");
256 if (!fullname.empty()) {
257 lyxerr[Debug::GUI] << "Full icon name is `"
258 << fullname << "'" << endl;
259 fl_set_pixmapbutton_file(obj, fullname.c_str());
263 if (act == LFUN_INSERT_MATH && !arg.empty()) {
264 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
268 lyxerr[Debug::GUI] << "Using mathed-provided icon"
270 fl_set_pixmapbutton_data(obj,
271 const_cast<char **>(pixmap));
276 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
277 fullname = LibFileSearch("images", "unknown", "xpm");
278 if (!fullname.empty()) {
279 lyxerr[Debug::GUI] << "Using default `unknown' icon"
281 fl_set_pixmapbutton_file(obj, fullname.c_str());
288 void Toolbar::Pimpl::set(bool doingmain)
290 // we shouldn't set if we have not cleaned
291 if (!cleaned) return;
296 fl_freeze_form(owner->getForm());
297 fl_addto_form(owner->getForm());
300 ToolbarList::iterator item = toollist.begin();
301 ToolbarList::iterator end = toollist.end();
302 for (; item != end; ++item) {
303 switch (item->action) {
304 case ToolbarDefaults::SEPARATOR:
307 case ToolbarDefaults::NEWLINE:
308 // Not supported yet.
310 case ToolbarDefaults::LAYOUTS:
311 xpos += standardspacing;
313 combox = new Combox(FL_COMBOX_DROPLIST);
314 combox->add(xpos, ypos, 135, height, 400);
315 combox->setcallback(layoutSelectedCB, this);
316 combox->resize(FL_RESIZE_ALL);
317 combox->gravity(NorthWestGravity, NorthWestGravity);
321 xpos += standardspacing;
323 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
327 fl_set_object_resize(obj, FL_RESIZE_ALL);
328 fl_set_object_gravity(obj,
331 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
332 static_cast<long>(item->action));
333 // Remove the blue feedback rectangle
334 fl_set_pixmapbutton_focus_outline(obj, 0);
336 // initialise the tooltip
337 string const tip = _(lyxaction.helpText(obj->argument));
338 tooltip_->init(obj, tip);
340 // The view that this object belongs to.
341 obj->u_vdata = owner;
343 setPixmap(obj, item->action, buttonwidth, height);
344 // we must remember to update the positions
347 /* Here will come a check to see if the new
348 * pos is within the bounds of the main frame,
349 * and perhaps wrap the toolbar if not.
357 fl_unfreeze_form(owner->getForm());
358 // Should be safe to do this here.
359 owner->updateLayoutChoice();
362 // set the state of the icons
369 void Toolbar::Pimpl::add(int action, bool doclean)
371 if (doclean && !cleaned) clean();
373 // this is what we do if we want to add to an existing
375 if (!doclean && owner) {
376 // first "hide" the toolbar buttons. This is not a real hide
377 // actually it deletes and frees the button altogether.
378 lyxerr << "Toolbar::add: \"hide\" the toolbar buttons."
383 fl_freeze_form(owner->getForm());
385 ToolbarList::iterator p = toollist.begin();
386 ToolbarList::iterator end = toollist.end();
387 for (; p != end; ++p) {
395 fl_unfreeze_form(owner->getForm());
396 cleaned = true; // this is not completely true, but OK anyway
399 // there exist some special actions not part of
400 // kb_action: SEPARATOR, LAYOUTS
403 newItem.action = action;
404 toollist.push_back(newItem);
408 void Toolbar::Pimpl::clean()
410 //reset(); // I do not understand what this reset() is, anyway
412 //now delete all the objects..
414 fl_freeze_form(owner->getForm());
416 // G++ vector does not have clear defined
418 toollist.erase(toollist.begin(), toollist.end());
420 lyxerr[Debug::GUI] << "Combox: " << combox << endl;
427 fl_unfreeze_form(owner->getForm());
428 lyxerr[Debug::GUI] << "toolbar cleaned" << endl;
433 void Toolbar::Pimpl::push(int nth)
435 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
436 << nth << '\'' << endl;
438 if (nth <= 0 || nth >= int(toollist.size())) {
439 // item nth not found...
443 fl_trigger_object(toollist[nth - 1].icon);
447 void Toolbar::Pimpl::reset()
449 //toollist = 0; // what is this supposed to do?
455 void Toolbar::Pimpl::lightReset() {
456 xpos = sxpos - standardspacing;