2 * figinset.C - part of LyX project
5 extern long int background_pixels;
7 /* Rework of path-handling (Matthias 04.07.1996 )
8 * ------------------------------------------------
9 * figinsets keep an absolute path to the eps-file.
10 * For the user alway a relative path appears
11 * (in lyx-file, latex-file and edit-popup).
12 * To calculate this relative path the path to the
13 * document where the figinset is in is needed.
14 * This is done by a reference to the buffer, called
15 * figinset::cbuffer. To be up to date the cbuffer
16 * is sometimes set to the current buffer
17 * bufferlist.current(), when it can be assumed that
18 * this operation happens in the current buffer.
19 * This is true for InsetFig::Edit(...),
20 * InsetFig::InsetFig(...), InsetFig::Read(...),
21 * InsetFig::Write and InsetFig::Latex(...).
22 * Therefore the bufferlist has to make sure that
23 * during these operations bufferlist.current()
24 * returns the buffer where the figinsets are in.
25 * This made few changes in buffer.C necessary.
27 * The above is not totally valid anymore. (Lgb)
37 #include FORMS_H_LOCATION
57 #include "support/filetools.h"
58 #include "LyXView.h" // just because of form_main
60 #include "LaTeXFeatures.h"
63 #include "lyx_gui_misc.h" // CancelCloseBoxCB
64 #include "support/FileInfo.h"
65 #include "support/lyxlib.h"
68 extern BufferView * current_view;
69 extern FL_OBJECT * figinset_canvas;
71 extern char ** environ; // is this only redundtant on linux systems? Lgb.
73 extern void ProhibitInput();
74 extern void AllowInput();
76 static float const DEG2PI = 57.295779513;
77 static int const figallocchunk = 32;
79 static int figinsref = 0; /* number of figures */
80 static int figarrsize = 0; /* current max number of figures */
81 static int bmpinsref = 0; /* number of bitmaps */
82 static int bmparrsize = 0; /* current max number of bitmaps */
84 struct queue_element {
85 float rx, ry; // resolution x and y
86 int ofsx, ofsy; // x and y translation
87 figdata * data; // we are doing it for this data
90 static int const MAXGS = 3; /* maximum 3 gs's at a time */
92 static Figref ** figures; /* all the figures */
93 static figdata ** bitmaps; /* all the bitmaps */
95 static queue<queue_element> gsqueue; // queue for ghostscripting
97 static int gsrunning = 0; /* currently so many gs's are running */
98 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
99 static char bittable[256]; /* bit reversion table */
101 static bool gs_color; // do we allocate colors for gs?
102 static bool color_visual; // is the visual color?
103 static bool gs_xcolor = false; // allocated extended colors
104 static unsigned long gs_pixels[128]; // allocated pixels
105 static int gs_num_pixels; // number of pixels allocated
106 static int gs_spc; // shades per color
107 static bool gs_gray; // is grayscale?
108 static int gs_allcolors; // number of all colors
110 static list<int> pidwaitlist; // pid wait list
112 //extern Colormap color_map;
120 val.foreground = BlackPixel(fl_display,
121 DefaultScreen(fl_display));
124 val.graphics_exposures = false;
125 val.line_style = LineSolid;
127 return XCreateGC(fl_display, RootWindow(fl_display, 0),
128 GCForeground | GCFunction | GCGraphicsExposures
129 | GCLineWidth | GCLineStyle , &val);
136 void addpidwait(int pid)
138 // adds pid to pid wait list
139 pidwaitlist.push_back(pid);
141 if (lyxerr.debugging()) {
142 lyxerr << "Pids to wait for: \n";
143 for (list<int>::const_iterator cit = pidwaitlist.begin();
144 cit != pidwaitlist.end(); ++cit) {
145 lyxerr << (*cit) << '\n';
152 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
157 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
159 if(lyxerr.debugging()) {
160 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
161 << "] pm:[" << e->data.l[1] << "]" << endl;
164 // just kill gs, that way it will work for sure
165 // This loop looks like S**T so it probably is...
166 for (int i = 0; i < bmpinsref; ++i)
167 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
169 figdata * p = bitmaps[i];
172 // first update p->bitmap, if necessary
173 if (p->bitmap != None
174 && p->flags > (1|8) && gs_color && p->wid) {
175 // query current colormap and re-render
176 // the pixmap with proper colors
178 XWindowAttributes wa;
179 register XImage * im;
184 int spc2 = gs_spc * gs_spc;
188 GC gc = local_gc_copy;
190 XGetWindowAttributes(fl_display,
195 if (lyxerr.debugging()) {
196 lyxerr << "Starting image translation "
199 << p->wid << "x" << p->hgh
201 << " " << XYPixmap << endl;
203 // now fork rendering process
205 if (forkstat == -1) {
207 << "Cannot fork, using slow "
208 "method for pixmap translation." << endl;
209 tmpdisp = fl_display;
210 } else if (forkstat > 0) { // parent
212 if (lyxerr.debugging()) {
213 lyxerr << "Spawned child "
216 addpidwait(forkstat);
219 tmpdisp = XOpenDisplay(XDisplayName(0));
222 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
223 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
225 if (lyxerr.debugging()) {
226 lyxerr << "Got the image" << endl;
229 if (lyxerr.debugging()) {
230 lyxerr << "Error getting the image" << endl;
235 // query current colormap
236 XColor * cmap = new XColor[gs_allcolors];
237 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
239 XQueryColors(tmpdisp, fl_state[fl_get_vclass()].colormap, cmap, gs_allcolors);
241 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
245 // now we process all the image
246 for (y = 0; y < p->hgh; ++y) {
247 for (int x = 0; x < wid; ++x) {
252 gs_pixels[((pc->red+6553)*
253 spc1/65535)*spc2+((pc->green+6553)*
254 spc1/65535)*gs_spc+((pc->blue+6553)*
259 // This must be correct.
261 if (lyxerr.debugging()) {
262 lyxerr << "Putting image back"
265 XPutImage(tmpdisp, p->bitmap,
267 0, 0, p->wid, p->hgh);
269 if (lyxerr.debugging()) {
270 lyxerr << "Done translation"
275 if (lyxerr.debugging()) {
276 lyxerr << "Killing gs "
279 lyx::kill(p->gspid, SIGHUP);
281 sprintf(tmp, "%s/~lyxgs%d.ps",
282 system_tempdir.c_str(),
286 XCloseDisplay(tmpdisp);
290 if (lyxerr.debugging()) {
291 lyxerr << "Killing gs "
294 lyx::kill(p->gspid, SIGHUP);
296 sprintf(tmp, "%s/~lyxgs%d.ps",
297 system_tempdir.c_str(),
307 static 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 = 65535 * (i / (num * num)) / (num - 1);
324 xcol.green = 65535 * ((i / num) % num) / (num - 1);
325 xcol.blue = 65535 * (i % num) / (num - 1);
326 xcol.flags = DoRed | DoGreen | DoBlue;
327 if (!XAllocColor(fl_display,
328 fl_state[fl_get_vclass()].colormap, &xcol)) {
329 if (i) XFreeColors(fl_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;
344 gs_num_pixels = num * num * num;
348 // allocate grayscale ramp
350 void AllocGrays(int num)
352 if (lyxerr.debugging()) {
353 lyxerr << "Allocating grayscale colormap "
358 lyxerr << "Error allocating grayscale colormap." << endl;
362 if (num > 128) num = 128;
364 for (int i = 0; i < num; ++i) {
365 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
366 xcol.flags = DoRed | DoGreen | DoBlue;
367 if (!XAllocColor(fl_display,
368 fl_state[fl_get_vclass()].colormap, &xcol)) {
369 if (i) XFreeColors(fl_display,
370 fl_state[fl_get_vclass()].colormap,
372 if (lyxerr.debugging()) {
373 lyxerr << "Cannot allocate grayscale "
379 gs_pixels[i] = xcol.pixel;
389 bmparrsize = figarrsize = figallocchunk;
390 typedef Figref * Figref_p;
391 figures = new Figref_p[figallocchunk];
392 typedef figdata * figdata_p;
393 bitmaps = new figdata_p[figallocchunk];
396 for (unsigned int i = 0; i < 256; ++i) {
398 for (unsigned int j = 0; j < 8; ++j)
399 if (i & (1 << (7-j))) k |= 1 << j;
400 bittable[i] = char(~k);
403 fl_add_canvas_handler(figinset_canvas, ClientMessage,
404 GhostscriptMsg, current_view->owner()->getMainForm());
406 // allocate color cube on pseudo-color display
409 local_gc_copy = createGC();
411 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
412 if (lyxerr.debugging()) {
413 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
414 vi->visualid, vi->c_class,
415 vi->bits_per_rgb, vi->map_entries);
417 color_visual = ( (vi->c_class == StaticColor) ||
418 (vi->c_class == PseudoColor) ||
419 (vi->c_class == TrueColor) ||
420 (vi->c_class == DirectColor) );
421 if ((vi->c_class & 1) == 0) return;
422 // now allocate colors
423 if (vi->c_class == GrayScale) {
424 // allocate grayscale
425 AllocGrays(vi->map_entries/2);
427 // allocate normal color
429 while (i * i * i * 2 > vi->map_entries) --i;
432 gs_allcolors = vi->map_entries;
443 lyxerr.debug() << "Unregistering figures..." << endl;
445 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
450 int FindBmpIndex(figdata * tmpdata)
453 while (i < bmpinsref) {
454 if (bitmaps[i] == tmpdata) return i;
461 static void freefigdata(figdata * tmpdata)
464 if (tmpdata->ref) return;
466 if (tmpdata->gspid > 0) {
467 int pid = tmpdata->gspid;
469 // kill ghostscript and unlink it's files
471 lyx::kill(pid, SIGKILL);
472 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
476 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
478 int i = FindBmpIndex(tmpdata);
480 while (i < bmpinsref) {
481 bitmaps[i] = bitmaps[i + 1];
487 static void runqueue()
489 // run queued requests for ghostscript, if any
490 if (!gsrunning && gs_color && !gs_xcolor) {
491 // here alloc all colors, so that gs will use only
492 // those we allocated for it
497 while (gsrunning < MAXGS) {
498 char tbuf[384], tbuf2[80];
502 if (gsqueue.empty()) {
503 if (!gsrunning && gs_xcolor) {
504 // de-allocate rest of colors
510 queue_element * p = &gsqueue.front();
519 if (lyxerr.debugging()) {
520 lyxerr << "GS start error! Cannot fork."
523 p->data->broken = true;
524 p->data->reading = false;
527 if (pid == 0) { // child
528 char ** env, rbuf[80], gbuf[40];
530 Display * tempdisp = XOpenDisplay(XDisplayName(0));
532 // create translation file
533 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
537 ofs << "gsave clippath pathbbox grestore\n"
539 << "/ury exch def /urx exch def /lly exch def "
541 << p->data->wid / 2.0 << " "
542 << p->data->hgh / 2.0 << " translate\n"
543 << p->data->angle << " rotate\n"
544 << -(p->data->raw_wid / 2.0) << " "
545 << -(p->data->raw_hgh / 2.0) << " translate\n"
546 << p->rx / 72.0 << " " << p->ry / 72.0
548 << -p->ofsx << " " << -p->ofsy << " translate\n"
550 ofs.close(); // Don't remove this.
552 // gs process - set ghostview environment first
553 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
554 figinset_canvas), p->data->bitmap);
556 // now set up ghostview property on a window
557 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
558 p->data->wid, p->data->hgh);
559 // #warning BUG seems that the only bug here
560 // might be the hardcoded dpi.. Bummer!
562 if (lyxerr.debugging()) {
563 lyxerr << "Will set GHOSTVIEW property to ["
564 << tbuf << "]" << endl;
566 // wait until property is deleted if executing multiple
569 // grab server to prevent other child
570 // interfering with setting GHOSTVIEW property
571 if (lyxerr.debugging()) {
572 lyxerr << "Grabbing the server"
575 XGrabServer(tempdisp);
576 prop = XListProperties(tempdisp,
578 figinset_canvas), &nprop);
582 for (i = 0; i < nprop; ++i) {
583 char * p = XGetAtomName(tempdisp,
585 if (strcmp(p, "GHOSTVIEW") == 0) {
591 XFree(reinterpret_cast<char *>(prop)); // jc:
593 // release the server
594 XUngrabServer(tempdisp);
596 // ok, property found, we must wait until
597 // ghostscript deletes it
598 if (lyxerr.debugging()) {
599 lyxerr << "Releasing the server\n["
601 << "] GHOSTVIEW property"
602 " found. Waiting." << endl;
608 XChangeProperty(tempdisp,
609 fl_get_canvas_id(figinset_canvas),
610 XInternAtom(tempdisp, "GHOSTVIEW", false),
611 XInternAtom(tempdisp, "STRING", false),
613 reinterpret_cast<unsigned char*>(tbuf),
616 switch (p->data->flags & 3) {
617 case 0: tbuf[0] = 'H'; break; // Hidden
618 case 1: tbuf[0] = 'M'; break; // Mono
619 case 2: tbuf[0] = 'G'; break; // Gray
622 tbuf[0] = 'C'; // Color
624 tbuf[0] = 'G'; // Gray
628 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
629 DefaultScreenOfDisplay(fl_display)),
630 fl_get_pixel(FL_WHITE));
632 XChangeProperty(tempdisp,
633 fl_get_canvas_id(figinset_canvas),
634 XInternAtom(tempdisp,
635 "GHOSTVIEW_COLORS", false),
636 XInternAtom(tempdisp, "STRING", false),
638 reinterpret_cast<unsigned char*>(tbuf),
640 XUngrabServer(tempdisp);
642 if (lyxerr.debugging()) {
643 lyxerr << "Releasing the server" << endl;
645 XCloseDisplay(tempdisp);
647 // set up environment
648 while (environ[ne]) ++ne;
649 typedef char * char_p;
650 env = new char_p[ne + 2];
652 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
655 // now make gs command
657 // close(1); do NOT close. If GS writes out
658 // errors it would hang. (Matthias 290596)
659 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
660 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
661 // now chdir into dir with .eps file, to be on the safe
663 chdir(OnlyPath(p->data->fname).c_str());
664 // make temp file name
665 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
667 if (lyxerr.debugging()) {
668 lyxerr << "starting gs " << tbuf << " "
670 << ", pid: " << getpid() << endl;
673 int err = execlp(lyxrc->ps_command.c_str(),
674 lyxrc->ps_command.c_str(),
676 "-dNOPAUSE", "-dQUIET",
679 p->data->fname.c_str(),
680 "showpage.ps", "quit.ps", "-", 0);
681 // if we are still there, an error occurred.
682 lyxerr << "Error executing ghostscript. "
683 << "Code: " << err << endl;
684 lyxerr.debug() << "Cmd: "
688 << p->data->fname << endl;
691 // normal process (parent)
692 if (lyxerr.debugging()) {
693 lyxerr << "GS [" << pid << "] started" << endl;
696 p->data->gspid = pid;
703 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
705 // recompute the stuff and put in the queue
709 p.rx = (float(data->raw_wid) * 72.0) / pswid;
710 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
716 // if possible, run the queue
721 static figdata * getfigdata(int wid, int hgh, string const & fname,
722 int psx, int psy, int pswid, int pshgh,
723 int raw_wid, int raw_hgh, float angle, char flags)
725 /* first search for an exact match with fname and width/height */
727 if (fname.empty()) return 0;
730 while (i < bmpinsref) {
731 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
732 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
733 bitmaps[i]->angle == angle) {
739 /* not found -> create new record or return 0 if no record */
741 if (bmpinsref > bmparrsize) {
742 // allocate more space
743 bmparrsize += figallocchunk;
744 typedef figdata * figdata_p;
745 figdata ** tmp = new figdata_p[bmparrsize];
747 sizeof(figdata*) * (bmparrsize - figallocchunk));
751 figdata * p = new figdata;
752 bitmaps[bmpinsref-1] = p;
755 p->raw_wid = raw_wid;
756 p->raw_hgh = raw_hgh;
760 XWindowAttributes wa;
761 XGetWindowAttributes(fl_display, fl_get_canvas_id(
762 figinset_canvas), &wa);
764 if (lyxerr.debugging()) {
765 lyxerr << "Create pixmap disp:" << fl_display
766 << " scr:" << DefaultScreen(fl_display)
769 << " depth:" << wa.depth << endl;
777 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
778 figinset_canvas), wid, hgh, wa.depth);
780 // initialize reading of .eps file with correct sizes and stuff
781 addwait(psx, psy, pswid, pshgh, p);
793 void getbitmap(figdata * p)
800 void makeupdatelist(figdata * p)
802 for (int i = 0; i < figinsref; ++i)
803 if (figures[i]->data == p) {
804 if (lyxerr.debugging()) {
805 lyxerr << "Updating inset "
809 // add inset figures[i]->inset into to_update list
810 current_view->pushIntoUpdateList(figures[i]->inset);
812 //PutInsetIntoInsetUpdateList(figures[i]->inset);
817 void sigchldchecker(pid_t pid, int * status)
819 lyxerr.debug() << "Got pid = " << pid << endl;
820 bool pid_handled = false;
821 for (int i = bmpinsref - 1; i >= 0; --i) {
822 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
823 lyxerr.debug() << "Found pid in bitmaps" << endl;
824 // now read the file and remove it from disk
825 figdata * p = bitmaps[i];
827 if (bitmaps[i]->gsdone) *status = 0;
829 lyxerr.debug() << "GS [" << pid
830 << "] exit OK." << endl;
832 lyxerr << "GS [" << pid << "] error "
834 << WIFEXITED(*status)
835 << " " << WEXITSTATUS(*status)
836 << " S:" << WIFSIGNALED(*status)
837 << " " << WTERMSIG(*status) << endl;
840 bitmap_waiting = true;
843 // remove temporary files
845 sprintf(tmp, "%s/~lyxgs%d.ps",
846 system_tempdir.c_str(),
852 makeupdatelist(bitmaps[i]);
859 lyxerr.debug() << "Checking pid in pidwait" << endl;
860 list<int>::iterator it = find(pidwaitlist.begin(),
861 pidwaitlist.end(), pid);
862 if (it != pidwaitlist.end()) {
863 lyxerr.debug() << "Found pid in pidwait\n"
864 << "Caught child pid of recompute "
865 "routine" << pid << endl;
866 pidwaitlist.erase(it);
870 lyxerr.debug() << "waitpid error" << endl;
873 lyxerr << "The process or process group specified by "
874 "pid does not exist or is not a child of "
875 "the calling process or can never be in the "
876 "states specified by options." << endl;
879 lyxerr << "waitpid() was interrupted due to the "
880 "receipt of a signal sent by the calling "
884 lyxerr << "An invalid value was specified for "
888 lyxerr << "Unknown error from waitpid" << endl;
891 } else if (pid == 0) {
892 lyxerr << "waitpid nohang" << endl;;
894 lyxerr.debug() << "normal exit from childhandler" << endl;
899 static void getbitmaps()
901 bitmap_waiting = false;
902 for (int i = 0; i < bmpinsref; ++i)
903 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
904 getbitmap(bitmaps[i]);
908 static void RegisterFigure(InsetFig * fi)
910 if (figinsref == 0) InitFigures();
913 if (figinsref > figarrsize) {
914 // allocate more space
915 figarrsize += figallocchunk;
916 typedef Figref * Figref_p;
917 Figref ** tmp = new Figref_p[figarrsize];
919 sizeof(Figref*)*(figarrsize-figallocchunk));
923 Figref * tmpfig = new Figref;
926 figures[figinsref-1] = tmpfig;
929 if (lyxerr.debugging()) {
930 lyxerr << "Register Figure: buffer:["
931 << current_view->buffer() << "]" << endl;
936 int FindFigIndex(Figref * tmpfig)
939 while (i < figinsref) {
940 if (figures[i] == tmpfig) return i;
947 static void UnregisterFigure(InsetFig * fi)
949 Figref * tmpfig = fi->figure;
951 if (tmpfig->data) freefigdata(tmpfig->data);
952 if (tmpfig->inset->form) {
953 if (tmpfig->inset->form->Figure->visible) {
954 fl_set_focus_object(tmpfig->inset->form->Figure,
955 tmpfig->inset->form->OkBtn);
956 fl_hide_form(tmpfig->inset->form->Figure);
958 #if FL_REVISION == 89
959 #warning Reactivate this free_form calls
961 fl_free_form(tmpfig->inset->form->Figure);
962 free(tmpfig->inset->form); // Why free?
963 tmpfig->inset->form = 0;
966 int i = FindFigIndex(tmpfig);
968 while (i < figinsref) {
969 figures[i] = figures[i+1];
974 if (figinsref == 0) DoneFigures();
978 static string NextToken(istream & is)
986 } while (!is.eof() && !isspace(c));
987 token.erase(token.length() - 1); // remove the isspace
993 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1003 psubfigure = subfigure = false;
1004 xwid = xhgh = angle = 0;
1006 raw_wid = raw_hgh = 0;
1007 changedfname = false;
1008 RegisterFigure(this);
1012 InsetFig::~InsetFig()
1014 if (lyxerr.debugging()) {
1015 lyxerr << "Figure destructor called" << endl;
1017 UnregisterFigure(this);
1021 int InsetFig::ascent(Painter &, LyXFont const &) const
1027 int InsetFig::descent(Painter &, LyXFont const &) const
1033 int InsetFig::width(Painter &, LyXFont const &) const
1039 void InsetFig::draw(Painter & pain, LyXFont const & f, int baseline, float & x) const
1043 if (bitmap_waiting) getbitmaps();
1045 // I wish that I didn't have to use this
1046 // but the figinset code is so complicated so
1047 // I don't want to fiddle with it now.
1049 if (figure && figure->data && figure->data->bitmap &&
1050 !figure->data->reading && !figure->data->broken) {
1052 pain.pixmap(int(x + 1), baseline - hgh,
1053 wid, hgh, figure->data->bitmap);
1056 pain.rectangle(int(x), baseline - hgh - 1,
1062 pain.rectangle(x, baseline - hgh - 1, wid + 1, hgh + 1);
1064 if (figure && figure->data) {
1065 if (figure->data->broken) msg = _("[render error]");
1066 else if (figure->data->reading) msg = _("[rendering ... ]");
1068 if (fname.empty()) msg = _("[no file]");
1069 else if ((flags & 3) == 0) msg = _("[not displayed]");
1070 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1072 if (!msg) msg = _("[unknown error]");
1074 font.setFamily(LyXFont::SANS_FAMILY);
1075 font.setSize(LyXFont::SIZE_FOOTNOTE);
1076 string justname = OnlyFilename (fname);
1077 pain.text(int(x + 8), baseline - font.maxAscent() - 4,
1080 font.setSize(LyXFont::SIZE_TINY);
1081 pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
1083 x += width(pain, font); // ?
1087 void InsetFig::Write(ostream & os) const
1090 os << "Figure size " << wid << " " << hgh << "\n";
1091 if (!fname.empty()) {
1092 string buf1 = OnlyPath(owner->fileName());
1093 string fname2 = MakeRelPath(fname, buf1);
1094 os << "file " << fname2 << "\n";
1096 if (!subcaption.empty())
1097 os << "subcaption " << subcaption << "\n";
1098 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1099 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1100 if (angle != 0) os << "angle " << angle << "\n";
1101 os << "flags " << flags << "\n";
1102 if (subfigure) os << "subfigure\n";
1106 void InsetFig::Read(LyXLex & lex)
1109 bool finished = false;
1111 while (lex.IsOK() && !finished) {
1114 string const token = lex.GetString();
1115 lyxerr.debug() << "Token: " << token << endl;
1119 else if (token == "\\end_inset") {
1121 } else if (token == "file") {
1123 buf = lex.GetString();
1124 string buf1 = OnlyPath(owner->fileName());
1125 fname = MakeAbsPath(buf, buf1);
1126 changedfname = true;
1128 } else if (token == "extra") {
1130 // kept for backwards compability. Delete in 0.13.x
1131 } else if (token == "subcaption") {
1133 subcaption = lex.GetString();
1134 } else if (token == "label") {
1136 // kept for backwards compability. Delete in 0.13.x
1137 } else if (token == "angle") {
1139 angle = lex.GetFloat();
1140 } else if (token == "size") {
1142 wid = lex.GetInteger();
1144 hgh = lex.GetInteger();
1145 } else if (token == "flags") {
1147 flags = pflags = lex.GetInteger();
1148 } else if (token == "subfigure") {
1149 subfigure = psubfigure = true;
1150 } else if (token == "width") {
1153 typ = lex.GetInteger();
1155 xwid = lex.GetFloat();
1157 case DEF: wtype = DEF; break;
1158 case CM: wtype = CM; break;
1159 case IN: wtype = IN; break;
1160 case PER_PAGE: wtype = PER_PAGE; break;
1161 case PER_COL: wtype = PER_COL; break;
1163 lyxerr.debug() << "Unknown type!" << endl;
1167 } else if (token == "height") {
1170 typ = lex.GetInteger();
1172 xhgh = lex.GetFloat();
1174 case DEF: htype = DEF; break;
1175 case CM: htype = CM; break;
1176 case IN: htype = IN; break;
1177 case PER_PAGE: htype = PER_PAGE; break;
1179 lyxerr.debug() << "Unknown type!" << endl;
1190 int InsetFig::Latex(ostream & os, signed char /* fragile*/ ) const
1193 if (!cmd.empty()) os << cmd << " ";
1198 int InsetFig::Latex(string & file, signed char /* fragile*/ ) const
1206 int InsetFig::Linuxdoc(string &/*file*/) const
1212 int InsetFig::DocBook(string & file) const
1214 string figurename = fname;
1216 if(suffixIs(figurename, ".eps"))
1217 figurename.erase(fname.length() - 5);
1219 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1224 void InsetFig::Validate(LaTeXFeatures & features) const
1226 features.graphics = true;
1227 if (subfigure) features.subfigure = true;
1231 unsigned char InsetFig::Editable() const
1237 bool InsetFig::Deletable() const
1243 void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
1245 lyxerr.debug() << "Editing InsetFig." << endl;
1248 // We should have RO-versions of the form instead.
1249 // The actual prevention of altering a readonly doc
1250 // is done in CallbackFig()
1251 if(bv->buffer()->isReadonly())
1252 WarnReadonly(bv->buffer()->fileName());
1255 form = create_form_Figure();
1256 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1257 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1258 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1259 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1262 if (form->Figure->visible) {
1263 fl_raise_form(form->Figure);
1265 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1266 FL_FULLBORDER, _("Figure"));
1271 Inset * InsetFig::Clone() const
1273 InsetFig * tmp = new InsetFig(100, 100, owner);
1275 if (lyxerr.debugging()) {
1276 lyxerr << "Clone Figure: buffer:["
1277 << current_view->buffer()
1278 << "], cbuffer:[xx]" << endl;
1283 tmp->raw_wid = raw_wid;
1284 tmp->raw_hgh = raw_hgh;
1289 tmp->pflags = pflags;
1290 tmp->subfigure = subfigure;
1291 tmp->psubfigure = psubfigure;
1299 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1300 // do not display if there is
1301 // "do not display" chosen (Matthias 260696)
1302 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1303 pswid, pshgh, raw_wid, raw_hgh,
1304 angle, flags & (3|8));
1305 } else tmp->figure->data = 0;
1306 tmp->subcaption = subcaption;
1307 tmp->changedfname = false;
1314 Inset::Code InsetFig::LyxCode() const
1316 return Inset::GRAPHICS_CODE;
1320 void InsetFig::Regenerate() const
1323 string resizeW, resizeH;
1324 string rotate, recmd;
1326 if (fname.empty()) {
1327 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1328 cmd += _("empty figure path");
1333 string buf1 = OnlyPath(owner->fileName());
1334 string fname2 = MakeRelPath(fname, buf1);
1336 string gcmd = "\\includegraphics{" + fname2 + '}';
1341 case CM:{// \resizebox*{h-length}{v-length}{text}
1343 sprintf(buf, "%g", xwid); // should find better
1350 sprintf(buf, "%g", xwid);
1357 sprintf(buf, "%g", xwid/100);
1359 resizeW += "\\textwidth";
1364 sprintf(buf, "%g", xwid/100);
1366 resizeW += "\\columnwidth";
1376 sprintf(buf, "%g", xhgh);
1383 sprintf(buf, "%g", xhgh);
1390 sprintf(buf, "%g", xhgh/100);
1392 resizeH += "\\textheight";
1396 // Doesn't occur; case exists to suppress compiler warnings.
1401 if (!resizeW.empty() || !resizeH.empty()) {
1402 recmd = "\\resizebox*{";
1403 if (!resizeW.empty())
1408 if (!resizeH.empty())
1418 sprintf(buf, "%g", angle);
1419 // \rotatebox{angle}{text}
1420 rotate = "\\rotatebox{";
1428 if (!rotate.empty()) cmdbuf += '}';
1429 if (!recmd.empty()) cmdbuf += '}';
1431 if (!subcaption.empty())
1432 cmdbuf = "\\subfigure[" + subcaption +
1433 "]{" + cmdbuf + "}";
1435 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1442 void InsetFig::TempRegenerate()
1445 string resizeW, resizeH;
1446 string rotate, recmd;
1448 char const * tfname = fl_get_input(form->EpsFile);
1449 string tsubcap = fl_get_input(form->Subcaption);
1450 float tangle = atof(fl_get_input(form->Angle));
1451 float txwid = atof(fl_get_input(form->Width));
1452 float txhgh = atof(fl_get_input(form->Height));
1454 if (!tfname || !*tfname) {
1455 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1456 cmd += _("empty figure path");
1461 string buf1 = OnlyPath(owner->fileName());
1462 string fname2 = MakeRelPath(tfname, buf1);
1463 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1464 string gcmd = "\\includegraphics{" + fname2 + '}';
1469 case CM: {// \resizebox*{h-length}{v-length}{text}
1471 sprintf(buf, "%g", txwid); // should find better
1478 sprintf(buf, "%g", txwid);
1485 sprintf(buf, "%g", txwid/100);
1487 resizeW += "\\textwidth";
1492 sprintf(buf, "%g", txwid/100);
1494 resizeW += "\\columnwidth";
1504 sprintf(buf, "%g", txhgh);
1511 sprintf(buf, "%g", txhgh);
1518 sprintf(buf, "%g", txhgh/100);
1520 resizeH += "\\textheight";
1524 // Doesn't occur; case exists to suppress compiler warnings.
1529 // \resizebox*{h-length}{v-length}{text}
1530 if (!resizeW.empty() || !resizeH.empty()) {
1531 recmd = "\\resizebox*{";
1532 if (!resizeW.empty())
1537 if (!resizeH.empty())
1546 sprintf(buf, "%g", tangle);
1547 // \rotatebox{angle}{text}
1548 rotate = "\\rotatebox{";
1556 if (!rotate.empty()) cmdbuf += '}';
1557 if (!recmd.empty()) cmdbuf += '}';
1558 if (psubfigure && !tsubcap.empty()) {
1559 cmdbuf = string("\\subfigure{") + tsubcap
1560 + string("}{") + cmdbuf + "}";
1565 void InsetFig::Recompute()
1567 bool changed = changedfname;
1568 int newx, newy, nraw_x, nraw_y;
1570 if (changed) GetPSSizes();
1572 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1573 float cos_a = cos (angle / DEG2PI);
1574 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1575 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1577 /* now recompute wid and hgh, and if that is changed, set changed */
1578 /* this depends on chosen size of the picture and its bbox */
1579 // This will be redone in 0.13 ... (hen)
1580 if (!fname.empty()) {
1581 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1589 newx = int(28.346 * xwid);
1592 newx = int(72 * xwid);
1594 case PER_PAGE: /* % of page */
1595 newx = int(5.95 * xwid);
1597 case PER_COL: /* % of col */
1598 newx = int(2.975 * xwid);
1602 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1606 //lyxerr << "This should not happen!" << endl;
1609 newy = int(28.346 * xhgh);
1612 newy = int(72 * xhgh);
1614 case PER_PAGE: /* % of page */
1615 newy = int(8.42 * xhgh);
1618 // Doesn't occur; case exists to suppress
1619 // compiler warnings.
1622 if (htype && !wtype && frame_hgh)
1623 newx = newy*frame_wid/frame_hgh;
1632 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1637 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1639 // cannot be zero, actually, set it to some minimum, so its clickable
1640 if (newx < 5) newx = 5;
1641 if (newy < 5) newy = 5;
1643 if (newx != wid || newy != hgh ||
1644 nraw_x != raw_wid || nraw_y != raw_hgh ||
1645 flags != pflags || subfigure != psubfigure)
1653 subfigure = psubfigure;
1656 figdata * pf = figure->data;
1659 if (!fname.empty() && (flags & 3)
1660 && !lyxrc->ps_command.empty()) {
1661 // do not display if there is "do not display"
1662 // chosen (Matthias 260696)
1663 figure->data = getfigdata(wid, hgh, fname,
1664 psx, psy, pswid, pshgh,
1666 angle, flags & (3|8));
1667 } else figure->data = 0;
1669 // free the old data
1670 if (pf) freefigdata(pf);
1673 changedfname = false;
1677 void InsetFig::GetPSSizes()
1679 /* get %%BoundingBox: from postscript file */
1681 /* defaults to associated size
1682 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1689 if (fname.empty()) return;
1691 ifstream ifs(fname.c_str());
1693 if (!ifs) return; // file not found !!!!
1695 /* defaults to A4 page */
1701 char lastchar = 0; ifs.get(lastchar);
1703 char c = 0; ifs.get(c);
1705 lyxerr.debug() << "End of (E)PS file reached and"
1706 " no BoundingBox!" << endl;
1709 if (c == '%' && lastchar == '%') {
1711 if (p.empty()) break;
1712 // we should not use this, with it we cannot
1713 // discover bounding box and end of file.
1714 //if (strcmp(p, "EndComments") == 0) break;
1715 lyxerr.debug() << "Token: `" << p << "'" << endl;
1716 if (p == "BoundingBox:") {
1717 float fpsx, fpsy, fpswid, fpshgh;
1718 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1721 pswid = int(fpswid);
1722 pshgh = int(fpshgh);
1724 if (lyxerr.debugging()) {
1725 lyxerr << "%%%%BoundingBox:"
1743 void InsetFig::CallbackFig(long arg)
1748 if (lyxerr.debugging()) {
1749 lyxerr << "Figure callback, arg " << arg << endl;
1755 case 12: /* width type */
1762 fl_deactivate_object(form->Width);
1767 fl_activate_object(form->Width);
1772 fl_activate_object(form->Width);
1777 fl_activate_object(form->Width);
1782 fl_activate_object(form->Width);
1785 lyxerr.debug() << "Unknown type!" << endl;
1792 case 22: /* height type */
1798 fl_deactivate_object(form->Height);
1803 fl_activate_object(form->Height);
1808 fl_activate_object(form->Height);
1813 fl_activate_object(form->Height);
1816 lyxerr.debug() << "Unknown type!" << endl;
1822 pflags = pflags & ~3; /* wysiwyg0 */
1825 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1828 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1831 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1834 pflags ^= 4; /* frame */
1837 pflags ^= 8; /* do translations */
1840 psubfigure = !psubfigure; /* This is a subfigure */
1843 regen = true; /* regenerate command */
1845 case 0: /* browse file */
1849 case 1: /* preview */
1850 p = fl_get_input(form->EpsFile);
1854 case 8: /* ok (apply and close) */
1855 if(!current_view->buffer()->isReadonly()) {
1858 xwid = atof(fl_get_input(form->Width));
1859 xhgh = atof(fl_get_input(form->Height));
1860 angle = atof(fl_get_input(form->Angle));
1861 p = fl_get_input(form->EpsFile);
1863 string buf1 = OnlyPath(owner->fileName());
1864 fname = MakeAbsPath(p, buf1);
1865 changedfname = true;
1867 if (!fname.empty()) {
1868 changedfname = true;
1872 subcaption = fl_get_input(form->Subcaption);
1876 /* now update inset */
1877 if (lyxerr.debugging()) {
1878 lyxerr << "Update: ["
1879 << wid << 'x' << hgh << ']' << endl;
1881 current_view->updateInset(this, true);
1883 fl_set_focus_object(form->Figure, form->OkBtn);
1884 fl_hide_form(form->Figure);
1885 #if FL_REVISION == 89
1886 #warning Reactivate this free_form calls
1888 fl_free_form(form->Figure);
1889 free(form); // Why free?
1895 // The user has already been informed about RO in ::Edit
1896 if(arg == 7) // if 'Apply'
1899 case 9: /* cancel = restore and close */
1900 fl_set_focus_object(form->Figure, form->OkBtn);
1901 fl_hide_form(form->Figure);
1902 #if FL_REVISION == 89
1903 #warning Reactivate this free_form calls
1904 #warning Jug, is this still a problem?
1906 fl_free_form(form->Figure);
1907 free(form); // Why free?
1913 if (regen) TempRegenerate();
1917 inline void DisableFigurePanel(FD_Figure * const form)
1919 fl_deactivate_object(form->EpsFile);
1920 fl_deactivate_object(form->Browse);
1921 fl_deactivate_object(form->Width);
1922 fl_deactivate_object(form->Height);
1923 fl_deactivate_object(form->Frame);
1924 fl_deactivate_object(form->Translations);
1925 fl_deactivate_object(form->Angle);
1926 fl_deactivate_object(form->HeightGrp);
1927 fl_deactivate_object(form->page2);
1928 fl_deactivate_object(form->Default2);
1929 fl_deactivate_object(form->cm2);
1930 fl_deactivate_object(form->in2);
1931 fl_deactivate_object(form->HeightLabel);
1932 fl_deactivate_object(form->WidthLabel);
1933 fl_deactivate_object(form->DisplayGrp);
1934 fl_deactivate_object(form->Wysiwyg3);
1935 fl_deactivate_object(form->Wysiwyg0);
1936 fl_deactivate_object(form->Wysiwyg2);
1937 fl_deactivate_object(form->Wysiwyg1);
1938 fl_deactivate_object(form->WidthGrp);
1939 fl_deactivate_object(form->Default1);
1940 fl_deactivate_object(form->cm1);
1941 fl_deactivate_object(form->in1);
1942 fl_deactivate_object(form->page1);
1943 fl_deactivate_object(form->column1);
1944 fl_deactivate_object(form->Subcaption);
1945 fl_deactivate_object(form->Subfigure);
1946 fl_deactivate_object (form->OkBtn);
1947 fl_deactivate_object (form->ApplyBtn);
1948 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1949 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1953 inline void EnableFigurePanel(FD_Figure * const form)
1955 fl_activate_object(form->EpsFile);
1956 fl_activate_object(form->Browse);
1957 fl_activate_object(form->Width);
1958 fl_activate_object(form->Height);
1959 fl_activate_object(form->Frame);
1960 fl_activate_object(form->Translations);
1961 fl_activate_object(form->Angle);
1962 fl_activate_object(form->HeightGrp);
1963 fl_activate_object(form->page2);
1964 fl_activate_object(form->Default2);
1965 fl_activate_object(form->cm2);
1966 fl_activate_object(form->in2);
1967 fl_activate_object(form->HeightLabel);
1968 fl_activate_object(form->WidthLabel);
1969 fl_activate_object(form->DisplayGrp);
1970 fl_activate_object(form->Wysiwyg3);
1971 fl_activate_object(form->Wysiwyg0);
1972 fl_activate_object(form->Wysiwyg2);
1973 fl_activate_object(form->Wysiwyg1);
1974 fl_activate_object(form->WidthGrp);
1975 fl_activate_object(form->Default1);
1976 fl_activate_object(form->cm1);
1977 fl_activate_object(form->in1);
1978 fl_activate_object(form->page1);
1979 fl_activate_object(form->column1);
1980 fl_activate_object(form->Subcaption);
1981 fl_activate_object(form->Subfigure);
1982 fl_activate_object (form->OkBtn);
1983 fl_activate_object (form->ApplyBtn);
1984 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1985 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1989 void InsetFig::RestoreForm()
1993 EnableFigurePanel(form);
1996 fl_set_button(form->Default1, (wtype == 0));
1997 fl_set_button(form->cm1, (wtype == 1));
1998 fl_set_button(form->in1, (wtype == 2));
1999 fl_set_button(form->page1, (wtype == 3));
2000 fl_set_button(form->column1, (wtype == 4));
2002 fl_deactivate_object(form->Width);
2004 fl_activate_object(form->Width);
2007 // enable and disable should be put here.
2009 fl_set_button(form->Default2, (htype == 0));
2010 fl_set_button(form->cm2, (htype == 1));
2011 fl_set_button(form->in2, (htype == 2));
2012 fl_set_button(form->page2, (htype == 3));
2013 // enable and disable should be put here.
2015 fl_deactivate_object(form->Height);
2017 fl_activate_object(form->Height);
2020 int pflags = flags & 3;
2021 fl_set_button(form->Wysiwyg0, (pflags == 0));
2022 fl_set_button(form->Wysiwyg1, (pflags == 1));
2023 fl_set_button(form->Wysiwyg2, (pflags == 2));
2024 fl_set_button(form->Wysiwyg3, (pflags == 3));
2025 fl_set_button(form->Frame, ((flags & 4) != 0));
2026 fl_set_button(form->Translations, ((flags & 8) != 0));
2027 fl_set_button(form->Subfigure, (subfigure != 0));
2029 psubfigure = subfigure;
2030 sprintf(buf, "%g", xwid);
2031 fl_set_input(form->Width, buf);
2032 sprintf(buf, "%g", xhgh);
2033 fl_set_input(form->Height, buf);
2034 sprintf(buf, "%g", angle);
2035 fl_set_input(form->Angle, buf);
2036 if (!fname.empty()){
2037 string buf1 = OnlyPath(owner->fileName());
2038 string fname2 = MakeRelPath(fname, buf1);
2039 fl_set_input(form->EpsFile, fname2.c_str());
2041 else fl_set_input(form->EpsFile, "");
2042 fl_set_input(form->Subcaption, subcaption.c_str());
2043 if(current_view->buffer()->isReadonly())
2044 DisableFigurePanel(form);
2050 void InsetFig::Preview(char const * p)
2055 lyxerr << "Cannot fork process!" << endl;
2060 return; // parent process
2063 string buf1 = OnlyPath(owner->fileName());
2064 string buf2 = MakeAbsPath(p, buf1);
2066 lyxerr << "Error during rendering "
2067 << execlp(lyxrc->view_pspic_command.c_str(),
2068 lyxrc->view_pspic_command.c_str(),
2075 void InsetFig::BrowseFile()
2077 static string current_figure_path;
2078 static int once = 0;
2081 if (lyxerr.debugging()) {
2082 lyxerr << "Filename: "
2083 << owner->fileName() << endl;
2085 string p = fl_get_input(form->EpsFile);
2087 string buf = MakeAbsPath(owner->fileName());
2088 string buf2 = OnlyPath(buf);
2090 buf = MakeAbsPath(p, buf2);
2091 buf = OnlyPath(buf);
2093 buf = OnlyPath(owner->fileName().c_str());
2096 // Does user clipart directory exist?
2097 string bufclip = AddName (user_lyxdir, "clipart");
2098 FileInfo fileInfo(bufclip);
2099 if (!(fileInfo.isOK() && fileInfo.isDir()))
2100 // No - bail out to system clipart directory
2101 bufclip = AddName (system_lyxdir, "clipart");
2104 fileDlg.SetButton(0, _("Clipart"), bufclip);
2105 fileDlg.SetButton(1, _("Document"), buf);
2111 p = fileDlg.Select(_("EPS Figure"),
2112 current_figure_path,
2115 p = fileDlg.Select(_("EPS Figure"), buf,
2120 if (p.empty()) return;
2122 buf = MakeRelPath(p, buf2);
2123 current_figure_path = OnlyPath(p);
2126 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2127 || contains(p, "%") || contains(p, " "))
2129 WriteAlert(_("Filename can't contain any "
2130 "of these characters:"),
2131 // xgettext:no-c-format
2132 _("space, '#', '~', '$' or '%'."));
2137 if (form) fl_set_input(form->EpsFile, buf.c_str());
2141 void GraphicsCB(FL_OBJECT * obj, long arg)
2143 /* obj->form contains the form */
2145 if (lyxerr.debugging()) {
2146 lyxerr << "GraphicsCB callback: " << arg << endl;
2149 /* find inset we were reacting to */
2150 for (int i = 0; i < figinsref; ++i)
2151 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2154 if (lyxerr.debugging()) {
2155 lyxerr << "Calling back figure " << i << endl;
2157 figures[i]->inset->CallbackFig(arg);
2163 void HideFiguresPopups()
2165 for (int i = 0; i < figinsref; ++i)
2166 if (figures[i]->inset->form
2167 && figures[i]->inset->form->Figure->visible) {
2168 if (lyxerr.debugging()) {
2169 lyxerr << "Hiding figure " << i << endl;
2171 // hide and free the form
2172 figures[i]->inset->CallbackFig(9);