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
51 #include "frontends/FileDialog.h"
52 #include "support/filetools.h"
53 #include "LyXView.h" // just because of form_main
55 #include "LaTeXFeatures.h"
58 #include "lyx_gui_misc.h" // CancelCloseBoxCB
59 #include "support/FileInfo.h"
60 #include "support/lyxlib.h"
61 #include "support/os.h"
64 #include "bufferview_funcs.h"
65 #include "ColorHandler.h"
66 #include "converter.h"
67 #include "frontends/Dialogs.h" // redrawGUI
68 #include "BufferView.h"
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::INFO] << "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::INFO] << "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::INFO] << "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::INFO] << "Found pid in bitmaps" << endl;
808 // now read the file and remove it from disk
811 if ((*it)->gsdone) *status = 0;
813 lyxerr[Debug::INFO] << "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::INFO] << "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::INFO] << "Found pid in pidwait\n"
844 << "Caught child pid of recompute "
845 "routine" << pid << endl;
846 pidwaitlist.erase(it);
850 lyxerr[Debug::INFO] << "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::INFO] << "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() && current_view) {
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::INFO] << "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::INFO] << "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::INFO] << "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 const 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::INFO] << "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 void InsetFig::edit(BufferView * bv, bool)
1250 Inset * InsetFig::clone(Buffer const & buffer, bool) const
1252 InsetFig * tmp = new InsetFig(100, 100, buffer);
1254 if (lyxerr.debugging()) {
1255 lyxerr << "Clone Figure: buffer:["
1257 << "], cbuffer:[xx]" << endl;
1262 tmp->raw_wid = raw_wid;
1263 tmp->raw_hgh = raw_hgh;
1268 tmp->pflags = pflags;
1269 tmp->subfigure = subfigure;
1270 tmp->psubfigure = psubfigure;
1278 string lfname = fname;
1279 if (!fname.empty() && GetExtension(fname).empty())
1281 if (!fname.empty() && IsFileReadable(lfname)
1282 && (flags & 3) && !lyxrc.ps_command.empty()
1284 // do not display if there is
1285 // "do not display" chosen (Matthias 260696)
1286 tmp->figure->data = getfigdata(wid, hgh, lfname, psx, psy,
1287 pswid, pshgh, raw_wid, raw_hgh,
1288 angle, flags & (3|8));
1289 } else tmp->figure->data = 0;
1290 tmp->subcaption = subcaption;
1291 tmp->changedfname = false;
1298 Inset::Code InsetFig::lyxCode() const
1300 return Inset::GRAPHICS_CODE;
1306 string const stringify(InsetFig::HWTYPE hw, float f, string suffix)
1312 case InsetFig::CM:// \resizebox*{h-length}{v-length}{text}
1313 res = tostr(f) + "cm";
1316 res = tostr(f) + "in";
1318 case InsetFig::PER_PAGE:
1319 res = tostr(f/100) + "\\text" + suffix;
1321 case InsetFig::PER_COL:
1322 // Doesn't occur for htype...
1323 res = tostr(f/100) + "\\column" + suffix;
1332 void InsetFig::regenerate() const
1340 if (fname.empty()) {
1341 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1342 cmd += _("empty figure path");
1347 string buf1 = OnlyPath(owner->fileName());
1348 string fname2 = MakeRelPath(fname, buf1);
1350 string gcmd = "\\includegraphics{" + fname2 + '}';
1351 resizeW = stringify(wtype, xwid, "width");
1352 resizeH = stringify(htype, xhgh, "height");
1354 if (!resizeW.empty() || !resizeH.empty()) {
1355 recmd = "\\resizebox*{";
1356 if (!resizeW.empty())
1361 if (!resizeH.empty())
1370 // \rotatebox{angle}{text}
1371 rotate = "\\rotatebox{" + tostr(angle) + "}{";
1377 if (!rotate.empty()) cmdbuf += '}';
1378 if (!recmd.empty()) cmdbuf += '}';
1380 if (!subcaption.empty())
1381 cmdbuf = "\\subfigure[" + subcaption +
1382 "]{" + cmdbuf + "}";
1384 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1391 void InsetFig::tempRegenerate()
1399 char const * tfname = fl_get_input(form->EpsFile);
1400 string tsubcap = fl_get_input(form->Subcaption);
1401 float tangle = atof(fl_get_input(form->Angle));
1402 float txwid = atof(fl_get_input(form->Width));
1403 float txhgh = atof(fl_get_input(form->Height));
1405 if (!tfname || !*tfname) {
1406 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1407 cmd += _("empty figure path");
1412 string buf1 = OnlyPath(owner->fileName());
1413 string fname2 = MakeRelPath(tfname, buf1);
1414 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1415 string gcmd = "\\includegraphics{" + fname2 + '}';
1417 resizeW = stringify(twtype, txwid, "width");
1418 resizeH = stringify(thtype, txhgh, "height");
1420 // \resizebox*{h-length}{v-length}{text}
1421 if (!resizeW.empty() || !resizeH.empty()) {
1422 recmd = "\\resizebox*{";
1423 if (!resizeW.empty())
1428 if (!resizeH.empty())
1436 // \rotatebox{angle}{text}
1437 rotate = "\\rotatebox{" + tostr(tangle) + "}{";
1440 cmdbuf = recmd + rotate + gcmd;
1441 if (!rotate.empty()) cmdbuf += '}';
1442 if (!recmd.empty()) cmdbuf += '}';
1443 if (psubfigure && !tsubcap.empty()) {
1444 cmdbuf = string("\\subfigure{") + tsubcap
1445 + string("}{") + cmdbuf + "}";
1450 void InsetFig::recompute()
1455 bool changed = changedfname;
1456 int newx, newy, nraw_x, nraw_y;
1458 if (changed) getPSSizes();
1460 float sin_a = sin(angle / DEG2PI); /* rotation; H. Zeller 021296 */
1461 float cos_a = cos(angle / DEG2PI);
1462 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1463 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1465 string lfname = fname;
1466 if (GetExtension(fname).empty())
1469 /* now recompute wid and hgh, and if that is changed, set changed */
1470 /* this depends on chosen size of the picture and its bbox */
1471 // This will be redone in 0.13 ... (hen)
1472 if (!lfname.empty() && IsFileReadable(lfname)) {
1473 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1481 newx = int(28.346 * xwid);
1484 newx = int(72 * xwid);
1486 case PER_PAGE: /* % of page */
1487 newx = int(5.95 * xwid);
1489 case PER_COL: /* % of col */
1490 newx = int(2.975 * xwid);
1494 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1498 //lyxerr << "This should not happen!" << endl;
1501 newy = int(28.346 * xhgh);
1504 newy = int(72 * xhgh);
1506 case PER_PAGE: /* % of page */
1507 newy = int(8.42 * xhgh);
1510 // Doesn't occur; case exists to suppress
1511 // compiler warnings.
1514 if (htype && !wtype && frame_hgh)
1515 newx = newy*frame_wid/frame_hgh;
1524 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1529 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1531 // cannot be zero, actually, set it to some minimum, so its clickable
1532 if (newx < 5) newx = 5;
1533 if (newy < 5) newy = 5;
1535 if (newx != wid || newy != hgh ||
1536 nraw_x != raw_wid || nraw_y != raw_hgh ||
1537 flags != pflags || subfigure != psubfigure)
1545 subfigure = psubfigure;
1548 figdata * pf = figure->data;
1551 if (!lfname.empty() && IsFileReadable(lfname) && (flags & 3)
1552 && !lyxrc.ps_command.empty()) {
1553 // do not display if there is "do not display"
1554 // chosen (Matthias 260696)
1555 figure->data = getfigdata(wid, hgh, lfname,
1556 psx, psy, pswid, pshgh,
1558 angle, flags & (3|8));
1559 } else figure->data = 0;
1561 // free the old data
1562 if (pf) freefigdata(pf);
1565 changedfname = false;
1569 void InsetFig::getPSSizes()
1571 /* get %%BoundingBox: from postscript file */
1573 /* defaults to associated size
1574 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1581 if (fname.empty()) return;
1583 string lfname = fname;
1584 if (GetExtension(fname).empty())
1586 ifstream ifs(lfname.c_str());
1588 if (!ifs) return; // file not found !!!!
1590 /* defaults to A4 page */
1596 char lastchar = 0; ifs.get(lastchar);
1598 char c = 0; ifs.get(c);
1600 lyxerr[Debug::INFO] << "End of (E)PS file reached and"
1601 " no BoundingBox!" << endl;
1604 if (c == '%' && lastchar == '%') {
1606 if (p.empty()) break;
1607 lyxerr[Debug::INFO] << "Token: `" << p << "'" << endl;
1608 if (p == "BoundingBox:") {
1609 float fpsx, fpsy, fpswid, fpshgh;
1610 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1613 pswid = int(fpswid);
1614 pshgh = int(fpshgh);
1616 if (lyxerr.debugging()) {
1617 lyxerr << "%%%%BoundingBox:"
1635 void InsetFig::callbackFig(long arg)
1640 if (lyxerr.debugging()) {
1641 lyxerr << "Figure callback, arg " << arg << endl;
1647 case 12: /* width type */
1654 fl_deactivate_object(form->Width);
1659 fl_activate_object(form->Width);
1664 fl_activate_object(form->Width);
1669 fl_activate_object(form->Width);
1674 fl_activate_object(form->Width);
1677 lyxerr[Debug::INFO] << "Unknown type!" << endl;
1684 case 22: /* height type */
1690 fl_deactivate_object(form->Height);
1695 fl_activate_object(form->Height);
1700 fl_activate_object(form->Height);
1705 fl_activate_object(form->Height);
1708 lyxerr[Debug::INFO] << "Unknown type!" << endl;
1714 pflags = pflags & ~3; /* wysiwyg0 */
1717 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1720 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1723 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1726 pflags ^= 4; /* frame */
1729 pflags ^= 8; /* do translations */
1732 psubfigure = !psubfigure; /* This is a subfigure */
1735 regen = true; /* regenerate command */
1737 case 0: /* browse file */
1741 case 1: /* preview */
1742 p = fl_get_input(form->EpsFile);
1746 case 8: /* ok (apply and close) */
1747 if (!current_view->buffer()->isReadonly()) {
1750 xwid = atof(fl_get_input(form->Width));
1751 xhgh = atof(fl_get_input(form->Height));
1752 angle = atof(fl_get_input(form->Angle));
1753 p = fl_get_input(form->EpsFile);
1755 string buf1 = OnlyPath(owner->fileName());
1756 fname = MakeAbsPath(p, buf1);
1757 changedfname = true;
1759 if (!fname.empty()) {
1760 changedfname = true;
1764 subcaption = fl_get_input(form->Subcaption);
1768 /* now update inset */
1769 if (lyxerr.debugging()) {
1770 lyxerr << "Update: ["
1771 << wid << 'x' << hgh << ']' << endl;
1773 current_view->updateInset(this, true);
1775 fl_set_focus_object(form->Figure, form->OkBtn);
1776 fl_hide_form(form->Figure);
1777 #if FL_REVISION == 89
1778 // CHECK Reactivate this free_form calls
1780 fl_free_form(form->Figure);
1781 free(form); // Why free?
1787 // The user has already been informed about RO in ::Edit
1788 if (arg == 7) // if 'Apply'
1791 case 9: /* cancel = restore and close */
1792 fl_set_focus_object(form->Figure, form->OkBtn);
1793 fl_hide_form(form->Figure);
1794 #if FL_REVISION == 89
1795 // CHECK Reactivate this free_form calls
1796 // Jug, is this still a problem?
1798 fl_free_form(form->Figure);
1799 free(form); // Why free?
1805 if (regen) tempRegenerate();
1810 void DisableFigurePanel(FD_Figure * const form)
1812 fl_deactivate_object(form->EpsFile);
1813 fl_deactivate_object(form->Browse);
1814 fl_deactivate_object(form->Width);
1815 fl_deactivate_object(form->Height);
1816 fl_deactivate_object(form->Frame);
1817 fl_deactivate_object(form->Translations);
1818 fl_deactivate_object(form->Angle);
1819 fl_deactivate_object(form->HeightGrp);
1820 fl_deactivate_object(form->page2);
1821 fl_deactivate_object(form->Default2);
1822 fl_deactivate_object(form->cm2);
1823 fl_deactivate_object(form->in2);
1824 fl_deactivate_object(form->HeightLabel);
1825 fl_deactivate_object(form->WidthLabel);
1826 fl_deactivate_object(form->DisplayGrp);
1827 fl_deactivate_object(form->Wysiwyg3);
1828 fl_deactivate_object(form->Wysiwyg0);
1829 fl_deactivate_object(form->Wysiwyg2);
1830 fl_deactivate_object(form->Wysiwyg1);
1831 fl_deactivate_object(form->WidthGrp);
1832 fl_deactivate_object(form->Default1);
1833 fl_deactivate_object(form->cm1);
1834 fl_deactivate_object(form->in1);
1835 fl_deactivate_object(form->page1);
1836 fl_deactivate_object(form->column1);
1837 fl_deactivate_object(form->Subcaption);
1838 fl_deactivate_object(form->Subfigure);
1839 fl_deactivate_object (form->OkBtn);
1840 fl_deactivate_object (form->ApplyBtn);
1841 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1842 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1847 void EnableFigurePanel(FD_Figure * const form)
1849 fl_activate_object(form->EpsFile);
1850 fl_activate_object(form->Browse);
1851 fl_activate_object(form->Width);
1852 fl_activate_object(form->Height);
1853 fl_activate_object(form->Frame);
1854 fl_activate_object(form->Translations);
1855 fl_activate_object(form->Angle);
1856 fl_activate_object(form->HeightGrp);
1857 fl_activate_object(form->page2);
1858 fl_activate_object(form->Default2);
1859 fl_activate_object(form->cm2);
1860 fl_activate_object(form->in2);
1861 fl_activate_object(form->HeightLabel);
1862 fl_activate_object(form->WidthLabel);
1863 fl_activate_object(form->DisplayGrp);
1864 fl_activate_object(form->Wysiwyg3);
1865 fl_activate_object(form->Wysiwyg0);
1866 fl_activate_object(form->Wysiwyg2);
1867 fl_activate_object(form->Wysiwyg1);
1868 fl_activate_object(form->WidthGrp);
1869 fl_activate_object(form->Default1);
1870 fl_activate_object(form->cm1);
1871 fl_activate_object(form->in1);
1872 fl_activate_object(form->page1);
1873 fl_activate_object(form->column1);
1874 fl_activate_object(form->Subcaption);
1875 fl_activate_object(form->Subfigure);
1876 fl_activate_object (form->OkBtn);
1877 fl_activate_object (form->ApplyBtn);
1878 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1879 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1883 void InsetFig::restoreForm()
1885 EnableFigurePanel(form);
1888 fl_set_button(form->Default1, (wtype == 0));
1889 fl_set_button(form->cm1, (wtype == 1));
1890 fl_set_button(form->in1, (wtype == 2));
1891 fl_set_button(form->page1, (wtype == 3));
1892 fl_set_button(form->column1, (wtype == 4));
1894 fl_deactivate_object(form->Width);
1896 fl_activate_object(form->Width);
1899 // enable and disable should be put here.
1901 fl_set_button(form->Default2, (htype == 0));
1902 fl_set_button(form->cm2, (htype == 1));
1903 fl_set_button(form->in2, (htype == 2));
1904 fl_set_button(form->page2, (htype == 3));
1905 // enable and disable should be put here.
1907 fl_deactivate_object(form->Height);
1909 fl_activate_object(form->Height);
1912 int piflags = flags & 3;
1913 fl_set_button(form->Wysiwyg0, (piflags == 0));
1914 fl_set_button(form->Wysiwyg1, (piflags == 1));
1915 fl_set_button(form->Wysiwyg2, (piflags == 2));
1916 fl_set_button(form->Wysiwyg3, (piflags == 3));
1917 fl_set_button(form->Frame, ((flags & 4) != 0));
1918 fl_set_button(form->Translations, ((flags & 8) != 0));
1919 fl_set_button(form->Subfigure, (subfigure != 0));
1921 psubfigure = subfigure;
1922 fl_set_input(form->Width, tostr(xwid).c_str());
1923 fl_set_input(form->Height, tostr(xhgh).c_str());
1924 fl_set_input(form->Angle, tostr(angle).c_str());
1925 if (!fname.empty()){
1926 string buf1 = OnlyPath(owner->fileName());
1927 string fname2 = MakeRelPath(fname, buf1);
1928 fl_set_input(form->EpsFile, fname2.c_str());
1930 else fl_set_input(form->EpsFile, "");
1931 fl_set_input(form->Subcaption, subcaption.c_str());
1932 if (current_view->buffer()->isReadonly())
1933 DisableFigurePanel(form);
1939 void InsetFig::preview(string const & p)
1942 if (GetExtension(tfname).empty())
1944 string buf1 = OnlyPath(owner->fileName());
1945 string buf2 = os::external_path(MakeAbsPath(tfname, buf1));
1946 if (!formats.View(owner, buf2, "eps"))
1947 lyxerr << "Can't view " << buf2 << endl;
1951 void InsetFig::browseFile()
1953 static string current_figure_path;
1956 if (lyxerr.debugging()) {
1957 lyxerr << "Filename: "
1958 << owner->fileName() << endl;
1960 string p = fl_get_input(form->EpsFile);
1962 string buf = MakeAbsPath(owner->fileName());
1963 string buf2 = OnlyPath(buf);
1965 buf = MakeAbsPath(p, buf2);
1966 buf = OnlyPath(buf);
1968 buf = OnlyPath(owner->fileName());
1971 // Does user clipart directory exist?
1972 string bufclip = AddName (user_lyxdir, "clipart");
1973 FileInfo fileInfo(bufclip);
1974 if (!(fileInfo.isOK() && fileInfo.isDir()))
1975 // No - bail out to system clipart directory
1976 bufclip = AddName (system_lyxdir, "clipart");
1979 FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"),
1980 LFUN_SELECT_FILE_SYNC,
1981 make_pair(string(_("Clip art")), string(bufclip)),
1982 make_pair(string(_("Documents")), string(buf)));
1986 string const path = (once) ? current_figure_path : buf;
1988 FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
1990 string const p = result.second;
1995 buf = MakeRelPath(p, buf2);
1996 current_figure_path = OnlyPath(p);
1999 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2000 || contains(p, "%") || contains(p, " ")) {
2001 WriteAlert(_("Filename can't contain any "
2002 "of these characters:"),
2003 // xgettext:no-c-format
2004 _("space, '#', '~', '$' or '%'."));
2009 if (form) fl_set_input(form->EpsFile, buf.c_str());
2013 void GraphicsCB(FL_OBJECT * obj, long arg)
2015 /* obj->form contains the form */
2017 if (lyxerr.debugging()) {
2018 lyxerr << "GraphicsCB callback: " << arg << endl;
2021 /* find inset we were reacting to */
2022 for (figures_type::iterator it = figures.begin();
2023 it != figures.end(); ++it)
2024 if ((*it)->inset->form && (*it)->inset->form->Figure
2026 if (lyxerr.debugging()) {
2027 lyxerr << "Calling back figure "
2030 (*it)->inset->callbackFig(arg);
2036 void HideFiguresPopups()
2038 for (figures_type::iterator it = figures.begin();
2039 it != figures.end(); ++it)
2040 if ((*it)->inset->form
2041 && (*it)->inset->form->Figure->visible) {
2042 if (lyxerr.debugging()) {
2043 lyxerr << "Hiding figure " << (*it) << endl;
2045 // hide and free the form
2046 (*it)->inset->callbackFig(9);