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
16 #include "XFormsToolbar.h"
19 #include "xforms_helpers.h"
20 #include "XFormsView.h"
23 #include "bufferparams.h"
25 #include "funcrequest.h"
26 #include "FuncStatus.h"
30 #include "lyx_forms.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()
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->func.action == int(ToolbarBackend::LAYOUTS) && combox_) {
119 LyXFunc const & lf = owner_->getLyXFunc();
121 lf.getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
122 setEnabled(combox_, enable);
129 FuncStatus const status = owner_->getLyXFunc().getStatus(p->func);
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.enabled()) {
143 fl_activate_object(p->icon);
145 // Is there a way here to specify a
146 // mask in order to show that the
147 // button is disabled? (JMarc)
148 fl_deactivate_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 if (!ob || !ob->u_vdata)
257 XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
258 XFormsView * owner = ptr->owner_;
259 owner->getLyXFunc().dispatch(ptr->funcs[ac], true);
265 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
275 void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
277 // we can only handle one toolbar
278 if (!toollist_.empty())
283 ToolbarBackend::item_iterator it = tb.items.begin();
284 ToolbarBackend::item_iterator end = tb.items.end();
285 for (; it != end; ++it)
286 add(it->first, it->second);
290 void XFormsToolbar::add(FuncRequest const & func, string const & tooltip)
295 switch (func.action) {
296 case ToolbarBackend::SEPARATOR:
299 case ToolbarBackend::MINIBUFFER:
302 case ToolbarBackend::LAYOUTS:
303 xpos += standardspacing;
307 combox_ = fl_add_combox(FL_DROPLIST_COMBOX,
308 xpos, ypos, 135, height, "");
309 fl_set_combox_browser_height(combox_, 400);
310 fl_set_object_boxtype(combox_, FL_DOWN_BOX);
311 fl_set_object_color(combox_, FL_MCOL, FL_MCOL);
312 fl_set_object_gravity(combox_, FL_NorthWest, FL_NorthWest);
313 fl_set_object_resize(combox_, FL_RESIZE_ALL);
315 combox_->u_vdata = this;
316 fl_set_object_callback(combox_, C_layoutSelectedCB, 0);
322 xpos += standardspacing;
324 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
328 fl_set_object_resize(obj, FL_RESIZE_ALL);
329 fl_set_object_gravity(obj,
333 Funcs::iterator fit = funcs.insert(funcs.end(), func);
334 int const index = distance(funcs.begin(), fit);
335 fl_set_object_callback(obj, C_Toolbar_ToolbarCB, index);
336 // Remove the blue feedback rectangle
337 fl_set_pixmapbutton_focus_outline(obj, 0);
339 tooltip_->init(obj, tooltip);
341 // The view that this object belongs to.
344 string const xpm = toolbarbackend.getIcon(func);
345 fl_set_pixmapbutton_file(obj, xpm.c_str());
347 // we must remember to update the positions
350 /* Here will come a check to see if the new
351 * pos is within the bounds of the main frame,
352 * and perhaps wrap the toolbar if not.
358 toollist_.push_back(item);