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 "LyXAction.h"
33 #include "support/lstrings.h"
35 #ifdef TWO_COLOR_ICONS
37 #include "emph_bw.xpm"
39 #include "foot_bw.xpm"
40 #include "math_bw.xpm"
41 #include "depth_bw.xpm"
42 #include "margin_bw.xpm"
43 #include "melt_bw.xpm"
44 #include "copy_bw.xpm"
45 #include "noun_bw.xpm"
46 #include "paste_bw.xpm"
47 #include "free_bw.xpm"
50 #include "open_bw.xpm"
51 #include "close_bw.xpm"
52 #include "save_bw.xpm"
53 #include "print1_bw.xpm"
54 #include "quit_bw.xpm"
55 #include "typeset_ps_bw.xpm"
56 #include "unknown_bw.xpm"
77 #include "typeset_ps.xpm"
78 #include "unknown.xpm"
81 // These pixmaps are the same regardless of color:
82 #include "bold_bw.xpm"
83 #include "make_ascii_bw.xpm"
84 #include "make_latex_bw.xpm"
85 #include "run_latex_bw.xpm"
86 #include "sans_bw.xpm"
87 #include "view_dvi_bw.xpm"
88 #include "view_ps_bw.xpm"
89 #include "layout_code.xpm"
90 #include "layout_latex.xpm"
91 #include "layout_scrap.xpm"
92 #include "layout_sec.xpm"
93 #include "layout_std.xpm"
97 // this one is not "C" because combox callbacks are really C++ %-|
98 extern void LayoutsCB(int, void *);
99 extern char const ** get_pixmap_from_symbol(char const * arg, int, int);
100 extern LyXAction lyxaction;
113 struct keyword_item toolTags[TO_LAST - 1] = {
115 { "\\end_toolbar", TO_ENDTOOLBAR },
116 { "\\layouts", TO_LAYOUTS },
117 { "\\newline", TO_NEWLINE },
118 { "\\separator", TO_SEPARATOR }
122 Toolbar::Toolbar(Toolbar const &rct, LyXView *o, int x, int y)
123 : owner(o), sxpos(x), sypos(y)
131 // extracts the toolbar struct form rct.
132 toolbarItem * tmplist = rct.toollist;
133 while (tmplist != 0) {
134 add(tmplist->action);
135 lyxerr[Debug::TOOLBAR] << "tool action: "
136 << tmplist->action << endl;
137 tmplist= tmplist->next;
143 // timer-cb for bubble-help (Matthias)
144 void Toolbar::BubbleTimerCB(FL_OBJECT *, long data)
146 FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
147 char * help = static_cast<char*>(ob->u_vdata);
148 fl_show_oneliner(help, ob->form->x + ob->x,
149 ob->form->y + ob->y + ob->h);
153 extern "C" void C_Toolbar_BubbleTimerCB(FL_OBJECT * ob, long data)
155 Toolbar::BubbleTimerCB(ob, data);
159 // post_handler for bubble-help (Matthias)
160 int Toolbar::BubblePost(FL_OBJECT *ob, int event,
161 FL_Coord /*mx*/, FL_Coord /*my*/,
162 int /*key*/, void */*xev*/)
164 string help = static_cast<char *>(ob->u_vdata);
165 Toolbar * t = reinterpret_cast<Toolbar*>(ob->u_ldata);
167 if(event == FL_ENTER && !help.empty()){
168 fl_set_object_callback(t->bubble_timer,
169 C_Toolbar_BubbleTimerCB,
170 reinterpret_cast<long>(ob));
171 fl_set_timer(t->bubble_timer, 1);
173 else if(event != FL_MOTION){
174 fl_set_timer(t->bubble_timer, 0);
181 extern "C" int C_Toolbar_BubblePost(FL_OBJECT * ob, int event,
182 FL_Coord /*mx*/, FL_Coord /*my*/,
185 return Toolbar::BubblePost(ob, event, 0, 0, key, xev);
190 void Toolbar::activate()
192 toolbarItem * tmp= 0;
193 toolbarItem * item = toollist;
197 fl_activate_object(item->icon);
204 void Toolbar::deactivate()
206 toolbarItem * tmp= 0;
207 toolbarItem * item = toollist;
211 fl_deactivate_object(item->icon);
218 void Toolbar::ToolbarCB(FL_OBJECT * ob, long ac)
220 #if FL_REVISION >= 89
221 Toolbar * t = static_cast<Toolbar*>(ob->u_vdata);
223 Toolbar * t = reinterpret_cast<Toolbar*>(ob->u_ldata);
226 string res = t->owner->getLyXFunc()->Dispatch(int(ac));
228 lyxerr[Debug::TOOLBAR] << res << endl;
232 extern "C" void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
234 Toolbar::ToolbarCB(ob, data);
238 int Toolbar::get_toolbar_func(string const & func)
240 int action = lyxaction.LookupFunc(func.c_str());
242 if (func == "separator"){
243 action = TOOL_SEPARATOR;
244 } else if (func == "layouts"){
245 action = TOOL_LAYOUTS;
256 //add(LFUN_CLOSEBUFFER);
272 add(LFUN_MARGINMELT);
286 void Toolbar::set(bool doingmain)
288 // we shouldn't set if we have not cleaned
289 if (!cleaned) return;
292 toolbarItem * item = toollist;
295 fl_freeze_form(owner->getForm());
296 fl_addto_form(owner->getForm());
300 // add the time if it don't exist
301 if (bubble_timer == 0)
302 bubble_timer = fl_add_timer(FL_HIDDEN_TIMER,
303 xpos, ypos, 0, 0, "Timer");
307 switch(item->action){
313 xpos += standardspacing;
315 combox = new Combox(FL_COMBOX_DROPLIST);
316 combox->add(xpos, ypos, 135, height, 400);
317 combox->setcallback(LayoutsCB);
318 combox->resize(FL_RESIZE_ALL);
319 combox->gravity(NorthWestGravity, NorthWestGravity);
324 xpos += standardspacing;
326 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
330 fl_set_object_boxtype(obj, FL_UP_BOX);
331 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
332 fl_set_object_resize(obj, FL_RESIZE_ALL);
333 fl_set_object_gravity(obj,
336 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
337 static_cast<long>(item->action));
338 // Remove the blue feedback rectangle
339 fl_set_pixmapbutton_focus_outline(obj, 0);
341 // set the bubble-help (Matthias)
342 #if FL_REVISION >= 89
344 fl_set_object_helper(obj, item->help.c_str());
345 // The toolbar that this object belongs too.
351 #warning This is dangerous!
353 obj->u_vdata = const_cast<char*>(item->help.c_str());
354 // we need to know what toolbar this item
355 // belongs too. (Lgb)
356 obj->u_ldata = reinterpret_cast<long>(this);
358 fl_set_object_posthandler(obj, C_Toolbar_BubblePost);
361 fl_set_pixmapbutton_data(obj, const_cast<char**>(item->pixmap));
363 // we must remember to update the positions
366 /* Here will come a check to see if the new
367 * pos is within the bounds of the main frame,
368 * and perhaps wrap the toolbar if not.
376 fl_unfreeze_form(owner->getForm());
377 // Should be safe to do this here.
378 owner->updateLayoutChoice();
385 char const ** Toolbar::getPixmap(kb_action action, string const & arg)
387 char const ** pixmap = unknown_xpm; //0
389 case LFUN_MENUOPEN: pixmap = open_xpm; break;
390 case LFUN_CLOSEBUFFER: pixmap = close_xpm; break;
391 case LFUN_MENUPRINT: pixmap = print1_xpm; break;
392 case LFUN_MENUWRITE: pixmap = save_xpm; break;
393 case LFUN_EMPH: pixmap = emph_xpm; break;
394 case LFUN_NOUN: pixmap = noun_xpm; break;
395 case LFUN_FREE: pixmap = free_xpm; break;
396 case LFUN_FOOTMELT: pixmap = foot_xpm; break;
397 case LFUN_DEPTH: pixmap = depth_xpm; break;
398 case LFUN_COPY: pixmap = copy_xpm; break;
399 case LFUN_CUT: pixmap = cut_xpm; break;
400 case LFUN_PASTE: pixmap = paste_xpm; break;
401 case LFUN_TEX: pixmap = tex_xpm; break;
402 case LFUN_MATH_MODE: pixmap = math_xpm; break;
403 case LFUN_MARGINMELT: pixmap = margin_xpm; break;
404 case LFUN_FIGURE: pixmap = fig_xpm; break;
405 case LFUN_TABLE: pixmap = tab_xpm; break;
406 case LFUN_MELT: pixmap = melt_xpm; break;
407 case LFUN_QUIT: pixmap = quit_xpm; break;
408 case LFUN_RUNDVIPS: pixmap = update_ps_xpm; break;
412 pixmap = make_ascii_xpm;
413 else if (arg == "latex")
414 pixmap = make_latex_xpm;
419 if (arg == "Section")
420 pixmap = layout_sec_xpm;
421 else if (arg == "LaTeX")
422 pixmap = layout_latex_xpm;
423 else if (arg == "LyX-Code")
424 pixmap = layout_code_xpm;
425 else if (arg == "Scrap")
426 pixmap = layout_scrap_xpm;
428 pixmap = layout_std_xpm;
432 case LFUN_BOLD : pixmap = bold_xpm; break;
433 case LFUN_SANS: pixmap = sans_xpm; break;
434 case LFUN_RUNLATEX: pixmap = run_latex_xpm; break;
435 case LFUN_BUILDPROG: pixmap = build_xpm; break;
436 case LFUN_PREVIEWPS: pixmap = view_ps_xpm; break;
437 case LFUN_PREVIEW: pixmap = view_dvi_xpm; break;
438 case LFUN_INSERT_MATH:
441 pixmap = get_pixmap_from_symbol(arg.c_str(),
447 //pixmap = unknown_xpm;
454 void Toolbar::add(int action, bool doclean)
456 if (doclean && !cleaned) clean();
458 // this is what we do if we want to add to an existing
460 if (!doclean && owner) {
461 // first «hide» the toolbar buttons. This is not a real hide
462 // actually it deletes and frees the button altogether.
463 lyxerr << "Toolbar::add: «hide» the toolbar buttons." << endl;
464 toolbarItem * tmp= 0;
465 toolbarItem * item = toollist;
469 fl_freeze_form(owner->getForm());
473 fl_delete_object(item->icon);
474 fl_free_object(item->icon);
482 fl_unfreeze_form(owner->getForm());
483 cleaned = true; // this is not completely true, but OK anyway
486 // there exist some special actions not part of
487 // kb_action: SEPARATOR, LAYOUTS
488 char const ** pixmap = 0;
491 toolbarItem * newItem, * tmp;
493 if (lyxaction.isPseudoAction(action)) {
495 kb_action act = static_cast<kb_action>
496 (lyxaction.retrieveActionArg(action, arg));
497 pixmap = getPixmap(act, arg);
498 help = lyxaction.helpText(act);
501 lyxerr.debug() << "Pseudo action " << action << endl;
503 pixmap = getPixmap(static_cast<kb_action>(action));
504 help = lyxaction.helpText(static_cast<kb_action>(action));
507 // adds an item to the list
509 || action == TOOL_SEPARATOR
510 || action == TOOL_LAYOUTS) {
511 newItem = new toolbarItem;
512 newItem->action = action;
513 newItem->pixmap = pixmap;
514 newItem->help = help;
515 // the new item is placed at the end of the list
518 while(tmp->next != 0)
520 // here is tmp->next == 0
528 void Toolbar::add(string const & func, bool doclean)
530 int tf = lyxaction.LookupFunc(func.c_str());
533 lyxerr << "Toolbar::add: no LyX command called`"
534 << func << "'exists!" << endl;
541 void Toolbar::clean()
543 toolbarItem * tmp = 0;
544 toolbarItem * item = toollist;
548 //now delete all the objects..
550 fl_freeze_form(owner->getForm());
556 lyxerr[Debug::TOOLBAR] << "Combox: " << combox << endl;
562 fl_unfreeze_form(owner->getForm());
563 lyxerr[Debug::TOOLBAR] << "toolbar cleaned" << endl;
568 void Toolbar::push(int nth)
570 lyxerr[Debug::TOOLBAR] << "Toolbar::push: trying to trigger no `"
571 << nth << '\'' << endl;
573 if (nth == 0) return;
576 toolbarItem * tmp = toollist;
580 fl_trigger_object(tmp->icon);
585 // item nth not found...
590 void Toolbar::read(LyXLex & lex)
593 if (lex.GetString() != "\\begin_toolbar")
594 lyxerr << "Toolbar::read: ERROR wrong token:`"
595 << lex.GetString() << '\'' << endl;
601 lex.pushTable(toolTags, TO_LAST - 1);
603 if (lyxerr.debugging(Debug::PARSER))
606 while (lex.IsOK() && !quit) {
608 lyxerr[Debug::TOOLBAR] << "Toolbar::read: current lex text: `"
609 << lex.GetString() << '\'' << endl;
614 func = lex.GetString();
615 lyxerr[Debug::TOOLBAR]
616 << "Toolbar::read TO_ADD func: `"
617 << func << "'" << endl;
635 // should not set automatically
640 lex.printError("Toolbar::read: "
641 "Unknown toolbar tag: `$$Token'");