1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-1999 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"
32 #include "support/lstrings.h"
34 #ifdef TWO_COLOR_ICONS
36 #include "emph_bw.xpm"
38 #include "foot_bw.xpm"
39 #include "math_bw.xpm"
40 #include "depth_bw.xpm"
41 #include "margin_bw.xpm"
42 #include "melt_bw.xpm"
43 #include "copy_bw.xpm"
44 #include "noun_bw.xpm"
45 #include "paste_bw.xpm"
46 #include "free_bw.xpm"
49 #include "open_bw.xpm"
50 #include "close_bw.xpm"
51 #include "save_bw.xpm"
52 #include "print1_bw.xpm"
53 #include "quit_bw.xpm"
54 #include "typeset_ps_bw.xpm"
55 #include "unknown_bw.xpm"
76 #include "typeset_ps.xpm"
77 #include "unknown.xpm"
80 // These pixmaps are the same regardless of color:
81 #include "bold_bw.xpm"
82 #include "make_ascii_bw.xpm"
83 #include "make_latex_bw.xpm"
84 #include "run_latex_bw.xpm"
85 #include "sans_bw.xpm"
86 #include "view_dvi_bw.xpm"
87 #include "view_ps_bw.xpm"
88 #include "layout_code.xpm"
89 #include "layout_latex.xpm"
90 #include "layout_scrap.xpm"
91 #include "layout_sec.xpm"
92 #include "layout_std.xpm"
95 extern void LayoutsCB(int, void*);
96 extern char** get_pixmap_from_symbol(char const *arg, int, int);
97 extern LyXAction lyxaction;
110 struct keyword_item toolTags[TO_LAST-1] = {
112 { "\\end_toolbar", TO_ENDTOOLBAR },
113 { "\\layouts", TO_LAYOUTS },
114 { "\\newline", TO_NEWLINE },
115 { "\\separator", TO_SEPARATOR }
119 Toolbar::Toolbar(Toolbar const &rct, LyXView *o, int x, int y)
120 : owner(o), sxpos(x), sypos(y)
126 // extracts the toolbar struct form rct.
127 toolbarItem *tmplist = rct.toollist;
128 while (tmplist != 0) {
129 add(tmplist->action);
130 lyxerr[Debug::TOOLBAR] << "tool action: "
131 << tmplist->action << endl;
132 tmplist=tmplist->next;
137 // timer-cb for bubble-help (Matthias)
138 void Toolbar::BubbleTimerCB(FL_OBJECT *, long data){
139 FL_OBJECT* ob = (FL_OBJECT*) data;
140 char* help = (char*) ob->u_vdata;
141 fl_show_oneliner(help, ob->form->x + ob->x,
142 ob->form->y + ob->y + ob->h);
146 // post_handler for bubble-help (Matthias)
147 int Toolbar::BubblePost(FL_OBJECT *ob, int event,
148 FL_Coord /*mx*/, FL_Coord /*my*/, int /*key*/, void */*xev*/)
150 string help = (char *)ob->u_vdata;
151 Toolbar *t = (Toolbar*)ob->u_ldata;
153 if(event == FL_ENTER && !help.empty()){
154 fl_set_object_callback(t->bubble_timer,
155 BubbleTimerCB, (long) ob);
156 fl_set_timer(t->bubble_timer, 1);
158 else if(event != FL_MOTION){
159 fl_set_timer(t->bubble_timer, 0);
166 void Toolbar::activate()
168 toolbarItem *item, *tmp=0;
173 fl_activate_object(item->icon);
180 void Toolbar::deactivate()
182 toolbarItem *item, *tmp=0;
187 fl_deactivate_object(item->icon);
194 void Toolbar::ToolbarCB(FL_OBJECT *ob, long ac)
196 Toolbar *t = (Toolbar*)ob->u_ldata;
198 string res = t->owner->getLyXFunc()->Dispatch(int(ac));
200 lyxerr[Debug::TOOLBAR] << res << endl;
204 int Toolbar::get_toolbar_func(string const & func)
206 int action = lyxaction.LookupFunc(func.c_str());
208 if (func == "separator"){
209 action = TOOL_SEPARATOR;
210 } else if (func == "layouts"){
211 action = TOOL_LAYOUTS;
222 //add(LFUN_CLOSEBUFFER);
238 add(LFUN_MARGINMELT);
252 void Toolbar::set(bool doingmain)
254 // we shouldn't set if we have not cleaned
255 if (!cleaned) return;
262 fl_freeze_form(owner->getForm());
263 fl_addto_form(owner->getForm());
267 // Ensure borderwidth is 2 to get visual feedback
268 int bw = fl_get_border_width();
269 fl_set_border_width(-2);
272 // add the time if it don't exist
273 if (bubble_timer == 0)
274 bubble_timer = fl_add_timer(FL_HIDDEN_TIMER,
275 xpos,ypos,0,0,"Timer");
278 switch(item->action){
284 xpos += standardspacing;
286 combox = new Combox(FL_COMBOX_DROPLIST);
287 combox->add(xpos, ypos, 135, height, 300);
288 combox->setcallback(LayoutsCB);
289 combox->resize(FL_RESIZE_ALL);
290 combox->gravity(NorthWestGravity, NorthWestGravity);
295 xpos += standardspacing;
297 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
301 fl_set_object_boxtype(obj,FL_UP_BOX);
302 fl_set_object_color(obj,FL_MCOL,FL_BLUE);
303 fl_set_object_resize(obj, FL_RESIZE_ALL);
304 fl_set_object_gravity(obj,
307 fl_set_object_callback(obj,ToolbarCB,
310 // Remove the blue feedback rectangle
311 fl_set_pixmapbutton_focus_outline(obj,0);
314 // set the bubble-help (Matthias)
315 obj->u_vdata = (void *) item->help.c_str();
316 // we need to know what toolbar this item
317 // belongs too. (Lgb)
318 obj->u_ldata = (long) this;
320 fl_set_object_posthandler(obj, BubblePost);
322 fl_set_pixmapbutton_data(obj,item->pixmap);
324 // we must remember to update the positions
327 /* Here will come a check to see if the new
328 * pos is within the bounds of the main frame,
329 * and perhaps wrap the toolbar if not.
335 // Reset borderwidth to its default value.
336 fl_set_border_width(bw);
340 fl_unfreeze_form(owner->getForm());
341 // Should be safe to do this here.
342 owner->updateLayoutChoice();
349 char **Toolbar::getPixmap(kb_action action, string const & arg)
351 char **pixmap = unknown_xpm; //0
353 case LFUN_MENUOPEN: pixmap = open_xpm; break;
354 case LFUN_CLOSEBUFFER: pixmap = close_xpm; break;
355 case LFUN_MENUPRINT: pixmap = print1_xpm; break;
356 case LFUN_MENUWRITE: pixmap = save_xpm; break;
357 case LFUN_EMPH: pixmap = emph_xpm; break;
358 case LFUN_NOUN: pixmap = noun_xpm; break;
359 case LFUN_FREE: pixmap = free_xpm; break;
360 case LFUN_FOOTMELT: pixmap = foot_xpm; break;
361 case LFUN_DEPTH: pixmap = depth_xpm; break;
362 case LFUN_COPY: pixmap = copy_xpm; break;
363 case LFUN_CUT: pixmap = cut_xpm; break;
364 case LFUN_PASTE: pixmap = paste_xpm; break;
365 case LFUN_TEX: pixmap = tex_xpm; break;
366 case LFUN_MATH_MODE: pixmap = math_xpm; break;
367 case LFUN_MARGINMELT: pixmap = margin_xpm; break;
368 case LFUN_FIGURE: pixmap = fig_xpm; break;
369 case LFUN_TABLE: pixmap = tab_xpm; break;
370 case LFUN_MELT: pixmap = melt_xpm; break;
371 case LFUN_QUIT: pixmap = quit_xpm; break;
372 case LFUN_RUNDVIPS: pixmap = update_ps_xpm; break;
376 pixmap = make_ascii_xpm;
377 else if (arg == "latex")
378 pixmap = make_latex_xpm;
383 if (arg == "Section")
384 pixmap = layout_sec_xpm;
385 else if (arg == "LaTeX")
386 pixmap = layout_latex_xpm;
387 else if (arg == "LyX-Code")
388 pixmap = layout_code_xpm;
389 else if (arg == "Scrap")
390 pixmap = layout_scrap_xpm;
392 pixmap = layout_std_xpm;
396 case LFUN_BOLD : pixmap = bold_xpm; break;
397 case LFUN_SANS: pixmap = sans_xpm; break;
398 case LFUN_RUNLATEX: pixmap = run_latex_xpm; break;
399 case LFUN_BUILDPROG: pixmap = build_xpm; break;
400 case LFUN_PREVIEWPS: pixmap = view_ps_xpm; break;
401 case LFUN_PREVIEW: pixmap = view_dvi_xpm; break;
402 case LFUN_INSERT_MATH:
405 pixmap = get_pixmap_from_symbol(arg.c_str(),
411 //pixmap = unknown_xpm;
418 void Toolbar::add(int action, bool doclean)
420 if (doclean && !cleaned) clean();
422 // this is what we do if we want to add to an existing
424 if (!doclean && owner) {
425 // first «hide» the toolbar buttons. This is not a real hide
426 // actually it deletes and frees the button altogether.
427 lyxerr << "Toolbar::add: «hide» the toolbar buttons." << endl;
428 toolbarItem *item, *tmp=0;
433 fl_freeze_form(owner->getForm());
437 fl_delete_object(item->icon);
438 fl_free_object(item->icon);
446 fl_unfreeze_form(owner->getForm());
447 cleaned = true; // this is not completely true, but OK anyway
450 // there exist some special actions not part of
451 // kb_action: SEPARATOR, LAYOUTS
455 toolbarItem *newItem,*tmp;
457 if (lyxaction.isPseudoAction(action)) {
459 kb_action act = (kb_action)lyxaction.retrieveActionArg(action, &arg);
460 pixmap = getPixmap(act, arg);
461 help = lyxaction.helpText(act);
464 lyxerr.debug() << "Pseudo action " << action << endl;
466 pixmap = getPixmap((kb_action)action);
467 help = lyxaction.helpText((kb_action)action);
470 // adds an item to the list
472 || action == TOOL_SEPARATOR
473 || action == TOOL_LAYOUTS)
475 newItem = new toolbarItem;
476 newItem->action = action;
477 newItem->pixmap = pixmap;
478 newItem->help = help;
479 // the new item is placed at the end of the list
482 while(tmp->next != 0)
484 // here is tmp->next == 0
489 //if (action == TOOL_LAYOUTS) {
490 // combox = new Combox(FL_COMBOX_DROPLIST);
495 void Toolbar::add(string const & func, bool doclean)
497 int tf = lyxaction.LookupFunc(func.c_str());
500 lyxerr << "Toolbar::add: no LyX command called`"
501 << func << "'exists!" << endl;
508 void Toolbar::clean()
510 toolbarItem *item, *tmp= 0;
515 //now delete all the objects..
517 fl_freeze_form(owner->getForm());
523 lyxerr[Debug::TOOLBAR] << "Combox: " << combox << endl;
529 fl_unfreeze_form(owner->getForm());
530 lyxerr[Debug::TOOLBAR] << "toolbar cleaned" << endl;
535 void Toolbar::push(int nth)
537 lyxerr[Debug::TOOLBAR] << "Toolbar::push: trying to trigger no `"
538 << nth << '\'' << endl;
540 if (nth == 0) return;
543 toolbarItem *tmp = toollist;
547 fl_trigger_object(tmp->icon);
552 // item nth not found...
557 void Toolbar::read(LyXLex &lex)
560 if (lex.GetString() != "\\begin_toolbar")
561 lyxerr << "Toolbar::read: ERROR wrong token:`"
562 << lex.GetString() << '\'' << endl;
568 lex.pushTable(toolTags, TO_LAST - 1);
570 if (lyxerr.debugging(Debug::PARSER))
573 while (lex.IsOK() && !quit) {
575 lyxerr[Debug::TOOLBAR] << "Toolbar::read: current lex text: `"
576 << lex.GetString() << '\'' << endl;
581 func = lex.GetString();
582 lyxerr[Debug::TOOLBAR]
583 << "Toolbar::read TO_ADD func: `"
584 << func << "'" << endl;
602 // should not set automatically
607 lex.printError("Toolbar::read: "
608 "Unknown toolbar tag: `$$Token'");