1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 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"
31 #include "LyXAction.h"
32 #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;
103 Toolbar::Toolbar(LyXView * o, int x, int y)
104 : owner(o), sxpos(x), sypos(y)
112 // extracts the default toolbar actions from LyXRC
113 for (ToolbarDefaults::const_iterator cit =
114 lyxrc.toolbardefaults.begin();
115 cit != lyxrc.toolbardefaults.end(); ++cit) {
117 lyxerr[Debug::TOOLBAR] << "tool action: "
124 // timer-cb for bubble-help (Matthias)
125 void Toolbar::BubbleTimerCB(FL_OBJECT *, long data)
127 FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
128 char * help = static_cast<char*>(ob->u_vdata);
129 fl_show_oneliner(help, ob->form->x + ob->x,
130 ob->form->y + ob->y + ob->h);
134 extern "C" void C_Toolbar_BubbleTimerCB(FL_OBJECT * ob, long data)
136 Toolbar::BubbleTimerCB(ob, data);
140 // post_handler for bubble-help (Matthias)
141 int Toolbar::BubblePost(FL_OBJECT *ob, int event,
142 FL_Coord /*mx*/, FL_Coord /*my*/,
143 int /*key*/, void */*xev*/)
145 string help = static_cast<char *>(ob->u_vdata);
146 Toolbar * t = reinterpret_cast<Toolbar*>(ob->u_ldata);
148 if(event == FL_ENTER && !help.empty()){
149 fl_set_object_callback(t->bubble_timer,
150 C_Toolbar_BubbleTimerCB,
151 reinterpret_cast<long>(ob));
152 fl_set_timer(t->bubble_timer, 1);
154 else if(event != FL_MOTION){
155 fl_set_timer(t->bubble_timer, 0);
162 extern "C" int C_Toolbar_BubblePost(FL_OBJECT * ob, int event,
163 FL_Coord /*mx*/, FL_Coord /*my*/,
166 return Toolbar::BubblePost(ob, event, 0, 0, key, xev);
171 void Toolbar::activate()
173 toolbarItem * tmp= 0;
174 toolbarItem * item = toollist;
178 fl_activate_object(item->icon);
185 void Toolbar::deactivate()
187 toolbarItem * tmp= 0;
188 toolbarItem * item = toollist;
192 fl_deactivate_object(item->icon);
199 void Toolbar::ToolbarCB(FL_OBJECT * ob, long ac)
201 #if FL_REVISION >= 89
202 Toolbar * t = static_cast<Toolbar*>(ob->u_vdata);
204 Toolbar * t = reinterpret_cast<Toolbar*>(ob->u_ldata);
207 string res = t->owner->getLyXFunc()->Dispatch(int(ac));
209 lyxerr[Debug::TOOLBAR] << res << endl;
213 extern "C" void C_Toolbar_ToolbarCB(FL_OBJECT * ob, long data)
215 Toolbar::ToolbarCB(ob, data);
219 int Toolbar::get_toolbar_func(string const & func)
221 int action = lyxaction.LookupFunc(func.c_str());
223 if (func == "separator"){
224 action = TOOL_SEPARATOR;
225 } else if (func == "layouts"){
226 action = TOOL_LAYOUTS;
233 void Toolbar::set(bool doingmain)
235 // we shouldn't set if we have not cleaned
236 if (!cleaned) return;
239 toolbarItem * item = toollist;
242 fl_freeze_form(owner->getForm());
243 fl_addto_form(owner->getForm());
247 // add the time if it don't exist
248 if (bubble_timer == 0)
249 bubble_timer = fl_add_timer(FL_HIDDEN_TIMER,
250 xpos, ypos, 0, 0, "Timer");
254 switch(item->action){
260 xpos += standardspacing;
262 combox = new Combox(FL_COMBOX_DROPLIST);
263 combox->add(xpos, ypos, 135, height, 400);
264 combox->setcallback(LayoutsCB);
265 combox->resize(FL_RESIZE_ALL);
266 combox->gravity(NorthWestGravity, NorthWestGravity);
271 xpos += standardspacing;
273 fl_add_pixmapbutton(FL_NORMAL_BUTTON,
277 fl_set_object_boxtype(obj, FL_UP_BOX);
278 fl_set_object_color(obj, FL_MCOL, FL_BLUE);
279 fl_set_object_resize(obj, FL_RESIZE_ALL);
280 fl_set_object_gravity(obj,
283 fl_set_object_callback(obj, C_Toolbar_ToolbarCB,
284 static_cast<long>(item->action));
285 // Remove the blue feedback rectangle
286 fl_set_pixmapbutton_focus_outline(obj, 0);
288 // set the bubble-help (Matthias)
289 #if FL_REVISION >= 89
291 fl_set_object_helper(obj, item->help.c_str());
292 // The toolbar that this object belongs too.
298 #warning This is dangerous!
300 obj->u_vdata = const_cast<char*>(item->help.c_str());
301 // we need to know what toolbar this item
302 // belongs too. (Lgb)
303 obj->u_ldata = reinterpret_cast<long>(this);
305 fl_set_object_posthandler(obj, C_Toolbar_BubblePost);
308 fl_set_pixmapbutton_data(obj, const_cast<char**>(item->pixmap));
310 // we must remember to update the positions
313 /* Here will come a check to see if the new
314 * pos is within the bounds of the main frame,
315 * and perhaps wrap the toolbar if not.
323 fl_unfreeze_form(owner->getForm());
324 // Should be safe to do this here.
325 owner->updateLayoutChoice();
332 char const ** Toolbar::getPixmap(kb_action action, string const & arg)
334 char const ** pixmap = unknown_xpm; //0
336 case LFUN_MENUOPEN: pixmap = open_xpm; break;
337 case LFUN_CLOSEBUFFER: pixmap = close_xpm; break;
338 case LFUN_MENUPRINT: pixmap = print1_xpm; break;
339 case LFUN_MENUWRITE: pixmap = save_xpm; break;
340 case LFUN_EMPH: pixmap = emph_xpm; break;
341 case LFUN_NOUN: pixmap = noun_xpm; break;
342 case LFUN_FREE: pixmap = free_xpm; break;
343 case LFUN_FOOTMELT: pixmap = foot_xpm; break;
344 case LFUN_DEPTH: pixmap = depth_xpm; break;
345 case LFUN_COPY: pixmap = copy_xpm; break;
346 case LFUN_CUT: pixmap = cut_xpm; break;
347 case LFUN_PASTE: pixmap = paste_xpm; break;
348 case LFUN_TEX: pixmap = tex_xpm; break;
349 case LFUN_MATH_MODE: pixmap = math_xpm; break;
350 case LFUN_MARGINMELT: pixmap = margin_xpm; break;
351 case LFUN_FIGURE: pixmap = fig_xpm; break;
352 case LFUN_TABLE: pixmap = tab_xpm; break;
353 case LFUN_MELT: pixmap = melt_xpm; break;
354 case LFUN_QUIT: pixmap = quit_xpm; break;
355 case LFUN_RUNDVIPS: pixmap = update_ps_xpm; break;
359 pixmap = make_ascii_xpm;
360 else if (arg == "latex")
361 pixmap = make_latex_xpm;
366 if (arg == "Section")
367 pixmap = layout_sec_xpm;
368 else if (arg == "LaTeX")
369 pixmap = layout_latex_xpm;
370 else if (arg == "LyX-Code")
371 pixmap = layout_code_xpm;
372 else if (arg == "Scrap")
373 pixmap = layout_scrap_xpm;
375 pixmap = layout_std_xpm;
379 case LFUN_BOLD : pixmap = bold_xpm; break;
380 case LFUN_SANS: pixmap = sans_xpm; break;
381 case LFUN_RUNLATEX: pixmap = run_latex_xpm; break;
382 case LFUN_BUILDPROG: pixmap = build_xpm; break;
383 case LFUN_PREVIEWPS: pixmap = view_ps_xpm; break;
384 case LFUN_PREVIEW: pixmap = view_dvi_xpm; break;
385 case LFUN_INSERT_MATH:
388 pixmap = get_pixmap_from_symbol(arg.c_str(),
394 //pixmap = unknown_xpm;
401 void Toolbar::add(int action, bool doclean)
403 if (doclean && !cleaned) clean();
405 // this is what we do if we want to add to an existing
407 if (!doclean && owner) {
408 // first «hide» the toolbar buttons. This is not a real hide
409 // actually it deletes and frees the button altogether.
410 lyxerr << "Toolbar::add: «hide» the toolbar buttons." << endl;
411 toolbarItem * tmp= 0;
412 toolbarItem * item = toollist;
416 fl_freeze_form(owner->getForm());
420 fl_delete_object(item->icon);
421 fl_free_object(item->icon);
429 fl_unfreeze_form(owner->getForm());
430 cleaned = true; // this is not completely true, but OK anyway
433 // there exist some special actions not part of
434 // kb_action: SEPARATOR, LAYOUTS
435 char const ** pixmap = 0;
438 toolbarItem * newItem, * tmp;
440 if (lyxaction.isPseudoAction(action)) {
442 kb_action act = static_cast<kb_action>
443 (lyxaction.retrieveActionArg(action, arg));
444 pixmap = getPixmap(act, arg);
445 help = lyxaction.helpText(act);
448 lyxerr.debug() << "Pseudo action " << action << endl;
450 pixmap = getPixmap(static_cast<kb_action>(action));
451 help = lyxaction.helpText(static_cast<kb_action>(action));
454 // adds an item to the list
456 || action == TOOL_SEPARATOR
457 || action == TOOL_LAYOUTS) {
458 newItem = new toolbarItem;
459 newItem->action = action;
460 newItem->pixmap = pixmap;
461 newItem->help = help;
462 // the new item is placed at the end of the list
465 while(tmp->next != 0)
467 // here is tmp->next == 0
475 void Toolbar::clean()
477 toolbarItem * tmp = 0;
478 toolbarItem * item = toollist;
482 //now delete all the objects..
484 fl_freeze_form(owner->getForm());
490 lyxerr[Debug::TOOLBAR] << "Combox: " << combox << endl;
496 fl_unfreeze_form(owner->getForm());
497 lyxerr[Debug::TOOLBAR] << "toolbar cleaned" << endl;
502 void Toolbar::push(int nth)
504 lyxerr[Debug::TOOLBAR] << "Toolbar::push: trying to trigger no `"
505 << nth << '\'' << endl;
507 if (nth == 0) return;
510 toolbarItem * tmp = toollist;
514 fl_trigger_object(tmp->icon);
519 // item nth not found...
524 void Toolbar::add(string const & func, bool doclean)
526 int tf = lyxaction.LookupFunc(func);
529 lyxerr << "Toolbar::add: no LyX command called`"
530 << func << "'exists!" << endl;