2 * figinset.C - part of LyX project
5 extern int reverse_video;
6 extern long int background_pixels;
8 /* Rework of path-handling (Matthias 04.07.1996 )
9 * ------------------------------------------------
10 * figinsets keep an absolute path to the eps-file.
11 * For the user alway a relative path appears
12 * (in lyx-file, latex-file and edit-popup).
13 * To calculate this relative path the path to the
14 * document where the figinset is in is needed.
15 * This is done by a reference to the buffer, called
16 * figinset::cbuffer. To be up to date the cbuffer
17 * is sometimes set to the current buffer
18 * bufferlist.current(), when it can be assumed that
19 * this operation happens in the current buffer.
20 * This is true for InsetFig::Edit(...),
21 * InsetFig::InsetFig(...), InsetFig::Read(...),
22 * InsetFig::Write and InsetFig::Latex(...).
23 * Therefore the bufferlist has to make sure that
24 * during these operations bufferlist.current()
25 * returns the buffer where the figinsets are in.
26 * This made few changes in buffer.C necessary.
28 * The above is not totally valid anymore. (Lgb)
38 #include FORMS_H_LOCATION
49 #include "support/filetools.h"
50 #include "LyXView.h" // just because of form_main
53 #include "LaTeXFeatures.h"
56 #include "lyx_gui_misc.h" // CancelCloseBoxCB
57 #include "support/FileInfo.h"
59 extern BufferView *current_view;
60 static volatile bool alarmed;
62 extern FL_OBJECT *figinset_canvas;
64 extern "C" void waitalarm(int)
69 extern char **environ; // is this only redundtant on linux systems? Lgb.
70 extern void UpdateInset(Inset* inset, bool mark_dirty = true);
71 // better for asyncron updating:
72 void PutInsetIntoInsetUpdateList(Inset* inset);
73 extern void ProhibitInput();
74 extern void AllowInput();
76 #define DEG2PI 57.295779513
77 #define 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 */
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 */
88 queue *next; /* next item in queue */
92 int pid; /* pid to wait for */
93 pidwait *next; /* next */
96 #define MAXGS 3 /* maximum 3 gs's at a time */
98 static Figref **figures; /* all the figures */
99 static figdata **bitmaps; /* all the bitmaps */
100 static queue *gsqueue = 0; /* queue for ghostscripting */
101 static int gsrunning = 0; /* currently so many gs's are running */
102 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
103 static char bittable[256]; /* bit reversion table */
105 static bool gs_color; // do we allocate colors for gs?
106 static bool color_visual; // is the visual color?
107 static bool gs_xcolor = false; // allocated extended colors
108 static unsigned long gs_pixels[128]; // allocated pixels
109 static int gs_num_pixels; // number of pixels allocated
110 static int gs_spc; // shades per color
111 static bool gs_gray; // is grayscale?
112 static int gs_allcolors; // number of all colors
114 static pidwait *pw = 0; // pid wait list
117 extern FD_form_main *fd_form_main;
118 extern Colormap color_map;
120 void addpidwait(int pid)
122 // adds pid to pid wait list
123 register pidwait *p = new pidwait;
129 if (lyxerr.debugging()) {
130 lyxerr << "Pids to wait for: " << p->pid << endl;
133 lyxerr << p->pid << endl;
139 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
145 XClientMessageEvent *e = (XClientMessageEvent*) ev;
147 if(lyxerr.debugging()) {
148 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
149 << "] pm:[" << e->data.l[1] << "]" << endl;
152 // just kill gs, that way it will work for sure
153 for (i = 0; i < bmpinsref; ++i)
154 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
156 figdata *p = bitmaps[i];
159 // first update p->bitmap, if necessary
160 if (p->bitmap != None && p->flags > (1|8) && gs_color && p->wid) {
161 // query current colormap and re-render
162 // the pixmap with proper colors
164 XWindowAttributes wa;
166 int i, y, wid1, spc1 = gs_spc-1,
167 spc2 = gs_spc*gs_spc, wid = p->wid,
170 GC gc = getGC(gc_copy);
172 XGetWindowAttributes(fl_display, fl_get_canvas_id(
173 figinset_canvas), &wa);
175 if (lyxerr.debugging()) {
177 << "Starting image translation "
180 << p->wid << "x" << p->hgh
182 << " " << XYPixmap << endl;
185 // now fork rendering process
187 if (forkstat == -1) {
188 lyxerr.debug() << "Cannot fork, using slow "
189 "method for pixmap translation." << endl;
190 tmpdisp = fl_display;
191 } else if (forkstat > 0) {
193 if (lyxerr.debugging()) {
194 lyxerr << "Spawned child "
197 addpidwait(forkstat);
198 break; // in parent process
200 tmpdisp = XOpenDisplay(XDisplayName(0));
203 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
204 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
206 if (lyxerr.debugging()) {
207 lyxerr << "Got the image" << endl;
210 if (lyxerr.debugging()) {
211 lyxerr << "Error getting the image" << endl;
215 // query current colormap
216 cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
217 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
218 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
221 // now we process all the image
222 for (y = 0; y < p->hgh; ++y) {
224 for (x = 0; x < wid; ++x) {
226 pc = cmap + XGetPixel(im, x, y);
228 XPutPixel(im, x, y, gs_pixels[((pc->red+6553)*
229 spc1/65535)*spc2+((pc->green+6553)*
230 spc1/65535)*gs_spc+((pc->blue+6553)*
235 if (lyxerr.debugging()) {
236 lyxerr << "Putting image back" << endl;
238 XPutImage(tmpdisp, p->bitmap, gc, im, 0, 0,
239 0, 0, p->wid, p->hgh);
241 if (lyxerr.debugging()) {
242 lyxerr << "Done translation" << endl;
245 if (lyxerr.debugging()) {
246 lyxerr << "Killing gs "
249 kill(p->gspid, SIGHUP);
251 sprintf(tmp, "%s/~lyxgs%d.ps",
252 system_tempdir.c_str(),
256 XCloseDisplay(tmpdisp);
260 if (lyxerr.debugging()) {
261 lyxerr << "Killing gs "
264 kill(p->gspid, SIGHUP);
266 sprintf(tmp, "%s/~lyxgs%d.ps",
267 system_tempdir.c_str(),
277 static void AllocColors(int num)
278 // allocate color cube numxnumxnum, if possible
283 if (lyxerr.debugging()) {
284 lyxerr << "Allocating color cube " << num
285 << 'x' << num << 'x' << num << endl;
289 lyxerr << "Error allocating color colormap." << endl;
293 if (num > 5) num = 5;
294 for (i = 0; i < num*num*num; ++i) {
295 xcol.red = 65535*(i/(num*num))/(num-1);
296 xcol.green = 65535*((i/num) % num)/(num-1);
297 xcol.blue = 65535*(i % num)/(num-1);
298 xcol.flags = DoRed | DoGreen | DoBlue;
299 if (!XAllocColor(fl_display, color_map, &xcol)) {
300 if (i) XFreeColors(fl_display, color_map,
302 if(lyxerr.debugging()) {
303 lyxerr << "Cannot allocate color cube "
309 gs_pixels[i] = xcol.pixel;
314 gs_num_pixels = num*num*num;
318 static void AllocGrays(int num)
319 // allocate grayscale ramp
324 if (lyxerr.debugging()) {
325 lyxerr << "Allocating grayscale ramp "
330 lyxerr << "Error allocating grayscale colormap." << endl;
334 if (num > 128) num = 128;
335 for (i = 0; i < num; ++i) {
336 xcol.red = xcol.green = xcol.blue = 65535*i/(num-1);
337 xcol.flags = DoRed | DoGreen | DoBlue;
338 if (!XAllocColor(fl_display, color_map, &xcol)) {
339 if (i) XFreeColors(fl_display, color_map,
341 if (lyxerr.debugging()) {
342 lyxerr << "Cannot allocate grayscale "
348 gs_pixels[i] = xcol.pixel;
358 unsigned int i, j, k;
361 bmparrsize = figarrsize = figallocchunk;
362 figures = (Figref**) malloc(sizeof(Figref*)*figallocchunk);
363 bitmaps = (figdata**) malloc(sizeof(figdata*)*figallocchunk);
365 for (i = 0; i < 256; ++i) {
367 for (j = 0; j < 8; ++j)
368 if (i & (1 << (7-j))) k |= 1 << j;
369 bittable[i] = (char) ~k;
372 fl_add_canvas_handler(figinset_canvas, ClientMessage,
373 GhostscriptMsg, fd_form_main);
375 // now we have to init color_map
376 if (!color_map) color_map = DefaultColormap(fl_display,
377 DefaultScreen(fl_display));
378 // allocate color cube on pseudo-color display
382 vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
383 if (lyxerr.debugging()) {
384 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
385 vi->visualid, vi->c_class,
386 vi->bits_per_rgb, vi->map_entries);
388 color_visual = ( (vi->c_class == StaticColor) ||
389 (vi->c_class == PseudoColor) ||
390 (vi->c_class == TrueColor) ||
391 (vi->c_class == DirectColor) );
392 if ((vi->c_class & 1) == 0) return;
393 // now allocate colors
394 if (vi->c_class == GrayScale) {
395 // allocate grayscale
396 AllocGrays(vi->map_entries/2);
398 // allocate normal color
400 while (i*i*i*2 > vi->map_entries) --i;
403 gs_allcolors = vi->map_entries;
414 lyxerr.debug() << "Unregistering figures..." << endl;
416 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
420 lyxerr.debug() << "Freeing up the colors..." << endl;
421 XFreeColors(fl_display, color_map, gs_pixels,
423 /******????????????????? what's planes in this case ??????***/
428 int FindBmpIndex(figdata *tmpdata)
431 while (i < bmpinsref) {
432 if (bitmaps[i] == tmpdata) return i;
439 static void chpixmap(Pixmap, int, int)
441 Display* tempdisp = XOpenDisplay(XDisplayName(0));
443 // here read the pixmap and change all colors to those we
446 XCloseDisplay(tempdisp);
450 static void freefigdata(figdata *tmpdata)
455 if (tmpdata->ref) return;
457 if (tmpdata->gspid > 0) {
458 int pid = tmpdata->gspid;
460 // change Pixmap according to our allocated colormap
461 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
462 // kill ghostscript and unlink it's files
465 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
469 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
471 i = FindBmpIndex(tmpdata);
473 while (i < bmpinsref) {
474 bitmaps[i] = bitmaps[i+1];
480 static void runqueue()
482 // run queued requests for ghostscript, if any
483 if (!gsrunning && gs_color && !gs_xcolor) {
484 // here alloc all colors, so that gs will use only
485 // those we allocated for it
490 while (gsrunning < MAXGS) {
493 char tbuf[384], tbuf2[80];
498 if (!gsrunning && gs_xcolor) {
499 // de-allocate rest of colors
515 if (lyxerr.debugging()) {
516 lyxerr << "GS start error! Cannot fork." << endl;
518 p->data->broken = true;
519 p->data->reading = false;
522 if (pid == 0) { // child
523 char **env, rbuf[80], gbuf[40];
525 Display* tempdisp = XOpenDisplay(XDisplayName(0));
527 // create translation file
528 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
531 FilePtr f(tbuf, FilePtr::write);
532 fprintf(f, "gsave clippath pathbbox grestore\n"
534 "/ury exch def /urx exch def /lly exch def "
540 "%d %d translate\nend\n",
541 p->data->wid / 2.0, p->data->hgh / 2.0,
543 - (p->data->raw_wid / 2.0), -(p->data->raw_hgh / 2.0),
544 p->rx / 72.0, p->ry / 72.0,
548 // DON'T EVER remove this!!
549 f.close(); // was this all? (Lgb)
551 // gs process - set ghostview environment first
552 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
553 figinset_canvas), p->data->bitmap);
555 // now set up ghostview property on a window
556 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
557 p->data->wid, p->data->hgh);
558 //#warning BUG seems that the only bug here might be the hardcoded dpi.. Bummer!
560 if (lyxerr.debugging()) {
561 lyxerr << "Will set GHOSTVIEW property to ["
562 << tbuf << "]" << endl;
564 // wait until property is deleted if executing multiple
567 // grab server to prevent other child interfering
568 // with setting GHOSTVIEW property
569 if (lyxerr.debugging()) {
570 lyxerr << "Grabbing the server" << endl;
572 XGrabServer(tempdisp);
573 prop = XListProperties(tempdisp, fl_get_canvas_id(
574 figinset_canvas), &nprop);
578 for (i = 0; i < nprop; ++i) {
579 char *p = XGetAtomName(tempdisp, prop[i]);
580 if (strcmp(p, "GHOSTVIEW") == 0) {
586 XFree((char *)prop); /* jc: */
588 // release the server
589 XUngrabServer(tempdisp);
591 // ok, property found, we must wait until ghostscript
593 if (lyxerr.debugging()) {
594 lyxerr << "Releasing the server" << endl;
597 << "] GHOSTVIEW property"
598 " found. Waiting." << endl;
601 #warning What is this doing? (wouldn't a sleep(1); work too?')
605 signal(SIGALRM, waitalarm);
606 while (!alarmed) pause();
609 XChangeProperty(tempdisp,
610 fl_get_canvas_id(figinset_canvas),
611 XInternAtom(tempdisp, "GHOSTVIEW", false),
612 XInternAtom(tempdisp, "STRING", false),
614 (unsigned char *) tbuf,
617 switch (p->data->flags & 3) {
618 case 0: tbuf[0] = 'H'; break; // Hidden
619 case 1: tbuf[0] = 'M'; break; // Mono
620 case 2: tbuf[0] = 'G'; break; // Gray
623 tbuf[0] = 'C'; // Color
625 tbuf[0] = 'G'; // Gray
630 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
631 DefaultScreenOfDisplay(fl_display)),
634 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
635 DefaultScreenOfDisplay(fl_display)),
639 XChangeProperty(tempdisp,
640 fl_get_canvas_id(figinset_canvas),
641 XInternAtom(tempdisp, "GHOSTVIEW_COLORS", false),
642 XInternAtom(tempdisp, "STRING", false),
644 (unsigned char *) tbuf,
646 XUngrabServer(tempdisp);
648 if (lyxerr.debugging()) {
649 lyxerr << "Releasing the server" << endl;
651 XCloseDisplay(tempdisp);
653 // set up environment
654 while (environ[ne]) ++ne;
655 env = (char **) malloc(sizeof(char*)*(ne+2));
657 memcpy(&env[1], environ, sizeof(char*)*(ne+1));
660 // now make gs command
662 // close(1); do NOT close. If GS writes out
663 // errors it would hang. (Matthias 290596)
664 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
665 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
666 // now chdir into dir with .eps file, to be on the safe
668 chdir(OnlyPath(p->data->fname).c_str());
669 // make temp file name
670 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
672 if (lyxerr.debugging()) {
673 printf("starting gs %s %s, pid: %d\n", tbuf,
674 p->data->fname.c_str(), int(getpid()));
677 int err = execlp(lyxrc->ps_command.c_str(),
678 lyxrc->ps_command.c_str(),
680 "-dNOPAUSE", "-dQUIET",
683 p->data->fname.c_str(),
684 "showpage.ps", "quit.ps", "-", 0);
685 // if we are still there, an error occurred.
686 lyxerr << "Error executing ghostscript. "
687 << "Code: " << err << endl;
688 lyxerr.debug() << "Cmd: "
692 << p->data->fname << endl;
695 // normal process (parent)
696 if (lyxerr.debugging()) {
697 lyxerr << "GS [" << pid << "] started" << endl;
699 gsqueue = gsqueue->next;
701 p->data->gspid = pid;
707 static void addwait(int psx, int psy, int pswid, int pshgh, figdata *data)
709 // recompute the stuff and put in the queue
714 p->rx = ((float)data->raw_wid*72)/pswid;
715 p->ry = ((float)data->raw_hgh*72)/pshgh;
720 // now put into queue
722 if (!gsqueue) gsqueue = p;
724 while (p2->next) p2 = p2->next;
728 // if possible, run the queue
733 static figdata *getfigdata(int wid, int hgh, string const & fname,
734 int psx, int psy, int pswid, int pshgh,
735 int raw_wid, int raw_hgh, float angle, char flags)
737 /* first search for an exact match with fname and width/height */
740 XWindowAttributes wa;
742 if (fname.empty()) return 0;
744 while (i < bmpinsref) {
745 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
746 bitmaps[i]->flags == flags && bitmaps[i]->fname==fname &&
747 bitmaps[i]->angle == angle) {
753 /* not found -> create new record or return 0 if no record */
755 if (bmpinsref > bmparrsize) {
756 // allocate more space
757 bmparrsize += figallocchunk;
758 figdata **tmp = (figdata**) malloc(sizeof(figdata*)*bmparrsize);
759 memcpy(tmp, bitmaps, sizeof(figdata*)*(bmparrsize-figallocchunk));
764 bitmaps[bmpinsref-1] = p;
767 p->raw_wid = raw_wid;
768 p->raw_hgh = raw_hgh;
772 XGetWindowAttributes(fl_display, fl_get_canvas_id(
773 figinset_canvas), &wa);
775 if (lyxerr.debugging()) {
776 lyxerr << "Create pixmap disp:" << fl_display
777 << " scr:" << DefaultScreen(fl_display)
780 << " depth:" << wa.depth << endl;
788 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
789 figinset_canvas), wid, hgh, wa.depth);
791 // initialize reading of .eps file with correct sizes and stuff
792 addwait(psx, psy, pswid, pshgh, p);
803 static void getbitmap(figdata *p)
809 static void makeupdatelist(figdata *p)
813 for (i = 0; i < figinsref; ++i) if (figures[i]->data == p) {
814 if (lyxerr.debugging()) {
815 lyxerr << "Updating inset " << figures[i]->inset
818 //UpdateInset(figures[i]->inset);
819 // add inset figures[i]->inset into to_update list
820 PutInsetIntoInsetUpdateList(figures[i]->inset);
825 void sigchldchecker(pid_t pid, int *status)
830 bool pid_handled = false;
832 lyxerr.debug() << "Got pid = " << pid << endl;
834 for (i = bmpinsref - 1; i >= 0; --i) {
835 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
836 lyxerr.debug() << "Found pid in bitmaps" << endl;
837 // now read the file and remove it from disk
840 if (bitmaps[i]->gsdone) *status = 0;
842 lyxerr.debug() << "GS [" << pid
843 << "] exit OK." << endl;
845 lyxerr << "GS [" << pid << "] error "
847 << WIFEXITED(*status)
848 << " " << WEXITSTATUS(*status)
849 << " S:" << WIFSIGNALED(*status)
850 << " " << WTERMSIG(*status) << endl;
853 bitmap_waiting = true;
856 // remove temporary files
858 sprintf(tmp, "%s/~lyxgs%d.ps",
859 system_tempdir.c_str(),
865 makeupdatelist(bitmaps[i]);
872 lyxerr.debug() << "Checking pid in pidwait" << endl;
873 pidwait *p = pw, *prev = 0;
876 lyxerr.debug() << "Found pid in pidwait" << endl;
877 lyxerr.debug() << "Caught child pid of recompute routine " << pid << endl;
879 prev->next = p->next;
891 lyxerr.debug() << "waitpid error" << endl;
894 lyxerr << "The process or process group specified by "
895 "pid does not exist or is not a child of "
896 "the calling process or can never be in the "
897 "states specified by options." << endl;
900 lyxerr << "waitpid() was interrupted due to the "
901 "receipt of a signal sent by the calling "
905 lyxerr << "An invalid value was specified for "
909 lyxerr << "Unknown error from waitpid" << endl;
912 } else if (pid == 0) {
913 lyxerr << "waitpid nohang" << endl;;
915 lyxerr.debug() << "normal exit from childhandler" << endl;
920 static void getbitmaps()
923 bitmap_waiting = false;
924 for (i = 0; i < bmpinsref; ++i)
925 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
926 getbitmap(bitmaps[i]);
930 static void RegisterFigure(InsetFig *fi)
934 if (figinsref == 0) InitFigures();
937 if (figinsref > figarrsize) {
938 // allocate more space
939 figarrsize += figallocchunk;
940 Figref **tmp = (Figref**) malloc(sizeof(Figref*)*figarrsize);
941 memcpy(tmp, figures, sizeof(Figref*)*(figarrsize-figallocchunk));
948 figures[figinsref-1] = tmpfig;
951 if (lyxerr.debugging()) {
952 lyxerr << "Register Figure: buffer:["
953 << current_view->currentBuffer() << "]" << endl;
958 int FindFigIndex(Figref *tmpfig)
961 while (i < figinsref) {
962 if (figures[i] == tmpfig) return i;
969 static void UnregisterFigure(InsetFig *fi)
971 Figref *tmpfig = fi->figure;
974 if (tmpfig->data) freefigdata(tmpfig->data);
975 if (tmpfig->inset->form) {
976 if (tmpfig->inset->form->Figure->visible) {
977 fl_set_focus_object(tmpfig->inset->form->Figure,
978 tmpfig->inset->form->OkBtn);
979 fl_hide_form(tmpfig->inset->form->Figure);
981 #if FL_REVISION == 89
982 #warning Reactivate this free_form calls
984 #if FL_REVISION != 89
985 fl_free_form(tmpfig->inset->form->Figure);
986 free(tmpfig->inset->form);
987 tmpfig->inset->form = 0;
990 i = FindFigIndex(tmpfig);
992 while (i < figinsref) {
993 figures[i] = figures[i+1];
998 if (figinsref == 0) DoneFigures();
1002 static char* NextToken(FILE *myfile)
1008 if (!feof(myfile)) {
1009 token = new char[256];
1013 } while (!feof(myfile) && !isspace(c));
1015 token[i-1]='\0'; /* just the end of a command */
1021 InsetFig::InsetFig(int tmpx, int tmpy, Buffer *o)
1031 psubfigure = subfigure = false;
1032 xwid = xhgh = angle = 0;
1033 raw_wid = raw_hgh = 0;
1034 changedfname = false;
1035 RegisterFigure(this);
1039 InsetFig::~InsetFig()
1041 if (lyxerr.debugging()) {
1042 lyxerr << "Figure destructor called" << endl;
1044 UnregisterFigure(this);
1048 int InsetFig::Ascent(LyXFont const&) const
1054 int InsetFig::Descent(LyXFont const&) const
1060 int InsetFig::Width(LyXFont const&) const
1066 void InsetFig::Draw(LyXFont font, LyXScreen &scr, int baseline, float &x)
1068 if (bitmap_waiting) getbitmaps();
1070 // I wish that I didn't have to use this
1071 // but the figinset code is so complicated so
1072 // I don't want to fiddle with it now.
1073 unsigned long pm = scr.getForeground();
1075 if (figure && figure->data && figure->data->bitmap &&
1076 !figure->data->reading && !figure->data->broken) {
1078 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1079 0, 0, wid, hgh, int(x+1), baseline-hgh);
1081 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1082 int(x), baseline - hgh - 1,
1087 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1089 baseline - hgh - 1, wid+1, hgh+1);
1090 if (figure && figure->data) {
1091 if (figure->data->broken) msg = _("[render error]");
1092 else if (figure->data->reading) msg = _("[rendering ... ]");
1094 if (fname.empty()) msg = _("[no file]");
1095 else if ((flags & 3) == 0) msg = _("[not displayed]");
1096 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1098 if (!msg) msg = _("[unknown error]");
1100 font.setFamily (LyXFont::SANS_FAMILY);
1101 font.setSize (LyXFont::SIZE_FOOTNOTE);
1102 string justname = OnlyFilename (fname);
1103 font.drawString(justname,pm,
1104 baseline - font.maxAscent() - 4,
1106 font.setSize (LyXFont::SIZE_TINY);
1107 font.drawText (msg, strlen(msg),pm,
1112 x += Width(font); // ?
1116 void InsetFig::Write(FILE *file)
1119 fprintf(file, "Figure size %d %d\n", wid, hgh);
1120 if (!fname.empty()) {
1121 string buf1 = OnlyPath(owner->getFileName());
1122 string fname2 = MakeRelPath(fname, buf1);
1123 fprintf(file, "file %s\n", fname2.c_str());
1125 if (!subcaption.empty())
1126 fprintf(file, "subcaption %s\n", subcaption.c_str());
1127 if (wtype) fprintf(file, "width %d %g\n", wtype, xwid);
1128 if (htype) fprintf(file, "height %d %g\n", htype, xhgh);
1129 if (angle != 0) fprintf(file, "angle %g\n", angle);
1130 fprintf(file, "flags %d\n", flags);
1131 if (subfigure) fprintf(file, "subfigure\n");
1135 void InsetFig::Read(LyXLex &lex)
1138 bool finished = false;
1140 while (lex.IsOK() && !finished) {
1143 string const token = lex.GetString();
1144 lyxerr.debug() << "Token: " << token << endl;
1148 else if (token == "\\end_inset") {
1150 } else if (token == "file") {
1152 buf = lex.GetString();
1153 string buf1 = OnlyPath(owner->getFileName());
1154 fname = MakeAbsPath(buf, buf1);
1155 changedfname = true;
1157 } else if (token == "extra") {
1159 // kept for backwards compability. Delete in 0.13.x
1160 } else if (token == "subcaption") {
1162 subcaption = lex.GetString();
1163 } else if (token == "label") {
1165 // kept for backwards compability. Delete in 0.13.x
1166 } else if (token == "angle") {
1168 angle = lex.GetFloat();
1169 } else if (token == "size") {
1171 wid = lex.GetInteger();
1173 hgh = lex.GetInteger();
1174 } else if (token == "flags") {
1176 flags = pflags = lex.GetInteger();
1177 } else if (token == "subfigure") {
1178 subfigure = psubfigure = true;
1179 } else if (token == "width") {
1182 typ = lex.GetInteger();
1184 xwid = lex.GetFloat();
1186 case DEF: wtype = DEF; break;
1187 case CM: wtype = CM; break;
1188 case IN: wtype = IN; break;
1189 case PER_PAGE: wtype = PER_PAGE; break;
1190 case PER_COL: wtype = PER_COL; break;
1192 lyxerr.debug() << "Unknown type!" << endl;
1196 } else if (token == "height") {
1199 typ = lex.GetInteger();
1201 xhgh = lex.GetFloat();
1203 case DEF: htype = DEF; break;
1204 case CM: htype = CM; break;
1205 case IN: htype = IN; break;
1206 case PER_PAGE: htype = PER_PAGE; break;
1208 lyxerr.debug() << "Unknown type!" << endl;
1219 int InsetFig::Latex(FILE *file, signed char /* fragile*/ )
1222 if (!cmd.empty()) fprintf(file, "%s ", cmd.c_str());
1227 int InsetFig::Latex(string &file, signed char /* fragile*/ )
1235 int InsetFig::Linuxdoc(string &/*file*/)
1241 int InsetFig::DocBook(string &file)
1243 string figurename=fname;
1245 if(suffixIs(figurename, ".eps"))
1246 figurename.erase(fname.length() - 5);
1248 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1253 void InsetFig::Validate(LaTeXFeatures &features) const
1255 features.graphics = true;
1256 if (subfigure) features.subfigure = true;
1260 unsigned char InsetFig::Editable() const
1266 bool InsetFig::Deletable() const
1272 void InsetFig::Edit(int, int)
1274 lyxerr.debug() << "Editing InsetFig." << endl;
1277 // We should have RO-versions of the form instead.
1278 // The actual prevention of altering a readonly doc
1279 // is done in CallbackFig()
1280 if(current_view->currentBuffer()->isReadonly())
1284 form = create_form_Figure();
1285 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1286 fl_set_object_return(form->Angle,FL_RETURN_ALWAYS);
1287 fl_set_object_return(form->Width,FL_RETURN_ALWAYS);
1288 fl_set_object_return(form->Height,FL_RETURN_ALWAYS);
1291 if (form->Figure->visible) {
1292 fl_raise_form(form->Figure);
1294 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1295 FL_FULLBORDER, _("Figure"));
1300 Inset *InsetFig::Clone()
1302 InsetFig *tmp = new InsetFig(100, 100, owner);
1304 if (lyxerr.debugging()) {
1305 lyxerr << "Clone Figure: buffer:["
1306 << current_view->currentBuffer()
1307 << "], cbuffer:[xx]" << endl;
1312 tmp->raw_wid = raw_wid;
1313 tmp->raw_hgh = raw_hgh;
1318 tmp->pflags = pflags;
1319 tmp->subfigure = subfigure;
1320 tmp->psubfigure = psubfigure;
1328 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1329 // do not display if there is "do not display" chosen (Matthias 260696)
1330 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1331 pswid, pshgh, raw_wid, raw_hgh,
1332 angle, flags & (3|8));
1333 } else tmp->figure->data = 0;
1334 tmp->subcaption = subcaption;
1335 tmp->changedfname = false;
1342 Inset::Code InsetFig::LyxCode() const
1344 return Inset::GRAPHICS_CODE;
1348 void InsetFig::Regenerate()
1352 string resizeW, resizeH;
1353 string rotate, recmd;
1355 if (fname.empty()) {
1356 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1357 cmd += _("empty figure path");
1359 //if (form) fl_set_object_label(form->cmd, "");
1363 string buf1 = OnlyPath(owner->getFileName());
1364 string fname2 = MakeRelPath(fname, buf1);
1366 gcmd = "\\includegraphics{" + fname2 + '}';
1371 case CM:{// \resizebox*{h-length}{v-length}{text}
1373 sprintf(buf, "%g", xwid); // should find better
1380 sprintf(buf, "%g", xwid);
1387 sprintf(buf, "%g", xwid/100);
1389 resizeW += "\\textwidth";
1394 sprintf(buf, "%g", xwid/100);
1396 resizeW += "\\columnwidth";
1406 sprintf(buf, "%g", xhgh);
1413 sprintf(buf, "%g", xhgh);
1420 sprintf(buf, "%g", xhgh/100);
1422 resizeH += "\\textheight";
1426 // Doesn't occur; case exists to suppress compiler warnings.
1431 if (!resizeW.empty() || !resizeH.empty()) {
1432 recmd = "\\resizebox*{";
1433 if (!resizeW.empty())
1438 if (!resizeH.empty())
1448 sprintf(buf, "%g", angle);
1449 // \rotatebox{angle}{text}
1450 rotate = "\\rotatebox{";
1458 if (!rotate.empty()) cmdbuf += '}';
1459 if (!recmd.empty()) cmdbuf += '}';
1461 if (!subcaption.empty())
1462 cmdbuf = "\\subfigure[" + subcaption +
1463 "]{" + cmdbuf + "}";
1465 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1470 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1474 void InsetFig::TempRegenerate()
1478 string resizeW, resizeH;
1479 string rotate, recmd;
1482 char const *tfname; // *textra;
1483 float tangle, txwid, txhgh;
1485 tfname = fl_get_input(form->EpsFile);
1486 tsubcap = fl_get_input(form->Subcaption);
1487 tangle = atof(fl_get_input(form->Angle));
1488 txwid = atof(fl_get_input(form->Width));
1489 txhgh = atof(fl_get_input(form->Height));
1491 if (!tfname || !*tfname) {
1492 //fl_set_object_label(form->cmd, "");
1493 //fl_redraw_object(form->cmd);
1494 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1495 cmd += _("empty figure path");
1500 string buf1 = OnlyPath(owner->getFileName());
1501 string fname2 = MakeRelPath(tfname, buf1);
1502 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1503 gcmd = "\\includegraphics{" + fname2 + '}';
1508 case CM: {// \resizebox*{h-length}{v-length}{text}
1510 sprintf(buf, "%g", txwid); // should find better
1517 sprintf(buf, "%g", txwid);
1524 sprintf(buf, "%g", txwid/100);
1526 resizeW += "\\textwidth";
1531 sprintf(buf, "%g", txwid/100);
1533 resizeW += "\\columnwidth";
1543 sprintf(buf, "%g", txhgh);
1550 sprintf(buf, "%g", txhgh);
1557 sprintf(buf, "%g", txhgh/100);
1559 resizeH += "\\textheight";
1563 // Doesn't occur; case exists to suppress compiler warnings.
1568 // \resizebox*{h-length}{v-length}{text}
1569 if (!resizeW.empty() || !resizeH.empty()) {
1570 recmd = "\\resizebox*{";
1571 if (!resizeW.empty())
1576 if (!resizeH.empty())
1585 sprintf(buf, "%g", tangle);
1586 // \rotatebox{angle}{text}
1587 rotate = "\\rotatebox{";
1595 if (!rotate.empty()) cmdbuf += '}';
1596 if (!recmd.empty()) cmdbuf += '}';
1597 if (psubfigure && !tsubcap.empty()) {
1598 cmdbuf = string("\\subfigure{") + tsubcap
1599 + string("}{") + cmdbuf + "}";
1603 //fl_set_object_label(form->cmd, cmdbuf.c_str());
1604 //fl_redraw_object(form->cmd);
1608 void InsetFig::Recompute()
1610 bool changed = changedfname;
1611 int newx, newy, nraw_x, nraw_y, frame_wid, frame_hgh;
1614 if (changed) GetPSSizes();
1616 sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1617 cos_a = cos (angle / DEG2PI);
1618 frame_wid = (int) ceil (fabs(cos_a * pswid) + fabs(sin_a * pshgh));
1619 frame_hgh= (int) ceil (fabs(cos_a * pshgh) + fabs(sin_a * pswid));
1621 /* now recompute wid and hgh, and if that is changed, set changed */
1622 /* this depends on chosen size of the picture and its bbox */
1623 // This will be redone in 0.13 ... (hen)
1624 if (!fname.empty()) {
1625 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1633 newx = (int) (28.346*xwid);
1636 newx = (int) (72*xwid);
1638 case PER_PAGE: /* % of page */
1639 newx = (int) (5.95*xwid);
1641 case PER_COL: /* % of col */
1642 newx = (int) (2.975*xwid);
1646 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1650 //lyxerr << "This should not happen!" << endl;
1653 newy = (int) (28.346*xhgh);
1656 newy = (int) (72*xhgh);
1658 case PER_PAGE: /* % of page */
1659 newy = (int) (8.42*xhgh);
1662 // Doesn't occur; case exists to suppress
1663 // compiler warnings.
1666 if (htype && !wtype && frame_hgh) newx = newy*frame_wid/frame_hgh;
1675 nraw_x = (int) ((1.0 * pswid * newx)/frame_wid);
1680 nraw_y = (int) ((1.0 * pshgh * newy)/frame_hgh);
1682 // cannot be zero, actually, set it to some minimum, so its clickable
1683 if (newx < 5) newx = 5;
1684 if (newy < 5) newy = 5;
1686 if (newx != wid || newy != hgh ||
1687 nraw_x != raw_wid || nraw_y != raw_hgh ||
1688 flags != pflags || subfigure != psubfigure)
1696 subfigure = psubfigure;
1699 figdata *pf = figure->data;
1702 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1703 // do not display if there is "do not display"
1704 // chosen (Matthias 260696)
1705 figure->data = getfigdata(wid, hgh, fname,
1706 psx, psy, pswid, pshgh,
1708 angle, flags & (3|8));
1709 } else figure->data = 0;
1711 // free the old data
1712 if (pf) freefigdata(pf);
1715 changedfname = false;
1719 void InsetFig::GetPSSizes()
1721 /* get %%BoundingBox: from postscript file */
1725 /* defaults to associated size
1726 * ..just in case the PS-file is not readable (Henner,24-Aug-97)
1733 if (fname.empty()) return;
1735 FilePtr f(fname, FilePtr::read);
1737 if (!f()) return; // file not found !!!!
1739 /* defaults to A4 page */
1745 lastchar = fgetc(f);
1749 lyxerr.debug() << "End of (E)PS file reached and"
1750 " no BoundingBox!" << endl;
1753 if (c == '%' && lastchar == '%') {
1756 if (strcmp(p, "EndComments") == 0) break;
1757 if (strcmp(p, "BoundingBox:") == 0) {
1758 float fpsx, fpsy, fpswid, fpshgh;
1759 if (fscanf(f, "%f %f %f %f", &fpsx, &fpsy,
1760 &fpswid, &fpshgh) == 4) {
1763 pswid = (int) fpswid;
1764 pshgh = (int) fpshgh;
1767 if (lyxerr.debugging()) {
1768 lyxerr << "%%%%BoundingBox:"
1789 void InsetFig::CallbackFig(long arg)
1794 if (lyxerr.debugging()) {
1795 printf("Figure callback, arg %ld\n", arg);
1801 case 12: /* width type */
1808 fl_deactivate_object(form->Width);
1813 fl_activate_object(form->Width);
1818 fl_activate_object(form->Width);
1823 fl_activate_object(form->Width);
1828 fl_activate_object(form->Width);
1831 lyxerr.debug() << "Unknown type!" << endl;
1838 case 22: /* height type */
1844 fl_deactivate_object(form->Height);
1849 fl_activate_object(form->Height);
1854 fl_activate_object(form->Height);
1859 fl_activate_object(form->Height);
1862 lyxerr.debug() << "Unknown type!" << endl;
1868 pflags = pflags & ~3; /* wysiwyg0 */
1871 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1874 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1877 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1880 pflags ^= 4; /* frame */
1883 pflags ^= 8; /* do translations */
1886 psubfigure = !psubfigure; /* This is a subfigure */
1889 regen = true; /* regenerate command */
1891 case 0: /* browse file */
1895 case 1: /* preview */
1896 p = fl_get_input(form->EpsFile);
1900 case 8: /* ok (apply and close) */
1901 if(!current_view->currentBuffer()->isReadonly())
1905 xwid = atof(fl_get_input(form->Width));
1906 xhgh = atof(fl_get_input(form->Height));
1907 angle = atof(fl_get_input(form->Angle));
1908 p = fl_get_input(form->EpsFile);
1910 string buf1 = OnlyPath(owner->getFileName());
1911 fname = MakeAbsPath(p, buf1);
1912 changedfname = true;
1914 if (!fname.empty()) {
1915 changedfname = true;
1919 subcaption = fl_get_input(form->Subcaption);
1923 /* now update inset */
1924 if (lyxerr.debugging()) {
1925 lyxerr << "Update: ["
1926 << wid << 'x' << hgh << ']' << endl;
1930 fl_set_focus_object(form->Figure, form->OkBtn);
1931 fl_hide_form(form->Figure);
1932 #if FL_REVISION == 89
1933 #warning Reactivate this free_form calls
1935 #if FL_REVISION != 89
1936 fl_free_form(form->Figure);
1943 // The user has already been informed about RO in ::Edit
1944 if(arg == 7) // if 'Apply'
1947 case 9: /* cancel = restore and close */
1948 fl_set_focus_object(form->Figure, form->OkBtn);
1949 fl_hide_form(form->Figure);
1950 #if FL_REVISION == 89
1951 #warning Reactivate this free_form calls
1953 #if FL_REVISION != 89
1954 fl_free_form(form->Figure);
1961 if (regen) TempRegenerate();
1964 inline void DisableFigurePanel(FD_Figure * const form)
1966 fl_deactivate_object(form->EpsFile);
1967 fl_deactivate_object(form->Browse);
1968 fl_deactivate_object(form->Width);
1969 fl_deactivate_object(form->Height);
1970 fl_deactivate_object(form->Frame);
1971 fl_deactivate_object(form->Translations);
1972 fl_deactivate_object(form->Angle);
1973 fl_deactivate_object(form->HeightGrp);
1974 fl_deactivate_object(form->page2);
1975 fl_deactivate_object(form->Default2);
1976 fl_deactivate_object(form->cm2);
1977 fl_deactivate_object(form->in2);
1978 fl_deactivate_object(form->HeightLabel);
1979 fl_deactivate_object(form->WidthLabel);
1980 fl_deactivate_object(form->DisplayGrp);
1981 fl_deactivate_object(form->Wysiwyg3);
1982 fl_deactivate_object(form->Wysiwyg0);
1983 fl_deactivate_object(form->Wysiwyg2);
1984 fl_deactivate_object(form->Wysiwyg1);
1985 fl_deactivate_object(form->WidthGrp);
1986 fl_deactivate_object(form->Default1);
1987 fl_deactivate_object(form->cm1);
1988 fl_deactivate_object(form->in1);
1989 fl_deactivate_object(form->page1);
1990 fl_deactivate_object(form->column1);
1991 fl_deactivate_object(form->Subcaption);
1992 fl_deactivate_object(form->Subfigure);
1993 fl_deactivate_object (form->OkBtn);
1994 fl_deactivate_object (form->ApplyBtn);
1995 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1996 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1999 inline void EnableFigurePanel(FD_Figure * const form)
2001 fl_activate_object(form->EpsFile);
2002 fl_activate_object(form->Browse);
2003 fl_activate_object(form->Width);
2004 fl_activate_object(form->Height);
2005 fl_activate_object(form->Frame);
2006 fl_activate_object(form->Translations);
2007 fl_activate_object(form->Angle);
2008 fl_activate_object(form->HeightGrp);
2009 fl_activate_object(form->page2);
2010 fl_activate_object(form->Default2);
2011 fl_activate_object(form->cm2);
2012 fl_activate_object(form->in2);
2013 fl_activate_object(form->HeightLabel);
2014 fl_activate_object(form->WidthLabel);
2015 fl_activate_object(form->DisplayGrp);
2016 fl_activate_object(form->Wysiwyg3);
2017 fl_activate_object(form->Wysiwyg0);
2018 fl_activate_object(form->Wysiwyg2);
2019 fl_activate_object(form->Wysiwyg1);
2020 fl_activate_object(form->WidthGrp);
2021 fl_activate_object(form->Default1);
2022 fl_activate_object(form->cm1);
2023 fl_activate_object(form->in1);
2024 fl_activate_object(form->page1);
2025 fl_activate_object(form->column1);
2026 fl_activate_object(form->Subcaption);
2027 fl_activate_object(form->Subfigure);
2028 fl_activate_object (form->OkBtn);
2029 fl_activate_object (form->ApplyBtn);
2030 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2031 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2034 void InsetFig::RestoreForm()
2039 EnableFigurePanel(form);
2042 fl_set_button(form->Default1, (wtype == 0));
2043 fl_set_button(form->cm1, (wtype == 1));
2044 fl_set_button(form->in1, (wtype == 2));
2045 fl_set_button(form->page1, (wtype == 3));
2046 fl_set_button(form->column1, (wtype == 4));
2048 fl_deactivate_object(form->Width);
2050 fl_activate_object(form->Width);
2053 // enable and disable should be put here.
2055 fl_set_button(form->Default2, (htype == 0));
2056 fl_set_button(form->cm2, (htype == 1));
2057 fl_set_button(form->in2, (htype == 2));
2058 fl_set_button(form->page2, (htype == 3));
2059 // enable and disable should be put here.
2061 fl_deactivate_object(form->Height);
2063 fl_activate_object(form->Height);
2067 fl_set_button(form->Wysiwyg0, (pflags == 0));
2068 fl_set_button(form->Wysiwyg1, (pflags == 1));
2069 fl_set_button(form->Wysiwyg2, (pflags == 2));
2070 fl_set_button(form->Wysiwyg3, (pflags == 3));
2071 fl_set_button(form->Frame, ((flags & 4) != 0));
2072 fl_set_button(form->Translations, ((flags & 8) != 0));
2073 fl_set_button(form->Subfigure, (subfigure != 0));
2075 psubfigure = subfigure;
2076 sprintf(buf, "%g", xwid);
2077 fl_set_input(form->Width, buf);
2078 sprintf(buf, "%g", xhgh);
2079 fl_set_input(form->Height, buf);
2080 sprintf(buf, "%g", angle);
2081 fl_set_input(form->Angle, buf);
2082 if (!fname.empty()){
2083 string buf1 = OnlyPath(owner->getFileName());
2084 string fname2 = MakeRelPath(fname, buf1);
2085 fl_set_input(form->EpsFile, fname2.c_str());
2087 else fl_set_input(form->EpsFile, "");
2088 fl_set_input(form->Subcaption, subcaption.c_str());
2089 if(current_view->currentBuffer()->isReadonly())
2090 DisableFigurePanel(form);
2096 void InsetFig::Preview(char const *p)
2103 lyxerr << "Cannot fork process!" << endl;
2108 return; // parent process
2111 string buf1 = OnlyPath(owner->getFileName());
2112 string buf2 = MakeAbsPath(p, buf1);
2114 lyxerr << "Error during rendering "
2115 << execlp(lyxrc->view_pspic_command.c_str(),
2116 lyxrc->view_pspic_command.c_str(),
2123 void InsetFig::BrowseFile()
2125 string buf, buf2, bufclip;
2126 static string current_figure_path;
2127 static int once = 0;
2130 if (lyxerr.debugging()) {
2131 lyxerr << "Filename: "
2132 << owner->getFileName() << endl;
2134 string p = fl_get_input(form->EpsFile);
2136 buf = MakeAbsPath(owner->getFileName());
2137 buf2 = OnlyPath(buf);
2139 buf = MakeAbsPath(p, buf2);
2140 buf = OnlyPath(buf);
2142 buf = OnlyPath(owner->getFileName().c_str());
2145 // Does user clipart directory exist?
2146 bufclip = AddName (user_lyxdir, "clipart");
2147 FileInfo fileInfo(bufclip);
2148 if (!(fileInfo.isOK() && fileInfo.isDir()))
2149 // No - bail out to system clipart directory
2150 bufclip = AddName (system_lyxdir, "clipart");
2153 fileDlg.SetButton(0, _("Clipart"), bufclip);
2154 fileDlg.SetButton(1, _("Document"), buf);
2160 p =fileDlg.Select(_("EPS Figure"), current_figure_path,
2163 p = fileDlg.Select(_("EPS Figure"), buf,
2168 if (p.empty()) return;
2170 buf = MakeRelPath(p, buf2);
2171 current_figure_path = OnlyPath(p);
2174 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2175 || contains(p, "%") || contains(p, " "))
2177 WriteAlert(_("Filename can't contain any of these characters:"), // xgettext:no-c-format
2178 _("space, '#', '~', '$' or '%'."));
2183 if (form) fl_set_input(form->EpsFile, buf.c_str());
2187 void GraphicsCB(FL_OBJECT *obj, long arg)
2189 /* obj->form contains the form */
2191 if (lyxerr.debugging()) {
2192 lyxerr << "GraphicsCB callback: " << arg << endl;
2195 /* find inset we were reacting to */
2196 for (int i = 0; i < figinsref; ++i)
2197 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2200 if (lyxerr.debugging()) {
2201 lyxerr << "Calling back figure " << i << endl;
2203 figures[i]->inset->CallbackFig(arg);
2209 void HideFiguresPopups()
2211 for (int i = 0; i < figinsref; ++i)
2212 if (figures[i]->inset->form
2213 && figures[i]->inset->form->Figure->visible) {
2214 if (lyxerr.debugging()) {
2215 lyxerr << "Hiding figure " << i << endl;
2217 // hide and free the form
2218 figures[i]->inset->CallbackFig(9);