1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 * This file is Copyright 1996-1998
12 *======================================================*/
14 // Added pseudo-action handling, asierra 180296
19 #pragma implementation "toolbar.h"
23 #include "lyx_gui_misc.h"
33 #ifdef TWO_COLOR_ICONS
35 #include "emph_bw.xpm"
37 #include "foot_bw.xpm"
38 #include "math_bw.xpm"
39 #include "depth_bw.xpm"
40 #include "margin_bw.xpm"
41 #include "melt_bw.xpm"
42 #include "copy_bw.xpm"
43 #include "noun_bw.xpm"
44 #include "paste_bw.xpm"
45 #include "free_bw.xpm"
48 #include "open_bw.xpm"
49 #include "close_bw.xpm"
50 #include "save_bw.xpm"
51 #include "print1_bw.xpm"
52 #include "quit_bw.xpm"
53 #include "typeset_ps_bw.xpm"
54 #include "unknown_bw.xpm"
75 #include "typeset_ps.xpm"
76 #include "unknown.xpm"
79 // These pixmaps are the same regardless of color:
80 #include "bold_bw.xpm"
81 #include "make_ascii_bw.xpm"
82 #include "make_latex_bw.xpm"
83 #include "run_latex_bw.xpm"
84 #include "sans_bw.xpm"
85 #include "view_dvi_bw.xpm"
86 #include "view_ps_bw.xpm"
87 #include "layout_code.xpm"
88 #include "layout_latex.xpm"
89 #include "layout_scrap.xpm"
90 #include "layout_sec.xpm"
91 #include "layout_std.xpm"
96 // $Id: toolbar.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $
98 #if !defined(lint) && !defined(WITH_WARNINGS)
99 static char vcid[] = "$Id: toolbar.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
102 extern void LayoutsCB(int, void*);
103 extern char** get_pixmap_from_symbol(char const *arg, int, int);
104 extern LyXAction lyxaction;
117 struct keyword_item toolTags[TO_LAST-1] = {
119 { "\\end_toolbar", TO_ENDTOOLBAR },
120 { "\\layouts", TO_LAYOUTS },
121 { "\\newline", TO_NEWLINE },
122 { "\\separator", TO_SEPARATOR }
126 Toolbar::Toolbar(Toolbar const &rct, LyXView *o, int x, int y)
127 : owner(o), sxpos(x), sypos(y)
133 // extracts the toolbar struct form rct.
134 toolbarItem *tmplist = rct.toollist;
135 while (tmplist != NULL) {
136 add(tmplist->action);
137 lyxerr.debug(LString("tool action: ") + int(tmplist->action),
139 tmplist=tmplist->next;
144 // timer-cb for bubble-help (Matthias)
145 void Toolbar::BubbleTimerCB(FL_OBJECT *, long data){
146 FL_OBJECT* ob = (FL_OBJECT*) data;
147 char* help = (char*) ob->u_vdata;
148 fl_show_oneliner(help, ob->form->x + ob->x,
149 ob->form->y + ob->y + ob->h);
153 // post_handler for bubble-help (Matthias)
154 int Toolbar::BubblePost(FL_OBJECT *ob, int event,
155 FL_Coord /*mx*/, FL_Coord /*my*/, int /*key*/, void */*xev*/)
157 LString help = (char *)ob->u_vdata;
158 Toolbar *t = (Toolbar*)ob->u_ldata;
160 if(event == FL_ENTER && !help.empty()){
161 fl_set_object_callback(t->bubble_timer,
162 BubbleTimerCB, (long) ob);
163 fl_set_timer(t->bubble_timer, 1);
165 else if(event != FL_MOTION){
166 fl_set_timer(t->bubble_timer, 0);
173 void Toolbar::activate()
175 toolbarItem *item, *tmp=NULL;
180 fl_activate_object(item->icon);
187 void Toolbar::deactivate()
189 toolbarItem *item, *tmp=NULL;
194 fl_deactivate_object(item->icon);
201 void Toolbar::ToolbarCB(FL_OBJECT *ob, long ac)
203 Toolbar *t = (Toolbar*)ob->u_ldata;
205 LString res = t->owner->getLyXFunc()->Dispatch(int(ac));
207 lyxerr.debug(res, Error::TOOLBAR);
211 int Toolbar::get_toolbar_func(LString const & func)
213 int action = lyxaction.LookupFunc(func.c_str());
215 if (func == "separator"){
216 action = TOOL_SEPARATOR;
217 } else if (func == "layouts"){
218 action = TOOL_LAYOUTS;
229 //add(LFUN_CLOSEBUFFER);
245 add(LFUN_MARGINMELT);
259 void Toolbar::set(bool doingmain)
261 // we shouldn't set if we have not cleaned
262 if (!cleaned) return;
269 fl_freeze_form(owner->getForm());
270 fl_addto_form(owner->getForm());
274 // Ensure borderwidth is 2 to get visual feedback
275 int bw = fl_get_border_width();
276 fl_set_border_width(-2);
279 // add the time if it don't exist
280 if (bubble_timer == NULL)
281 bubble_timer = fl_add_timer(FL_HIDDEN_TIMER,
282 xpos,ypos,0,0,"Timer");
284 while(item != NULL) {
285 switch(item->action){
291 xpos += standardspacing;
293 combox = new Combox(FL_COMBOX_DROPLIST);
294 combox->add(xpos, ypos, 135, height, 300);
295 combox->setcallback(LayoutsCB);
296 combox->resize(FL_RESIZE_ALL);
297 combox->gravity(NorthWestGravity, NorthWestGravity);
302 xpos += standardspacing;
304 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
308 fl_set_object_boxtype(obj,FL_UP_BOX);
309 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
310 fl_set_object_resize(obj, FL_RESIZE_ALL);
311 fl_set_object_gravity(obj,
314 fl_set_object_callback(obj,ToolbarCB,
317 // Remove the blue feedback rectangle
318 fl_set_pixmapbutton_focus_outline(obj,0);
321 // set the bubble-help (Matthias)
322 obj->u_vdata = (void *) item->help.c_str();
323 // we need to know what toolbar this item
324 // belongs too. (Lgb)
325 obj->u_ldata = (long) this;
327 fl_set_object_posthandler(obj, BubblePost);
329 fl_set_pixmapbutton_data(obj,item->pixmap);
331 // we must remember to update the positions
334 /* Here will come a check to see if the new
335 * pos is within the bounds of the main frame,
336 * and perhaps wrap the toolbar if not.
342 // Reset borderwidth to its default value.
343 fl_set_border_width(bw);
347 fl_unfreeze_form(owner->getForm());
348 // Should be safe to do this here.
349 owner->updateLayoutChoice();
356 char **Toolbar::getPixmap(kb_action action, LString const & arg)
358 char **pixmap = unknown_xpm; //NULL
360 case LFUN_MENUOPEN: pixmap = open_xpm; break;
361 case LFUN_CLOSEBUFFER: pixmap = close_xpm; break;
362 case LFUN_MENUPRINT: pixmap = print1_xpm; break;
363 case LFUN_MENUWRITE: pixmap = save_xpm; break;
364 case LFUN_EMPH: pixmap = emph_xpm; break;
365 case LFUN_NOUN: pixmap = noun_xpm; break;
366 case LFUN_FREE: pixmap = free_xpm; break;
367 case LFUN_FOOTMELT: pixmap = foot_xpm; break;
368 case LFUN_DEPTH: pixmap = depth_xpm; break;
369 case LFUN_COPY: pixmap = copy_xpm; break;
370 case LFUN_CUT: pixmap = cut_xpm; break;
371 case LFUN_PASTE: pixmap = paste_xpm; break;
372 case LFUN_TEX: pixmap = tex_xpm; break;
373 case LFUN_MATH_MODE: pixmap = math_xpm; break;
374 case LFUN_MARGINMELT: pixmap = margin_xpm; break;
375 case LFUN_FIGURE: pixmap = fig_xpm; break;
376 case LFUN_TABLE: pixmap = tab_xpm; break;
377 case LFUN_MELT: pixmap = melt_xpm; break;
378 case LFUN_QUIT: pixmap = quit_xpm; break;
379 case LFUN_RUNDVIPS: pixmap = update_ps_xpm; break;
383 pixmap = make_ascii_xpm;
384 else if (arg == "latex")
385 pixmap = make_latex_xpm;
390 if (arg == "Section")
391 pixmap = layout_sec_xpm;
392 else if (arg == "LaTeX")
393 pixmap = layout_latex_xpm;
394 else if (arg == "LyX-Code")
395 pixmap = layout_code_xpm;
396 else if (arg == "Scrap")
397 pixmap = layout_scrap_xpm;
399 pixmap = layout_std_xpm;
403 case LFUN_BOLD : pixmap = bold_xpm; break;
404 case LFUN_SANS: pixmap = sans_xpm; break;
405 case LFUN_RUNLATEX: pixmap = run_latex_xpm; break;
406 case LFUN_BUILDPROG: pixmap = build_xpm; break;
407 case LFUN_PREVIEWPS: pixmap = view_ps_xpm; break;
408 case LFUN_PREVIEW: pixmap = view_dvi_xpm; break;
409 case LFUN_INSERT_MATH:
412 pixmap = get_pixmap_from_symbol(arg.c_str(),
418 //pixmap = unknown_xpm;
425 void Toolbar::add(int action, bool doclean)
427 if (doclean && !cleaned) clean();
429 // this is what we do if we want to add to an existing
431 if (!doclean && owner) {
432 // first «hide» the toolbar buttons. This is not a real hide
433 // actually it deletes and frees the button altogether.
434 lyxerr.print("Toolbar::add: «hide» the toolbar buttons.");
435 toolbarItem *item, *tmp=NULL;
440 fl_freeze_form(owner->getForm());
444 fl_delete_object(item->icon);
445 fl_free_object(item->icon);
453 fl_unfreeze_form(owner->getForm());
454 cleaned = true; // this is not completely true, but OK anyway
457 // there exist some special actions not part of
458 // kb_action: SEPARATOR, LAYOUTS
459 char **pixmap = NULL;
462 toolbarItem *newItem,*tmp;
464 if (lyxaction.isPseudoAction(action)) {
466 kb_action act = (kb_action)lyxaction.retrieveActionArg(action, &arg);
467 pixmap = getPixmap(act, arg);
468 help = lyxaction.helpText(act);
471 lyxerr.debug(LString("Pseudo action ") + int(action));
473 pixmap = getPixmap((kb_action)action);
474 help = lyxaction.helpText((kb_action)action);
477 // adds an item to the list
479 || action == TOOL_SEPARATOR
480 || action == TOOL_LAYOUTS)
482 newItem = new toolbarItem;
483 newItem->action = action;
484 newItem->pixmap = pixmap;
485 newItem->help = help;
486 // the new item is placed at the end of the list
489 while(tmp->next != NULL)
491 // here is tmp->next == NULL
496 //if (action == TOOL_LAYOUTS) {
497 // combox = new Combox(FL_COMBOX_DROPLIST);
502 void Toolbar::add(LString const & func, bool doclean)
504 int tf = lyxaction.LookupFunc(func.c_str());
507 lyxerr.print("Toolbar::add: no LyX command called`"
515 void Toolbar::clean()
517 toolbarItem *item, *tmp= NULL;
522 //now delete all the objects..
524 fl_freeze_form(owner->getForm());
530 //lyxerr.print(LString("Combox: ") + int(combox));
536 fl_unfreeze_form(owner->getForm());
537 lyxerr.debug("toolbar cleaned",Error::TOOLBAR);
542 void Toolbar::push(int nth)
544 lyxerr.debug(LString("Toolbar::push: trying to trigger no `")+nth+'\'',
547 if (nth == 0) return;
550 toolbarItem *tmp = toollist;
554 fl_trigger_object(tmp->icon);
559 // item nth not found...
564 void Toolbar::read(LyXLex &lex)
567 if (lex.GetString() != "\\begin_toolbar")
568 lyxerr.print("Toolbar::read: ERROR wrong token:`"
569 +lex.GetString()+'\'');
575 lex.pushTable(toolTags, TO_LAST - 1);
577 if (lyxerr.debugging(Error::LEX_PARSER))
580 while (lex.IsOK() && !quit) {
582 lyxerr.debug("Toolbar::read: current lex text: `"
583 +lex.GetString()+'\'',Error::TOOLBAR);
588 func = lex.GetString();
589 lyxerr.debug("Toolbar::read TO_ADD func: `"
590 + func + "'", Error::TOOLBAR);
608 // should not set automatically
613 lex.printError("Toolbar::read: "
614 "Unknown toolbar tag: `$$Token'");