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"
25 #include "funcrequest.h"
28 #include FORMS_H_LOCATION
30 #include "ToolbarDefaults.h"
31 #include "LyXAction.h"
33 #include "support/LAssert.h"
34 #include "support/filetools.h"
35 #include "support/lstrings.h"
40 const int standardspacing = 2; // the usual space between items
41 const int sepspace = 6; // extra space
42 const int buttonwidth = 30; // the standard button width
43 const int height = 30; // the height of all items in the toolbar
45 Toolbar::Pimpl::toolbarItem::toolbarItem()
46 : action(LFUN_NOACTION), icon(0)
50 Toolbar::Pimpl::toolbarItem::~toolbarItem()
52 // Lars said here that ~XFormsView() dealt with the icons.
53 // This is not true. But enabling this causes crashes,
54 // because somehow we kill the same icon twice :(
60 void Toolbar::Pimpl::toolbarItem::kill_icon()
63 fl_delete_object(icon);
70 Toolbar::Pimpl::toolbarItem &
71 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
76 // If we already have an icon, release it.
77 // But we don't copy the icon from ti
87 Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
88 : owner_(static_cast<XFormsView *>(o)), xpos(x), ypos(y)
91 tooltip_ = new Tooltips();
95 Toolbar::Pimpl::~Pimpl()
97 fl_freeze_form(owner_->getForm());
99 // G++ vector does not have clear defined
101 toollist_.erase(toollist_.begin(), toollist_.end());
105 fl_unfreeze_form(owner_->getForm());
110 void Toolbar::Pimpl::update()
112 ToolbarList::const_iterator p = toollist_.begin();
113 ToolbarList::const_iterator end = toollist_.end();
114 for (; p != end; ++p) {
115 if (p->action == ToolbarDefaults::LAYOUTS && combox_) {
116 if (owner_->getLyXFunc().getStatus(LFUN_LAYOUT).disabled())
117 combox_->deactivate();
126 FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
127 if (status.onoff(true)) {
128 // I'd like to use a different color
129 // here, but then the problem is to
130 // know how to use transparency with
131 // Xpm library. It seems pretty
132 // complicated to me (JMarc)
133 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
134 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
136 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
137 fl_set_object_boxtype(p->icon, FL_UP_BOX);
139 if (status.disabled()) {
140 // Is there a way here to specify a
141 // mask in order to show that the
142 // button is disabled? (JMarc)
143 fl_deactivate_object(p->icon);
146 fl_activate_object(p->icon);
151 // this one is not "C" because combox callbacks are really C++ %-|
152 void Toolbar::Pimpl::layoutSelectedCB(int, void * arg, Combox *)
154 reinterpret_cast<Toolbar::Pimpl *>(arg)->layoutSelected();
158 void Toolbar::Pimpl::layoutSelected()
160 string const & layoutguiname = combox_->getline();
161 LyXTextClass const & tc =
162 owner_->buffer()->params.getLyXTextClass();
164 LyXTextClass::const_iterator end = tc.end();
165 for (LyXTextClass::const_iterator cit = tc.begin();
167 if (_((*cit)->name()) == layoutguiname) {
168 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()));
172 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
177 void Toolbar::Pimpl::setLayout(string const & layout)
180 LyXTextClass const & tc =
181 owner_->buffer()->params.getLyXTextClass();
182 combox_->select(_(tc[layout]->name()));
187 void Toolbar::Pimpl::updateLayoutList(bool force)
189 // Update the layout display
190 if (!combox_) return;
192 // If textclass is different, we need to update the list
193 if (combox_->empty() || force) {
195 LyXTextClass const & tc =
196 owner_->buffer()->params.getLyXTextClass();
197 LyXTextClass::const_iterator end = tc.end();
198 for (LyXTextClass::const_iterator cit = tc.begin();
200 // ignore obsolete entries
201 if ((*cit)->obsoleted_by().empty())
202 combox_->addline(_((*cit)->name()));
205 // we need to do this.
210 void Toolbar::Pimpl::clearLayoutList()
219 void Toolbar::Pimpl::openLayoutList()
228 void ToolbarCB(FL_OBJECT * ob, long ac)
230 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
232 owner->getLyXFunc().dispatch(int(ac), true);
239 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
247 void setPixmap(FL_OBJECT * obj, int action)
250 FuncRequest ev = lyxaction.retrieveActionArg(action);
252 string const name = lyxaction.getActionName(ev.action);
253 if (!ev.argument.empty())
254 xpm_name = subst(name + ' ' + ev.argument, ' ','_');
258 string fullname = LibFileSearch("images", xpm_name, "xpm");
260 if (ev.action == LFUN_INSERT_MATH && !ev.argument.empty()) {
261 string arg = ev.argument.substr(1);
262 fullname = LibFileSearch("images/math/", arg, "xpm");
265 if (!fullname.empty()) {
266 lyxerr[Debug::GUI] << "Full icon name is `"
267 << fullname << "'" << endl;
268 fl_set_pixmapbutton_file(obj, fullname.c_str());
272 lyxerr << "Unable to find icon `" << xpm_name << "'" << endl;
273 fullname = LibFileSearch("images", "unknown", "xpm");
274 if (!fullname.empty()) {
275 lyxerr[Debug::GUI] << "Using default `unknown' icon"
277 fl_set_pixmapbutton_file(obj, fullname.c_str());
284 void Toolbar::Pimpl::add(int action)
289 item.action = action;
292 case ToolbarDefaults::SEPARATOR:
295 case ToolbarDefaults::NEWLINE:
296 // Not supported yet.
298 case ToolbarDefaults::LAYOUTS:
299 xpos += standardspacing;
301 combox_ = new Combox(FL_COMBOX_DROPLIST);
302 combox_->add(xpos, ypos, 135, height, 400);
303 combox_->setcallback(layoutSelectedCB, this);
304 combox_->resize(FL_RESIZE_ALL);
305 combox_->gravity(NorthWestGravity, NorthWestGravity);
309 xpos += standardspacing;
311 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
315 fl_set_object_resize(obj, FL_RESIZE_ALL);
316 fl_set_object_gravity(obj,
319 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
320 static_cast<long>(action));
321 // Remove the blue feedback rectangle
322 fl_set_pixmapbutton_focus_outline(obj, 0);
324 // initialise the tooltip
325 string const tip = _(lyxaction.helpText(obj->argument));
326 tooltip_->init(obj, tip);
328 // The view that this object belongs to.
329 obj->u_vdata = owner_;
331 setPixmap(obj, action);
332 // we must remember to update the positions
335 /* Here will come a check to see if the new
336 * pos is within the bounds of the main frame,
337 * and perhaps wrap the toolbar if not.
342 toollist_.push_back(item);