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"
31 #include FORMS_H_LOCATION
33 #include "support/LAssert.h"
34 #include "support/filetools.h"
35 #include "support/lstrings.h"
39 extern LyXAction lyxaction;
42 const int standardspacing = 2; // the usual space between items
43 const int sepspace = 6; // extra space
44 const int buttonwidth = 30; // the standard button width
45 const int height = 30; // the height of all items in the toolbar
47 Toolbar::Pimpl::toolbarItem::toolbarItem()
49 action = LFUN_NOACTION;
54 Toolbar::Pimpl::toolbarItem::~toolbarItem()
56 // It seems that now this is taken care of
57 // in the XFormsView destructor. (Lgb)
62 void Toolbar::Pimpl::toolbarItem::clean()
65 fl_delete_object(icon);
72 Toolbar::Pimpl::toolbarItem &
73 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
75 // Are we assigning the object onto itself?
79 // If we already have an icon, release it.
82 // do we have to check icon too?
84 icon = 0; // locally we need to get the icon anew
91 Toolbar::Pimpl::Pimpl(LyXView * o, Dialogs & d, int x, int y)
92 : owner(static_cast<XFormsView *>(o)), sxpos(x), sypos(y)
95 tooltip_ = new Tooltips(d);
99 Toolbar::Pimpl::~Pimpl()
106 void Toolbar::Pimpl::update()
108 ToolbarList::const_iterator p = toollist.begin();
109 ToolbarList::const_iterator end = toollist.end();
110 for (; p != end; ++p) {
112 FuncStatus status = owner->getLyXFunc()->getStatus(p->action);
113 if (status.onoff(true)) {
114 // I'd like to use a different color
115 // here, but then the problem is to
116 // know how to use transparency with
117 // Xpm library. It seems pretty
118 // complicated to me (JMarc)
119 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
120 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
122 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
123 fl_set_object_boxtype(p->icon, FL_UP_BOX);
125 if (status.disabled()) {
126 // Is there a way here to specify a
127 // mask in order to show that the
128 // button is disabled? (JMarc)
129 fl_deactivate_object(p->icon);
132 fl_activate_object(p->icon);
133 } else if (p->action == ToolbarDefaults::LAYOUTS && combox) {
134 if (owner->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled())
135 combox->deactivate();
143 // this one is not "C" because combox callbacks are really C++ %-|
144 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
146 Toolbar::Pimpl * tb = reinterpret_cast<Toolbar::Pimpl *>(arg);
148 tb->layoutSelected();
152 void Toolbar::Pimpl::layoutSelected()
154 string const & layoutguiname = combox->getline();
155 LyXTextClass const & tc =
156 textclasslist[owner->buffer()->params.textclass];
158 LyXTextClass::const_iterator end = tc.end();
159 for (LyXTextClass::const_iterator cit = tc.begin();
161 if (_((*cit)->name()) == layoutguiname) {
162 owner->getLyXFunc()->dispatch(LFUN_LAYOUT, (*cit)->name());
166 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
171 void Toolbar::Pimpl::setLayout(string const & layout)
174 LyXTextClass const & tc =
175 textclasslist[owner->buffer()->params.textclass];
176 combox->select(_(tc[layout]->name()));
181 void Toolbar::Pimpl::updateLayoutList(bool force)
183 // Update the layout display
186 // If textclass is different, we need to update the list
187 if (combox->empty() || force) {
189 LyXTextClass const & tc =
190 textclasslist[owner->buffer()->params.textclass];
191 LyXTextClass::const_iterator end = tc.end();
192 for (LyXTextClass::const_iterator cit = tc.begin();
194 // ignore obsolete entries
195 if ((*cit)->obsoleted_by().empty())
196 combox->addline(_((*cit)->name()));
199 // we need to do this.
204 void Toolbar::Pimpl::clearLayoutList()
213 void Toolbar::Pimpl::openLayoutList()
222 void ToolbarCB(FL_OBJECT * ob, long ac)
224 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
226 owner->getLyXFunc()->dispatch(int(ac), true);
233 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
241 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
246 const kb_action act = lyxaction.retrieveActionArg(action, arg);
247 string const name = lyxaction.getActionName(act);
249 xpm_name = subst(name + ' ' + arg, ' ','_');
253 string fullname = LibFileSearch("images", xpm_name, "xpm");
255 if (!fullname.empty()) {
256 lyxerr[Debug::GUI] << "Full icon name is `"
257 << fullname << "'" << endl;
258 fl_set_pixmapbutton_file(obj, fullname.c_str());
262 if (act == LFUN_INSERT_MATH && !arg.empty()) {
263 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
267 lyxerr[Debug::GUI] << "Using mathed-provided icon"
269 fl_set_pixmapbutton_data(obj,
270 const_cast<char **>(pixmap));
275 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
276 fullname = LibFileSearch("images", "unknown", "xpm");
277 if (!fullname.empty()) {
278 lyxerr[Debug::GUI] << "Using default `unknown' icon"
280 fl_set_pixmapbutton_file(obj, fullname.c_str());
287 void Toolbar::Pimpl::set(bool doingmain)
289 // we shouldn't set if we have not cleaned
290 if (!cleaned) return;
295 fl_freeze_form(owner->getForm());
296 fl_addto_form(owner->getForm());
299 ToolbarList::iterator item = toollist.begin();
300 ToolbarList::iterator end = toollist.end();
301 for (; item != end; ++item) {
302 switch (item->action) {
303 case ToolbarDefaults::SEPARATOR:
306 case ToolbarDefaults::NEWLINE:
307 // Not supported yet.
309 case ToolbarDefaults::LAYOUTS:
310 xpos += standardspacing;
312 combox = new Combox(FL_COMBOX_DROPLIST);
313 combox->add(xpos, ypos, 135, height, 400);
314 combox->setcallback(layoutSelectedCB, this);
315 combox->resize(FL_RESIZE_ALL);
316 combox->gravity(NorthWestGravity, NorthWestGravity);
320 xpos += standardspacing;
322 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
326 fl_set_object_resize(obj, FL_RESIZE_ALL);
327 fl_set_object_gravity(obj,
330 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
331 static_cast<long>(item->action));
332 // Remove the blue feedback rectangle
333 fl_set_pixmapbutton_focus_outline(obj, 0);
335 // initialise the tooltip
336 string const tip = _(lyxaction.helpText(obj->argument));
337 tooltip_->init(obj, tip);
339 // The view that this object belongs to.
340 obj->u_vdata = owner;
342 setPixmap(obj, item->action, buttonwidth, height);
343 // we must remember to update the positions
346 /* Here will come a check to see if the new
347 * pos is within the bounds of the main frame,
348 * and perhaps wrap the toolbar if not.
356 fl_unfreeze_form(owner->getForm());
357 // Should be safe to do this here.
358 owner->updateLayoutChoice();
361 // set the state of the icons
368 void Toolbar::Pimpl::add(int action, bool doclean)
370 if (doclean && !cleaned) clean();
372 // this is what we do if we want to add to an existing
374 if (!doclean && owner) {
375 // first "hide" the toolbar buttons. This is not a real hide
376 // actually it deletes and frees the button altogether.
377 lyxerr << "Toolbar::add: \"hide\" the toolbar buttons."
382 fl_freeze_form(owner->getForm());
384 ToolbarList::iterator p = toollist.begin();
385 ToolbarList::iterator end = toollist.end();
386 for (; p != end; ++p) {
394 fl_unfreeze_form(owner->getForm());
395 cleaned = true; // this is not completely true, but OK anyway
398 // there exist some special actions not part of
399 // kb_action: SEPARATOR, LAYOUTS
402 newItem.action = action;
403 toollist.push_back(newItem);
407 void Toolbar::Pimpl::clean()
409 //reset(); // I do not understand what this reset() is, anyway
411 //now delete all the objects..
413 fl_freeze_form(owner->getForm());
415 // G++ vector does not have clear defined
417 toollist.erase(toollist.begin(), toollist.end());
419 lyxerr[Debug::GUI] << "Combox: " << combox << endl;
426 fl_unfreeze_form(owner->getForm());
427 lyxerr[Debug::GUI] << "toolbar cleaned" << endl;
432 void Toolbar::Pimpl::push(int nth)
434 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
435 << nth << '\'' << endl;
437 if (nth <= 0 || nth >= int(toollist.size())) {
438 // item nth not found...
442 fl_trigger_object(toollist[nth - 1].icon);
446 void Toolbar::Pimpl::reset()
448 //toollist = 0; // what is this supposed to do?
454 void Toolbar::Pimpl::lightReset() {
455 xpos = sxpos - standardspacing;