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
78 using std::ostringstream;
83 extern BufferView * current_view;
84 extern FL_OBJECT * figinset_canvas;
86 extern char ** environ; // is this only redundtant on linux systems? Lgb.
88 // xforms doesn't define this (but it should be in <forms.h>).
90 FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
94 float const DEG2PI = 57.295779513;
96 struct queue_element {
97 float rx, ry; // resolution x and y
98 int ofsx, ofsy; // x and y translation
99 figdata * data; // we are doing it for this data
102 int const MAXGS = 3; /* maximum 3 gs's at a time */
104 typedef vector<Figref *> figures_type;
105 typedef vector<figdata *> bitmaps_type;
106 figures_type figures; // all figures
107 bitmaps_type bitmaps; // all bitmaps
109 queue<queue_element> gsqueue; // queue for ghostscripting
111 int gsrunning = 0; /* currently so many gs's are running */
112 bool bitmap_waiting = false; /* bitmaps are waiting finished */
114 bool gs_color; // do we allocate colors for gs?
115 bool color_visual; // is the visual color?
116 bool gs_xcolor = false; // allocated extended colors
117 unsigned long gs_pixels[128]; // allocated pixels
118 int gs_spc; // shades per color
119 int gs_allcolors; // number of all colors
121 list<int> pidwaitlist; // pid wait list
126 val.foreground = BlackPixel(fl_get_display(),
127 DefaultScreen(fl_get_display()));
130 val.graphics_exposures = false;
131 val.line_style = LineSolid;
133 return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
134 GCForeground | GCFunction | GCGraphicsExposures
135 | GCLineWidth | GCLineStyle , &val);
141 void addpidwait(int pid)
143 // adds pid to pid wait list
144 pidwaitlist.push_back(pid);
146 if (lyxerr.debugging()) {
147 lyxerr << "Pids to wait for: \n";
148 copy(pidwaitlist.begin(), pidwaitlist.end(),
149 std::ostream_iterator<int>(lyxerr, "\n"));
155 string make_tmp(int pid)
157 return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
161 void kill_gs(int pid, int sig)
163 if (lyxerr.debugging())
164 lyxerr << "Killing gs " << pid << endl;
166 lyx::unlink(make_tmp(pid));
171 int GhostscriptMsg(XEvent * ev, void *)
173 // bin all events not of interest
174 if (ev->type != ClientMessage)
177 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
179 if (lyxerr.debugging()) {
180 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
181 << "] pm:[" << e->data.l[1] << "]" << endl;
184 // just kill gs, that way it will work for sure
185 // This loop looks like S**T so it probably is...
186 for (bitmaps_type::iterator it = bitmaps.begin();
187 it != bitmaps.end(); ++it)
188 if (static_cast<long>((*it)->bitmap) ==
189 static_cast<long>(e->data.l[1])) {
194 // first update p->bitmap, if necessary
195 if (p->bitmap != None
196 && p->flags > (1|8) && gs_color && p->wid) {
197 // query current colormap and re-render
198 // the pixmap with proper colors
199 XWindowAttributes wa;
200 register XImage * im;
203 int spc1 = gs_spc - 1;
204 int spc2 = gs_spc * gs_spc;
208 GC gc = local_gc_copy;
210 XGetWindowAttributes(fl_get_display(),
214 XFlush(fl_get_display());
215 if (lyxerr.debugging()) {
216 lyxerr << "Starting image translation "
219 << p->wid << "x" << p->hgh
221 << " " << XYPixmap << endl;
223 // now fork rendering process
225 if (forkstat == -1) {
227 << "Cannot fork, using slow "
228 "method for pixmap translation." << endl;
229 tmpdisp = fl_get_display();
230 } else if (forkstat > 0) { // parent
232 if (lyxerr.debugging()) {
233 lyxerr << "Spawned child "
236 addpidwait(forkstat);
239 tmpdisp = XOpenDisplay(DisplayString(fl_get_display()));
242 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
243 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
245 if (lyxerr.debugging()) {
246 lyxerr << "Got the image" << endl;
249 if (lyxerr.debugging()) {
250 lyxerr << "Error getting the image" << endl;
255 // query current colormap
256 XColor * cmap = new XColor[gs_allcolors];
257 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
258 XQueryColors(tmpdisp,
259 fl_state[fl_get_vclass()]
263 // now we process all the image
264 for (y = 0; y < p->hgh; ++y) {
265 for (int x = 0; x < wid; ++x) {
270 gs_pixels[((pc->red+6553)*
271 spc1/65535)*spc2+((pc->green+6553)*
272 spc1/65535)*gs_spc+((pc->blue+6553)*
277 // This must be correct.
279 if (lyxerr.debugging()) {
280 lyxerr << "Putting image back"
283 XPutImage(tmpdisp, p->bitmap,
285 0, 0, p->wid, p->hgh);
287 if (lyxerr.debugging()) {
288 lyxerr << "Done translation"
293 kill_gs(p->gspid, SIGHUP);
295 XCloseDisplay(tmpdisp);
299 kill_gs(p->gspid, SIGHUP);
307 void AllocColors(int num)
308 // allocate color cube numxnumxnum, if possible
310 if (lyxerr.debugging()) {
311 lyxerr << "Allocating color cube " << num
312 << 'x' << num << 'x' << num << endl;
316 lyxerr << "Error allocating color colormap." << endl;
320 if (num > 5) num = 5;
322 for (int i = 0; i < num * num * num; ++i) {
323 xcol.red = short(65535 * (i / (num * num)) / (num - 1));
324 xcol.green = short(65535 * ((i / num) % num) / (num - 1));
325 xcol.blue = short(65535 * (i % num) / (num - 1));
326 xcol.flags = DoRed | DoGreen | DoBlue;
327 if (!XAllocColor(fl_get_display(),
328 fl_state[fl_get_vclass()].colormap, &xcol)) {
329 if (i) XFreeColors(fl_get_display(),
330 fl_state[fl_get_vclass()].colormap,
332 if (lyxerr.debugging()) {
333 lyxerr << "Cannot allocate color cube "
336 AllocColors(num - 1);
339 gs_pixels[i] = xcol.pixel;
346 // allocate grayscale ramp
347 void AllocGrays(int num)
349 if (lyxerr.debugging()) {
350 lyxerr << "Allocating grayscale colormap "
355 lyxerr << "Error allocating grayscale colormap." << endl;
359 if (num > 128) num = 128;
361 for (int i = 0; i < num; ++i) {
362 xcol.red = xcol.green = xcol.blue = short(65535 * i / (num - 1));
363 xcol.flags = DoRed | DoGreen | DoBlue;
364 if (!XAllocColor(fl_get_display(),
365 fl_state[fl_get_vclass()].colormap, &xcol)) {
366 if (i) XFreeColors(fl_get_display(),
367 fl_state[fl_get_vclass()].colormap,
369 if (lyxerr.debugging()) {
370 lyxerr << "Cannot allocate grayscale "
376 gs_pixels[i] = xcol.pixel;
383 // if bitmaps and figures are not empty we will leak mem
387 // allocate color cube on pseudo-color display
391 /* we want to capture every event, in order to work around an
394 fl_set_preemptive_callback(fl_get_canvas_id(figinset_canvas), GhostscriptMsg, 0);
396 local_gc_copy = createGC();
398 Visual * vi = DefaultVisual(fl_get_display(),
399 DefaultScreen(fl_get_display()));
400 if (lyxerr.debugging()) {
401 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
402 vi->visualid, vi->c_class,
403 vi->bits_per_rgb, vi->map_entries);
405 color_visual = ( (vi->c_class == StaticColor) ||
406 (vi->c_class == PseudoColor) ||
407 (vi->c_class == TrueColor) ||
408 (vi->c_class == DirectColor) );
409 if ((vi->c_class & 1) == 0) return;
410 // now allocate colors
411 if (vi->c_class == GrayScale) {
412 // allocate grayscale
413 AllocGrays(vi->map_entries/2);
415 // allocate normal color
417 while (i * i * i * 2 > vi->map_entries) --i;
420 gs_allcolors = vi->map_entries;
427 // if bitmaps and figures are not empty we will leak mem
431 lyxerr.debug() << "Unregistering figures..." << endl;
435 void freefigdata(figdata * tmpdata)
438 if (tmpdata->ref) return;
440 if (tmpdata->gspid > 0) {
441 int pid = tmpdata->gspid;
442 // kill ghostscript and unlink it's files
444 kill_gs(pid, SIGKILL);
447 if (tmpdata->bitmap) XFreePixmap(fl_get_display(), tmpdata->bitmap);
448 bitmaps.erase(find(bitmaps.begin(), bitmaps.end(), tmpdata));
455 // This _have_ to be set before the fork!
456 unsigned long background_pixel =
457 lyxColorHandler->colorPixel(LColor::background);
459 // run queued requests for ghostscript, if any
460 if (!gsrunning && gs_color && !gs_xcolor) {
461 // here alloc all colors, so that gs will use only
462 // those we allocated for it
467 while (gsrunning < MAXGS) {
468 //char tbuf[384]; //, tbuf2[80];
472 if (gsqueue.empty()) {
473 if (!gsrunning && gs_xcolor) {
474 // de-allocate rest of colors
480 queue_element * p = &gsqueue.front();
489 if (lyxerr.debugging()) {
490 lyxerr << "GS start error! Cannot fork."
493 p->data->broken = true;
494 p->data->reading = false;
497 if (pid == 0) { // child
500 Display * tempdisp = XOpenDisplay(DisplayString(fl_get_display()));
502 // create translation file
504 ofs.open(make_tmp(getpid()).c_str());
505 ofs << "gsave clippath pathbbox grestore\n"
507 << "/ury exch def /urx exch def /lly exch def "
509 << p->data->wid / 2.0 << " "
510 << p->data->hgh / 2.0 << " translate\n"
511 << p->data->angle << " rotate\n"
512 << -(p->data->raw_wid / 2.0) << " "
513 << -(p->data->raw_hgh / 2.0) << " translate\n"
514 << p->rx / 72.0 << " " << p->ry / 72.0
516 << -p->ofsx << " " << -p->ofsy << " translate\n"
518 ofs.close(); // Don't remove this.
520 // gs process - set ghostview environment first
522 t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
523 << ' ' << p->data->bitmap;
524 // now set up ghostview property on a window
525 // #ifdef WITH_WARNINGS
526 // #warning BUG seems that the only bug here
527 // might be the hardcoded dpi.. Bummer!
530 t1 << "0 0 0 0 " << p->data->wid << ' '
531 << p->data->hgh << " 72 72 0 0 0 0";
533 if (lyxerr.debugging()) {
534 lyxerr << "Will set GHOSTVIEW property to ["
535 << t1.str() << "]" << endl;
537 // wait until property is deleted if executing multiple
539 XGrabServer(tempdisp);
541 // grab server to prevent other child
542 // interfering with setting GHOSTVIEW property
543 // The grabbing goes on for too long, is it
544 // really needed? (Lgb)
545 // I moved most of the grabs... (Lgb)
546 if (lyxerr.debugging()) {
547 lyxerr << "Grabbing the server"
550 prop = XListProperties(tempdisp,
552 figinset_canvas), &nprop);
556 for (i = 0; i < nprop; ++i) {
557 char * p = XGetAtomName(tempdisp,
559 if (compare(p, "GHOSTVIEW") == 0) {
561 // We free it when we leave so we don't leak.
567 XFree(reinterpret_cast<char *>(prop)); // jc:
569 // ok, property found, we must wait until
570 // ghostscript deletes it
571 if (lyxerr.debugging()) {
572 lyxerr << "Releasing the server\n["
574 << "] GHOSTVIEW property"
575 " found. Waiting." << endl;
577 XUngrabServer(tempdisp);
580 XGrabServer(tempdisp);
582 XChangeProperty(tempdisp,
583 fl_get_canvas_id(figinset_canvas),
584 XInternAtom(tempdisp, "GHOSTVIEW", false),
585 XInternAtom(tempdisp, "STRING", false),
587 reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
588 int(t1.str().size()));
589 XUngrabServer(tempdisp);
594 switch (p->data->flags & 3) {
595 case 0: t3 << 'H'; break; // Hidden
596 case 1: t3 << 'M'; break; // Mono
597 case 2: t3 << 'G'; break; // Gray
606 t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
607 << ' ' << background_pixel;
609 XGrabServer(tempdisp);
610 XChangeProperty(tempdisp,
611 fl_get_canvas_id(figinset_canvas),
612 XInternAtom(tempdisp,
613 "GHOSTVIEW_COLORS", false),
614 XInternAtom(tempdisp, "STRING", false),
616 reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str().c_str())),
617 int(t3.str().size()));
618 XUngrabServer(tempdisp);
621 if (lyxerr.debugging()) {
622 lyxerr << "Releasing the server" << endl;
624 XCloseDisplay(tempdisp);
626 // set up environment
629 typedef char * char_p;
630 env = new char_p[ne + 2];
631 string tmp = t2.str().c_str();
632 env[0] = new char[tmp.size() + 1];
633 std::copy(tmp.begin(), tmp.end(), env[0]);
634 env[0][tmp.size()] = '\0';
635 ::memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
638 // now make gs command
640 // close(1); do NOT close. If GS writes out
641 // errors it would hang. (Matthias 290596)
643 string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
644 string gbuf = "-g" + tostr(p->data->wid) + "x" + tostr(p->data->hgh);
646 // now chdir into dir with .eps file, to be on the safe
648 lyx::chdir(OnlyPath(p->data->fname));
649 // make temp file name
650 string tmpf = make_tmp(getpid());
651 if (lyxerr.debugging()) {
652 lyxerr << "starting gs " << tmpf << " "
654 << ", pid: " << getpid() << endl;
657 int err = ::execlp(lyxrc.ps_command.c_str(),
658 lyxrc.ps_command.c_str(),
660 "-dNOPAUSE", "-dQUIET",
662 rbuf.c_str(), gbuf.c_str(), tmpf.c_str(),
663 p->data->fname.c_str(),
664 "showpage.ps", "quit.ps", "-", 0);
665 // if we are still there, an error occurred.
666 lyxerr << "Error executing ghostscript. "
667 << "Code: " << err << endl;
668 lyxerr.debug() << "Cmd: "
672 << p->data->fname << endl;
675 // normal process (parent)
676 if (lyxerr.debugging()) {
677 lyxerr << "GS [" << pid << "] started" << endl;
680 p->data->gspid = pid;
687 void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
689 // recompute the stuff and put in the queue
693 p.rx = (float(data->raw_wid) * 72.0) / pswid;
694 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
700 // if possible, run the queue
705 figdata * getfigdata(int wid, int hgh, string const & fname,
706 int psx, int psy, int pswid, int pshgh,
707 int raw_wid, int raw_hgh, float angle, char flags)
709 /* first search for an exact match with fname and width/height */
711 if (fname.empty() || !IsFileReadable(fname))
714 for (bitmaps_type::iterator it = bitmaps.begin();
715 it != bitmaps.end(); ++it) {
716 if ((*it)->wid == wid && (*it)->hgh == hgh &&
717 (*it)->flags == flags && (*it)->fname == fname &&
718 (*it)->angle == angle) {
723 figdata * p = new figdata;
726 p->raw_wid = raw_wid;
727 p->raw_hgh = raw_hgh;
731 bitmaps.push_back(p);
732 XWindowAttributes wa;
733 XGetWindowAttributes(fl_get_display(), fl_get_canvas_id(
734 figinset_canvas), &wa);
736 if (lyxerr.debugging()) {
737 lyxerr << "Create pixmap disp:" << fl_get_display()
738 << " scr:" << DefaultScreen(fl_get_display())
741 << " depth:" << wa.depth << endl;
749 p->bitmap = XCreatePixmap(fl_get_display(), fl_get_canvas_id(
750 figinset_canvas), wid, hgh, wa.depth);
752 // initialize reading of .eps file with correct sizes and stuff
753 addwait(psx, psy, pswid, pshgh, p);
764 void getbitmap(figdata * p)
770 void makeupdatelist(figdata * p)
772 for (figures_type::iterator it = figures.begin();
773 it != figures.end(); ++it)
774 if ((*it)->data == p) {
775 if (lyxerr.debugging()) {
776 lyxerr << "Updating inset "
780 // add inset figures[i]->inset into to_update list
781 current_view->pushIntoUpdateList((*it)->inset);
788 // this func is only "called" in spellchecker.C
789 void sigchldchecker(pid_t pid, int * status)
791 lyxerr.debug() << "Got pid = " << pid << endl;
792 bool pid_handled = false;
793 for (bitmaps_type::iterator it = bitmaps.begin();
794 it != bitmaps.end(); ++it) {
795 if ((*it)->reading && pid == (*it)->gspid) {
796 lyxerr.debug() << "Found pid in bitmaps" << endl;
797 // now read the file and remove it from disk
800 if ((*it)->gsdone) *status = 0;
802 lyxerr.debug() << "GS [" << pid
803 << "] exit OK." << endl;
805 lyxerr << "GS [" << pid << "] error "
807 << WIFEXITED(*status)
808 << " " << WEXITSTATUS(*status)
809 << " S:" << WIFSIGNALED(*status)
810 << " " << WTERMSIG(*status) << endl;
813 bitmap_waiting = true;
816 // remove temporary files
817 lyx::unlink(make_tmp(p->gspid));
821 makeupdatelist((*it));
828 lyxerr.debug() << "Checking pid in pidwait" << endl;
829 list<int>::iterator it = find(pidwaitlist.begin(),
830 pidwaitlist.end(), pid);
831 if (it != pidwaitlist.end()) {
832 lyxerr.debug() << "Found pid in pidwait\n"
833 << "Caught child pid of recompute "
834 "routine" << pid << endl;
835 pidwaitlist.erase(it);
839 lyxerr.debug() << "waitpid error" << endl;
842 lyxerr << "The process or process group specified by "
843 "pid does not exist or is not a child of "
844 "the calling process or can never be in the "
845 "states specified by options." << endl;
848 lyxerr << "waitpid() was interrupted due to the "
849 "receipt of a signal sent by the calling "
853 lyxerr << "An invalid value was specified for "
857 lyxerr << "Unknown error from waitpid" << endl;
860 } else if (pid == 0) {
861 lyxerr << "waitpid nohang" << endl;;
863 lyxerr.debug() << "normal exit from childhandler" << endl;
872 bitmap_waiting = false;
873 for (bitmaps_type::iterator it = bitmaps.begin();
874 it != bitmaps.end(); ++it)
875 if ((*it)->gspid > 0 && !(*it)->reading)
880 void RegisterFigure(InsetFig * fi)
882 if (figures.empty()) InitFigures();
884 Figref * tmpfig = new Figref;
887 figures.push_back(tmpfig);
890 if (lyxerr.debugging()) {
891 lyxerr << "Register Figure: buffer:["
892 << current_view->buffer() << "]" << endl;
897 void UnregisterFigure(InsetFig * fi)
902 Figref * tmpfig = fi->figure;
904 if (tmpfig->data) freefigdata(tmpfig->data);
905 if (tmpfig->inset->form) {
906 if (tmpfig->inset->form->Figure->visible) {
907 fl_set_focus_object(tmpfig->inset->form->Figure,
908 tmpfig->inset->form->OkBtn);
909 fl_hide_form(tmpfig->inset->form->Figure);
911 #if FL_REVISION == 89
912 // CHECK Reactivate this free_form calls
914 fl_free_form(tmpfig->inset->form->Figure);
915 free(tmpfig->inset->form); // Why free?
916 tmpfig->inset->form = 0;
919 figures.erase(find(figures.begin(), figures.end(), tmpfig));
922 if (figures.empty()) DoneFigures();
928 InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
938 psubfigure = subfigure = false;
939 xwid = xhgh = angle = 0;
941 raw_wid = raw_hgh = 0;
942 changedfname = false;
943 RegisterFigure(this);
944 r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &InsetFig::redraw));
948 InsetFig::~InsetFig()
950 if (lyxerr.debugging()) {
951 lyxerr << "Figure destructor called" << endl;
953 UnregisterFigure(this);
958 void InsetFig::redraw()
960 if (form && form->Figure->visible)
961 fl_redraw_form(form->Figure);
965 int InsetFig::ascent(BufferView *, LyXFont const &) const
971 int InsetFig::descent(BufferView *, LyXFont const &) const
977 int InsetFig::width(BufferView *, LyXFont const &) const
983 void InsetFig::draw(BufferView * bv, LyXFont const & f,
984 int baseline, float & x, bool) const
987 Painter & pain = bv->painter();
989 if (bitmap_waiting) getbitmaps();
991 // I wish that I didn't have to use this
992 // but the figinset code is so complicated so
993 // I don't want to fiddle with it now.
995 if (figure && figure->data && figure->data->bitmap &&
996 !figure->data->reading && !figure->data->broken) {
998 pain.pixmap(int(x + 1), baseline - hgh,
999 wid, hgh, figure->data->bitmap);
1002 pain.rectangle(int(x), baseline - hgh - 1,
1006 char const * msg = 0;
1007 string lfname = fname;
1008 if (!fname.empty() && GetExtension(fname).empty())
1011 pain.rectangle(int(x), baseline - hgh - 1, wid + 1, hgh + 1);
1013 if (figure && figure->data) {
1014 if (figure->data->broken) msg = _("[render error]");
1015 else if (figure->data->reading) msg = _("[rendering ... ]");
1017 else if (fname.empty())
1018 msg = _("[no file]");
1019 else if (!IsFileReadable(lfname))
1020 msg = _("[bad file name]");
1021 else if ((flags & 3) == 0)
1022 msg = _("[not displayed]");
1023 else if (lyxrc.ps_command.empty())
1024 msg = _("[no ghostscript]");
1026 if (!msg) msg = _("[unknown error]");
1028 font.setFamily(LyXFont::SANS_FAMILY);
1029 font.setSize(LyXFont::SIZE_FOOTNOTE);
1030 string justname = OnlyFilename (fname);
1031 pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4,
1034 font.setSize(LyXFont::SIZE_TINY);
1035 pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
1037 x += width(bv, font); // ?
1041 void InsetFig::Write(Buffer const *, ostream & os) const
1044 os << "Figure size " << wid << " " << hgh << "\n";
1045 if (!fname.empty()) {
1046 string buf1 = OnlyPath(owner->fileName());
1047 string fname2 = MakeRelPath(fname, buf1);
1048 os << "file " << fname2 << "\n";
1050 if (!subcaption.empty())
1051 os << "subcaption " << subcaption << "\n";
1052 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1053 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1054 if (angle != 0) os << "angle " << angle << "\n";
1055 os << "flags " << flags << "\n";
1056 if (subfigure) os << "subfigure\n";
1060 void InsetFig::Read(Buffer const *, LyXLex & lex)
1063 bool finished = false;
1065 while (lex.IsOK() && !finished) {
1068 string const token = lex.GetString();
1069 lyxerr.debug() << "Token: " << token << endl;
1073 else if (token == "\\end_inset") {
1075 } else if (token == "file") {
1077 buf = lex.GetString();
1078 string buf1 = OnlyPath(owner->fileName());
1079 fname = MakeAbsPath(buf, buf1);
1080 changedfname = true;
1082 } else if (token == "extra") {
1084 // kept for backwards compability. Delete in 0.13.x
1085 } else if (token == "subcaption") {
1087 subcaption = lex.GetString();
1088 } else if (token == "label") {
1090 // kept for backwards compability. Delete in 0.13.x
1091 } else if (token == "angle") {
1093 angle = lex.GetFloat();
1094 } else if (token == "size") {
1096 wid = lex.GetInteger();
1098 hgh = lex.GetInteger();
1099 } else if (token == "flags") {
1101 flags = pflags = lex.GetInteger();
1102 } else if (token == "subfigure") {
1103 subfigure = psubfigure = true;
1104 } else if (token == "width") {
1107 typ = lex.GetInteger();
1109 xwid = lex.GetFloat();
1111 case DEF: wtype = DEF; break;
1112 case CM: wtype = CM; break;
1113 case IN: wtype = IN; break;
1114 case PER_PAGE: wtype = PER_PAGE; break;
1115 case PER_COL: wtype = PER_COL; break;
1117 lyxerr.debug() << "Unknown type!" << endl;
1121 } else if (token == "height") {
1124 typ = lex.GetInteger();
1126 xhgh = lex.GetFloat();
1128 case DEF: htype = DEF; break;
1129 case CM: htype = CM; break;
1130 case IN: htype = IN; break;
1131 case PER_PAGE: htype = PER_PAGE; break;
1133 lyxerr.debug() << "Unknown type!" << endl;
1144 int InsetFig::Latex(Buffer const *, ostream & os,
1145 bool /* fragile*/, bool /* fs*/) const
1148 if (!cmd.empty()) os << cmd << " ";
1153 int InsetFig::Ascii(Buffer const *, ostream &, int) const
1159 int InsetFig::Linuxdoc(Buffer const *, ostream &) const
1165 int InsetFig::DocBook(Buffer const *, ostream & os) const
1167 string buf1 = OnlyPath(owner->fileName());
1168 string figurename = MakeRelPath(fname, buf1);
1170 if (suffixIs(figurename, ".eps"))
1171 figurename.erase(figurename.length() - 4);
1173 os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
1178 void InsetFig::Validate(LaTeXFeatures & features) const
1180 features.graphics = true;
1181 if (subfigure) features.subfigure = true;
1185 Inset::EDITABLE InsetFig::Editable() const
1191 bool InsetFig::Deletable() const
1197 string const InsetFig::EditMessage() const
1199 return _("Opened figure");
1203 void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
1205 lyxerr.debug() << "Editing InsetFig." << endl;
1208 // We should have RO-versions of the form instead.
1209 // The actual prevention of altering a readonly doc
1210 // is done in CallbackFig()
1211 if (bv->buffer()->isReadonly())
1212 WarnReadonly(bv->buffer()->fileName());
1215 form = create_form_Figure();
1216 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1217 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1218 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1219 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1222 if (form->Figure->visible) {
1223 fl_raise_form(form->Figure);
1225 fl_show_form(form->Figure,
1226 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
1232 Inset * InsetFig::Clone(Buffer const & buffer) const
1234 InsetFig * tmp = new InsetFig(100, 100, buffer);
1236 if (lyxerr.debugging()) {
1237 lyxerr << "Clone Figure: buffer:["
1239 << "], cbuffer:[xx]" << endl;
1244 tmp->raw_wid = raw_wid;
1245 tmp->raw_hgh = raw_hgh;
1250 tmp->pflags = pflags;
1251 tmp->subfigure = subfigure;
1252 tmp->psubfigure = psubfigure;
1260 string lfname = fname;
1261 if (!fname.empty() && GetExtension(fname).empty())
1263 if (!fname.empty() && IsFileReadable(lfname)
1264 && (flags & 3) && !lyxrc.ps_command.empty()
1266 // do not display if there is
1267 // "do not display" chosen (Matthias 260696)
1268 tmp->figure->data = getfigdata(wid, hgh, lfname, psx, psy,
1269 pswid, pshgh, raw_wid, raw_hgh,
1270 angle, flags & (3|8));
1271 } else tmp->figure->data = 0;
1272 tmp->subcaption = subcaption;
1273 tmp->changedfname = false;
1280 Inset::Code InsetFig::LyxCode() const
1282 return Inset::GRAPHICS_CODE;
1288 string const stringify(InsetFig::HWTYPE hw, float f, string suffix)
1294 case InsetFig::CM:// \resizebox*{h-length}{v-length}{text}
1295 res = tostr(f) + "cm";
1298 res = tostr(f) + "in";
1300 case InsetFig::PER_PAGE:
1301 res = tostr(f/100) + "\\text" + suffix;
1303 case InsetFig::PER_COL:
1304 // Doesn't occur for htype...
1305 res = tostr(f/100) + "\\column" + suffix;
1314 void InsetFig::Regenerate() const
1317 string resizeW, resizeH;
1318 string rotate, recmd;
1320 if (fname.empty()) {
1321 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1322 cmd += _("empty figure path");
1327 string buf1 = OnlyPath(owner->fileName());
1328 string fname2 = MakeRelPath(fname, buf1);
1330 string gcmd = "\\includegraphics{" + fname2 + '}';
1331 resizeW = stringify(wtype, xwid, "width");
1332 resizeH = stringify(htype, xhgh, "height");
1334 if (!resizeW.empty() || !resizeH.empty()) {
1335 recmd = "\\resizebox*{";
1336 if (!resizeW.empty())
1341 if (!resizeH.empty())
1350 // \rotatebox{angle}{text}
1351 rotate = "\\rotatebox{" + tostr(angle) + "}{";
1357 if (!rotate.empty()) cmdbuf += '}';
1358 if (!recmd.empty()) cmdbuf += '}';
1360 if (!subcaption.empty())
1361 cmdbuf = "\\subfigure[" + subcaption +
1362 "]{" + cmdbuf + "}";
1364 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1371 void InsetFig::TempRegenerate()
1374 string resizeW, resizeH;
1375 string rotate, recmd;
1377 char const * tfname = fl_get_input(form->EpsFile);
1378 string tsubcap = fl_get_input(form->Subcaption);
1379 float tangle = atof(fl_get_input(form->Angle));
1380 float txwid = atof(fl_get_input(form->Width));
1381 float txhgh = atof(fl_get_input(form->Height));
1383 if (!tfname || !*tfname) {
1384 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1385 cmd += _("empty figure path");
1390 string buf1 = OnlyPath(owner->fileName());
1391 string fname2 = MakeRelPath(tfname, buf1);
1392 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1393 string gcmd = "\\includegraphics{" + fname2 + '}';
1395 resizeW = stringify(twtype, txwid, "width");
1396 resizeH = stringify(thtype, txhgh, "height");
1398 // \resizebox*{h-length}{v-length}{text}
1399 if (!resizeW.empty() || !resizeH.empty()) {
1400 recmd = "\\resizebox*{";
1401 if (!resizeW.empty())
1406 if (!resizeH.empty())
1414 // \rotatebox{angle}{text}
1415 rotate = "\\rotatebox{" + tostr(tangle) + "}{";
1418 cmdbuf = recmd + rotate + gcmd;
1419 if (!rotate.empty()) cmdbuf += '}';
1420 if (!recmd.empty()) cmdbuf += '}';
1421 if (psubfigure && !tsubcap.empty()) {
1422 cmdbuf = string("\\subfigure{") + tsubcap
1423 + string("}{") + cmdbuf + "}";
1428 void InsetFig::Recompute()
1433 bool changed = changedfname;
1434 int newx, newy, nraw_x, nraw_y;
1436 if (changed) GetPSSizes();
1438 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1439 float cos_a = cos (angle / DEG2PI);
1440 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1441 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1443 string lfname = fname;
1444 if (GetExtension(fname).empty())
1447 /* now recompute wid and hgh, and if that is changed, set changed */
1448 /* this depends on chosen size of the picture and its bbox */
1449 // This will be redone in 0.13 ... (hen)
1450 if (!lfname.empty() && IsFileReadable(lfname)) {
1451 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1459 newx = int(28.346 * xwid);
1462 newx = int(72 * xwid);
1464 case PER_PAGE: /* % of page */
1465 newx = int(5.95 * xwid);
1467 case PER_COL: /* % of col */
1468 newx = int(2.975 * xwid);
1472 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1476 //lyxerr << "This should not happen!" << endl;
1479 newy = int(28.346 * xhgh);
1482 newy = int(72 * xhgh);
1484 case PER_PAGE: /* % of page */
1485 newy = int(8.42 * xhgh);
1488 // Doesn't occur; case exists to suppress
1489 // compiler warnings.
1492 if (htype && !wtype && frame_hgh)
1493 newx = newy*frame_wid/frame_hgh;
1502 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1507 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1509 // cannot be zero, actually, set it to some minimum, so its clickable
1510 if (newx < 5) newx = 5;
1511 if (newy < 5) newy = 5;
1513 if (newx != wid || newy != hgh ||
1514 nraw_x != raw_wid || nraw_y != raw_hgh ||
1515 flags != pflags || subfigure != psubfigure)
1523 subfigure = psubfigure;
1526 figdata * pf = figure->data;
1529 if (!lfname.empty() && IsFileReadable(lfname) && (flags & 3)
1530 && !lyxrc.ps_command.empty()) {
1531 // do not display if there is "do not display"
1532 // chosen (Matthias 260696)
1533 figure->data = getfigdata(wid, hgh, lfname,
1534 psx, psy, pswid, pshgh,
1536 angle, flags & (3|8));
1537 } else figure->data = 0;
1539 // free the old data
1540 if (pf) freefigdata(pf);
1543 changedfname = false;
1547 void InsetFig::GetPSSizes()
1549 /* get %%BoundingBox: from postscript file */
1551 /* defaults to associated size
1552 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1559 if (fname.empty()) return;
1561 string lfname = fname;
1562 if (GetExtension(fname).empty())
1564 ifstream ifs(lfname.c_str());
1566 if (!ifs) return; // file not found !!!!
1568 /* defaults to A4 page */
1574 char lastchar = 0; ifs.get(lastchar);
1576 char c = 0; ifs.get(c);
1578 lyxerr.debug() << "End of (E)PS file reached and"
1579 " no BoundingBox!" << endl;
1582 if (c == '%' && lastchar == '%') {
1584 if (p.empty()) break;
1585 lyxerr.debug() << "Token: `" << p << "'" << endl;
1586 if (p == "BoundingBox:") {
1587 float fpsx, fpsy, fpswid, fpshgh;
1588 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1591 pswid = int(fpswid);
1592 pshgh = int(fpshgh);
1594 if (lyxerr.debugging()) {
1595 lyxerr << "%%%%BoundingBox:"
1613 void InsetFig::CallbackFig(long arg)
1618 if (lyxerr.debugging()) {
1619 lyxerr << "Figure callback, arg " << arg << endl;
1625 case 12: /* width type */
1632 fl_deactivate_object(form->Width);
1637 fl_activate_object(form->Width);
1642 fl_activate_object(form->Width);
1647 fl_activate_object(form->Width);
1652 fl_activate_object(form->Width);
1655 lyxerr.debug() << "Unknown type!" << endl;
1662 case 22: /* height type */
1668 fl_deactivate_object(form->Height);
1673 fl_activate_object(form->Height);
1678 fl_activate_object(form->Height);
1683 fl_activate_object(form->Height);
1686 lyxerr.debug() << "Unknown type!" << endl;
1692 pflags = pflags & ~3; /* wysiwyg0 */
1695 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1698 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1701 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1704 pflags ^= 4; /* frame */
1707 pflags ^= 8; /* do translations */
1710 psubfigure = !psubfigure; /* This is a subfigure */
1713 regen = true; /* regenerate command */
1715 case 0: /* browse file */
1719 case 1: /* preview */
1720 p = fl_get_input(form->EpsFile);
1724 case 8: /* ok (apply and close) */
1725 if (!current_view->buffer()->isReadonly()) {
1728 xwid = atof(fl_get_input(form->Width));
1729 xhgh = atof(fl_get_input(form->Height));
1730 angle = atof(fl_get_input(form->Angle));
1731 p = fl_get_input(form->EpsFile);
1733 string buf1 = OnlyPath(owner->fileName());
1734 fname = MakeAbsPath(p, buf1);
1735 changedfname = true;
1737 if (!fname.empty()) {
1738 changedfname = true;
1742 subcaption = fl_get_input(form->Subcaption);
1746 /* now update inset */
1747 if (lyxerr.debugging()) {
1748 lyxerr << "Update: ["
1749 << wid << 'x' << hgh << ']' << endl;
1751 current_view->updateInset(this, true);
1753 fl_set_focus_object(form->Figure, form->OkBtn);
1754 fl_hide_form(form->Figure);
1755 #if FL_REVISION == 89
1756 // CHECK Reactivate this free_form calls
1758 fl_free_form(form->Figure);
1759 free(form); // Why free?
1765 // The user has already been informed about RO in ::Edit
1766 if (arg == 7) // if 'Apply'
1769 case 9: /* cancel = restore and close */
1770 fl_set_focus_object(form->Figure, form->OkBtn);
1771 fl_hide_form(form->Figure);
1772 #if FL_REVISION == 89
1773 // CHECK Reactivate this free_form calls
1774 // Jug, is this still a problem?
1776 fl_free_form(form->Figure);
1777 free(form); // Why free?
1783 if (regen) TempRegenerate();
1788 void DisableFigurePanel(FD_Figure * const form)
1790 fl_deactivate_object(form->EpsFile);
1791 fl_deactivate_object(form->Browse);
1792 fl_deactivate_object(form->Width);
1793 fl_deactivate_object(form->Height);
1794 fl_deactivate_object(form->Frame);
1795 fl_deactivate_object(form->Translations);
1796 fl_deactivate_object(form->Angle);
1797 fl_deactivate_object(form->HeightGrp);
1798 fl_deactivate_object(form->page2);
1799 fl_deactivate_object(form->Default2);
1800 fl_deactivate_object(form->cm2);
1801 fl_deactivate_object(form->in2);
1802 fl_deactivate_object(form->HeightLabel);
1803 fl_deactivate_object(form->WidthLabel);
1804 fl_deactivate_object(form->DisplayGrp);
1805 fl_deactivate_object(form->Wysiwyg3);
1806 fl_deactivate_object(form->Wysiwyg0);
1807 fl_deactivate_object(form->Wysiwyg2);
1808 fl_deactivate_object(form->Wysiwyg1);
1809 fl_deactivate_object(form->WidthGrp);
1810 fl_deactivate_object(form->Default1);
1811 fl_deactivate_object(form->cm1);
1812 fl_deactivate_object(form->in1);
1813 fl_deactivate_object(form->page1);
1814 fl_deactivate_object(form->column1);
1815 fl_deactivate_object(form->Subcaption);
1816 fl_deactivate_object(form->Subfigure);
1817 fl_deactivate_object (form->OkBtn);
1818 fl_deactivate_object (form->ApplyBtn);
1819 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1820 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1825 void EnableFigurePanel(FD_Figure * const form)
1827 fl_activate_object(form->EpsFile);
1828 fl_activate_object(form->Browse);
1829 fl_activate_object(form->Width);
1830 fl_activate_object(form->Height);
1831 fl_activate_object(form->Frame);
1832 fl_activate_object(form->Translations);
1833 fl_activate_object(form->Angle);
1834 fl_activate_object(form->HeightGrp);
1835 fl_activate_object(form->page2);
1836 fl_activate_object(form->Default2);
1837 fl_activate_object(form->cm2);
1838 fl_activate_object(form->in2);
1839 fl_activate_object(form->HeightLabel);
1840 fl_activate_object(form->WidthLabel);
1841 fl_activate_object(form->DisplayGrp);
1842 fl_activate_object(form->Wysiwyg3);
1843 fl_activate_object(form->Wysiwyg0);
1844 fl_activate_object(form->Wysiwyg2);
1845 fl_activate_object(form->Wysiwyg1);
1846 fl_activate_object(form->WidthGrp);
1847 fl_activate_object(form->Default1);
1848 fl_activate_object(form->cm1);
1849 fl_activate_object(form->in1);
1850 fl_activate_object(form->page1);
1851 fl_activate_object(form->column1);
1852 fl_activate_object(form->Subcaption);
1853 fl_activate_object(form->Subfigure);
1854 fl_activate_object (form->OkBtn);
1855 fl_activate_object (form->ApplyBtn);
1856 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1857 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1861 void InsetFig::RestoreForm()
1863 EnableFigurePanel(form);
1866 fl_set_button(form->Default1, (wtype == 0));
1867 fl_set_button(form->cm1, (wtype == 1));
1868 fl_set_button(form->in1, (wtype == 2));
1869 fl_set_button(form->page1, (wtype == 3));
1870 fl_set_button(form->column1, (wtype == 4));
1872 fl_deactivate_object(form->Width);
1874 fl_activate_object(form->Width);
1877 // enable and disable should be put here.
1879 fl_set_button(form->Default2, (htype == 0));
1880 fl_set_button(form->cm2, (htype == 1));
1881 fl_set_button(form->in2, (htype == 2));
1882 fl_set_button(form->page2, (htype == 3));
1883 // enable and disable should be put here.
1885 fl_deactivate_object(form->Height);
1887 fl_activate_object(form->Height);
1890 int piflags = flags & 3;
1891 fl_set_button(form->Wysiwyg0, (piflags == 0));
1892 fl_set_button(form->Wysiwyg1, (piflags == 1));
1893 fl_set_button(form->Wysiwyg2, (piflags == 2));
1894 fl_set_button(form->Wysiwyg3, (piflags == 3));
1895 fl_set_button(form->Frame, ((flags & 4) != 0));
1896 fl_set_button(form->Translations, ((flags & 8) != 0));
1897 fl_set_button(form->Subfigure, (subfigure != 0));
1899 psubfigure = subfigure;
1900 fl_set_input(form->Width, tostr(xwid).c_str());
1901 fl_set_input(form->Height, tostr(xhgh).c_str());
1902 fl_set_input(form->Angle, tostr(angle).c_str());
1903 if (!fname.empty()){
1904 string buf1 = OnlyPath(owner->fileName());
1905 string fname2 = MakeRelPath(fname, buf1);
1906 fl_set_input(form->EpsFile, fname2.c_str());
1908 else fl_set_input(form->EpsFile, "");
1909 fl_set_input(form->Subcaption, subcaption.c_str());
1910 if (current_view->buffer()->isReadonly())
1911 DisableFigurePanel(form);
1917 void InsetFig::Preview(string const & p)
1920 if (GetExtension(tfname).empty())
1922 string buf1 = OnlyPath(owner->fileName());
1923 string buf2 = os::external_path(MakeAbsPath(tfname, buf1));
1924 if (!formats.View(owner, buf2, "eps"))
1925 lyxerr << "Can't view " << buf2 << endl;
1928 void InsetFig::BrowseFile()
1930 static string current_figure_path;
1931 static int once = 0;
1933 if (lyxerr.debugging()) {
1934 lyxerr << "Filename: "
1935 << owner->fileName() << endl;
1937 string p = fl_get_input(form->EpsFile);
1939 string buf = MakeAbsPath(owner->fileName());
1940 string buf2 = OnlyPath(buf);
1942 buf = MakeAbsPath(p, buf2);
1943 buf = OnlyPath(buf);
1945 buf = OnlyPath(owner->fileName());
1948 // Does user clipart directory exist?
1949 string bufclip = AddName (user_lyxdir, "clipart");
1950 FileInfo fileInfo(bufclip);
1951 if (!(fileInfo.isOK() && fileInfo.isDir()))
1952 // No - bail out to system clipart directory
1953 bufclip = AddName (system_lyxdir, "clipart");
1956 FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"),
1957 LFUN_SELECT_FILE_SYNC,
1958 make_pair(string(_("Clip art")), string(bufclip)),
1959 make_pair(string(_("Documents")), string(buf)));
1963 string const path = (once) ? current_figure_path : buf;
1965 FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
1967 string const p = result.second;
1972 buf = MakeRelPath(p, buf2);
1973 current_figure_path = OnlyPath(p);
1976 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
1977 || contains(p, "%") || contains(p, " ")) {
1978 WriteAlert(_("Filename can't contain any "
1979 "of these characters:"),
1980 // xgettext:no-c-format
1981 _("space, '#', '~', '$' or '%'."));
1986 if (form) fl_set_input(form->EpsFile, buf.c_str());
1990 void GraphicsCB(FL_OBJECT * obj, long arg)
1992 /* obj->form contains the form */
1994 if (lyxerr.debugging()) {
1995 lyxerr << "GraphicsCB callback: " << arg << endl;
1998 /* find inset we were reacting to */
1999 for (figures_type::iterator it = figures.begin();
2000 it != figures.end(); ++it)
2001 if ((*it)->inset->form && (*it)->inset->form->Figure
2003 if (lyxerr.debugging()) {
2004 lyxerr << "Calling back figure "
2007 (*it)->inset->CallbackFig(arg);
2013 void HideFiguresPopups()
2015 for (figures_type::iterator it = figures.begin();
2016 it != figures.end(); ++it)
2017 if ((*it)->inset->form
2018 && (*it)->inset->form->Figure->visible) {
2019 if (lyxerr.debugging()) {
2020 lyxerr << "Hiding figure " << (*it) << endl;
2022 // hide and free the form
2023 (*it)->inset->CallbackFig(9);