2 * \file xforms/Toolbar_pimpl.C
3 * Copyright 1995 Matthias Ettrich
4 * Copyright 1996-1998 Lars Gullik Bjønnes
5 * This file is part of LyX, the document processor.
6 * Licence details can be found in the file COPYING.
8 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS
13 // Added pseudo-action handling, asierra 180296
18 #include "Toolbar_pimpl.h"
20 #include "XFormsView.h"
22 #include "FuncStatus.h"
24 #include "funcrequest.h"
27 #include "lyx_forms.h"
29 #include "xforms_helpers.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 /// Display toolbar, not implemented. But moved out of line so that
61 /// linking will work properly.
62 void Toolbar::Pimpl::displayToolbar(ToolbarBackend::Toolbar const & tb,
67 void Toolbar::Pimpl::toolbarItem::kill_icon()
70 fl_delete_object(icon);
77 Toolbar::Pimpl::toolbarItem &
78 Toolbar::Pimpl::toolbarItem::operator=(toolbarItem const & ti)
83 // If we already have an icon, release it.
84 // But we don't copy the icon from ti
94 Toolbar::Pimpl::Pimpl(LyXView * o, int x, int y)
95 : owner_(static_cast<XFormsView *>(o)), combox_(0), xpos(x), ypos(y)
97 tooltip_ = new Tooltips();
101 Toolbar::Pimpl::~Pimpl()
103 fl_freeze_form(owner_->getForm());
105 // G++ vector does not have clear defined
107 toollist_.erase(toollist_.begin(), toollist_.end());
109 fl_unfreeze_form(owner_->getForm());
114 void Toolbar::Pimpl::update()
116 ToolbarList::const_iterator p = toollist_.begin();
117 ToolbarList::const_iterator end = toollist_.end();
118 for (; p != end; ++p) {
119 if (p->action == ToolbarBackend::LAYOUTS && combox_) {
120 LyXFunc const & lf = owner_->getLyXFunc();
122 lf.getStatus(LFUN_LAYOUT).disabled();
123 setEnabled(combox_, !disable);
130 FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
131 if (status.onoff(true)) {
132 // I'd like to use a different color
133 // here, but then the problem is to
134 // know how to use transparency with
135 // Xpm library. It seems pretty
136 // complicated to me (JMarc)
137 fl_set_object_color(p->icon, FL_LEFT_BCOL, FL_BLUE);
138 fl_set_object_boxtype(p->icon, FL_DOWN_BOX);
140 fl_set_object_color(p->icon, FL_MCOL, FL_BLUE);
141 fl_set_object_boxtype(p->icon, FL_UP_BOX);
143 if (status.disabled()) {
144 // Is there a way here to specify a
145 // mask in order to show that the
146 // button is disabled? (JMarc)
147 fl_deactivate_object(p->icon);
150 fl_activate_object(p->icon);
157 void C_layoutSelectedCB(FL_OBJECT * ob, long)
159 if (!ob || !ob->u_vdata)
161 Toolbar::Pimpl * ptr = static_cast<Toolbar::Pimpl *>(ob->u_vdata);
162 ptr->layoutSelected();
168 void Toolbar::Pimpl::layoutSelected()
173 string const & layoutguiname = getString(combox_);
174 LyXTextClass const & tc =
175 owner_->buffer()->params.getLyXTextClass();
177 LyXTextClass::const_iterator end = tc.end();
178 for (LyXTextClass::const_iterator cit = tc.begin();
180 if (_((*cit)->name()) == layoutguiname) {
181 owner_->getLyXFunc().dispatch(FuncRequest(LFUN_LAYOUT, (*cit)->name()), true);
185 lyxerr << "ERROR (Toolbar::Pimpl::layoutSelected): layout not found!"
190 void Toolbar::Pimpl::setLayout(string const & layout)
195 LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
196 string const layoutname = _(tc[layout]->name());
198 int const nnames = fl_get_combox_maxitems(combox_);
199 for (int i = 1; i <= nnames; ++i) {
200 string const name = fl_get_combox_line(combox_, i);
201 if (name == layoutname) {
202 fl_set_combox(combox_, i);
209 void Toolbar::Pimpl::updateLayoutList(bool force)
214 // If textclass is different, we need to update the list
215 if (fl_get_combox_maxitems(combox_) == 0 || force) {
216 fl_clear_combox(combox_);
217 LyXTextClass const & tc =
218 owner_->buffer()->params.getLyXTextClass();
219 LyXTextClass::const_iterator end = tc.end();
220 for (LyXTextClass::const_iterator cit = tc.begin();
222 // ignore obsolete entries
223 if ((*cit)->obsoleted_by().empty()) {
224 string const & name = _((*cit)->name());
225 fl_addto_combox(combox_, name.c_str());
229 // we need to do this.
230 fl_redraw_object(combox_);
234 void Toolbar::Pimpl::clearLayoutList()
239 fl_clear_combox(combox_);
240 fl_redraw_object(combox_);
244 void Toolbar::Pimpl::openLayoutList()
249 fl_show_combox_browser(combox_);
255 void ToolbarCB(FL_OBJECT * ob, long ac)
257 XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
259 owner->getLyXFunc().dispatch(int(ac), true);
265 void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
275 void Toolbar::Pimpl::add(ToolbarBackend::Toolbar const & tb)
277 // we can only handle one toolbar
278 if (!toollist_.empty())
281 ToolbarBackend::item_iterator it = tb.items.begin();
282 ToolbarBackend::item_iterator end = tb.items.end();
283 for (; it != end; ++it)
284 add(it->first, it->second);
288 void Toolbar::Pimpl::add(int action, string const & tooltip)
291 item.action = action;
294 case ToolbarBackend::SEPARATOR:
297 case ToolbarBackend::MINIBUFFER:
300 case ToolbarBackend::LAYOUTS:
301 xpos += standardspacing;
305 combox_ = fl_add_combox(FL_DROPLIST_COMBOX,
306 xpos, ypos, 135, height, "");
307 fl_set_combox_browser_height(combox_, 400);
308 fl_set_object_boxtype(combox_, FL_DOWN_BOX);
309 fl_set_object_color(combox_, FL_MCOL, FL_MCOL);
310 fl_set_object_gravity(combox_, FL_NorthWest, FL_NorthWest);
311 fl_set_object_resize(combox_, FL_RESIZE_ALL);
313 combox_->u_vdata = this;
314 fl_set_object_callback(combox_, C_layoutSelectedCB, 0);
320 xpos += standardspacing;
322 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
326 fl_set_object_resize(obj, FL_RESIZE_ALL);
327 fl_set_object_gravity(obj,
330 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
331 static_cast<long>(action));
332 // Remove the blue feedback rectangle
333 fl_set_pixmapbutton_focus_outline(obj, 0);
335 tooltip_->init(obj, tooltip);
337 // The view that this object belongs to.
338 obj->u_vdata = owner_;
340 string const xpm = toolbarbackend.getIcon(action);
341 fl_set_pixmapbutton_file(obj, xpm.c_str());
343 // we must remember to update the positions
346 /* Here will come a check to see if the new
347 * pos is within the bounds of the main frame,
348 * and perhaps wrap the toolbar if not.
354 toollist_.push_back(item);