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 "lyxtextclasslist.h"
27 #include "LyXAction.h"
28 #include "MathsSymbols.h"
32 #include "support/LAssert.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
38 extern LyXAction lyxaction;
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()
48 action = LFUN_NOACTION;
53 Toolbar::Pimpl::toolbarItem::~toolbarItem()
59 void Toolbar::Pimpl::toolbarItem::clean()
62 fl_delete_object(icon);
69 Toolbar::Pimpl::toolbarItem &
70 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
72 // Are we assigning the object onto itself?
76 // If we already have an icon, release it.
79 // do we have to check icon too?
81 icon = 0; // locally we need to get the icon anew
88 Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
89 : owner(static_cast<XFormsView *>(o)), sxpos(x), sypos(y)
92 tooltip_ = new Tooltips();
96 Toolbar::Pimpl::~Pimpl()
103 void Toolbar::Pimpl::activate()
105 ToolbarList::const_iterator p = toollist.begin();
106 ToolbarList::const_iterator end = toollist.end();
107 for (; p != end; ++p) {
109 fl_activate_object(p->icon);
115 void Toolbar::Pimpl::deactivate()
117 ToolbarList::const_iterator p = toollist.begin();
118 ToolbarList::const_iterator end = toollist.end();
119 for (; p != end; ++p) {
121 fl_deactivate_object(p->icon);
127 void Toolbar::Pimpl::update()
129 ToolbarList::const_iterator p = toollist.begin();
130 ToolbarList::const_iterator end = toollist.end();
131 for (; p != end; ++p) {
133 FuncStatus status = owner->getLyXFunc()->getStatus(p->action);
134 if (status.onoff(true)) {
135 // I'd like to use a different color
136 // here, but then the problem is to
137 // know how to use transparency with
138 // Xpm library. It seems pretty
139 // complicated to me (JMarc)
140 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
141 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
143 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
144 fl_set_object_boxtype(p->icon, FL_UP_BOX);
146 if (status.disabled()) {
147 // Is there a way here to specify a
148 // mask in order to show that the
149 // button is disabled? (JMarc)
150 fl_deactivate_object(p->icon);
153 fl_activate_object(p->icon);
154 } else if (p->action == ToolbarDefaults::LAYOUTS && combox) {
155 if (owner->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled())
156 combox->deactivate();
164 // this one is not "C" because combox callbacks are really C++ %-|
165 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
167 Toolbar::Pimpl * tb = reinterpret_cast<Toolbar::Pimpl *>(arg);
169 tb->layoutSelected();
173 void Toolbar::Pimpl::layoutSelected()
175 string const & layoutguiname = combox->getline();
176 LyXTextClass const & tc =
177 textclasslist[owner->buffer()->params.textclass];
179 LyXTextClass::const_iterator end = tc.end();
180 for (LyXTextClass::const_iterator cit = tc.begin();
182 if (_(cit->name()) == layoutguiname) {
183 owner->getLyXFunc()->dispatch(LFUN_LAYOUT, cit->name());
187 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
192 void Toolbar::Pimpl::setLayout(string const & layout)
195 LyXTextClass const & tc =
196 textclasslist[owner->buffer()->params.textclass];
197 combox->select(_(tc[layout].name()));
202 void Toolbar::Pimpl::updateLayoutList(bool force)
204 // Update the layout display
207 // If textclass is different, we need to update the list
208 if (combox->empty() || force) {
210 LyXTextClass const & tc =
211 textclasslist[owner->buffer()->params.textclass];
212 LyXTextClass::const_iterator end = tc.end();
213 for (LyXTextClass::const_iterator cit = tc.begin();
215 // ignore obsolete entries
216 if (cit->obsoleted_by().empty())
217 combox->addline(_(cit->name()));
220 // we need to do this.
225 void Toolbar::Pimpl::clearLayoutList()
234 void Toolbar::Pimpl::openLayoutList()
243 void ToolbarCB(FL_OBJECT * ob, long ac)
245 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
247 owner->getLyXFunc()->verboseDispatch(int(ac), true);
254 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
262 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
267 const kb_action act = lyxaction.retrieveActionArg(action, arg);
268 string const name = lyxaction.getActionName(act);
270 xpm_name = subst(name + ' ' + arg, ' ','_');
274 string fullname = LibFileSearch("images", xpm_name, "xpm");
276 if (!fullname.empty()) {
277 lyxerr[Debug::GUI] << "Full icon name is `"
278 << fullname << "'" << endl;
279 fl_set_pixmapbutton_file(obj, fullname.c_str());
283 if (act == LFUN_INSERT_MATH && !arg.empty()) {
284 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
288 lyxerr[Debug::GUI] << "Using mathed-provided icon"
290 fl_set_pixmapbutton_data(obj,
291 const_cast<char **>(pixmap));
296 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
297 fullname = LibFileSearch("images", "unknown", "xpm");
298 if (!fullname.empty()) {
299 lyxerr[Debug::GUI] << "Using default `unknown' icon"
301 fl_set_pixmapbutton_file(obj, fullname.c_str());
308 void Toolbar::Pimpl::set(bool doingmain)
310 // we shouldn't set if we have not cleaned
311 if (!cleaned) return;
316 fl_freeze_form(owner->getForm());
317 fl_addto_form(owner->getForm());
320 ToolbarList::iterator item = toollist.begin();
321 ToolbarList::iterator end = toollist.end();
322 for (; item != end; ++item) {
323 switch (item->action) {
324 case ToolbarDefaults::SEPARATOR:
327 case ToolbarDefaults::NEWLINE:
328 // Not supported yet.
330 case ToolbarDefaults::LAYOUTS:
331 xpos += standardspacing;
333 combox = new Combox(FL_COMBOX_DROPLIST);
334 combox->add(xpos, ypos, 135, height, 400);
335 combox->setcallback(layoutSelectedCB, this);
336 combox->resize(FL_RESIZE_ALL);
337 combox->gravity(NorthWestGravity, NorthWestGravity);
341 xpos += standardspacing;
343 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
347 fl_set_object_resize(obj, FL_RESIZE_ALL);
348 fl_set_object_gravity(obj,
351 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
352 static_cast<long>(item->action));
353 // Remove the blue feedback rectangle
354 fl_set_pixmapbutton_focus_outline(obj, 0);
356 // initialise the tooltip
357 string const tip = _(lyxaction.helpText(obj->argument));
358 tooltip_->initTooltip(obj, tip);
360 // The view that this object belongs to.
361 obj->u_vdata = owner;
363 setPixmap(obj, item->action, buttonwidth, height);
364 // we must remember to update the positions
367 /* Here will come a check to see if the new
368 * pos is within the bounds of the main frame,
369 * and perhaps wrap the toolbar if not.
377 fl_unfreeze_form(owner->getForm());
378 // Should be safe to do this here.
379 owner->updateLayoutChoice();
382 // set the state of the icons
389 void Toolbar::Pimpl::add(int action, bool doclean)
391 if (doclean && !cleaned) clean();
393 // this is what we do if we want to add to an existing
395 if (!doclean && owner) {
396 // first "hide" the toolbar buttons. This is not a real hide
397 // actually it deletes and frees the button altogether.
398 lyxerr << "Toolbar::add: \"hide\" the toolbar buttons."
403 fl_freeze_form(owner->getForm());
405 ToolbarList::iterator p = toollist.begin();
406 ToolbarList::iterator end = toollist.end();
407 for (; p != end; ++p) {
415 fl_unfreeze_form(owner->getForm());
416 cleaned = true; // this is not completely true, but OK anyway
419 // there exist some special actions not part of
420 // kb_action: SEPARATOR, LAYOUTS
423 newItem.action = action;
424 toollist.push_back(newItem);
428 void Toolbar::Pimpl::clean()
430 //reset(); // I do not understand what this reset() is, anyway
432 //now delete all the objects..
434 fl_freeze_form(owner->getForm());
436 // G++ vector does not have clear defined
438 toollist.erase(toollist.begin(), toollist.end());
440 lyxerr[Debug::GUI] << "Combox: " << combox << endl;
447 fl_unfreeze_form(owner->getForm());
448 lyxerr[Debug::GUI] << "toolbar cleaned" << endl;
453 void Toolbar::Pimpl::push(int nth)
455 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
456 << nth << '\'' << endl;
458 if (nth <= 0 || nth >= int(toollist.size())) {
459 // item nth not found...
463 fl_trigger_object(toollist[nth - 1].icon);
467 void Toolbar::Pimpl::reset()
469 //toollist = 0; // what is this supposed to do?
475 void Toolbar::Pimpl::lightReset() {
476 xpos = sxpos - standardspacing;