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"
24 #include "funcrequest.h"
25 #include "FuncStatus.h"
29 #include "lyx_forms.h"
36 const int standardspacing = 2; // the usual space between items
37 const int sepspace = 6; // extra space
38 const int buttonwidth = 30; // the standard button width
39 const int height = 30; // the height of all items in the toolbar
41 XFormsToolbar::toolbarItem::toolbarItem()
42 : action(LFUN_NOACTION), icon(0)
46 XFormsToolbar::toolbarItem::~toolbarItem()
48 // Lars said here that ~XFormsView() dealt with the icons.
49 // This is not true. But enabling this causes crashes,
50 // because somehow we kill the same icon twice :(
56 /// Display toolbar, not implemented. But moved out of line so that
57 /// linking will work properly.
58 void XFormsToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/,
63 void XFormsToolbar::toolbarItem::kill_icon()
66 fl_delete_object(icon);
73 XFormsToolbar::toolbarItem &
74 XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti)
79 // If we already have an icon, release it.
80 // But we don't copy the icon from ti
90 XFormsToolbar::XFormsToolbar(LyXView * o, int x, int y)
91 : owner_(static_cast<XFormsView *>(o)), combox_(0), xpos(x), ypos(y)
93 tooltip_ = new Tooltips();
97 XFormsToolbar::~XFormsToolbar()
99 fl_freeze_form(owner_->getForm());
101 // G++ vector does not have clear defined
103 toollist_.erase(toollist_.begin(), toollist_.end());
105 fl_unfreeze_form(owner_->getForm());
110 void XFormsToolbar::update()
112 ToolbarList::const_iterator p = toollist_.begin();
113 ToolbarList::const_iterator end = toollist_.end();
114 for (; p != end; ++p) {
115 if (p->action == ToolbarBackend::LAYOUTS && combox_) {
116 LyXFunc const & lf = owner_->getLyXFunc();
118 lf.getStatus(LFUN_LAYOUT).disabled();
119 setEnabled(combox_, !disable);
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);
153 void C_layoutSelectedCB(FL_OBJECT * ob, long)
155 if (!ob || !ob->u_vdata)
157 XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
158 ptr->layoutSelected();
164 void XFormsToolbar::layoutSelected()
169 string const & layoutguiname = getString(combox_);
170 LyXTextClass const & tc =
171 owner_->buffer()->params.getLyXTextClass();
173 LyXTextClass::const_iterator end = tc.end();
174 for (LyXTextClass::const_iterator cit = tc.begin();
176 if (_((*cit)->name()) == layoutguiname) {
177 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
181 lyxerr << "ERROR (XFormsToolbar::layoutSelected): layout not found!"
186 void XFormsToolbar::setLayout(string const & layout)
191 LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
192 string const layoutname = _(tc[layout]->name());
194 int const nnames = fl_get_combox_maxitems(combox_);
195 for (int i = 1; i <= nnames; ++i) {
196 string const name = fl_get_combox_line(combox_, i);
197 if (name == layoutname) {
198 fl_set_combox(combox_, i);
205 void XFormsToolbar::updateLayoutList()
210 fl_clear_combox(combox_);
211 LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
212 LyXTextClass::const_iterator end = tc.end();
213 for (LyXTextClass::const_iterator cit = tc.begin();
215 // ignore obsolete entries
216 if ((*cit)->obsoleted_by().empty()) {
217 string const & name = _((*cit)->name());
218 fl_addto_combox(combox_, name.c_str());
222 // we need to do this.
223 fl_redraw_object(combox_);
227 void XFormsToolbar::clearLayoutList()
232 Toolbar::clearLayoutList();
233 fl_clear_combox(combox_);
234 fl_redraw_object(combox_);
238 void XFormsToolbar::openLayoutList()
243 fl_show_combox_browser(combox_);
249 void ToolbarCB(FL_OBJECT * ob, long ac)
251 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
253 owner->getLyXFunc().dispatch(int(ac), true);
259 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
269 void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
271 // we can only handle one toolbar
272 if (!toollist_.empty())
275 ToolbarBackend::item_iterator it = tb.items.begin();
276 ToolbarBackend::item_iterator end = tb.items.end();
277 for (; it != end; ++it)
278 add(it->first, it->second);
282 void XFormsToolbar::add(int action, string const & tooltip)
285 item.action = action;
288 case ToolbarBackend::SEPARATOR:
291 case ToolbarBackend::MINIBUFFER:
294 case ToolbarBackend::LAYOUTS:
295 xpos += standardspacing;
299 combox_ = fl_add_combox(FL_DROPLIST_COMBOX,
300 xpos, ypos, 135, height, "");
301 fl_set_combox_browser_height(combox_, 400);
302 fl_set_object_boxtype(combox_, FL_DOWN_BOX);
303 fl_set_object_color(combox_, FL_MCOL, FL_MCOL);
304 fl_set_object_gravity(combox_, FL_NorthWest, FL_NorthWest);
305 fl_set_object_resize(combox_, FL_RESIZE_ALL);
307 combox_->u_vdata = this;
308 fl_set_object_callback(combox_, C_layoutSelectedCB, 0);
314 xpos += standardspacing;
316 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
320 fl_set_object_resize(obj, FL_RESIZE_ALL);
321 fl_set_object_gravity(obj,
324 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
325 static_cast<long>(action));
326 // Remove the blue feedback rectangle
327 fl_set_pixmapbutton_focus_outline(obj, 0);
329 tooltip_->init(obj, tooltip);
331 // The view that this object belongs to.
332 obj->u_vdata = owner_;
334 string const xpm = toolbarbackend.getIcon(action);
335 fl_set_pixmapbutton_file(obj, xpm.c_str());
337 // we must remember to update the positions
340 /* Here will come a check to see if the new
341 * pos is within the bounds of the main frame,
342 * and perhaps wrap the toolbar if not.
348 toollist_.push_back(item);