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"
83 #ifndef CXX_GLOBAL_CSTD
92 extern BufferView * current_view;
93 extern FL_OBJECT * figinset_canvas;
95 extern char ** environ; // is this only redundtant on linux systems? Lgb.
97 // xforms doesn't define this (but it should be in <forms.h>).
99 FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
103 float const DEG2PI = 57.295779513;
105 struct queue_element {
106 float rx, ry; // resolution x and y
107 int ofsx, ofsy; // x and y translation
108 figdata * data; // we are doing it for this data
111 int const MAXGS = 3; /* maximum 3 gs's at a time */
113 typedef vector<Figref *> figures_type;
114 typedef vector<figdata *> bitmaps_type;
115 figures_type figures; // all figures
116 bitmaps_type bitmaps; // all bitmaps
118 queue<queue_element> gsqueue; // queue for ghostscripting
120 int gsrunning = 0; /* currently so many gs's are running */
121 bool bitmap_waiting = false; /* bitmaps are waiting finished */
123 bool gs_color; // do we allocate colors for gs?
124 bool color_visual; // is the visual color?
125 bool gs_xcolor = false; // allocated extended colors
126 unsigned long gs_pixels[128]; // allocated pixels
127 int gs_spc; // shades per color
128 int gs_allcolors; // number of all colors
130 list<int> pidwaitlist; // pid wait list
135 val.foreground = BlackPixel(fl_get_display(),
136 DefaultScreen(fl_get_display()));
139 val.graphics_exposures = false;
140 val.line_style = LineSolid;
142 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
143 GCForeground | GCFunction | GCGraphicsExposures
144 | GCLineWidth | GCLineStyle , &val);
150 void addpidwait(int pid)
152 // adds pid to pid wait list
153 pidwaitlist.push_back(pid);
155 if (lyxerr.debugging()) {
156 lyxerr << "Pids to wait for: \n";
157 copy(pidwaitlist.begin(), pidwaitlist.end(),
158 std::ostream_iterator<int>(lyxerr, "\n"));
164 string make_tmp(int pid)
166 return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
170 void kill_gs(int pid, int sig)
172 if (lyxerr.debugging())
173 lyxerr << "Killing gs " << pid << endl;
175 lyx::unlink(make_tmp(pid));
180 int GhostscriptMsg(XEvent * ev, void *)
182 // bin all events not of interest
183 if (ev->type != ClientMessage)
186 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
188 if (lyxerr.debugging()) {
189 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
190 << "] pm:[" << e->data.l[1] << "]" << endl;
193 // just kill gs, that way it will work for sure
194 // This loop looks like S**T so it probably is...
195 for (bitmaps_type::iterator it = bitmaps.begin();
196 it != bitmaps.end(); ++it)
197 if (static_cast<long>((*it)->bitmap) ==
198 static_cast<long>(e->data.l[1])) {
203 // first update p->bitmap, if necessary
204 if (p->bitmap != None
205 && p->flags > (1|8) && gs_color && p->wid) {
206 // query current colormap and re-render
207 // the pixmap with proper colors
208 XWindowAttributes wa;
209 register XImage * im;
212 int spc1 = gs_spc - 1;
213 int spc2 = gs_spc * gs_spc;
217 GC gc = local_gc_copy;
219 XGetWindowAttributes(fl_get_display(),
223 XFlush(fl_get_display());
224 if (lyxerr.debugging()) {
225 lyxerr << "Starting image translation "
228 << p->wid << "x" << p->hgh
230 << " " << XYPixmap << endl;
232 // now fork rendering process
234 if (forkstat == -1) {
236 << "Cannot fork, using slow "
237 "method for pixmap translation." << endl;
238 tmpdisp = fl_get_display();
239 } else if (forkstat > 0) { // parent
241 if (lyxerr.debugging()) {
242 lyxerr << "Spawned child "
245 addpidwait(forkstat);
248 tmpdisp = XOpenDisplay(DisplayString(fl_get_display()));
251 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
252 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
254 if (lyxerr.debugging()) {
255 lyxerr << "Got the image" << endl;
258 if (lyxerr.debugging()) {
259 lyxerr << "Error getting the image" << endl;
264 // query current colormap
265 XColor * cmap = new XColor[gs_allcolors];
266 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
267 XQueryColors(tmpdisp,
268 fl_state[fl_get_vclass()]
272 // now we process all the image
273 for (y = 0; y < p->hgh; ++y) {
274 for (int x = 0; x < wid; ++x) {
279 gs_pixels[((pc->red+6553)*
280 spc1/65535)*spc2+((pc->green+6553)*
281 spc1/65535)*gs_spc+((pc->blue+6553)*
286 // This must be correct.
288 if (lyxerr.debugging()) {
289 lyxerr << "Putting image back"
292 XPutImage(tmpdisp, p->bitmap,
294 0, 0, p->wid, p->hgh);
296 if (lyxerr.debugging()) {
297 lyxerr << "Done translation"
302 kill_gs(p->gspid, SIGHUP);
304 XCloseDisplay(tmpdisp);
308 kill_gs(p->gspid, SIGHUP);
316 void AllocColors(int num)
317 // allocate color cube numxnumxnum, if possible
319 if (lyxerr.debugging()) {
320 lyxerr << "Allocating color cube " << num
321 << 'x' << num << 'x' << num << endl;
325 lyxerr << "Error allocating color colormap." << endl;
329 if (num > 5) num = 5;
331 for (int i = 0; i < num * num * num; ++i) {
332 xcol.red = short(65535 * (i / (num * num)) / (num - 1));
333 xcol.green = short(65535 * ((i / num) % num) / (num - 1));
334 xcol.blue = short(65535 * (i % num) / (num - 1));
335 xcol.flags = DoRed | DoGreen | DoBlue;
336 if (!XAllocColor(fl_get_display(),
337 fl_state[fl_get_vclass()].colormap, &xcol)) {
338 if (i) XFreeColors(fl_get_display(),
339 fl_state[fl_get_vclass()].colormap,
341 if (lyxerr.debugging()) {
342 lyxerr << "Cannot allocate color cube "
345 AllocColors(num - 1);
348 gs_pixels[i] = xcol.pixel;
355 // allocate grayscale ramp
356 void AllocGrays(int num)
358 if (lyxerr.debugging()) {
359 lyxerr << "Allocating grayscale colormap "
364 lyxerr << "Error allocating grayscale colormap." << endl;
368 if (num > 128) num = 128;
370 for (int i = 0; i < num; ++i) {
371 xcol.red = xcol.green = xcol.blue = short(65535 * i / (num - 1));
372 xcol.flags = DoRed | DoGreen | DoBlue;
373 if (!XAllocColor(fl_get_display(),
374 fl_state[fl_get_vclass()].colormap, &xcol)) {
375 if (i) XFreeColors(fl_get_display(),
376 fl_state[fl_get_vclass()].colormap,
378 if (lyxerr.debugging()) {
379 lyxerr << "Cannot allocate grayscale "
385 gs_pixels[i] = xcol.pixel;
392 // if bitmaps and figures are not empty we will leak mem
396 // allocate color cube on pseudo-color display
400 /* we want to capture every event, in order to work around an
403 fl_set_preemptive_callback(fl_get_canvas_id(figinset_canvas), GhostscriptMsg, 0);
405 local_gc_copy = createGC();
407 Visual * vi = DefaultVisual(fl_get_display(),
408 DefaultScreen(fl_get_display()));
409 if (lyxerr.debugging()) {
410 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
411 vi->visualid, vi->c_class,
412 vi->bits_per_rgb, vi->map_entries);
414 color_visual = ( (vi->c_class == StaticColor) ||
415 (vi->c_class == PseudoColor) ||
416 (vi->c_class == TrueColor) ||
417 (vi->c_class == DirectColor) );
418 if ((vi->c_class & 1) == 0) return;
419 // now allocate colors
420 if (vi->c_class == GrayScale) {
421 // allocate grayscale
422 AllocGrays(vi->map_entries/2);
424 // allocate normal color
426 while (i * i * i * 2 > vi->map_entries) --i;
429 gs_allcolors = vi->map_entries;
436 // if bitmaps and figures are not empty we will leak mem
440 lyxerr[Debug::INFO] << "Unregistering figures..." << endl;
444 void freefigdata(figdata * tmpdata)
447 if (tmpdata->ref) return;
449 if (tmpdata->gspid > 0) {
450 int pid = tmpdata->gspid;
451 // kill ghostscript and unlink it's files
453 kill_gs(pid, SIGKILL);
456 if (tmpdata->bitmap) XFreePixmap(fl_get_display(), tmpdata->bitmap);
457 bitmaps.erase(find(bitmaps.begin(), bitmaps.end(), tmpdata));
464 // This _have_ to be set before the fork!
465 unsigned long background_pixel =
466 lyxColorHandler->colorPixel(LColor::background);
468 // run queued requests for ghostscript, if any
469 if (!gsrunning && gs_color && !gs_xcolor) {
470 // here alloc all colors, so that gs will use only
471 // those we allocated for it
476 while (gsrunning < MAXGS) {
477 //char tbuf[384]; //, tbuf2[80];
481 if (gsqueue.empty()) {
482 if (!gsrunning && gs_xcolor) {
483 // de-allocate rest of colors
489 queue_element * p = &gsqueue.front();
498 if (lyxerr.debugging()) {
499 lyxerr << "GS start error! Cannot fork."
502 p->data->broken = true;
503 p->data->reading = false;
506 if (pid == 0) { // child
509 Display * tempdisp = XOpenDisplay(DisplayString(fl_get_display()));
511 // create translation file
513 ofs.open(make_tmp(getpid()).c_str());
514 ofs << "gsave clippath pathbbox grestore\n"
516 << "/ury exch def /urx exch def /lly exch def "
518 << p->data->wid / 2.0 << " "
519 << p->data->hgh / 2.0 << " translate\n"
520 << p->data->angle << " rotate\n"
521 << -(p->data->raw_wid / 2.0) << " "
522 << -(p->data->raw_hgh / 2.0) << " translate\n"
523 << p->rx / 72.0 << " " << p->ry / 72.0
525 << -p->ofsx << " " << -p->ofsy << " translate\n"
527 ofs.close(); // Don't remove this.
529 // gs process - set ghostview environment first
531 t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
532 << ' ' << p->data->bitmap;
533 // now set up ghostview property on a window
534 // #ifdef WITH_WARNINGS
535 // #warning BUG seems that the only bug here
536 // might be the hardcoded dpi.. Bummer!
539 t1 << "0 0 0 0 " << p->data->wid << ' '
540 << p->data->hgh << " 72 72 0 0 0 0";
542 if (lyxerr.debugging()) {
543 lyxerr << "Will set GHOSTVIEW property to ["
544 << t1.str() << "]" << endl;
546 // wait until property is deleted if executing multiple
548 XGrabServer(tempdisp);
550 // grab server to prevent other child
551 // interfering with setting GHOSTVIEW property
552 // The grabbing goes on for too long, is it
553 // really needed? (Lgb)
554 // I moved most of the grabs... (Lgb)
555 if (lyxerr.debugging()) {
556 lyxerr << "Grabbing the server"
559 prop = XListProperties(tempdisp,
561 figinset_canvas), &nprop);
565 for (i = 0; i < nprop; ++i) {
566 char * p = XGetAtomName(tempdisp,
568 if (compare(p, "GHOSTVIEW") == 0) {
570 // We free it when we leave so we don't leak.
576 XFree(reinterpret_cast<char *>(prop)); // jc:
578 // ok, property found, we must wait until
579 // ghostscript deletes it
580 if (lyxerr.debugging()) {
581 lyxerr << "Releasing the server\n["
583 << "] GHOSTVIEW property"
584 " found. Waiting." << endl;
586 XUngrabServer(tempdisp);
589 XGrabServer(tempdisp);
591 XChangeProperty(tempdisp,
592 fl_get_canvas_id(figinset_canvas),
593 XInternAtom(tempdisp, "GHOSTVIEW", false),
594 XInternAtom(tempdisp, "STRING", false),
596 reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
597 int(t1.str().size()));
598 XUngrabServer(tempdisp);
603 switch (p->data->flags & 3) {
604 case 0: t3 << 'H'; break; // Hidden
605 case 1: t3 << 'M'; break; // Mono
606 case 2: t3 << 'G'; break; // Gray
615 t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
616 << ' ' << background_pixel;
618 XGrabServer(tempdisp);
619 XChangeProperty(tempdisp,
620 fl_get_canvas_id(figinset_canvas),
621 XInternAtom(tempdisp,
622 "GHOSTVIEW_COLORS", false),
623 XInternAtom(tempdisp, "STRING", false),
625 reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str().c_str())),
626 int(t3.str().size()));
627 XUngrabServer(tempdisp);
630 if (lyxerr.debugging()) {
631 lyxerr << "Releasing the server" << endl;
633 XCloseDisplay(tempdisp);
635 // set up environment
638 typedef char * char_p;
639 env = new char_p[ne + 2];
640 string tmp = t2.str().c_str();
641 env[0] = new char[tmp.size() + 1];
642 std::copy(tmp.begin(), tmp.end(), env[0]);
643 env[0][tmp.size()] = '\0';
644 memcpy(&env[1], environ,
645 sizeof(char*) * (ne + 1));
648 // now make gs command
650 // close(1); do NOT close. If GS writes out
651 // errors it would hang. (Matthias 290596)
653 string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
654 string gbuf = "-g" + tostr(p->data->wid) + "x" + tostr(p->data->hgh);
656 // now chdir into dir with .eps file, to be on the safe
658 lyx::chdir(OnlyPath(p->data->fname));
659 // make temp file name
660 string tmpf = make_tmp(getpid());
661 if (lyxerr.debugging()) {
662 lyxerr << "starting gs " << tmpf << " "
664 << ", pid: " << getpid() << endl;
667 int err = ::execlp(lyxrc.ps_command.c_str(),
668 lyxrc.ps_command.c_str(),
670 "-dNOPAUSE", "-dQUIET",
672 rbuf.c_str(), gbuf.c_str(), tmpf.c_str(),
673 p->data->fname.c_str(),
674 "showpage.ps", "quit.ps", "-", 0);
675 // if we are still there, an error occurred.
676 lyxerr << "Error executing ghostscript. "
677 << "Code: " << err << endl;
678 lyxerr[Debug::INFO] << "Cmd: "
682 << p->data->fname << endl;
685 // normal process (parent)
686 if (lyxerr.debugging()) {
687 lyxerr << "GS [" << pid << "] started" << endl;
690 p->data->gspid = pid;
697 void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
699 // recompute the stuff and put in the queue
703 p.rx = (float(data->raw_wid) * 72.0) / pswid;
704 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
710 // if possible, run the queue
715 figdata * getfigdata(int wid, int hgh, string const & fname,
716 int psx, int psy, int pswid, int pshgh,
717 int raw_wid, int raw_hgh, float angle, char flags)
719 /* first search for an exact match with fname and width/height */
721 if (fname.empty() || !IsFileReadable(fname))
724 for (bitmaps_type::iterator it = bitmaps.begin();
725 it != bitmaps.end(); ++it) {
726 if ((*it)->wid == wid && (*it)->hgh == hgh &&
727 (*it)->flags == flags && (*it)->fname == fname &&
728 (*it)->angle == angle) {
733 figdata * p = new figdata;
736 p->raw_wid = raw_wid;
737 p->raw_hgh = raw_hgh;
741 bitmaps.push_back(p);
742 XWindowAttributes wa;
743 XGetWindowAttributes(fl_get_display(), fl_get_canvas_id(
744 figinset_canvas), &wa);
746 if (lyxerr.debugging()) {
747 lyxerr << "Create pixmap disp:" << fl_get_display()
748 << " scr:" << DefaultScreen(fl_get_display())
751 << " depth:" << wa.depth << endl;
759 p->bitmap = XCreatePixmap(fl_get_display(), fl_get_canvas_id(
760 figinset_canvas), wid, hgh, wa.depth);
762 // initialize reading of .eps file with correct sizes and stuff
763 addwait(psx, psy, pswid, pshgh, p);
774 void getbitmap(figdata * p)
780 void makeupdatelist(figdata * p)
782 for (figures_type::iterator it = figures.begin();
783 it != figures.end(); ++it)
784 if ((*it)->data == p) {
785 if (lyxerr.debugging()) {
786 lyxerr << "Updating inset "
790 // add inset figures[i]->inset into to_update list
791 current_view->pushIntoUpdateList((*it)->inset);
798 // this func is only "called" in spellchecker.C
799 void sigchldchecker(pid_t pid, int * status)
801 lyxerr[Debug::INFO] << "Got pid = " << pid << endl;
802 bool pid_handled = false;
803 for (bitmaps_type::iterator it = bitmaps.begin();
804 it != bitmaps.end(); ++it) {
805 if ((*it)->reading && pid == (*it)->gspid) {
806 lyxerr[Debug::INFO] << "Found pid in bitmaps" << endl;
807 // now read the file and remove it from disk
810 if ((*it)->gsdone) *status = 0;
812 lyxerr[Debug::INFO] << "GS [" << pid
813 << "] exit OK." << endl;
815 lyxerr << "GS [" << pid << "] error "
817 << WIFEXITED(*status)
818 << " " << WEXITSTATUS(*status)
819 << " S:" << WIFSIGNALED(*status)
820 << " " << WTERMSIG(*status) << endl;
823 bitmap_waiting = true;
826 // remove temporary files
827 lyx::unlink(make_tmp(p->gspid));
831 makeupdatelist((*it));
838 lyxerr[Debug::INFO] << "Checking pid in pidwait" << endl;
839 list<int>::iterator it = find(pidwaitlist.begin(),
840 pidwaitlist.end(), pid);
841 if (it != pidwaitlist.end()) {
842 lyxerr[Debug::INFO] << "Found pid in pidwait\n"
843 << "Caught child pid of recompute "
844 "routine" << pid << endl;
845 pidwaitlist.erase(it);
849 lyxerr[Debug::INFO] << "waitpid error" << endl;
852 lyxerr << "The process or process group specified by "
853 "pid does not exist or is not a child of "
854 "the calling process or can never be in the "
855 "states specified by options." << endl;
858 lyxerr << "waitpid() was interrupted due to the "
859 "receipt of a signal sent by the calling "
863 lyxerr << "An invalid value was specified for "
867 lyxerr << "Unknown error from waitpid" << endl;
870 } else if (pid == 0) {
871 lyxerr << "waitpid nohang" << endl;;
873 lyxerr[Debug::INFO] << "normal exit from childhandler" << endl;
882 bitmap_waiting = false;
883 for (bitmaps_type::iterator it = bitmaps.begin();
884 it != bitmaps.end(); ++it)
885 if ((*it)->gspid > 0 && !(*it)->reading)
890 void RegisterFigure(InsetFig * fi)
892 if (figures.empty()) InitFigures();
894 Figref * tmpfig = new Figref;
897 figures.push_back(tmpfig);
900 if (lyxerr.debugging()) {
901 lyxerr << "Register Figure: buffer:["
902 << current_view->buffer() << "]" << endl;
907 void UnregisterFigure(InsetFig * fi)
912 Figref * tmpfig = fi->figure;
914 if (tmpfig->data) freefigdata(tmpfig->data);
915 if (tmpfig->inset->form) {
916 if (tmpfig->inset->form->Figure->visible) {
917 fl_set_focus_object(tmpfig->inset->form->Figure,
918 tmpfig->inset->form->OkBtn);
919 fl_hide_form(tmpfig->inset->form->Figure);
921 #if FL_REVISION == 89
922 // CHECK Reactivate this free_form calls
924 fl_free_form(tmpfig->inset->form->Figure);
925 free(tmpfig->inset->form); // Why free?
926 tmpfig->inset->form = 0;
929 figures.erase(find(figures.begin(), figures.end(), tmpfig));
932 if (figures.empty()) DoneFigures();
938 InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
948 psubfigure = subfigure = false;
949 xwid = xhgh = angle = 0;
951 raw_wid = raw_hgh = 0;
952 changedfname = false;
953 RegisterFigure(this);
954 r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &InsetFig::redraw));
958 InsetFig::~InsetFig()
960 if (lyxerr.debugging()) {
961 lyxerr << "Figure destructor called" << endl;
963 UnregisterFigure(this);
968 void InsetFig::redraw()
970 if (form && form->Figure->visible)
971 fl_redraw_form(form->Figure);
975 int InsetFig::ascent(BufferView *, LyXFont const &) const
981 int InsetFig::descent(BufferView *, LyXFont const &) const
987 int InsetFig::width(BufferView *, LyXFont const &) const
993 void InsetFig::draw(BufferView * bv, LyXFont const & f,
994 int baseline, float & x, bool) const
997 Painter & pain = bv->painter();
999 if (bitmap_waiting) getbitmaps();
1001 // I wish that I didn't have to use this
1002 // but the figinset code is so complicated so
1003 // I don't want to fiddle with it now.
1005 if (figure && figure->data && figure->data->bitmap &&
1006 !figure->data->reading && !figure->data->broken) {
1008 pain.pixmap(int(x + 1), baseline - hgh,
1009 wid, hgh, figure->data->bitmap);
1012 pain.rectangle(int(x), baseline - hgh - 1,
1016 //char const * msg = 0;
1018 string lfname = fname;
1019 if (!fname.empty() && GetExtension(fname).empty())
1022 pain.rectangle(int(x), baseline - hgh - 1, wid + 1, hgh + 1);
1024 if (figure && figure->data) {
1025 if (figure->data->broken) msg = _("[render error]");
1026 else if (figure->data->reading) msg = _("[rendering ... ]");
1028 else if (fname.empty())
1029 msg = _("[no file]");
1030 else if (!IsFileReadable(lfname))
1031 msg = _("[bad file name]");
1032 else if ((flags & 3) == 0)
1033 msg = _("[not displayed]");
1034 else if (lyxrc.ps_command.empty())
1035 msg = _("[no ghostscript]");
1037 if (msg.empty()) msg = _("[unknown error]");
1039 font.setFamily(LyXFont::SANS_FAMILY);
1040 font.setSize(LyXFont::SIZE_FOOTNOTE);
1041 string const justname = OnlyFilename (fname);
1042 pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4,
1045 font.setSize(LyXFont::SIZE_TINY);
1046 pain.text(int(x + 8), baseline - 4, msg, font);
1048 x += width(bv, font); // ?
1052 void InsetFig::write(Buffer const *, ostream & os) const
1055 os << "Figure size " << wid << " " << hgh << "\n";
1056 if (!fname.empty()) {
1057 string buf1 = OnlyPath(owner->fileName());
1058 string fname2 = MakeRelPath(fname, buf1);
1059 os << "file " << fname2 << "\n";
1061 if (!subcaption.empty())
1062 os << "subcaption " << subcaption << "\n";
1063 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1064 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1065 if (angle != 0) os << "angle " << angle << "\n";
1066 os << "flags " << flags << "\n";
1067 if (subfigure) os << "subfigure\n";
1071 void InsetFig::read(Buffer const *, LyXLex & lex)
1074 bool finished = false;
1076 while (lex.IsOK() && !finished) {
1079 string const token = lex.GetString();
1080 lyxerr[Debug::INFO] << "Token: " << token << endl;
1084 else if (token == "\\end_inset") {
1086 } else if (token == "file") {
1088 buf = lex.GetString();
1089 string buf1 = OnlyPath(owner->fileName());
1090 fname = MakeAbsPath(buf, buf1);
1091 changedfname = true;
1093 } else if (token == "extra") {
1095 // kept for backwards compability. Delete in 0.13.x
1096 } else if (token == "subcaption") {
1098 subcaption = lex.GetString();
1099 } else if (token == "label") {
1101 // kept for backwards compability. Delete in 0.13.x
1102 } else if (token == "angle") {
1104 angle = lex.GetFloat();
1105 } else if (token == "size") {
1107 wid = lex.GetInteger();
1109 hgh = lex.GetInteger();
1110 } else if (token == "flags") {
1112 flags = pflags = lex.GetInteger();
1113 } else if (token == "subfigure") {
1114 subfigure = psubfigure = true;
1115 } else if (token == "width") {
1118 typ = lex.GetInteger();
1120 xwid = lex.GetFloat();
1122 case DEF: wtype = DEF; break;
1123 case CM: wtype = CM; break;
1124 case IN: wtype = IN; break;
1125 case PER_PAGE: wtype = PER_PAGE; break;
1126 case PER_COL: wtype = PER_COL; break;
1128 lyxerr[Debug::INFO] << "Unknown type!" << endl;
1132 } else if (token == "height") {
1135 typ = lex.GetInteger();
1137 xhgh = lex.GetFloat();
1139 case DEF: htype = DEF; break;
1140 case CM: htype = CM; break;
1141 case IN: htype = IN; break;
1142 case PER_PAGE: htype = PER_PAGE; break;
1144 lyxerr[Debug::INFO] << "Unknown type!" << endl;
1155 int InsetFig::latex(Buffer const *, ostream & os,
1156 bool /* fragile*/, bool /* fs*/) const
1159 if (!cmd.empty()) os << cmd << " ";
1164 int InsetFig::ascii(Buffer const *, ostream &, int) const
1170 int InsetFig::linuxdoc(Buffer const *, ostream &) const
1176 int InsetFig::docBook(Buffer const *, ostream & os) const
1178 string const buf1 = OnlyPath(owner->fileName());
1179 string figurename = MakeRelPath(fname, buf1);
1181 if (suffixIs(figurename, ".eps"))
1182 figurename.erase(figurename.length() - 4);
1184 os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
1189 void InsetFig::validate(LaTeXFeatures & features) const
1191 features.graphics = true;
1192 if (subfigure) features.subfigure = true;
1196 Inset::EDITABLE InsetFig::editable() const
1202 bool InsetFig::deletable() const
1208 string const InsetFig::editMessage() const
1210 return _("Opened figure");
1214 void InsetFig::edit(BufferView * bv, int, int, unsigned int)
1216 lyxerr[Debug::INFO] << "Editing InsetFig." << endl;
1219 // We should have RO-versions of the form instead.
1220 // The actual prevention of altering a readonly doc
1221 // is done in CallbackFig()
1222 if (bv->buffer()->isReadonly())
1223 WarnReadonly(bv->buffer()->fileName());
1226 form = create_form_Figure();
1227 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1228 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1229 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1230 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1233 if (form->Figure->visible) {
1234 fl_raise_form(form->Figure);
1236 fl_show_form(form->Figure,
1237 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
1243 Inset * InsetFig::clone(Buffer const & buffer, bool) const
1245 InsetFig * tmp = new InsetFig(100, 100, buffer);
1247 if (lyxerr.debugging()) {
1248 lyxerr << "Clone Figure: buffer:["
1250 << "], cbuffer:[xx]" << endl;
1255 tmp->raw_wid = raw_wid;
1256 tmp->raw_hgh = raw_hgh;
1261 tmp->pflags = pflags;
1262 tmp->subfigure = subfigure;
1263 tmp->psubfigure = psubfigure;
1271 string lfname = fname;
1272 if (!fname.empty() && GetExtension(fname).empty())
1274 if (!fname.empty() && IsFileReadable(lfname)
1275 && (flags & 3) && !lyxrc.ps_command.empty()
1277 // do not display if there is
1278 // "do not display" chosen (Matthias 260696)
1279 tmp->figure->data = getfigdata(wid, hgh, lfname, psx, psy,
1280 pswid, pshgh, raw_wid, raw_hgh,
1281 angle, flags & (3|8));
1282 } else tmp->figure->data = 0;
1283 tmp->subcaption = subcaption;
1284 tmp->changedfname = false;
1291 Inset::Code InsetFig::lyxCode() const
1293 return Inset::GRAPHICS_CODE;
1299 string const stringify(InsetFig::HWTYPE hw, float f, string suffix)
1305 case InsetFig::CM:// \resizebox*{h-length}{v-length}{text}
1306 res = tostr(f) + "cm";
1309 res = tostr(f) + "in";
1311 case InsetFig::PER_PAGE:
1312 res = tostr(f/100) + "\\text" + suffix;
1314 case InsetFig::PER_COL:
1315 // Doesn't occur for htype...
1316 res = tostr(f/100) + "\\column" + suffix;
1325 void InsetFig::regenerate() const
1333 if (fname.empty()) {
1334 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1335 cmd += _("empty figure path");
1340 string buf1 = OnlyPath(owner->fileName());
1341 string fname2 = MakeRelPath(fname, buf1);
1343 string gcmd = "\\includegraphics{" + fname2 + '}';
1344 resizeW = stringify(wtype, xwid, "width");
1345 resizeH = stringify(htype, xhgh, "height");
1347 if (!resizeW.empty() || !resizeH.empty()) {
1348 recmd = "\\resizebox*{";
1349 if (!resizeW.empty())
1354 if (!resizeH.empty())
1363 // \rotatebox{angle}{text}
1364 rotate = "\\rotatebox{" + tostr(angle) + "}{";
1370 if (!rotate.empty()) cmdbuf += '}';
1371 if (!recmd.empty()) cmdbuf += '}';
1373 if (!subcaption.empty())
1374 cmdbuf = "\\subfigure[" + subcaption +
1375 "]{" + cmdbuf + "}";
1377 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1384 void InsetFig::tempRegenerate()
1392 char const * tfname = fl_get_input(form->EpsFile);
1393 string tsubcap = fl_get_input(form->Subcaption);
1394 float tangle = atof(fl_get_input(form->Angle));
1395 float txwid = atof(fl_get_input(form->Width));
1396 float txhgh = atof(fl_get_input(form->Height));
1398 if (!tfname || !*tfname) {
1399 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1400 cmd += _("empty figure path");
1405 string buf1 = OnlyPath(owner->fileName());
1406 string fname2 = MakeRelPath(tfname, buf1);
1407 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1408 string gcmd = "\\includegraphics{" + fname2 + '}';
1410 resizeW = stringify(twtype, txwid, "width");
1411 resizeH = stringify(thtype, txhgh, "height");
1413 // \resizebox*{h-length}{v-length}{text}
1414 if (!resizeW.empty() || !resizeH.empty()) {
1415 recmd = "\\resizebox*{";
1416 if (!resizeW.empty())
1421 if (!resizeH.empty())
1429 // \rotatebox{angle}{text}
1430 rotate = "\\rotatebox{" + tostr(tangle) + "}{";
1433 cmdbuf = recmd + rotate + gcmd;
1434 if (!rotate.empty()) cmdbuf += '}';
1435 if (!recmd.empty()) cmdbuf += '}';
1436 if (psubfigure && !tsubcap.empty()) {
1437 cmdbuf = string("\\subfigure{") + tsubcap
1438 + string("}{") + cmdbuf + "}";
1443 void InsetFig::recompute()
1448 bool changed = changedfname;
1449 int newx, newy, nraw_x, nraw_y;
1451 if (changed) getPSSizes();
1453 float sin_a = sin(angle / DEG2PI); /* rotation; H. Zeller 021296 */
1454 float cos_a = cos(angle / DEG2PI);
1455 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1456 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1458 string lfname = fname;
1459 if (GetExtension(fname).empty())
1462 /* now recompute wid and hgh, and if that is changed, set changed */
1463 /* this depends on chosen size of the picture and its bbox */
1464 // This will be redone in 0.13 ... (hen)
1465 if (!lfname.empty() && IsFileReadable(lfname)) {
1466 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1474 newx = int(28.346 * xwid);
1477 newx = int(72 * xwid);
1479 case PER_PAGE: /* % of page */
1480 newx = int(5.95 * xwid);
1482 case PER_COL: /* % of col */
1483 newx = int(2.975 * xwid);
1487 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1491 //lyxerr << "This should not happen!" << endl;
1494 newy = int(28.346 * xhgh);
1497 newy = int(72 * xhgh);
1499 case PER_PAGE: /* % of page */
1500 newy = int(8.42 * xhgh);
1503 // Doesn't occur; case exists to suppress
1504 // compiler warnings.
1507 if (htype && !wtype && frame_hgh)
1508 newx = newy*frame_wid/frame_hgh;
1517 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1522 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1524 // cannot be zero, actually, set it to some minimum, so its clickable
1525 if (newx < 5) newx = 5;
1526 if (newy < 5) newy = 5;
1528 if (newx != wid || newy != hgh ||
1529 nraw_x != raw_wid || nraw_y != raw_hgh ||
1530 flags != pflags || subfigure != psubfigure)
1538 subfigure = psubfigure;
1541 figdata * pf = figure->data;
1544 if (!lfname.empty() && IsFileReadable(lfname) && (flags & 3)
1545 && !lyxrc.ps_command.empty()) {
1546 // do not display if there is "do not display"
1547 // chosen (Matthias 260696)
1548 figure->data = getfigdata(wid, hgh, lfname,
1549 psx, psy, pswid, pshgh,
1551 angle, flags & (3|8));
1552 } else figure->data = 0;
1554 // free the old data
1555 if (pf) freefigdata(pf);
1558 changedfname = false;
1562 void InsetFig::getPSSizes()
1564 /* get %%BoundingBox: from postscript file */
1566 /* defaults to associated size
1567 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1574 if (fname.empty()) return;
1576 string lfname = fname;
1577 if (GetExtension(fname).empty())
1579 ifstream ifs(lfname.c_str());
1581 if (!ifs) return; // file not found !!!!
1583 /* defaults to A4 page */
1589 char lastchar = 0; ifs.get(lastchar);
1591 char c = 0; ifs.get(c);
1593 lyxerr[Debug::INFO] << "End of (E)PS file reached and"
1594 " no BoundingBox!" << endl;
1597 if (c == '%' && lastchar == '%') {
1599 if (p.empty()) break;
1600 lyxerr[Debug::INFO] << "Token: `" << p << "'" << endl;
1601 if (p == "BoundingBox:") {
1602 float fpsx, fpsy, fpswid, fpshgh;
1603 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1606 pswid = int(fpswid);
1607 pshgh = int(fpshgh);
1609 if (lyxerr.debugging()) {
1610 lyxerr << "%%%%BoundingBox:"
1628 void InsetFig::callbackFig(long arg)
1633 if (lyxerr.debugging()) {
1634 lyxerr << "Figure callback, arg " << arg << endl;
1640 case 12: /* width type */
1647 fl_deactivate_object(form->Width);
1652 fl_activate_object(form->Width);
1657 fl_activate_object(form->Width);
1662 fl_activate_object(form->Width);
1667 fl_activate_object(form->Width);
1670 lyxerr[Debug::INFO] << "Unknown type!" << endl;
1677 case 22: /* height type */
1683 fl_deactivate_object(form->Height);
1688 fl_activate_object(form->Height);
1693 fl_activate_object(form->Height);
1698 fl_activate_object(form->Height);
1701 lyxerr[Debug::INFO] << "Unknown type!" << endl;
1707 pflags = pflags & ~3; /* wysiwyg0 */
1710 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1713 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1716 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1719 pflags ^= 4; /* frame */
1722 pflags ^= 8; /* do translations */
1725 psubfigure = !psubfigure; /* This is a subfigure */
1728 regen = true; /* regenerate command */
1730 case 0: /* browse file */
1734 case 1: /* preview */
1735 p = fl_get_input(form->EpsFile);
1739 case 8: /* ok (apply and close) */
1740 if (!current_view->buffer()->isReadonly()) {
1743 xwid = atof(fl_get_input(form->Width));
1744 xhgh = atof(fl_get_input(form->Height));
1745 angle = atof(fl_get_input(form->Angle));
1746 p = fl_get_input(form->EpsFile);
1748 string buf1 = OnlyPath(owner->fileName());
1749 fname = MakeAbsPath(p, buf1);
1750 changedfname = true;
1752 if (!fname.empty()) {
1753 changedfname = true;
1757 subcaption = fl_get_input(form->Subcaption);
1761 /* now update inset */
1762 if (lyxerr.debugging()) {
1763 lyxerr << "Update: ["
1764 << wid << 'x' << hgh << ']' << endl;
1766 current_view->updateInset(this, true);
1768 fl_set_focus_object(form->Figure, form->OkBtn);
1769 fl_hide_form(form->Figure);
1770 #if FL_REVISION == 89
1771 // CHECK Reactivate this free_form calls
1773 fl_free_form(form->Figure);
1774 free(form); // Why free?
1780 // The user has already been informed about RO in ::Edit
1781 if (arg == 7) // if 'Apply'
1784 case 9: /* cancel = restore and close */
1785 fl_set_focus_object(form->Figure, form->OkBtn);
1786 fl_hide_form(form->Figure);
1787 #if FL_REVISION == 89
1788 // CHECK Reactivate this free_form calls
1789 // Jug, is this still a problem?
1791 fl_free_form(form->Figure);
1792 free(form); // Why free?
1798 if (regen) tempRegenerate();
1803 void DisableFigurePanel(FD_Figure * const form)
1805 fl_deactivate_object(form->EpsFile);
1806 fl_deactivate_object(form->Browse);
1807 fl_deactivate_object(form->Width);
1808 fl_deactivate_object(form->Height);
1809 fl_deactivate_object(form->Frame);
1810 fl_deactivate_object(form->Translations);
1811 fl_deactivate_object(form->Angle);
1812 fl_deactivate_object(form->HeightGrp);
1813 fl_deactivate_object(form->page2);
1814 fl_deactivate_object(form->Default2);
1815 fl_deactivate_object(form->cm2);
1816 fl_deactivate_object(form->in2);
1817 fl_deactivate_object(form->HeightLabel);
1818 fl_deactivate_object(form->WidthLabel);
1819 fl_deactivate_object(form->DisplayGrp);
1820 fl_deactivate_object(form->Wysiwyg3);
1821 fl_deactivate_object(form->Wysiwyg0);
1822 fl_deactivate_object(form->Wysiwyg2);
1823 fl_deactivate_object(form->Wysiwyg1);
1824 fl_deactivate_object(form->WidthGrp);
1825 fl_deactivate_object(form->Default1);
1826 fl_deactivate_object(form->cm1);
1827 fl_deactivate_object(form->in1);
1828 fl_deactivate_object(form->page1);
1829 fl_deactivate_object(form->column1);
1830 fl_deactivate_object(form->Subcaption);
1831 fl_deactivate_object(form->Subfigure);
1832 fl_deactivate_object (form->OkBtn);
1833 fl_deactivate_object (form->ApplyBtn);
1834 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1835 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1840 void EnableFigurePanel(FD_Figure * const form)
1842 fl_activate_object(form->EpsFile);
1843 fl_activate_object(form->Browse);
1844 fl_activate_object(form->Width);
1845 fl_activate_object(form->Height);
1846 fl_activate_object(form->Frame);
1847 fl_activate_object(form->Translations);
1848 fl_activate_object(form->Angle);
1849 fl_activate_object(form->HeightGrp);
1850 fl_activate_object(form->page2);
1851 fl_activate_object(form->Default2);
1852 fl_activate_object(form->cm2);
1853 fl_activate_object(form->in2);
1854 fl_activate_object(form->HeightLabel);
1855 fl_activate_object(form->WidthLabel);
1856 fl_activate_object(form->DisplayGrp);
1857 fl_activate_object(form->Wysiwyg3);
1858 fl_activate_object(form->Wysiwyg0);
1859 fl_activate_object(form->Wysiwyg2);
1860 fl_activate_object(form->Wysiwyg1);
1861 fl_activate_object(form->WidthGrp);
1862 fl_activate_object(form->Default1);
1863 fl_activate_object(form->cm1);
1864 fl_activate_object(form->in1);
1865 fl_activate_object(form->page1);
1866 fl_activate_object(form->column1);
1867 fl_activate_object(form->Subcaption);
1868 fl_activate_object(form->Subfigure);
1869 fl_activate_object (form->OkBtn);
1870 fl_activate_object (form->ApplyBtn);
1871 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1872 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1876 void InsetFig::restoreForm()
1878 EnableFigurePanel(form);
1881 fl_set_button(form->Default1, (wtype == 0));
1882 fl_set_button(form->cm1, (wtype == 1));
1883 fl_set_button(form->in1, (wtype == 2));
1884 fl_set_button(form->page1, (wtype == 3));
1885 fl_set_button(form->column1, (wtype == 4));
1887 fl_deactivate_object(form->Width);
1889 fl_activate_object(form->Width);
1892 // enable and disable should be put here.
1894 fl_set_button(form->Default2, (htype == 0));
1895 fl_set_button(form->cm2, (htype == 1));
1896 fl_set_button(form->in2, (htype == 2));
1897 fl_set_button(form->page2, (htype == 3));
1898 // enable and disable should be put here.
1900 fl_deactivate_object(form->Height);
1902 fl_activate_object(form->Height);
1905 int piflags = flags & 3;
1906 fl_set_button(form->Wysiwyg0, (piflags == 0));
1907 fl_set_button(form->Wysiwyg1, (piflags == 1));
1908 fl_set_button(form->Wysiwyg2, (piflags == 2));
1909 fl_set_button(form->Wysiwyg3, (piflags == 3));
1910 fl_set_button(form->Frame, ((flags & 4) != 0));
1911 fl_set_button(form->Translations, ((flags & 8) != 0));
1912 fl_set_button(form->Subfigure, (subfigure != 0));
1914 psubfigure = subfigure;
1915 fl_set_input(form->Width, tostr(xwid).c_str());
1916 fl_set_input(form->Height, tostr(xhgh).c_str());
1917 fl_set_input(form->Angle, tostr(angle).c_str());
1918 if (!fname.empty()){
1919 string buf1 = OnlyPath(owner->fileName());
1920 string fname2 = MakeRelPath(fname, buf1);
1921 fl_set_input(form->EpsFile, fname2.c_str());
1923 else fl_set_input(form->EpsFile, "");
1924 fl_set_input(form->Subcaption, subcaption.c_str());
1925 if (current_view->buffer()->isReadonly())
1926 DisableFigurePanel(form);
1932 void InsetFig::preview(string const & p)
1935 if (GetExtension(tfname).empty())
1937 string buf1 = OnlyPath(owner->fileName());
1938 string buf2 = os::external_path(MakeAbsPath(tfname, buf1));
1939 if (!formats.View(owner, buf2, "eps"))
1940 lyxerr << "Can't view " << buf2 << endl;
1944 void InsetFig::browseFile()
1946 static string current_figure_path;
1949 if (lyxerr.debugging()) {
1950 lyxerr << "Filename: "
1951 << owner->fileName() << endl;
1953 string p = fl_get_input(form->EpsFile);
1955 string buf = MakeAbsPath(owner->fileName());
1956 string buf2 = OnlyPath(buf);
1958 buf = MakeAbsPath(p, buf2);
1959 buf = OnlyPath(buf);
1961 buf = OnlyPath(owner->fileName());
1964 // Does user clipart directory exist?
1965 string bufclip = AddName (user_lyxdir, "clipart");
1966 FileInfo fileInfo(bufclip);
1967 if (!(fileInfo.isOK() && fileInfo.isDir()))
1968 // No - bail out to system clipart directory
1969 bufclip = AddName (system_lyxdir, "clipart");
1972 FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"),
1973 LFUN_SELECT_FILE_SYNC,
1974 make_pair(string(_("Clip art")), string(bufclip)),
1975 make_pair(string(_("Documents")), string(buf)));
1979 string const path = (once) ? current_figure_path : buf;
1981 FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
1983 string const p = result.second;
1988 buf = MakeRelPath(p, buf2);
1989 current_figure_path = OnlyPath(p);
1992 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
1993 || contains(p, "%") || contains(p, " ")) {
1994 WriteAlert(_("Filename can't contain any "
1995 "of these characters:"),
1996 // xgettext:no-c-format
1997 _("space, '#', '~', '$' or '%'."));
2002 if (form) fl_set_input(form->EpsFile, buf.c_str());
2006 void GraphicsCB(FL_OBJECT * obj, long arg)
2008 /* obj->form contains the form */
2010 if (lyxerr.debugging()) {
2011 lyxerr << "GraphicsCB callback: " << arg << endl;
2014 /* find inset we were reacting to */
2015 for (figures_type::iterator it = figures.begin();
2016 it != figures.end(); ++it)
2017 if ((*it)->inset->form && (*it)->inset->form->Figure
2019 if (lyxerr.debugging()) {
2020 lyxerr << "Calling back figure "
2023 (*it)->inset->callbackFig(arg);
2029 void HideFiguresPopups()
2031 for (figures_type::iterator it = figures.begin();
2032 it != figures.end(); ++it)
2033 if ((*it)->inset->form
2034 && (*it)->inset->form->Figure->visible) {
2035 if (lyxerr.debugging()) {
2036 lyxerr << "Hiding figure " << (*it) << endl;
2038 // hide and free the form
2039 (*it)->inset->callbackFig(9);