]> git.lyx.org Git - lyx.git/blobdiff - src/toolbar.C
more changes, read the Changelog
[lyx.git] / src / toolbar.C
index 7a5a68a7370ac6462e386356a15adceb5918ed2b..db68e6c949af13e935bfec30d0d0c6f38971eadf 100644 (file)
@@ -4,7 +4,7 @@
  *           LyX, The Document Processor
  *
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-1999 The LyX Team.
+ *           Copyright 1995-2000 The LyX Team.
  *
  *           This file is Copyright 1996-1998
  *           Lars Gullik Bjønnes
 #include "lyxlex.h"
 #include "debug.h"
 #include "combox.h"
-#include "lyx_cb.h"
 #include "LyXView.h"
+#include "LyXAction.h"
 #include "support/lstrings.h"
+#include "lyxrc.h"
 
 #ifdef TWO_COLOR_ICONS
 #include "cut_bw.xpm"
 #include "layout_std.xpm"
 #include "build.xpm"
 
+using std::endl;
+
 // this one is not "C" because combox callbacks are really C++ %-|
-extern void LayoutsCB(int, void*);
-extern char** get_pixmap_from_symbol(char const *arg, int, int);
+extern void LayoutsCB(int, void *);
+extern char const ** get_pixmap_from_symbol(char const * arg, int, int);
 extern LyXAction lyxaction;
 
 
-enum _tooltags {
-       TO_ADD = 1,
-       TO_ENDTOOLBAR,
-        TO_SEPARATOR,
-        TO_LAYOUTS,
-        TO_NEWLINE,
-       TO_LAST
-};
-
-
-struct keyword_item toolTags[TO_LAST-1] = {
-       { "\\add", TO_ADD },
-       { "\\end_toolbar", TO_ENDTOOLBAR },
-        { "\\layouts", TO_LAYOUTS },
-        { "\\newline", TO_NEWLINE },
-        { "\\separator", TO_SEPARATOR }
-};
-
-
-Toolbar::Toolbar(Toolbar const &rct, LyXView *o, int x, int y)
+Toolbar::Toolbar(LyXView * o, int x, int y)
        : owner(o), sxpos(x), sypos(y)
 {
        combox = 0;
+#if FL_REVISION < 89
        bubble_timer = 0;
+#endif
        reset();
 
-       // extracts the toolbar struct form rct.
-       toolbarItem *tmplist = rct.toollist;
-       while (tmplist != 0) {
-               add(tmplist->action);
+       // extracts the default toolbar actions from LyXRC
+       for (ToolbarDefaults::const_iterator cit =
+                    lyxrc.toolbardefaults.begin();
+            cit != lyxrc.toolbardefaults.end(); ++cit) {
+               add((*cit));
                lyxerr[Debug::TOOLBAR] << "tool action: "
-                                      << tmplist->action << endl;
-               tmplist= tmplist->next;
+                                      << (*cit) << endl;
        }
 }
 
 
+#if FL_REVISION < 89
 // timer-cb for bubble-help (Matthias)
 void Toolbar::BubbleTimerCB(FL_OBJECT *, long data)
 {
-       FL_OBJECT* ob = (FL_OBJECT*) data;
-       char* help = (char*) ob->u_vdata;
+       FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
+       char * help = static_cast<char*>(ob->u_vdata);
        fl_show_oneliner(help, ob->form->x + ob->x,
                         ob->form->y + ob->y + ob->h);
 }
 
-extern "C" void C_Toolbar_BubbleTimerCB(FL_OBJECT *ob, long data)
+
+extern "C" void C_Toolbar_BubbleTimerCB(FL_OBJECT * ob, long data)
 {
        Toolbar::BubbleTimerCB(ob, data);
 }
 
+
 // post_handler for bubble-help (Matthias)
 int Toolbar::BubblePost(FL_OBJECT *ob, int event,
-            FL_Coord /*mx*/, FL_Coord /*my*/, int /*key*/, void */*xev*/)
+                       FL_Coord /*mx*/, FL_Coord /*my*/,
+                       int /*key*/, void */*xev*/)
 {
-       string help = (char *)ob->u_vdata;
-       Toolbar *t = (Toolbar*)ob->u_ldata;
+       string help = static_cast<char *>(ob->u_vdata);
+       Toolbar * t = reinterpret_cast<Toolbar*>(ob->u_ldata);
        
        if(event == FL_ENTER && !help.empty()){
                fl_set_object_callback(t->bubble_timer,
-                                      C_Toolbar_BubbleTimerCB, (long) ob);
+                                      C_Toolbar_BubbleTimerCB,
+                                      reinterpret_cast<long>(ob));
                fl_set_timer(t->bubble_timer, 1);
        }
        else if(event != FL_MOTION){
@@ -168,17 +159,20 @@ int Toolbar::BubblePost(FL_OBJECT *ob, int event,
        return 0;
 }
 
-extern "C" int C_Toolbar_BubblePost(FL_OBJECT *ob, int event,
-                                  FL_Coord /*mx*/, FL_Coord /*my*/, 
-                                  int key, void *xev)
+
+extern "C" int C_Toolbar_BubblePost(FL_OBJECT * ob, int event,
+                                   FL_Coord /*mx*/, FL_Coord /*my*/, 
+                                   int key, void * xev)
 {
        return Toolbar::BubblePost(ob, event, 0, 0, key, xev);
 }
+#endif
+
 
 void Toolbar::activate()
 {
-       toolbarItem *item, *tmp= 0;
-       item = toollist;
+       toolbarItem * tmp= 0;
+       toolbarItem * item = toollist;
        while(item){
                tmp = item->next;
                if (item->icon) {
@@ -191,8 +185,8 @@ void Toolbar::activate()
 
 void Toolbar::deactivate()
 {
-       toolbarItem *item, *tmp= 0;
-       item = toollist;
+       toolbarItem * tmp= 0;
+       toolbarItem * item = toollist;
        while(item){
                tmp = item->next;
                if (item->icon) {
@@ -203,27 +197,33 @@ void Toolbar::deactivate()
 }
 
 
-void Toolbar::ToolbarCB(FL_OBJECT *ob, long ac)
+void Toolbar::ToolbarCB(FL_OBJECT * ob, long ac)
 {
-       Toolbar *t = (Toolbar*)ob->u_ldata;
+#if FL_REVISION >= 89
+       Toolbar * t = static_cast<Toolbar*>(ob->u_vdata);
+#else
+       Toolbar * t = reinterpret_cast<Toolbar*>(ob->u_ldata);
+#endif
        
        string res = t->owner->getLyXFunc()->Dispatch(int(ac));
        if(!res.empty())
                lyxerr[Debug::TOOLBAR] << res << endl;
 }
 
-extern "C" void C_Toolbar_ToolbarCB(FL_OBJECT *ob, long data)
+
+extern "C" void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
 {
        Toolbar::ToolbarCB(ob, data);
 }
 
+
 int Toolbar::get_toolbar_func(string const & func)
 {
        int action = lyxaction.LookupFunc(func.c_str());
        if (action == -1) {
-               if (func == "separator"){
-                       action = TOOL_SEPARATOR;
-               } else if (func == "layouts"){
+               if (func == "separator"){
+                       action = TOOL_SEPARATOR;
+               } else if (func == "layouts"){
                         action = TOOL_LAYOUTS;
                 } else action = 0;
        }
@@ -231,126 +231,94 @@ int Toolbar::get_toolbar_func(string const & func)
 }
 
 
-void Toolbar::init()
-{
-       add(TOOL_LAYOUTS);
-       add(LFUN_MENUOPEN);
-       //add(LFUN_CLOSEBUFFER);
-       add(LFUN_MENUWRITE);
-       add(LFUN_MENUPRINT);
-       add(TOOL_SEPARATOR);
-
-       add(LFUN_CUT);
-       add(LFUN_COPY);
-       add(LFUN_PASTE);
-       add(TOOL_SEPARATOR);
-       
-       add(LFUN_EMPH);
-       add(LFUN_NOUN);
-       add(LFUN_FREE);
-       add(TOOL_SEPARATOR);
-       
-       add(LFUN_FOOTMELT);
-       add(LFUN_MARGINMELT);
-       add(LFUN_DEPTH);
-       add(TOOL_SEPARATOR);
-
-       add(LFUN_TEX);
-        add(LFUN_MATH_MODE);
-       add(TOOL_SEPARATOR);
-
-       add(LFUN_FIGURE);
-       add(LFUN_TABLE);
-       //add(LFUN_MELT);
-}
-
-
 void Toolbar::set(bool doingmain)
 {
        // we shouldn't set if we have not cleaned
        if (!cleaned) return;
        
-       toolbarItem *item;
-       FL_OBJECT *obj;
-       item = toollist;
+       FL_OBJECT * obj;
+       toolbarItem * item = toollist;
        
        if (!doingmain) {
                fl_freeze_form(owner->getForm());
                fl_addto_form(owner->getForm());
        }
 
-#if FL_REVISION <86
-       // Ensure borderwidth is 2 to get visual feedback
-       int bw = fl_get_border_width();
-       fl_set_border_width(-2);
-#endif
-
+#if FL_REVISION < 89
        // add the time if it don't exist
        if (bubble_timer == 0)
                bubble_timer = fl_add_timer(FL_HIDDEN_TIMER,
                                            xpos, ypos, 0, 0, "Timer");
+#endif
        
        while(item != 0) {
                switch(item->action){
-                 case TOOL_SEPARATOR:
-                         xpos += sepspace;
-                         item = item->next;
-                         break;
-                 case TOOL_LAYOUTS:
-                         xpos += standardspacing;
-                         if (!combox)
-                                 combox = new Combox(FL_COMBOX_DROPLIST);
-                         combox->add(xpos, ypos, 135, height, 300);
-                         combox->setcallback(LayoutsCB);
-                         combox->resize(FL_RESIZE_ALL);
-                         combox->gravity(NorthWestGravity, NorthWestGravity);
-                         item = item->next;
-                         xpos += 135;
-                         break;
-                 default:
-                         xpos += standardspacing;
-                         item->icon = obj = 
-                                 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
-                                                     xpos, ypos,
-                                                     buttonwidth,
-                                                     height, "");
-                         fl_set_object_boxtype(obj, FL_UP_BOX);
-                         fl_set_object_color(obj, FL_MCOL, FL_BLUE);
-                         fl_set_object_resize(obj, FL_RESIZE_ALL);
-                         fl_set_object_gravity(obj,
-                                               NorthWestGravity,
-                                               NorthWestGravity);
-                         fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
-                                                (long)item->action);
-#if FL_REVISION >85
-                         // Remove the blue feedback rectangle
-                         fl_set_pixmapbutton_focus_outline(obj, 0);
+               case TOOL_SEPARATOR:
+                       xpos += sepspace;
+                       item = item->next;
+                       break;
+               case TOOL_LAYOUTS:
+                       xpos += standardspacing;
+                       if (!combox)
+                               combox = new Combox(FL_COMBOX_DROPLIST);
+                       combox->add(xpos, ypos, 135, height, 400);
+                       combox->setcallback(LayoutsCB);
+                       combox->resize(FL_RESIZE_ALL);
+                       combox->gravity(NorthWestGravity, NorthWestGravity);
+                       item = item->next;
+                       xpos += 135;
+                       break;
+               default:
+                       xpos += standardspacing;
+                       item->icon = obj = 
+                               fl_add_pixmapbutton(FL_NORMAL_BUTTON,
+                                                   xpos, ypos,
+                                                   buttonwidth,
+                                                   height, "");
+                       fl_set_object_boxtype(obj, FL_UP_BOX);
+                       fl_set_object_color(obj, FL_MCOL, FL_BLUE);
+                       fl_set_object_resize(obj, FL_RESIZE_ALL);
+                       fl_set_object_gravity(obj,
+                                             NorthWestGravity,
+                                             NorthWestGravity);
+                       fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
+                                              static_cast<long>(item->action));
+                       // Remove the blue feedback rectangle
+                       fl_set_pixmapbutton_focus_outline(obj, 0);
+
+                       // set the bubble-help (Matthias)
+#if FL_REVISION >= 89
+                       // Set the tooltip
+                       fl_set_object_helper(obj, item->help.c_str());
+                       // The toolbar that this object belongs too.
+                       obj->u_vdata = this;
+                       
+                       
+#else
+#ifdef WITH_WARNINGS
+#warning This is dangerous!
 #endif
-
-                         // set the bubble-help (Matthias)
-                         obj->u_vdata = (void *) item->help.c_str();
-                         // we need to know what toolbar this item
-                         // belongs too. (Lgb)
-                         obj->u_ldata = (long) this;
+                       obj->u_vdata = const_cast<char*>(item->help.c_str());
+                       // we need to know what toolbar this item
+                       // belongs too. (Lgb)
+                       obj->u_ldata = reinterpret_cast<long>(this);
                          
-                         fl_set_object_posthandler(obj, C_Toolbar_BubblePost);
-
-                         fl_set_pixmapbutton_data(obj, item->pixmap);
-                         item = item->next;
-                         // we must remember to update the positions
-                         xpos += buttonwidth;
-                         // ypos is constant
-                         /* Here will come a check to see if the new
-                          * pos is within the bounds of the main frame,
-                          * and perhaps wrap the toolbar if not.
-                          */
-                         break;
+                       fl_set_object_posthandler(obj, C_Toolbar_BubblePost);
+#endif
+
+                       fl_set_pixmapbutton_data(obj, const_cast<char**>(item->pixmap));
+                       item = item->next;
+                       // we must remember to update the positions
+                       xpos += buttonwidth;
+                       // ypos is constant
+                       /* Here will come a check to see if the new
+                        * pos is within the bounds of the main frame,
+                        * and perhaps wrap the toolbar if not.
+                        */
+                       break;
                }
        }
-#if FL_REVISION <86
-       // Reset borderwidth to its default value.
-       fl_set_border_width(bw);
-#endif
+
        if (!doingmain) {
                fl_end_form();
                fl_unfreeze_form(owner->getForm());
@@ -362,9 +330,9 @@ void Toolbar::set(bool doingmain)
 }
 
 
-char **Toolbar::getPixmap(kb_action action, string const & arg)
+char const ** Toolbar::getPixmap(kb_action action, string const & arg)
 {
-       char **pixmap = unknown_xpm; //0
+       char const ** pixmap = unknown_xpm; //0
        switch(action){
        case LFUN_MENUOPEN:    pixmap = open_xpm; break;
        case LFUN_CLOSEBUFFER: pixmap = close_xpm; break;
@@ -441,8 +409,8 @@ void Toolbar::add(int action, bool doclean)
                // first «hide» the toolbar buttons. This is not a real hide
                // actually it deletes and frees the button altogether.
                lyxerr << "Toolbar::add: «hide» the toolbar buttons." << endl;
-               toolbarItem *item, *tmp= 0;
-               item = toollist;
+               toolbarItem * tmp= 0;
+               toolbarItem * item = toollist;
 
                lightReset();
                
@@ -465,29 +433,29 @@ void Toolbar::add(int action, bool doclean)
        
        // there exist some special actions not part of
        // kb_action: SEPARATOR, LAYOUTS
-       char **pixmap = 0;
+       char const ** pixmap = 0;
        string help;
 
-       toolbarItem *newItem,*tmp;
+       toolbarItem * newItem, * tmp;
 
        if (lyxaction.isPseudoAction(action)) {
-               char const *arg;
-               kb_action act = (kb_action)lyxaction.retrieveActionArg(action, &arg);
+               string arg;
+               kb_action act = static_cast<kb_action>
+                       (lyxaction.retrieveActionArg(action, arg));
                pixmap = getPixmap(act, arg);
                help = lyxaction.helpText(act);
                help += " ";
                help += arg;
                lyxerr.debug() << "Pseudo action " << action << endl;
        } else {
-               pixmap = getPixmap((kb_action)action);
-               help = lyxaction.helpText((kb_action)action);
+               pixmap = getPixmap(static_cast<kb_action>(action));
+               help = lyxaction.helpText(static_cast<kb_action>(action));
        }
        
        // adds an item to the list
        if (pixmap != 0
            || action == TOOL_SEPARATOR
-           || action == TOOL_LAYOUTS)
-       {
+           || action == TOOL_LAYOUTS) {
                newItem = new toolbarItem;
                newItem->action = action;
                newItem->pixmap = pixmap;
@@ -497,34 +465,18 @@ void Toolbar::add(int action, bool doclean)
                if (tmp != 0){
                        while(tmp->next != 0)
                                tmp = tmp->next;
-                       // here is tmp->next == 0
+                               // here is tmp->next == 0
                        tmp->next = newItem;
                } else
                        toollist = newItem;
        }
-       //if (action == TOOL_LAYOUTS) {
-       //      combox = new Combox(FL_COMBOX_DROPLIST);
-       //}
-}
-
-
-void Toolbar::add(string const & func, bool doclean)
-{
-       int tf = lyxaction.LookupFunc(func.c_str());
-
-       if (tf == -1){
-               lyxerr << "Toolbar::add: no LyX command called`"
-                      << func << "'exists!" << endl; 
-       } else {
-               add(tf, doclean);
-       }
 }
 
 
 void Toolbar::clean()
 {
-       toolbarItem *item, *tmp= 0;
-       item = toollist;
+       toolbarItem * tmp = 0;
+       toolbarItem * item = toollist;
 
        reset();
 
@@ -555,10 +507,10 @@ void Toolbar::push(int nth)
        
        if (nth == 0) return;
 
-       int count= 0;
-       toolbarItem *tmp = toollist;
+       int count = 0;
+       toolbarItem * tmp = toollist;
        while (tmp) {
-               count++;
+               ++count;
                if (count == nth) {
                        fl_trigger_object(tmp->icon);
                        return;
@@ -570,60 +522,32 @@ void Toolbar::push(int nth)
 }
 
 
-void Toolbar::read(LyXLex &lex)
+void Toolbar::add(string const & func, bool doclean)
 {
-       //consistency check
-       if (lex.GetString() != "\\begin_toolbar")
-               lyxerr << "Toolbar::read: ERROR wrong token:`"
-                      << lex.GetString() << '\'' << endl;
-
-       clean();
-       string func;
-       bool quit = false;
-       
-       lex.pushTable(toolTags, TO_LAST - 1);
+       int tf = lyxaction.LookupFunc(func);
 
-       if (lyxerr.debugging(Debug::PARSER))
-               lex.printTable();
-       
-       while (lex.IsOK() && !quit) {
-               
-               lyxerr[Debug::TOOLBAR] << "Toolbar::read: current lex text: `"
-                                      << lex.GetString() << '\'' << endl;
-
-               switch(lex.lex()) {
-                 case TO_ADD:
-                         if (lex.EatLine()) {
-                                 func = lex.GetString();
-                                 lyxerr[Debug::TOOLBAR]
-                                         << "Toolbar::read TO_ADD func: `"
-                                         << func << "'" << endl;
-                                 add(func);
-                         }
-                         break;
-                  
-                 case TO_SEPARATOR:
-                         add(TOOL_SEPARATOR);
-                         break;
-                  
-                 case TO_LAYOUTS:
-                         add(TOOL_LAYOUTS);
-                         break;
-                  
-                 case TO_NEWLINE:
-                         add(TOOL_NEWLINE);
-                         break;
-                       
-                 case TO_ENDTOOLBAR:
-                         // should not set automatically
-                         //set();
-                         quit = true;
-                         break;
-                 default:
-                         lex.printError("Toolbar::read: "
-                                         "Unknown toolbar tag: `$$Token'");
-                         break;
-               }
+       if (tf == -1) {
+               lyxerr << "Toolbar::add: no LyX command called`"
+                      << func << "'exists!" << endl; 
+       } else {
+               add(tf, doclean);
        }
-       lex.popTable();
 }
+
+
+void Toolbar::reset() 
+{
+       toollist = 0;
+       cleaned = false;
+       lightReset();
+}
+
+//  void Toolbar::lightReset()
+//  {
+//     standardspacing = 2; // the usual space between items
+//     sepspace = 6; // extra space
+//     xpos = sxpos - standardspacing;
+//     ypos = sypos;
+//     buttonwidth = 30; // the standard button width
+//     height = 30; // the height of all items in the toolbar
+//  }