]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/XFormsToolbar.C
Tiny clean-ups.
[lyx.git] / src / frontends / xforms / XFormsToolbar.C
index a99ae6ec8ca30d94b318f2e0dcfc37acef88b926..7b6bda4e57bb959d448bbc9ff981c759ef2fbc07 100644 (file)
@@ -6,34 +6,33 @@
  * \author Lars Gullik Bjønnes
  * \author Jean-Marc Lasgouttes
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 //  Added pseudo-action handling, asierra 180296
 
 #include <config.h>
 
-
 #include "XFormsToolbar.h"
-#include "debug.h"
+
+#include "Tooltips.h"
+#include "xforms_helpers.h"
 #include "XFormsView.h"
-#include "lyxfunc.h"
-#include "FuncStatus.h"
+
 #include "buffer.h"
+#include "bufferparams.h"
+#include "debug.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
-#include "Tooltips.h"
+#include "lyxfunc.h"
+
 #include "lyx_forms.h"
 #include "combox.h"
-#include "xforms_helpers.h"
-
-#include "LyXAction.h"
-
-#include "support/LAssert.h"
-#include "support/filetools.h"
-#include "support/lstrings.h"
 
 using std::endl;
+using std::string;
+
 
 // some constants
 const int standardspacing = 2; // the usual space between items
@@ -42,7 +41,7 @@ const int buttonwidth = 30; // the standard button width
 const int height = 30; // the height of all items in the toolbar
 
 XFormsToolbar::toolbarItem::toolbarItem()
-       : action(LFUN_NOACTION), icon(0)
+       : icon(0)
 {}
 
 
@@ -83,7 +82,7 @@ XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti)
        // But we don't copy the icon from ti
        kill_icon();
 
-       action = ti.action;
+       func = ti.func;
 
        return *this;
 }
@@ -93,7 +92,7 @@ XFormsToolbar::toolbarItem::operator=(toolbarItem const & ti)
 XFormsToolbar::XFormsToolbar(LyXView * o, int x, int y)
        : owner_(static_cast<XFormsView *>(o)), combox_(0), xpos(x), ypos(y)
 {
-       tooltip_ = new Tooltips();
+       tooltip_ = new Tooltips;
 }
 
 
@@ -115,10 +114,10 @@ void XFormsToolbar::update()
        ToolbarList::const_iterator p = toollist_.begin();
        ToolbarList::const_iterator end = toollist_.end();
        for (; p != end; ++p) {
-               if (p->action == ToolbarBackend::LAYOUTS && combox_) {
+               if (p->func.action == int(ToolbarBackend::LAYOUTS) && combox_) {
                        LyXFunc const & lf = owner_->getLyXFunc();
                        bool const disable =
-                               lf.getStatus(LFUN_LAYOUT).disabled();
+                               lf.getStatus(FuncRequest(LFUN_LAYOUT)).disabled();
                        setEnabled(combox_, !disable);
                        continue;
                }
@@ -126,7 +125,7 @@ void XFormsToolbar::update()
                if (!p->icon)
                        continue;
 
-               FuncStatus const status = owner_->getLyXFunc().getStatus(p->action);
+               FuncStatus const status = owner_->getLyXFunc().getStatus(p->func);
                if (status.onoff(true)) {
                        // I'd like to use a different color
                        // here, but then the problem is to
@@ -171,7 +170,7 @@ void XFormsToolbar::layoutSelected()
 
        string const & layoutguiname = getString(combox_);
        LyXTextClass const & tc =
-               owner_->buffer()->params.getLyXTextClass();
+               owner_->buffer()->params().getLyXTextClass();
 
        LyXTextClass::const_iterator end = tc.end();
        for (LyXTextClass::const_iterator cit = tc.begin();
@@ -191,7 +190,7 @@ void XFormsToolbar::setLayout(string const & layout)
        if (!combox_)
                return;
 
-       LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
+       LyXTextClass const & tc = owner_->buffer()->params().getLyXTextClass();
        string const layoutname = _(tc[layout]->name());
 
        int const nnames = fl_get_combox_maxitems(combox_);
@@ -211,7 +210,7 @@ void XFormsToolbar::updateLayoutList()
                return;
 
        fl_clear_combox(combox_);
-       LyXTextClass const & tc = owner_->buffer()->params.getLyXTextClass();
+       LyXTextClass const & tc = owner_->buffer()->params().getLyXTextClass();
        LyXTextClass::const_iterator end = tc.end();
        for (LyXTextClass::const_iterator cit = tc.begin();
             cit != end; ++cit) {
@@ -251,9 +250,12 @@ namespace {
 
 void ToolbarCB(FL_OBJECT * ob, long ac)
 {
-       XFormsView * owner = static_cast<XFormsView *>(ob->u_vdata);
+       if (!ob || !ob->u_vdata)
+               return;
 
-       owner->getLyXFunc().dispatch(int(ac), true);
+       XFormsToolbar * ptr = static_cast<XFormsToolbar *>(ob->u_vdata);
+       XFormsView * owner = ptr->owner_;
+       owner->getLyXFunc().dispatch(ptr->funcs[ac], true);
 }
 
 
@@ -275,6 +277,8 @@ void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
        if (!toollist_.empty())
                return;
 
+       funcs.clear();
+
        ToolbarBackend::item_iterator it = tb.items.begin();
        ToolbarBackend::item_iterator end = tb.items.end();
        for (; it != end; ++it)
@@ -282,12 +286,12 @@ void XFormsToolbar::add(ToolbarBackend::Toolbar const & tb)
 }
 
 
-void XFormsToolbar::add(int action, string const & tooltip)
+void XFormsToolbar::add(FuncRequest const & func, string const & tooltip)
 {
        toolbarItem item;
-       item.action = action;
+       item.func = func;
 
-       switch (action) {
+       switch (func.action) {
        case ToolbarBackend::SEPARATOR:
                xpos += sepspace;
                break;
@@ -324,17 +328,19 @@ void XFormsToolbar::add(int action, string const & tooltip)
                fl_set_object_gravity(obj,
                                      NorthWestGravity,
                                      NorthWestGravity);
-               fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
-                                      static_cast<long>(action));
+
+               Funcs::iterator fit = funcs.insert(funcs.end(), func);
+               int const index = std::distance(funcs.begin(), fit);
+               fl_set_object_callback(obj, C_Toolbar_ToolbarCB, index);
                // Remove the blue feedback rectangle
                fl_set_pixmapbutton_focus_outline(obj, 0);
 
                tooltip_->init(obj, tooltip);
 
                // The view that this object belongs to.
-               obj->u_vdata = owner_;
+               obj->u_vdata = this;
 
-               string const xpm = toolbarbackend.getIcon(action);
+               string const xpm = toolbarbackend.getIcon(func);
                fl_set_pixmapbutton_file(obj, xpm.c_str());
 
                // we must remember to update the positions