2 * figinset.C - part of LyX project
5 /* Rework of path-handling (Matthias 04.07.1996 )
6 * ------------------------------------------------
7 * figinsets keep an absolute path to the eps-file.
8 * For the user alway a relative path appears
9 * (in lyx-file, latex-file and edit-popup).
10 * To calculate this relative path the path to the
11 * document where the figinset is in is needed.
12 * This is done by a reference to the buffer, called
13 * figinset::cbuffer. To be up to date the cbuffer
14 * is sometimes set to the current buffer
15 * bufferlist.current(), when it can be assumed that
16 * this operation happens in the current buffer.
17 * This is true for InsetFig::Edit(...),
18 * InsetFig::InsetFig(...), InsetFig::Read(...),
19 * InsetFig::Write and InsetFig::Latex(...).
20 * Therefore the bufferlist has to make sure that
21 * during these operations bufferlist.current()
22 * returns the buffer where the figinsets are in.
23 * This made few changes in buffer.C necessary.
25 * The above is not totally valid anymore. (Lgb)
42 #include FORMS_H_LOCATION
50 #include "frontends/FileDialog.h"
51 #include "support/filetools.h"
52 #include "LyXView.h" // just because of form_main
54 #include "LaTeXFeatures.h"
57 #include "lyx_gui_misc.h" // CancelCloseBoxCB
58 #include "support/FileInfo.h"
59 #include "support/lyxlib.h"
60 #include "support/os.h"
63 #include "bufferview_funcs.h"
64 #include "ColorHandler.h"
65 #include "converter.h"
66 #include "frontends/Dialogs.h" // redrawGUI
67 #include "BufferView.h"
79 using std::ostringstream;
84 #ifndef CXX_GLOBAL_CSTD
93 extern BufferView * current_view;
94 extern FL_OBJECT * figinset_canvas;
96 extern char ** environ; // is this only redundtant on linux systems? Lgb.
98 // xforms doesn't define this (but it should be in <forms.h>).
100 FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
104 float const DEG2PI = 57.295779513;
106 struct queue_element {
107 float rx, ry; // resolution x and y
108 int ofsx, ofsy; // x and y translation
109 figdata * data; // we are doing it for this data
112 int const MAXGS = 3; /* maximum 3 gs's at a time */
114 typedef vector<Figref *> figures_type;
115 typedef vector<figdata *> bitmaps_type;
116 figures_type figures; // all figures
117 bitmaps_type bitmaps; // all bitmaps
119 queue<queue_element> gsqueue; // queue for ghostscripting
121 int gsrunning = 0; /* currently so many gs's are running */
122 bool bitmap_waiting = false; /* bitmaps are waiting finished */
124 bool gs_color; // do we allocate colors for gs?
125 bool color_visual; // is the visual color?
126 bool gs_xcolor = false; // allocated extended colors
127 unsigned long gs_pixels[128]; // allocated pixels
128 int gs_spc; // shades per color
129 int gs_allcolors; // number of all colors
131 list<int> pidwaitlist; // pid wait list
136 val.foreground = BlackPixel(fl_get_display(),
137 DefaultScreen(fl_get_display()));
140 val.graphics_exposures = false;
141 val.line_style = LineSolid;
143 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
144 GCForeground | GCFunction | GCGraphicsExposures
145 | GCLineWidth | GCLineStyle , &val);
151 void addpidwait(int pid)
153 // adds pid to pid wait list
154 pidwaitlist.push_back(pid);
156 if (lyxerr.debugging()) {
157 lyxerr << "Pids to wait for: \n";
158 copy(pidwaitlist.begin(), pidwaitlist.end(),
159 std::ostream_iterator<int>(lyxerr, "\n"));
165 string make_tmp(int pid)
167 return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
171 void kill_gs(int pid, int sig)
173 if (lyxerr.debugging())
174 lyxerr << "Killing gs " << pid << endl;
176 lyx::unlink(make_tmp(pid));
181 int GhostscriptMsg(XEvent * ev, void *)
183 // bin all events not of interest
184 if (ev->type != ClientMessage)
187 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
189 if (lyxerr.debugging()) {
190 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
191 << "] pm:[" << e->data.l[1] << "]" << endl;
194 // just kill gs, that way it will work for sure
195 // This loop looks like S**T so it probably is...
196 for (bitmaps_type::iterator it = bitmaps.begin();
197 it != bitmaps.end(); ++it)
198 if (static_cast<long>((*it)->bitmap) ==
199 static_cast<long>(e->data.l[1])) {
204 // first update p->bitmap, if necessary
205 if (p->bitmap != None
206 && p->flags > (1|8) && gs_color && p->wid) {
207 // query current colormap and re-render
208 // the pixmap with proper colors
209 XWindowAttributes wa;
210 register XImage * im;
213 int spc1 = gs_spc - 1;
214 int spc2 = gs_spc * gs_spc;
218 GC gc = local_gc_copy;
220 XGetWindowAttributes(fl_get_display(),
224 XFlush(fl_get_display());
225 if (lyxerr.debugging()) {
226 lyxerr << "Starting image translation "
229 << p->wid << "x" << p->hgh
231 << " " << XYPixmap << endl;
233 // now fork rendering process
235 if (forkstat == -1) {
237 << "Cannot fork, using slow "
238 "method for pixmap translation." << endl;
239 tmpdisp = fl_get_display();
240 } else if (forkstat > 0) { // parent
242 if (lyxerr.debugging()) {
243 lyxerr << "Spawned child "
246 addpidwait(forkstat);
249 tmpdisp = XOpenDisplay(DisplayString(fl_get_display()));
252 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
253 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
255 if (lyxerr.debugging()) {
256 lyxerr << "Got the image" << endl;
259 if (lyxerr.debugging()) {
260 lyxerr << "Error getting the image" << endl;
265 // query current colormap
266 XColor * cmap = new XColor[gs_allcolors];
267 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
268 XQueryColors(tmpdisp,
269 fl_state[fl_get_vclass()]
273 // now we process all the image
274 for (y = 0; y < p->hgh; ++y) {
275 for (int x = 0; x < wid; ++x) {
280 gs_pixels[((pc->red+6553)*
281 spc1/65535)*spc2+((pc->green+6553)*
282 spc1/65535)*gs_spc+((pc->blue+6553)*
287 // This must be correct.
289 if (lyxerr.debugging()) {
290 lyxerr << "Putting image back"
293 XPutImage(tmpdisp, p->bitmap,
295 0, 0, p->wid, p->hgh);
297 if (lyxerr.debugging()) {
298 lyxerr << "Done translation"
303 kill_gs(p->gspid, SIGHUP);
305 XCloseDisplay(tmpdisp);
309 kill_gs(p->gspid, SIGHUP);
317 void AllocColors(int num)
318 // allocate color cube numxnumxnum, if possible
320 if (lyxerr.debugging()) {
321 lyxerr << "Allocating color cube " << num
322 << 'x' << num << 'x' << num << endl;
326 lyxerr << "Error allocating color colormap." << endl;
330 if (num > 5) num = 5;
332 for (int i = 0; i < num * num * num; ++i) {
333 xcol.red = short(65535 * (i / (num * num)) / (num - 1));
334 xcol.green = short(65535 * ((i / num) % num) / (num - 1));
335 xcol.blue = short(65535 * (i % num) / (num - 1));
336 xcol.flags = DoRed | DoGreen | DoBlue;
337 if (!XAllocColor(fl_get_display(),
338 fl_state[fl_get_vclass()].colormap, &xcol)) {
339 if (i) XFreeColors(fl_get_display(),
340 fl_state[fl_get_vclass()].colormap,
342 if (lyxerr.debugging()) {
343 lyxerr << "Cannot allocate color cube "
346 AllocColors(num - 1);
349 gs_pixels[i] = xcol.pixel;
356 // allocate grayscale ramp
357 void AllocGrays(int num)
359 if (lyxerr.debugging()) {
360 lyxerr << "Allocating grayscale colormap "
365 lyxerr << "Error allocating grayscale colormap." << endl;
369 if (num > 128) num = 128;
371 for (int i = 0; i < num; ++i) {
372 xcol.red = xcol.green = xcol.blue = short(65535 * i / (num - 1));
373 xcol.flags = DoRed | DoGreen | DoBlue;
374 if (!XAllocColor(fl_get_display(),
375 fl_state[fl_get_vclass()].colormap, &xcol)) {
376 if (i) XFreeColors(fl_get_display(),
377 fl_state[fl_get_vclass()].colormap,
379 if (lyxerr.debugging()) {
380 lyxerr << "Cannot allocate grayscale "
386 gs_pixels[i] = xcol.pixel;
393 // if bitmaps and figures are not empty we will leak mem
397 // allocate color cube on pseudo-color display
401 /* we want to capture every event, in order to work around an
404 fl_set_preemptive_callback(fl_get_canvas_id(figinset_canvas), GhostscriptMsg, 0);
406 local_gc_copy = createGC();
408 Visual * vi = DefaultVisual(fl_get_display(),
409 DefaultScreen(fl_get_display()));
410 if (lyxerr.debugging()) {
411 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
412 vi->visualid, vi->c_class,
413 vi->bits_per_rgb, vi->map_entries);
415 color_visual = ( (vi->c_class == StaticColor) ||
416 (vi->c_class == PseudoColor) ||
417 (vi->c_class == TrueColor) ||
418 (vi->c_class == DirectColor) );
419 if ((vi->c_class & 1) == 0) return;
420 // now allocate colors
421 if (vi->c_class == GrayScale) {
422 // allocate grayscale
423 AllocGrays(vi->map_entries/2);
425 // allocate normal color
427 while (i * i * i * 2 > vi->map_entries) --i;
430 gs_allcolors = vi->map_entries;
437 // if bitmaps and figures are not empty we will leak mem
441 lyxerr.debug() << "Unregistering figures..." << endl;
445 void freefigdata(figdata * tmpdata)
448 if (tmpdata->ref) return;
450 if (tmpdata->gspid > 0) {
451 int pid = tmpdata->gspid;
452 // kill ghostscript and unlink it's files
454 kill_gs(pid, SIGKILL);
457 if (tmpdata->bitmap) XFreePixmap(fl_get_display(), tmpdata->bitmap);
458 bitmaps.erase(find(bitmaps.begin(), bitmaps.end(), tmpdata));
465 // This _have_ to be set before the fork!
466 unsigned long background_pixel =
467 lyxColorHandler->colorPixel(LColor::background);
469 // run queued requests for ghostscript, if any
470 if (!gsrunning && gs_color && !gs_xcolor) {
471 // here alloc all colors, so that gs will use only
472 // those we allocated for it
477 while (gsrunning < MAXGS) {
478 //char tbuf[384]; //, tbuf2[80];
482 if (gsqueue.empty()) {
483 if (!gsrunning && gs_xcolor) {
484 // de-allocate rest of colors
490 queue_element * p = &gsqueue.front();
499 if (lyxerr.debugging()) {
500 lyxerr << "GS start error! Cannot fork."
503 p->data->broken = true;
504 p->data->reading = false;
507 if (pid == 0) { // child
510 Display * tempdisp = XOpenDisplay(DisplayString(fl_get_display()));
512 // create translation file
514 ofs.open(make_tmp(getpid()).c_str());
515 ofs << "gsave clippath pathbbox grestore\n"
517 << "/ury exch def /urx exch def /lly exch def "
519 << p->data->wid / 2.0 << " "
520 << p->data->hgh / 2.0 << " translate\n"
521 << p->data->angle << " rotate\n"
522 << -(p->data->raw_wid / 2.0) << " "
523 << -(p->data->raw_hgh / 2.0) << " translate\n"
524 << p->rx / 72.0 << " " << p->ry / 72.0
526 << -p->ofsx << " " << -p->ofsy << " translate\n"
528 ofs.close(); // Don't remove this.
530 // gs process - set ghostview environment first
532 t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
533 << ' ' << p->data->bitmap;
534 // now set up ghostview property on a window
535 // #ifdef WITH_WARNINGS
536 // #warning BUG seems that the only bug here
537 // might be the hardcoded dpi.. Bummer!
540 t1 << "0 0 0 0 " << p->data->wid << ' '
541 << p->data->hgh << " 72 72 0 0 0 0";
543 if (lyxerr.debugging()) {
544 lyxerr << "Will set GHOSTVIEW property to ["
545 << t1.str() << "]" << endl;
547 // wait until property is deleted if executing multiple
549 XGrabServer(tempdisp);
551 // grab server to prevent other child
552 // interfering with setting GHOSTVIEW property
553 // The grabbing goes on for too long, is it
554 // really needed? (Lgb)
555 // I moved most of the grabs... (Lgb)
556 if (lyxerr.debugging()) {
557 lyxerr << "Grabbing the server"
560 prop = XListProperties(tempdisp,
562 figinset_canvas), &nprop);
566 for (i = 0; i < nprop; ++i) {
567 char * p = XGetAtomName(tempdisp,
569 if (compare(p, "GHOSTVIEW") == 0) {
571 // We free it when we leave so we don't leak.
577 XFree(reinterpret_cast<char *>(prop)); // jc:
579 // ok, property found, we must wait until
580 // ghostscript deletes it
581 if (lyxerr.debugging()) {
582 lyxerr << "Releasing the server\n["
584 << "] GHOSTVIEW property"
585 " found. Waiting." << endl;
587 XUngrabServer(tempdisp);
590 XGrabServer(tempdisp);
592 XChangeProperty(tempdisp,
593 fl_get_canvas_id(figinset_canvas),
594 XInternAtom(tempdisp, "GHOSTVIEW", false),
595 XInternAtom(tempdisp, "STRING", false),
597 reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
598 int(t1.str().size()));
599 XUngrabServer(tempdisp);
604 switch (p->data->flags & 3) {
605 case 0: t3 << 'H'; break; // Hidden
606 case 1: t3 << 'M'; break; // Mono
607 case 2: t3 << 'G'; break; // Gray
616 t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
617 << ' ' << background_pixel;
619 XGrabServer(tempdisp);
620 XChangeProperty(tempdisp,
621 fl_get_canvas_id(figinset_canvas),
622 XInternAtom(tempdisp,
623 "GHOSTVIEW_COLORS", false),
624 XInternAtom(tempdisp, "STRING", false),
626 reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str().c_str())),
627 int(t3.str().size()));
628 XUngrabServer(tempdisp);
631 if (lyxerr.debugging()) {
632 lyxerr << "Releasing the server" << endl;
634 XCloseDisplay(tempdisp);
636 // set up environment
639 typedef char * char_p;
640 env = new char_p[ne + 2];
641 string tmp = t2.str().c_str();
642 env[0] = new char[tmp.size() + 1];
643 std::copy(tmp.begin(), tmp.end(), env[0]);
644 env[0][tmp.size()] = '\0';
645 memcpy(&env[1], environ,
646 sizeof(char*) * (ne + 1));
649 // now make gs command
651 // close(1); do NOT close. If GS writes out
652 // errors it would hang. (Matthias 290596)
654 string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
655 string gbuf = "-g" + tostr(p->data->wid) + "x" + tostr(p->data->hgh);
657 // now chdir into dir with .eps file, to be on the safe
659 lyx::chdir(OnlyPath(p->data->fname));
660 // make temp file name
661 string tmpf = make_tmp(getpid());
662 if (lyxerr.debugging()) {
663 lyxerr << "starting gs " << tmpf << " "
665 << ", pid: " << getpid() << endl;
668 int err = ::execlp(lyxrc.ps_command.c_str(),
669 lyxrc.ps_command.c_str(),
671 "-dNOPAUSE", "-dQUIET",
673 rbuf.c_str(), gbuf.c_str(), tmpf.c_str(),
674 p->data->fname.c_str(),
675 "showpage.ps", "quit.ps", "-", 0);
676 // if we are still there, an error occurred.
677 lyxerr << "Error executing ghostscript. "
678 << "Code: " << err << endl;
679 lyxerr.debug() << "Cmd: "
683 << p->data->fname << endl;
686 // normal process (parent)
687 if (lyxerr.debugging()) {
688 lyxerr << "GS [" << pid << "] started" << endl;
691 p->data->gspid = pid;
698 void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
700 // recompute the stuff and put in the queue
704 p.rx = (float(data->raw_wid) * 72.0) / pswid;
705 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
711 // if possible, run the queue
716 figdata * getfigdata(int wid, int hgh, string const & fname,
717 int psx, int psy, int pswid, int pshgh,
718 int raw_wid, int raw_hgh, float angle, char flags)
720 /* first search for an exact match with fname and width/height */
722 if (fname.empty() || !IsFileReadable(fname))
725 for (bitmaps_type::iterator it = bitmaps.begin();
726 it != bitmaps.end(); ++it) {
727 if ((*it)->wid == wid && (*it)->hgh == hgh &&
728 (*it)->flags == flags && (*it)->fname == fname &&
729 (*it)->angle == angle) {
734 figdata * p = new figdata;
737 p->raw_wid = raw_wid;
738 p->raw_hgh = raw_hgh;
742 bitmaps.push_back(p);
743 XWindowAttributes wa;
744 XGetWindowAttributes(fl_get_display(), fl_get_canvas_id(
745 figinset_canvas), &wa);
747 if (lyxerr.debugging()) {
748 lyxerr << "Create pixmap disp:" << fl_get_display()
749 << " scr:" << DefaultScreen(fl_get_display())
752 << " depth:" << wa.depth << endl;
760 p->bitmap = XCreatePixmap(fl_get_display(), fl_get_canvas_id(
761 figinset_canvas), wid, hgh, wa.depth);
763 // initialize reading of .eps file with correct sizes and stuff
764 addwait(psx, psy, pswid, pshgh, p);
775 void getbitmap(figdata * p)
781 void makeupdatelist(figdata * p)
783 for (figures_type::iterator it = figures.begin();
784 it != figures.end(); ++it)
785 if ((*it)->data == p) {
786 if (lyxerr.debugging()) {
787 lyxerr << "Updating inset "
791 // add inset figures[i]->inset into to_update list
792 current_view->pushIntoUpdateList((*it)->inset);
799 // this func is only "called" in spellchecker.C
800 void sigchldchecker(pid_t pid, int * status)
802 lyxerr.debug() << "Got pid = " << pid << endl;
803 bool pid_handled = false;
804 for (bitmaps_type::iterator it = bitmaps.begin();
805 it != bitmaps.end(); ++it) {
806 if ((*it)->reading && pid == (*it)->gspid) {
807 lyxerr.debug() << "Found pid in bitmaps" << endl;
808 // now read the file and remove it from disk
811 if ((*it)->gsdone) *status = 0;
813 lyxerr.debug() << "GS [" << pid
814 << "] exit OK." << endl;
816 lyxerr << "GS [" << pid << "] error "
818 << WIFEXITED(*status)
819 << " " << WEXITSTATUS(*status)
820 << " S:" << WIFSIGNALED(*status)
821 << " " << WTERMSIG(*status) << endl;
824 bitmap_waiting = true;
827 // remove temporary files
828 lyx::unlink(make_tmp(p->gspid));
832 makeupdatelist((*it));
839 lyxerr.debug() << "Checking pid in pidwait" << endl;
840 list<int>::iterator it = find(pidwaitlist.begin(),
841 pidwaitlist.end(), pid);
842 if (it != pidwaitlist.end()) {
843 lyxerr.debug() << "Found pid in pidwait\n"
844 << "Caught child pid of recompute "
845 "routine" << pid << endl;
846 pidwaitlist.erase(it);
850 lyxerr.debug() << "waitpid error" << endl;
853 lyxerr << "The process or process group specified by "
854 "pid does not exist or is not a child of "
855 "the calling process or can never be in the "
856 "states specified by options." << endl;
859 lyxerr << "waitpid() was interrupted due to the "
860 "receipt of a signal sent by the calling "
864 lyxerr << "An invalid value was specified for "
868 lyxerr << "Unknown error from waitpid" << endl;
871 } else if (pid == 0) {
872 lyxerr << "waitpid nohang" << endl;;
874 lyxerr.debug() << "normal exit from childhandler" << endl;
883 bitmap_waiting = false;
884 for (bitmaps_type::iterator it = bitmaps.begin();
885 it != bitmaps.end(); ++it)
886 if ((*it)->gspid > 0 && !(*it)->reading)
891 void RegisterFigure(InsetFig * fi)
893 if (figures.empty()) InitFigures();
895 Figref * tmpfig = new Figref;
898 figures.push_back(tmpfig);
901 if (lyxerr.debugging()) {
902 lyxerr << "Register Figure: buffer:["
903 << current_view->buffer() << "]" << endl;
908 void UnregisterFigure(InsetFig * fi)
913 Figref * tmpfig = fi->figure;
915 if (tmpfig->data) freefigdata(tmpfig->data);
916 if (tmpfig->inset->form) {
917 if (tmpfig->inset->form->Figure->visible) {
918 fl_set_focus_object(tmpfig->inset->form->Figure,
919 tmpfig->inset->form->OkBtn);
920 fl_hide_form(tmpfig->inset->form->Figure);
922 #if FL_REVISION == 89
923 // CHECK Reactivate this free_form calls
925 fl_free_form(tmpfig->inset->form->Figure);
926 free(tmpfig->inset->form); // Why free?
927 tmpfig->inset->form = 0;
930 figures.erase(find(figures.begin(), figures.end(), tmpfig));
933 if (figures.empty()) DoneFigures();
939 InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
949 psubfigure = subfigure = false;
950 xwid = xhgh = angle = 0;
952 raw_wid = raw_hgh = 0;
953 changedfname = false;
954 RegisterFigure(this);
955 r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &InsetFig::redraw));
959 InsetFig::~InsetFig()
961 if (lyxerr.debugging()) {
962 lyxerr << "Figure destructor called" << endl;
964 UnregisterFigure(this);
969 void InsetFig::redraw()
971 if (form && form->Figure->visible)
972 fl_redraw_form(form->Figure);
976 int InsetFig::ascent(BufferView *, LyXFont const &) const
982 int InsetFig::descent(BufferView *, LyXFont const &) const
988 int InsetFig::width(BufferView *, LyXFont const &) const
994 void InsetFig::draw(BufferView * bv, LyXFont const & f,
995 int baseline, float & x, bool) const
998 Painter & pain = bv->painter();
1000 if (bitmap_waiting) getbitmaps();
1002 // I wish that I didn't have to use this
1003 // but the figinset code is so complicated so
1004 // I don't want to fiddle with it now.
1006 if (figure && figure->data && figure->data->bitmap &&
1007 !figure->data->reading && !figure->data->broken) {
1009 pain.pixmap(int(x + 1), baseline - hgh,
1010 wid, hgh, figure->data->bitmap);
1013 pain.rectangle(int(x), baseline - hgh - 1,
1017 //char const * msg = 0;
1019 string lfname = fname;
1020 if (!fname.empty() && GetExtension(fname).empty())
1023 pain.rectangle(int(x), baseline - hgh - 1, wid + 1, hgh + 1);
1025 if (figure && figure->data) {
1026 if (figure->data->broken) msg = _("[render error]");
1027 else if (figure->data->reading) msg = _("[rendering ... ]");
1029 else if (fname.empty())
1030 msg = _("[no file]");
1031 else if (!IsFileReadable(lfname))
1032 msg = _("[bad file name]");
1033 else if ((flags & 3) == 0)
1034 msg = _("[not displayed]");
1035 else if (lyxrc.ps_command.empty())
1036 msg = _("[no ghostscript]");
1038 if (msg.empty()) msg = _("[unknown error]");
1040 font.setFamily(LyXFont::SANS_FAMILY);
1041 font.setSize(LyXFont::SIZE_FOOTNOTE);
1042 string const justname = OnlyFilename (fname);
1043 pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4,
1046 font.setSize(LyXFont::SIZE_TINY);
1047 pain.text(int(x + 8), baseline - 4, msg, font);
1049 x += width(bv, font); // ?
1053 void InsetFig::Write(Buffer const *, ostream & os) const
1056 os << "Figure size " << wid << " " << hgh << "\n";
1057 if (!fname.empty()) {
1058 string buf1 = OnlyPath(owner->fileName());
1059 string fname2 = MakeRelPath(fname, buf1);
1060 os << "file " << fname2 << "\n";
1062 if (!subcaption.empty())
1063 os << "subcaption " << subcaption << "\n";
1064 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1065 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1066 if (angle != 0) os << "angle " << angle << "\n";
1067 os << "flags " << flags << "\n";
1068 if (subfigure) os << "subfigure\n";
1072 void InsetFig::Read(Buffer const *, LyXLex & lex)
1075 bool finished = false;
1077 while (lex.IsOK() && !finished) {
1080 string const token = lex.GetString();
1081 lyxerr.debug() << "Token: " << token << endl;
1085 else if (token == "\\end_inset") {
1087 } else if (token == "file") {
1089 buf = lex.GetString();
1090 string buf1 = OnlyPath(owner->fileName());
1091 fname = MakeAbsPath(buf, buf1);
1092 changedfname = true;
1094 } else if (token == "extra") {
1096 // kept for backwards compability. Delete in 0.13.x
1097 } else if (token == "subcaption") {
1099 subcaption = lex.GetString();
1100 } else if (token == "label") {
1102 // kept for backwards compability. Delete in 0.13.x
1103 } else if (token == "angle") {
1105 angle = lex.GetFloat();
1106 } else if (token == "size") {
1108 wid = lex.GetInteger();
1110 hgh = lex.GetInteger();
1111 } else if (token == "flags") {
1113 flags = pflags = lex.GetInteger();
1114 } else if (token == "subfigure") {
1115 subfigure = psubfigure = true;
1116 } else if (token == "width") {
1119 typ = lex.GetInteger();
1121 xwid = lex.GetFloat();
1123 case DEF: wtype = DEF; break;
1124 case CM: wtype = CM; break;
1125 case IN: wtype = IN; break;
1126 case PER_PAGE: wtype = PER_PAGE; break;
1127 case PER_COL: wtype = PER_COL; break;
1129 lyxerr.debug() << "Unknown type!" << endl;
1133 } else if (token == "height") {
1136 typ = lex.GetInteger();
1138 xhgh = lex.GetFloat();
1140 case DEF: htype = DEF; break;
1141 case CM: htype = CM; break;
1142 case IN: htype = IN; break;
1143 case PER_PAGE: htype = PER_PAGE; break;
1145 lyxerr.debug() << "Unknown type!" << endl;
1156 int InsetFig::Latex(Buffer const *, ostream & os,
1157 bool /* fragile*/, bool /* fs*/) const
1160 if (!cmd.empty()) os << cmd << " ";
1165 int InsetFig::Ascii(Buffer const *, ostream &, int) const
1171 int InsetFig::Linuxdoc(Buffer const *, ostream &) const
1177 int InsetFig::DocBook(Buffer const *, ostream & os) const
1179 string buf1 = OnlyPath(owner->fileName());
1180 string figurename = MakeRelPath(fname, buf1);
1182 if (suffixIs(figurename, ".eps"))
1183 figurename.erase(figurename.length() - 4);
1185 os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
1190 void InsetFig::Validate(LaTeXFeatures & features) const
1192 features.graphics = true;
1193 if (subfigure) features.subfigure = true;
1197 Inset::EDITABLE InsetFig::Editable() const
1203 bool InsetFig::Deletable() const
1209 string const InsetFig::EditMessage() const
1211 return _("Opened figure");
1215 void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
1217 lyxerr.debug() << "Editing InsetFig." << endl;
1220 // We should have RO-versions of the form instead.
1221 // The actual prevention of altering a readonly doc
1222 // is done in CallbackFig()
1223 if (bv->buffer()->isReadonly())
1224 WarnReadonly(bv->buffer()->fileName());
1227 form = create_form_Figure();
1228 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1229 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1230 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1231 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1234 if (form->Figure->visible) {
1235 fl_raise_form(form->Figure);
1237 fl_show_form(form->Figure,
1238 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
1244 Inset * InsetFig::Clone(Buffer const & buffer) const
1246 InsetFig * tmp = new InsetFig(100, 100, buffer);
1248 if (lyxerr.debugging()) {
1249 lyxerr << "Clone Figure: buffer:["
1251 << "], cbuffer:[xx]" << endl;
1256 tmp->raw_wid = raw_wid;
1257 tmp->raw_hgh = raw_hgh;
1262 tmp->pflags = pflags;
1263 tmp->subfigure = subfigure;
1264 tmp->psubfigure = psubfigure;
1272 string lfname = fname;
1273 if (!fname.empty() && GetExtension(fname).empty())
1275 if (!fname.empty() && IsFileReadable(lfname)
1276 && (flags & 3) && !lyxrc.ps_command.empty()
1278 // do not display if there is
1279 // "do not display" chosen (Matthias 260696)
1280 tmp->figure->data = getfigdata(wid, hgh, lfname, psx, psy,
1281 pswid, pshgh, raw_wid, raw_hgh,
1282 angle, flags & (3|8));
1283 } else tmp->figure->data = 0;
1284 tmp->subcaption = subcaption;
1285 tmp->changedfname = false;
1292 Inset::Code InsetFig::LyxCode() const
1294 return Inset::GRAPHICS_CODE;
1300 string const stringify(InsetFig::HWTYPE hw, float f, string suffix)
1306 case InsetFig::CM:// \resizebox*{h-length}{v-length}{text}
1307 res = tostr(f) + "cm";
1310 res = tostr(f) + "in";
1312 case InsetFig::PER_PAGE:
1313 res = tostr(f/100) + "\\text" + suffix;
1315 case InsetFig::PER_COL:
1316 // Doesn't occur for htype...
1317 res = tostr(f/100) + "\\column" + suffix;
1326 void InsetFig::Regenerate() const
1329 string resizeW, resizeH;
1330 string rotate, recmd;
1332 if (fname.empty()) {
1333 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1334 cmd += _("empty figure path");
1339 string buf1 = OnlyPath(owner->fileName());
1340 string fname2 = MakeRelPath(fname, buf1);
1342 string gcmd = "\\includegraphics{" + fname2 + '}';
1343 resizeW = stringify(wtype, xwid, "width");
1344 resizeH = stringify(htype, xhgh, "height");
1346 if (!resizeW.empty() || !resizeH.empty()) {
1347 recmd = "\\resizebox*{";
1348 if (!resizeW.empty())
1353 if (!resizeH.empty())
1362 // \rotatebox{angle}{text}
1363 rotate = "\\rotatebox{" + tostr(angle) + "}{";
1369 if (!rotate.empty()) cmdbuf += '}';
1370 if (!recmd.empty()) cmdbuf += '}';
1372 if (!subcaption.empty())
1373 cmdbuf = "\\subfigure[" + subcaption +
1374 "]{" + cmdbuf + "}";
1376 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1383 void InsetFig::TempRegenerate()
1386 string resizeW, resizeH;
1387 string rotate, recmd;
1389 char const * tfname = fl_get_input(form->EpsFile);
1390 string tsubcap = fl_get_input(form->Subcaption);
1391 float tangle = atof(fl_get_input(form->Angle));
1392 float txwid = atof(fl_get_input(form->Width));
1393 float txhgh = atof(fl_get_input(form->Height));
1395 if (!tfname || !*tfname) {
1396 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1397 cmd += _("empty figure path");
1402 string buf1 = OnlyPath(owner->fileName());
1403 string fname2 = MakeRelPath(tfname, buf1);
1404 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1405 string gcmd = "\\includegraphics{" + fname2 + '}';
1407 resizeW = stringify(twtype, txwid, "width");
1408 resizeH = stringify(thtype, txhgh, "height");
1410 // \resizebox*{h-length}{v-length}{text}
1411 if (!resizeW.empty() || !resizeH.empty()) {
1412 recmd = "\\resizebox*{";
1413 if (!resizeW.empty())
1418 if (!resizeH.empty())
1426 // \rotatebox{angle}{text}
1427 rotate = "\\rotatebox{" + tostr(tangle) + "}{";
1430 cmdbuf = recmd + rotate + gcmd;
1431 if (!rotate.empty()) cmdbuf += '}';
1432 if (!recmd.empty()) cmdbuf += '}';
1433 if (psubfigure && !tsubcap.empty()) {
1434 cmdbuf = string("\\subfigure{") + tsubcap
1435 + string("}{") + cmdbuf + "}";
1440 void InsetFig::Recompute()
1445 bool changed = changedfname;
1446 int newx, newy, nraw_x, nraw_y;
1448 if (changed) GetPSSizes();
1450 float sin_a = sin(angle / DEG2PI); /* rotation; H. Zeller 021296 */
1451 float cos_a = cos(angle / DEG2PI);
1452 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1453 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1455 string lfname = fname;
1456 if (GetExtension(fname).empty())
1459 /* now recompute wid and hgh, and if that is changed, set changed */
1460 /* this depends on chosen size of the picture and its bbox */
1461 // This will be redone in 0.13 ... (hen)
1462 if (!lfname.empty() && IsFileReadable(lfname)) {
1463 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1471 newx = int(28.346 * xwid);
1474 newx = int(72 * xwid);
1476 case PER_PAGE: /* % of page */
1477 newx = int(5.95 * xwid);
1479 case PER_COL: /* % of col */
1480 newx = int(2.975 * xwid);
1484 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1488 //lyxerr << "This should not happen!" << endl;
1491 newy = int(28.346 * xhgh);
1494 newy = int(72 * xhgh);
1496 case PER_PAGE: /* % of page */
1497 newy = int(8.42 * xhgh);
1500 // Doesn't occur; case exists to suppress
1501 // compiler warnings.
1504 if (htype && !wtype && frame_hgh)
1505 newx = newy*frame_wid/frame_hgh;
1514 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1519 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1521 // cannot be zero, actually, set it to some minimum, so its clickable
1522 if (newx < 5) newx = 5;
1523 if (newy < 5) newy = 5;
1525 if (newx != wid || newy != hgh ||
1526 nraw_x != raw_wid || nraw_y != raw_hgh ||
1527 flags != pflags || subfigure != psubfigure)
1535 subfigure = psubfigure;
1538 figdata * pf = figure->data;
1541 if (!lfname.empty() && IsFileReadable(lfname) && (flags & 3)
1542 && !lyxrc.ps_command.empty()) {
1543 // do not display if there is "do not display"
1544 // chosen (Matthias 260696)
1545 figure->data = getfigdata(wid, hgh, lfname,
1546 psx, psy, pswid, pshgh,
1548 angle, flags & (3|8));
1549 } else figure->data = 0;
1551 // free the old data
1552 if (pf) freefigdata(pf);
1555 changedfname = false;
1559 void InsetFig::GetPSSizes()
1561 /* get %%BoundingBox: from postscript file */
1563 /* defaults to associated size
1564 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1571 if (fname.empty()) return;
1573 string lfname = fname;
1574 if (GetExtension(fname).empty())
1576 ifstream ifs(lfname.c_str());
1578 if (!ifs) return; // file not found !!!!
1580 /* defaults to A4 page */
1586 char lastchar = 0; ifs.get(lastchar);
1588 char c = 0; ifs.get(c);
1590 lyxerr.debug() << "End of (E)PS file reached and"
1591 " no BoundingBox!" << endl;
1594 if (c == '%' && lastchar == '%') {
1596 if (p.empty()) break;
1597 lyxerr.debug() << "Token: `" << p << "'" << endl;
1598 if (p == "BoundingBox:") {
1599 float fpsx, fpsy, fpswid, fpshgh;
1600 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1603 pswid = int(fpswid);
1604 pshgh = int(fpshgh);
1606 if (lyxerr.debugging()) {
1607 lyxerr << "%%%%BoundingBox:"
1625 void InsetFig::CallbackFig(long arg)
1630 if (lyxerr.debugging()) {
1631 lyxerr << "Figure callback, arg " << arg << endl;
1637 case 12: /* width type */
1644 fl_deactivate_object(form->Width);
1649 fl_activate_object(form->Width);
1654 fl_activate_object(form->Width);
1659 fl_activate_object(form->Width);
1664 fl_activate_object(form->Width);
1667 lyxerr.debug() << "Unknown type!" << endl;
1674 case 22: /* height type */
1680 fl_deactivate_object(form->Height);
1685 fl_activate_object(form->Height);
1690 fl_activate_object(form->Height);
1695 fl_activate_object(form->Height);
1698 lyxerr.debug() << "Unknown type!" << endl;
1704 pflags = pflags & ~3; /* wysiwyg0 */
1707 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1710 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1713 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1716 pflags ^= 4; /* frame */
1719 pflags ^= 8; /* do translations */
1722 psubfigure = !psubfigure; /* This is a subfigure */
1725 regen = true; /* regenerate command */
1727 case 0: /* browse file */
1731 case 1: /* preview */
1732 p = fl_get_input(form->EpsFile);
1736 case 8: /* ok (apply and close) */
1737 if (!current_view->buffer()->isReadonly()) {
1740 xwid = atof(fl_get_input(form->Width));
1741 xhgh = atof(fl_get_input(form->Height));
1742 angle = atof(fl_get_input(form->Angle));
1743 p = fl_get_input(form->EpsFile);
1745 string buf1 = OnlyPath(owner->fileName());
1746 fname = MakeAbsPath(p, buf1);
1747 changedfname = true;
1749 if (!fname.empty()) {
1750 changedfname = true;
1754 subcaption = fl_get_input(form->Subcaption);
1758 /* now update inset */
1759 if (lyxerr.debugging()) {
1760 lyxerr << "Update: ["
1761 << wid << 'x' << hgh << ']' << endl;
1763 current_view->updateInset(this, true);
1765 fl_set_focus_object(form->Figure, form->OkBtn);
1766 fl_hide_form(form->Figure);
1767 #if FL_REVISION == 89
1768 // CHECK Reactivate this free_form calls
1770 fl_free_form(form->Figure);
1771 free(form); // Why free?
1777 // The user has already been informed about RO in ::Edit
1778 if (arg == 7) // if 'Apply'
1781 case 9: /* cancel = restore and close */
1782 fl_set_focus_object(form->Figure, form->OkBtn);
1783 fl_hide_form(form->Figure);
1784 #if FL_REVISION == 89
1785 // CHECK Reactivate this free_form calls
1786 // Jug, is this still a problem?
1788 fl_free_form(form->Figure);
1789 free(form); // Why free?
1795 if (regen) TempRegenerate();
1800 void DisableFigurePanel(FD_Figure * const form)
1802 fl_deactivate_object(form->EpsFile);
1803 fl_deactivate_object(form->Browse);
1804 fl_deactivate_object(form->Width);
1805 fl_deactivate_object(form->Height);
1806 fl_deactivate_object(form->Frame);
1807 fl_deactivate_object(form->Translations);
1808 fl_deactivate_object(form->Angle);
1809 fl_deactivate_object(form->HeightGrp);
1810 fl_deactivate_object(form->page2);
1811 fl_deactivate_object(form->Default2);
1812 fl_deactivate_object(form->cm2);
1813 fl_deactivate_object(form->in2);
1814 fl_deactivate_object(form->HeightLabel);
1815 fl_deactivate_object(form->WidthLabel);
1816 fl_deactivate_object(form->DisplayGrp);
1817 fl_deactivate_object(form->Wysiwyg3);
1818 fl_deactivate_object(form->Wysiwyg0);
1819 fl_deactivate_object(form->Wysiwyg2);
1820 fl_deactivate_object(form->Wysiwyg1);
1821 fl_deactivate_object(form->WidthGrp);
1822 fl_deactivate_object(form->Default1);
1823 fl_deactivate_object(form->cm1);
1824 fl_deactivate_object(form->in1);
1825 fl_deactivate_object(form->page1);
1826 fl_deactivate_object(form->column1);
1827 fl_deactivate_object(form->Subcaption);
1828 fl_deactivate_object(form->Subfigure);
1829 fl_deactivate_object (form->OkBtn);
1830 fl_deactivate_object (form->ApplyBtn);
1831 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1832 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1837 void EnableFigurePanel(FD_Figure * const form)
1839 fl_activate_object(form->EpsFile);
1840 fl_activate_object(form->Browse);
1841 fl_activate_object(form->Width);
1842 fl_activate_object(form->Height);
1843 fl_activate_object(form->Frame);
1844 fl_activate_object(form->Translations);
1845 fl_activate_object(form->Angle);
1846 fl_activate_object(form->HeightGrp);
1847 fl_activate_object(form->page2);
1848 fl_activate_object(form->Default2);
1849 fl_activate_object(form->cm2);
1850 fl_activate_object(form->in2);
1851 fl_activate_object(form->HeightLabel);
1852 fl_activate_object(form->WidthLabel);
1853 fl_activate_object(form->DisplayGrp);
1854 fl_activate_object(form->Wysiwyg3);
1855 fl_activate_object(form->Wysiwyg0);
1856 fl_activate_object(form->Wysiwyg2);
1857 fl_activate_object(form->Wysiwyg1);
1858 fl_activate_object(form->WidthGrp);
1859 fl_activate_object(form->Default1);
1860 fl_activate_object(form->cm1);
1861 fl_activate_object(form->in1);
1862 fl_activate_object(form->page1);
1863 fl_activate_object(form->column1);
1864 fl_activate_object(form->Subcaption);
1865 fl_activate_object(form->Subfigure);
1866 fl_activate_object (form->OkBtn);
1867 fl_activate_object (form->ApplyBtn);
1868 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1869 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1873 void InsetFig::RestoreForm()
1875 EnableFigurePanel(form);
1878 fl_set_button(form->Default1, (wtype == 0));
1879 fl_set_button(form->cm1, (wtype == 1));
1880 fl_set_button(form->in1, (wtype == 2));
1881 fl_set_button(form->page1, (wtype == 3));
1882 fl_set_button(form->column1, (wtype == 4));
1884 fl_deactivate_object(form->Width);
1886 fl_activate_object(form->Width);
1889 // enable and disable should be put here.
1891 fl_set_button(form->Default2, (htype == 0));
1892 fl_set_button(form->cm2, (htype == 1));
1893 fl_set_button(form->in2, (htype == 2));
1894 fl_set_button(form->page2, (htype == 3));
1895 // enable and disable should be put here.
1897 fl_deactivate_object(form->Height);
1899 fl_activate_object(form->Height);
1902 int piflags = flags & 3;
1903 fl_set_button(form->Wysiwyg0, (piflags == 0));
1904 fl_set_button(form->Wysiwyg1, (piflags == 1));
1905 fl_set_button(form->Wysiwyg2, (piflags == 2));
1906 fl_set_button(form->Wysiwyg3, (piflags == 3));
1907 fl_set_button(form->Frame, ((flags & 4) != 0));
1908 fl_set_button(form->Translations, ((flags & 8) != 0));
1909 fl_set_button(form->Subfigure, (subfigure != 0));
1911 psubfigure = subfigure;
1912 fl_set_input(form->Width, tostr(xwid).c_str());
1913 fl_set_input(form->Height, tostr(xhgh).c_str());
1914 fl_set_input(form->Angle, tostr(angle).c_str());
1915 if (!fname.empty()){
1916 string buf1 = OnlyPath(owner->fileName());
1917 string fname2 = MakeRelPath(fname, buf1);
1918 fl_set_input(form->EpsFile, fname2.c_str());
1920 else fl_set_input(form->EpsFile, "");
1921 fl_set_input(form->Subcaption, subcaption.c_str());
1922 if (current_view->buffer()->isReadonly())
1923 DisableFigurePanel(form);
1929 void InsetFig::Preview(string const & p)
1932 if (GetExtension(tfname).empty())
1934 string buf1 = OnlyPath(owner->fileName());
1935 string buf2 = os::external_path(MakeAbsPath(tfname, buf1));
1936 if (!formats.View(owner, buf2, "eps"))
1937 lyxerr << "Can't view " << buf2 << endl;
1941 void InsetFig::BrowseFile()
1943 static string current_figure_path;
1946 if (lyxerr.debugging()) {
1947 lyxerr << "Filename: "
1948 << owner->fileName() << endl;
1950 string p = fl_get_input(form->EpsFile);
1952 string buf = MakeAbsPath(owner->fileName());
1953 string buf2 = OnlyPath(buf);
1955 buf = MakeAbsPath(p, buf2);
1956 buf = OnlyPath(buf);
1958 buf = OnlyPath(owner->fileName());
1961 // Does user clipart directory exist?
1962 string bufclip = AddName (user_lyxdir, "clipart");
1963 FileInfo fileInfo(bufclip);
1964 if (!(fileInfo.isOK() && fileInfo.isDir()))
1965 // No - bail out to system clipart directory
1966 bufclip = AddName (system_lyxdir, "clipart");
1969 FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"),
1970 LFUN_SELECT_FILE_SYNC,
1971 make_pair(string(_("Clip art")), string(bufclip)),
1972 make_pair(string(_("Documents")), string(buf)));
1976 string const path = (once) ? current_figure_path : buf;
1978 FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
1980 string const p = result.second;
1985 buf = MakeRelPath(p, buf2);
1986 current_figure_path = OnlyPath(p);
1989 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
1990 || contains(p, "%") || contains(p, " ")) {
1991 WriteAlert(_("Filename can't contain any "
1992 "of these characters:"),
1993 // xgettext:no-c-format
1994 _("space, '#', '~', '$' or '%'."));
1999 if (form) fl_set_input(form->EpsFile, buf.c_str());
2003 void GraphicsCB(FL_OBJECT * obj, long arg)
2005 /* obj->form contains the form */
2007 if (lyxerr.debugging()) {
2008 lyxerr << "GraphicsCB callback: " << arg << endl;
2011 /* find inset we were reacting to */
2012 for (figures_type::iterator it = figures.begin();
2013 it != figures.end(); ++it)
2014 if ((*it)->inset->form && (*it)->inset->form->Figure
2016 if (lyxerr.debugging()) {
2017 lyxerr << "Calling back figure "
2020 (*it)->inset->CallbackFig(arg);
2026 void HideFiguresPopups()
2028 for (figures_type::iterator it = figures.begin();
2029 it != figures.end(); ++it)
2030 if ((*it)->inset->form
2031 && (*it)->inset->form->Figure->visible) {
2032 if (lyxerr.debugging()) {
2033 lyxerr << "Hiding figure " << (*it) << endl;
2035 // hide and free the form
2036 (*it)->inset->CallbackFig(9);