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()
60 void Toolbar::Pimpl::toolbarItem::clean()
63 fl_delete_object(icon);
70 Toolbar::Pimpl::toolbarItem &
71 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
73 // Are we assigning the object onto itself?
77 // If we already have an icon, release it.
80 // do we have to check icon too?
82 icon = 0; // locally we need to get the icon anew
89 Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
90 : owner(static_cast<XFormsView *>(o)), sxpos(x), sypos(y)
93 tooltip_ = new Tooltips;
97 Toolbar::Pimpl::~Pimpl()
104 void Toolbar::Pimpl::activate()
106 ToolbarList::const_iterator p = toollist.begin();
107 ToolbarList::const_iterator end = toollist.end();
108 for (; p != end; ++p) {
110 fl_activate_object(p->icon);
116 void Toolbar::Pimpl::deactivate()
118 ToolbarList::const_iterator p = toollist.begin();
119 ToolbarList::const_iterator end = toollist.end();
120 for (; p != end; ++p) {
122 fl_deactivate_object(p->icon);
128 void Toolbar::Pimpl::update()
130 ToolbarList::const_iterator p = toollist.begin();
131 ToolbarList::const_iterator end = toollist.end();
132 for (; p != end; ++p) {
134 FuncStatus status = owner->getLyXFunc()->getStatus(p->action);
135 if (status.onoff(true)) {
136 // I'd like to use a different color
137 // here, but then the problem is to
138 // know how to use transparency with
139 // Xpm library. It seems pretty
140 // complicated to me (JMarc)
141 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
142 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
144 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
145 fl_set_object_boxtype(p->icon, FL_UP_BOX);
147 if (status.disabled()) {
148 // Is there a way here to specify a
149 // mask in order to show that the
150 // button is disabled? (JMarc)
151 fl_deactivate_object(p->icon);
154 fl_activate_object(p->icon);
155 } else if (p->action == ToolbarDefaults::LAYOUTS && combox) {
156 if (owner->getLyXFunc()->getStatus(LFUN_LAYOUT).disabled())
157 combox->deactivate();
165 // this one is not "C" because combox callbacks are really C++ %-|
166 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
168 Toolbar::Pimpl * tb = reinterpret_cast<Toolbar::Pimpl *>(arg);
170 tb->layoutSelected();
174 void Toolbar::Pimpl::layoutSelected()
176 string const & layoutguiname = combox->getline();
177 LyXTextClass const & tc =
178 textclasslist[owner->buffer()->params.textclass];
180 LyXTextClass::const_iterator end = tc.end();
181 for (LyXTextClass::const_iterator cit = tc.begin();
183 if (_(cit->name()) == layoutguiname) {
184 owner->getLyXFunc()->dispatch(LFUN_LAYOUT, cit->name());
188 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
193 void Toolbar::Pimpl::setLayout(string const & layout)
196 LyXTextClass const & tc =
197 textclasslist[owner->buffer()->params.textclass];
198 combox->select(_(tc[layout].name()));
203 void Toolbar::Pimpl::updateLayoutList(bool force)
205 // Update the layout display
208 // If textclass is different, we need to update the list
209 if (combox->empty() || force) {
211 LyXTextClass const & tc =
212 textclasslist[owner->buffer()->params.textclass];
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 combox->addline(_(cit->name()));
221 // we need to do this.
226 void Toolbar::Pimpl::clearLayoutList()
235 void Toolbar::Pimpl::openLayoutList()
244 void ToolbarCB(FL_OBJECT * ob, long ac)
246 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
248 owner->getLyXFunc()->verboseDispatch(int(ac), true);
255 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
263 void setPixmap(FL_OBJECT * obj, int action, int buttonwidth, int height)
268 const kb_action act = lyxaction.retrieveActionArg(action, arg);
269 string const name = lyxaction.getActionName(act);
271 xpm_name = subst(name + ' ' + arg, ' ','_');
275 string fullname = LibFileSearch("images", xpm_name, "xpm");
277 if (!fullname.empty()) {
278 lyxerr[Debug::GUI] << "Full icon name is `"
279 << fullname << "'" << endl;
280 fl_set_pixmapbutton_file(obj, fullname.c_str());
284 if (act == LFUN_INSERT_MATH && !arg.empty()) {
285 char const ** pixmap = get_pixmap_from_symbol(arg.c_str(),
289 lyxerr[Debug::GUI] << "Using mathed-provided icon"
291 fl_set_pixmapbutton_data(obj,
292 const_cast<char **>(pixmap));
297 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
298 fullname = LibFileSearch("images", "unknown", "xpm");
299 if (!fullname.empty()) {
300 lyxerr[Debug::GUI] << "Using default `unknown' icon"
302 fl_set_pixmapbutton_file(obj, fullname.c_str());
309 void Toolbar::Pimpl::set(bool doingmain)
311 // we shouldn't set if we have not cleaned
312 if (!cleaned) return;
317 fl_freeze_form(owner->getForm());
318 fl_addto_form(owner->getForm());
321 ToolbarList::iterator item = toollist.begin();
322 ToolbarList::iterator end = toollist.end();
323 for (; item != end; ++item) {
324 switch (item->action) {
325 case ToolbarDefaults::SEPARATOR:
328 case ToolbarDefaults::NEWLINE:
329 // Not supported yet.
331 case ToolbarDefaults::LAYOUTS:
332 xpos += standardspacing;
334 combox = new Combox(FL_COMBOX_DROPLIST);
335 combox->add(xpos, ypos, 135, height, 400);
336 combox->setcallback(layoutSelectedCB, this);
337 combox->resize(FL_RESIZE_ALL);
338 combox->gravity(NorthWestGravity, NorthWestGravity);
342 xpos += standardspacing;
344 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
348 fl_set_object_resize(obj, FL_RESIZE_ALL);
349 fl_set_object_gravity(obj,
352 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
353 static_cast<long>(item->action));
354 // Remove the blue feedback rectangle
355 fl_set_pixmapbutton_focus_outline(obj, 0);
357 // initialise the tooltip
358 string const tip = _(lyxaction.helpText(obj->argument));
359 tooltip_->init(obj, tip);
361 // The view that this object belongs to.
362 obj->u_vdata = owner;
364 setPixmap(obj, item->action, buttonwidth, height);
365 // we must remember to update the positions
368 /* Here will come a check to see if the new
369 * pos is within the bounds of the main frame,
370 * and perhaps wrap the toolbar if not.
378 fl_unfreeze_form(owner->getForm());
379 // Should be safe to do this here.
380 owner->updateLayoutChoice();
383 // set the state of the icons
390 void Toolbar::Pimpl::add(int action, bool doclean)
392 if (doclean && !cleaned) clean();
394 // this is what we do if we want to add to an existing
396 if (!doclean && owner) {
397 // first "hide" the toolbar buttons. This is not a real hide
398 // actually it deletes and frees the button altogether.
399 lyxerr << "Toolbar::add: \"hide\" the toolbar buttons."
404 fl_freeze_form(owner->getForm());
406 ToolbarList::iterator p = toollist.begin();
407 ToolbarList::iterator end = toollist.end();
408 for (; p != end; ++p) {
416 fl_unfreeze_form(owner->getForm());
417 cleaned = true; // this is not completely true, but OK anyway
420 // there exist some special actions not part of
421 // kb_action: SEPARATOR, LAYOUTS
424 newItem.action = action;
425 toollist.push_back(newItem);
429 void Toolbar::Pimpl::clean()
431 //reset(); // I do not understand what this reset() is, anyway
433 //now delete all the objects..
435 fl_freeze_form(owner->getForm());
437 // G++ vector does not have clear defined
439 toollist.erase(toollist.begin(), toollist.end());
441 lyxerr[Debug::GUI] << "Combox: " << combox << endl;
448 fl_unfreeze_form(owner->getForm());
449 lyxerr[Debug::GUI] << "toolbar cleaned" << endl;
454 void Toolbar::Pimpl::push(int nth)
456 lyxerr[Debug::GUI] << "Toolbar::push: trying to trigger no `"
457 << nth << '\'' << endl;
459 if (nth <= 0 || nth >= int(toollist.size())) {
460 // item nth not found...
464 fl_trigger_object(toollist[nth - 1].icon);
468 void Toolbar::Pimpl::reset()
470 //toollist = 0; // what is this supposed to do?
476 void Toolbar::Pimpl::lightReset() {
477 xpos = sxpos - standardspacing;