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"
38 const int standardspacing = 2; // the usual space between items
39 const int sepspace = 6; // extra space
40 const int buttonwidth = 30; // the standard button width
41 const int height = 30; // the height of all items in the toolbar
43 XFormsToolbar::toolbarItem::toolbarItem()
48 XFormsToolbar::toolbarItem::~toolbarItem()
50 // Lars said here that ~XFormsView() dealt with the icons.
51 // This is not true. But enabling this causes crashes,
52 // because somehow we kill the same icon twice :(
58 /// Display toolbar, not implemented. But moved out of line so that
59 /// linking will work properly.
60 void XFormsToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/,
65 void XFormsToolbar::toolbarItem::kill_icon()
68 fl_delete_object(icon);
75 XFormsToolbar::toolbarItem &
76 XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti)
81 // If we already have an icon, release it.
82 // But we don't copy the icon from ti
92 XFormsToolbar::XFormsToolbar(LyXView * o, int x, int y)
93 : owner_(static_cast<XFormsView *>(o)), combox_(0), xpos(x), ypos(y)
95 tooltip_ = new Tooltips;
99 XFormsToolbar::~XFormsToolbar()
101 fl_freeze_form(owner_->getForm());
103 // G++ vector does not have clear defined
105 toollist_.erase(toollist_.begin(), toollist_.end());
107 fl_unfreeze_form(owner_->getForm());
112 void XFormsToolbar::update()
114 ToolbarList::const_iterator p = toollist_.begin();
115 ToolbarList::const_iterator end = toollist_.end();
116 for (; p != end; ++p) {
117 if (p->func.action == int(ToolbarBackend::LAYOUTS) && combox_) {
118 LyXFunc const & lf = owner_->getLyXFunc();
120 lf.getStatus(FuncRequest(LFUN_LAYOUT)).disabled();
121 setEnabled(combox_, !disable);
128 FuncStatus const status = owner_->getLyXFunc().getStatus(p->func);
129 if (status.onoff(true)) {
130 // I'd like to use a different color
131 // here, but then the problem is to
132 // know how to use transparency with
133 // Xpm library. It seems pretty
134 // complicated to me (JMarc)
135 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
136 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
138 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
139 fl_set_object_boxtype(p->icon, FL_UP_BOX);
141 if (status.disabled()) {
142 // Is there a way here to specify a
143 // mask in order to show that the
144 // button is disabled? (JMarc)
145 fl_deactivate_object(p->icon);
148 fl_activate_object(p->icon);
155 void C_layoutSelectedCB(FL_OBJECT * ob, long)
157 if (!ob || !ob->u_vdata)
159 XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
160 ptr->layoutSelected();
166 void XFormsToolbar::layoutSelected()
171 string const & layoutguiname = getString(combox_);
172 LyXTextClass const & tc =
173 owner_->buffer()->params().getLyXTextClass();
175 LyXTextClass::const_iterator end = tc.end();
176 for (LyXTextClass::const_iterator cit = tc.begin();
178 if (_((*cit)->name()) == layoutguiname) {
179 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
183 lyxerr << "ERROR (XFormsToolbar::layoutSelected): layout not found!"
188 void XFormsToolbar::setLayout(string const & layout)
193 LyXTextClass const & tc = owner_->buffer()->params().getLyXTextClass();
194 string const layoutname = _(tc[layout]->name());
196 int const nnames = fl_get_combox_maxitems(combox_);
197 for (int i = 1; i <= nnames; ++i) {
198 string const name = fl_get_combox_line(combox_, i);
199 if (name == layoutname) {
200 fl_set_combox(combox_, i);
207 void XFormsToolbar::updateLayoutList()
212 fl_clear_combox(combox_);
213 LyXTextClass const & tc = owner_->buffer()->params().getLyXTextClass();
214 LyXTextClass::const_iterator end = tc.end();
215 for (LyXTextClass::const_iterator cit = tc.begin();
217 // ignore obsolete entries
218 if ((*cit)->obsoleted_by().empty()) {
219 string const & name = _((*cit)->name());
220 fl_addto_combox(combox_, name.c_str());
224 // we need to do this.
225 fl_redraw_object(combox_);
229 void XFormsToolbar::clearLayoutList()
234 Toolbar::clearLayoutList();
235 fl_clear_combox(combox_);
236 fl_redraw_object(combox_);
240 void XFormsToolbar::openLayoutList()
245 fl_show_combox_browser(combox_);
251 void ToolbarCB(FL_OBJECT * ob, long ac)
253 if (!ob || !ob->u_vdata)
256 XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
257 XFormsView * owner = ptr->owner_;
258 owner->getLyXFunc().dispatch(ptr->funcs[ac], true);
264 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
274 void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
276 // we can only handle one toolbar
277 if (!toollist_.empty())
282 ToolbarBackend::item_iterator it = tb.items.begin();
283 ToolbarBackend::item_iterator end = tb.items.end();
284 for (; it != end; ++it)
285 add(it->first, it->second);
289 void XFormsToolbar::add(FuncRequest const & func, string const & tooltip)
294 switch (func.action) {
295 case ToolbarBackend::SEPARATOR:
298 case ToolbarBackend::MINIBUFFER:
301 case ToolbarBackend::LAYOUTS:
302 xpos += standardspacing;
306 combox_ = fl_add_combox(FL_DROPLIST_COMBOX,
307 xpos, ypos, 135, height, "");
308 fl_set_combox_browser_height(combox_, 400);
309 fl_set_object_boxtype(combox_, FL_DOWN_BOX);
310 fl_set_object_color(combox_, FL_MCOL, FL_MCOL);
311 fl_set_object_gravity(combox_, FL_NorthWest, FL_NorthWest);
312 fl_set_object_resize(combox_, FL_RESIZE_ALL);
314 combox_->u_vdata = this;
315 fl_set_object_callback(combox_, C_layoutSelectedCB, 0);
321 xpos += standardspacing;
323 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
327 fl_set_object_resize(obj, FL_RESIZE_ALL);
328 fl_set_object_gravity(obj,
332 Funcs::iterator fit = funcs.insert(funcs.end(), func);
333 int const index = std::distance(funcs.begin(), fit);
334 fl_set_object_callback(obj, C_Toolbar_ToolbarCB, index);
335 // Remove the blue feedback rectangle
336 fl_set_pixmapbutton_focus_outline(obj, 0);
338 tooltip_->init(obj, tooltip);
340 // The view that this object belongs to.
343 string const xpm = toolbarbackend.getIcon(func);
344 fl_set_pixmapbutton_file(obj, xpm.c_str());
346 // we must remember to update the positions
349 /* Here will come a check to see if the new
350 * pos is within the bounds of the main frame,
351 * and perhaps wrap the toolbar if not.
357 toollist_.push_back(item);