2 * \file XFormsToolbar.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
12 // Added pseudo-action handling, asierra 180296
17 #include "XFormsToolbar.h"
19 #include "XFormsView.h"
21 #include "FuncStatus.h"
23 #include "funcrequest.h"
26 #include "lyx_forms.h"
28 #include "xforms_helpers.h"
30 #include "LyXAction.h"
32 #include "support/LAssert.h"
33 #include "support/filetools.h"
34 #include "support/lstrings.h"
39 const int standardspacing = 2; // the usual space between items
40 const int sepspace = 6; // extra space
41 const int buttonwidth = 30; // the standard button width
42 const int height = 30; // the height of all items in the toolbar
44 XFormsToolbar::toolbarItem::toolbarItem()
45 : action(LFUN_NOACTION), icon(0)
49 XFormsToolbar::toolbarItem::~toolbarItem()
51 // Lars said here that ~XFormsView() dealt with the icons.
52 // This is not true. But enabling this causes crashes,
53 // because somehow we kill the same icon twice :(
59 /// Display toolbar, not implemented. But moved out of line so that
60 /// linking will work properly.
61 void XFormsToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/,
66 void XFormsToolbar::toolbarItem::kill_icon()
69 fl_delete_object(icon);
76 XFormsToolbar::toolbarItem &
77 XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti)
82 // If we already have an icon, release it.
83 // But we don't copy the icon from ti
93 XFormsToolbar::XFormsToolbar(LyXView * o, int x, int y)
94 : owner_(static_cast<XFormsView *>(o)), combox_(0), xpos(x), ypos(y)
96 tooltip_ = new Tooltips();
100 XFormsToolbar::~XFormsToolbar()
102 fl_freeze_form(owner_->getForm());
104 // G++ vector does not have clear defined
106 toollist_.erase(toollist_.begin(), toollist_.end());
108 fl_unfreeze_form(owner_->getForm());
113 void XFormsToolbar::update()
115 ToolbarList::const_iterator p = toollist_.begin();
116 ToolbarList::const_iterator end = toollist_.end();
117 for (; p != end; ++p) {
118 if (p->action == ToolbarBackend::LAYOUTS && combox_) {
119 LyXFunc const & lf = owner_->getLyXFunc();
121 lf.getStatus(LFUN_LAYOUT).disabled();
122 setEnabled(combox_, !disable);
129 FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
130 if (status.onoff(true)) {
131 // I'd like to use a different color
132 // here, but then the problem is to
133 // know how to use transparency with
134 // Xpm library. It seems pretty
135 // complicated to me (JMarc)
136 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
137 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
139 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
140 fl_set_object_boxtype(p->icon, FL_UP_BOX);
142 if (status.disabled()) {
143 // Is there a way here to specify a
144 // mask in order to show that the
145 // button is disabled? (JMarc)
146 fl_deactivate_object(p->icon);
149 fl_activate_object(p->icon);
156 void C_layoutSelectedCB(FL_OBJECT * ob, long)
158 if (!ob || !ob->u_vdata)
160 XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
161 ptr->layoutSelected();
167 void XFormsToolbar::layoutSelected()
172 string const & layoutguiname = getString(combox_);
173 LyXTextClass const & tc =
174 owner_->buffer()->params.getLyXTextClass();
176 LyXTextClass::const_iterator end = tc.end();
177 for (LyXTextClass::const_iterator cit = tc.begin();
179 if (_((*cit)->name()) == layoutguiname) {
180 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
184 lyxerr << "ERROR (XFormsToolbar::layoutSelected): layout not found!"
189 void XFormsToolbar::setLayout(string const & layout)
194 LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
195 string const layoutname = _(tc[layout]->name());
197 int const nnames = fl_get_combox_maxitems(combox_);
198 for (int i = 1; i <= nnames; ++i) {
199 string const name = fl_get_combox_line(combox_, i);
200 if (name == layoutname) {
201 fl_set_combox(combox_, i);
208 void XFormsToolbar::updateLayoutList()
213 fl_clear_combox(combox_);
214 LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
215 LyXTextClass::const_iterator end = tc.end();
216 for (LyXTextClass::const_iterator cit = tc.begin();
218 // ignore obsolete entries
219 if ((*cit)->obsoleted_by().empty()) {
220 string const & name = _((*cit)->name());
221 fl_addto_combox(combox_, name.c_str());
225 // we need to do this.
226 fl_redraw_object(combox_);
230 void XFormsToolbar::clearLayoutList()
235 Toolbar::clearLayoutList();
236 fl_clear_combox(combox_);
237 fl_redraw_object(combox_);
241 void XFormsToolbar::openLayoutList()
246 fl_show_combox_browser(combox_);
252 void ToolbarCB(FL_OBJECT * ob, long ac)
254 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
256 owner->getLyXFunc().dispatch(int(ac), true);
262 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
272 void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
274 // we can only handle one toolbar
275 if (!toollist_.empty())
278 ToolbarBackend::item_iterator it = tb.items.begin();
279 ToolbarBackend::item_iterator end = tb.items.end();
280 for (; it != end; ++it)
281 add(it->first, it->second);
285 void XFormsToolbar::add(int action, string const & tooltip)
288 item.action = action;
291 case ToolbarBackend::SEPARATOR:
294 case ToolbarBackend::MINIBUFFER:
297 case ToolbarBackend::LAYOUTS:
298 xpos += standardspacing;
302 combox_ = fl_add_combox(FL_DROPLIST_COMBOX,
303 xpos, ypos, 135, height, "");
304 fl_set_combox_browser_height(combox_, 400);
305 fl_set_object_boxtype(combox_, FL_DOWN_BOX);
306 fl_set_object_color(combox_, FL_MCOL, FL_MCOL);
307 fl_set_object_gravity(combox_, FL_NorthWest, FL_NorthWest);
308 fl_set_object_resize(combox_, FL_RESIZE_ALL);
310 combox_->u_vdata = this;
311 fl_set_object_callback(combox_, C_layoutSelectedCB, 0);
317 xpos += standardspacing;
319 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
323 fl_set_object_resize(obj, FL_RESIZE_ALL);
324 fl_set_object_gravity(obj,
327 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
328 static_cast<long>(action));
329 // Remove the blue feedback rectangle
330 fl_set_pixmapbutton_focus_outline(obj, 0);
332 tooltip_->init(obj, tooltip);
334 // The view that this object belongs to.
335 obj->u_vdata = owner_;
337 string const xpm = toolbarbackend.getIcon(action);
338 fl_set_pixmapbutton_file(obj, xpm.c_str());
340 // we must remember to update the positions
343 /* Here will come a check to see if the new
344 * pos is within the bounds of the main frame,
345 * and perhaps wrap the toolbar if not.
351 toollist_.push_back(item);