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
51 #include "support/filetools.h"
52 #include "LyXView.h" // just because of form_main
55 #include "LaTeXFeatures.h"
58 #include "lyx_gui_misc.h" // CancelCloseBoxCB
59 #include "support/FileInfo.h"
60 #include "support/lyxlib.h"
62 extern BufferView * current_view;
64 static volatile bool alarmed;
66 extern FL_OBJECT * figinset_canvas;
69 extern "C" void waitalarm(int)
75 extern char ** environ; // is this only redundtant on linux systems? Lgb.
76 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
77 // better for asyncron updating:
78 void PutInsetIntoInsetUpdateList(Inset * inset);
79 extern void ProhibitInput();
80 extern void AllowInput();
82 static float const DEG2PI = 57.295779513;
83 static int const figallocchunk = 32;
85 static int figinsref = 0; /* number of figures */
86 static int figarrsize = 0; /* current max number of figures */
87 static int bmpinsref = 0; /* number of bitmaps */
88 static int bmparrsize = 0; /* current max number of bitmaps */
91 float rx, ry; /* resolution x and y */
92 int ofsx, ofsy; /* x and y translation */
93 figdata * data; /* we are doing it for this data */
94 queue * next; /* next item in queue */
98 int pid; /* pid to wait for */
99 pidwait * next; /* next */
102 static int const MAXGS = 3; /* maximum 3 gs's at a time */
104 static Figref ** figures; /* all the figures */
105 static figdata ** bitmaps; /* all the bitmaps */
106 static queue * gsqueue = 0; /* queue for ghostscripting */
107 static int gsrunning = 0; /* currently so many gs's are running */
108 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
109 static char bittable[256]; /* bit reversion table */
111 static bool gs_color; // do we allocate colors for gs?
112 static bool color_visual; // is the visual color?
113 static bool gs_xcolor = false; // allocated extended colors
114 static unsigned long gs_pixels[128]; // allocated pixels
115 static int gs_num_pixels; // number of pixels allocated
116 static int gs_spc; // shades per color
117 static bool gs_gray; // is grayscale?
118 static int gs_allcolors; // number of all colors
120 static pidwait * pw = 0; // pid wait list
123 extern Colormap color_map;
125 void addpidwait(int pid)
127 // adds pid to pid wait list
128 register pidwait * p = new pidwait;
134 if (lyxerr.debugging()) {
135 lyxerr << "Pids to wait for: " << p->pid << endl;
138 lyxerr << p->pid << endl;
144 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
149 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
151 if(lyxerr.debugging()) {
152 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
153 << "] pm:[" << e->data.l[1] << "]" << endl;
156 // just kill gs, that way it will work for sure
157 // This loop looks like S**T so it probably is...
158 for (int i = 0; i < bmpinsref; ++i)
159 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
161 figdata * p = bitmaps[i];
164 // first update p->bitmap, if necessary
165 if (p->bitmap != None
166 && p->flags > (1|8) && gs_color && p->wid) {
167 // query current colormap and re-render
168 // the pixmap with proper colors
170 XWindowAttributes wa;
171 register XImage * im;
172 int i, y, wid1, spc1 = gs_spc-1,
173 spc2 = gs_spc * gs_spc, wid = p->wid,
176 GC gc = getGC(gc_copy);
178 XGetWindowAttributes(fl_display,
183 if (lyxerr.debugging()) {
184 lyxerr << "Starting image translation "
187 << p->wid << "x" << p->hgh
189 << " " << XYPixmap << endl;
191 // now fork rendering process
193 if (forkstat == -1) {
195 << "Cannot fork, using slow "
196 "method for pixmap translation." << endl;
197 tmpdisp = fl_display;
198 } else if (forkstat > 0) {
200 if (lyxerr.debugging()) {
201 lyxerr << "Spawned child "
204 addpidwait(forkstat);
205 break; // in parent process
207 tmpdisp = XOpenDisplay(XDisplayName(0));
210 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
211 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
213 if (lyxerr.debugging()) {
214 lyxerr << "Got the image" << endl;
217 if (lyxerr.debugging()) {
218 lyxerr << "Error getting the image" << endl;
223 // query current colormap
224 //cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
225 XColor * cmap = new XColor[gs_allcolors];
226 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
227 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
230 // now we process all the image
231 for (y = 0; y < p->hgh; ++y) {
232 for (int x = 0; x < wid; ++x) {
237 gs_pixels[((pc->red+6553)*
238 spc1/65535)*spc2+((pc->green+6553)*
239 spc1/65535)*gs_spc+((pc->blue+6553)*
244 // This must be correct.
246 if (lyxerr.debugging()) {
247 lyxerr << "Putting image back"
250 XPutImage(tmpdisp, p->bitmap,
252 0, 0, p->wid, p->hgh);
254 if (lyxerr.debugging()) {
255 lyxerr << "Done translation"
260 if (lyxerr.debugging()) {
261 lyxerr << "Killing gs "
264 lyx::kill(p->gspid, SIGHUP);
266 sprintf(tmp, "%s/~lyxgs%d.ps",
267 system_tempdir.c_str(),
271 XCloseDisplay(tmpdisp);
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(),
292 static void AllocColors(int num)
293 // allocate color cube numxnumxnum, if possible
295 if (lyxerr.debugging()) {
296 lyxerr << "Allocating color cube " << num
297 << 'x' << num << 'x' << num << endl;
301 lyxerr << "Error allocating color colormap." << endl;
305 if (num > 5) num = 5;
307 for (int i = 0; i < num * num * num; ++i) {
308 xcol.red = 65535 * (i / (num * num)) / (num - 1);
309 xcol.green = 65535 * ((i / num) % num) / (num - 1);
310 xcol.blue = 65535 * (i % num) / (num - 1);
311 xcol.flags = DoRed | DoGreen | DoBlue;
312 if (!XAllocColor(fl_display, color_map, &xcol)) {
313 if (i) XFreeColors(fl_display, color_map,
315 if(lyxerr.debugging()) {
316 lyxerr << "Cannot allocate color cube "
319 AllocColors(num - 1);
322 gs_pixels[i] = xcol.pixel;
327 gs_num_pixels = num * num * num;
331 // allocate grayscale ramp
333 void AllocGrays(int num)
335 if (lyxerr.debugging()) {
336 lyxerr << "Allocating grayscale colormap "
341 lyxerr << "Error allocating grayscale colormap." << endl;
345 if (num > 128) num = 128;
347 for (int i = 0; i < num; ++i) {
348 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
349 xcol.flags = DoRed | DoGreen | DoBlue;
350 if (!XAllocColor(fl_display, color_map, &xcol)) {
351 if (i) XFreeColors(fl_display, color_map,
353 if (lyxerr.debugging()) {
354 lyxerr << "Cannot allocate grayscale "
360 gs_pixels[i] = xcol.pixel;
370 bmparrsize = figarrsize = figallocchunk;
371 figures = static_cast<Figref**>
372 (malloc(sizeof(Figref*) * figallocchunk));
373 bitmaps = static_cast<figdata**>
374 (malloc(sizeof(figdata*) * figallocchunk));
377 for (unsigned int i = 0; i < 256; ++i) {
379 for (unsigned int j = 0; j < 8; ++j)
380 if (i & (1 << (7-j))) k |= 1 << j;
381 bittable[i] = char(~k);
384 fl_add_canvas_handler(figinset_canvas, ClientMessage,
385 GhostscriptMsg, current_view->owner()->getMainForm());
387 // now we have to init color_map
388 if (!color_map) color_map = DefaultColormap(fl_display,
389 DefaultScreen(fl_display));
390 // allocate color cube on pseudo-color display
394 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
395 if (lyxerr.debugging()) {
396 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
397 vi->visualid, vi->c_class,
398 vi->bits_per_rgb, vi->map_entries);
400 color_visual = ( (vi->c_class == StaticColor) ||
401 (vi->c_class == PseudoColor) ||
402 (vi->c_class == TrueColor) ||
403 (vi->c_class == DirectColor) );
404 if ((vi->c_class & 1) == 0) return;
405 // now allocate colors
406 if (vi->c_class == GrayScale) {
407 // allocate grayscale
408 AllocGrays(vi->map_entries/2);
410 // allocate normal color
412 while (i * i * i * 2 > vi->map_entries) --i;
415 gs_allcolors = vi->map_entries;
426 lyxerr.debug() << "Unregistering figures..." << endl;
428 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
432 lyxerr.debug() << "Freeing up the colors..." << endl;
433 XFreeColors(fl_display, color_map, gs_pixels,
435 /******????????????????? what's planes in this case ??????***/
440 int FindBmpIndex(figdata * tmpdata)
443 while (i < bmpinsref) {
444 if (bitmaps[i] == tmpdata) return i;
451 static void chpixmap(Pixmap, int, int)
454 Display * tempdisp = XOpenDisplay(XDisplayName(0));
456 // here read the pixmap and change all colors to those we
459 XCloseDisplay(tempdisp);
464 static void freefigdata(figdata * tmpdata)
467 if (tmpdata->ref) return;
469 if (tmpdata->gspid > 0) {
470 int pid = tmpdata->gspid;
472 // change Pixmap according to our allocated colormap
473 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
474 // kill ghostscript and unlink it's files
476 lyx::kill(pid, SIGKILL);
477 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
481 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
483 int i = FindBmpIndex(tmpdata);
485 while (i < bmpinsref) {
486 bitmaps[i] = bitmaps[i + 1];
492 static void runqueue()
494 // run queued requests for ghostscript, if any
495 if (!gsrunning && gs_color && !gs_xcolor) {
496 // here alloc all colors, so that gs will use only
497 // those we allocated for it
502 while (gsrunning < MAXGS) {
503 char tbuf[384], tbuf2[80];
508 if (!gsrunning && gs_xcolor) {
509 // de-allocate rest of colors
525 if (lyxerr.debugging()) {
526 lyxerr << "GS start error! Cannot fork."
529 p->data->broken = true;
530 p->data->reading = false;
533 if (pid == 0) { // child
534 char ** env, rbuf[80], gbuf[40];
536 Display * tempdisp = XOpenDisplay(XDisplayName(0));
538 // create translation file
539 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
543 ofs << "gsave clippath pathbbox grestore\n"
545 << "/ury exch def /urx exch def /lly exch def "
547 << p->data->wid / 2.0 << " "
548 << p->data->hgh / 2.0 << " translate\n"
549 << p->data->angle << " rotate\n"
550 << -(p->data->raw_wid / 2.0) << " "
551 << -(p->data->raw_hgh / 2.0) << " translate\n"
552 << p->rx / 72.0 << " " << p->ry / 72.0
554 << -p->ofsx << " " << -p->ofsy << " translate\n"
556 ofs.close(); // Don't remove this.
558 // gs process - set ghostview environment first
559 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
560 figinset_canvas), p->data->bitmap);
562 // now set up ghostview property on a window
563 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
564 p->data->wid, p->data->hgh);
565 // #warning BUG seems that the only bug here
566 // might be the hardcoded dpi.. Bummer!
568 if (lyxerr.debugging()) {
569 lyxerr << "Will set GHOSTVIEW property to ["
570 << tbuf << "]" << endl;
572 // wait until property is deleted if executing multiple
575 // grab server to prevent other child
576 // interfering with setting GHOSTVIEW property
577 if (lyxerr.debugging()) {
578 lyxerr << "Grabbing the server"
581 XGrabServer(tempdisp);
582 prop = XListProperties(tempdisp,
584 figinset_canvas), &nprop);
588 for (i = 0; i < nprop; ++i) {
589 char * p = XGetAtomName(tempdisp,
591 if (strcmp(p, "GHOSTVIEW") == 0) {
597 XFree(reinterpret_cast<char *>(prop)); // jc:
599 // release the server
600 XUngrabServer(tempdisp);
602 // ok, property found, we must wait until
603 // ghostscript deletes it
604 if (lyxerr.debugging()) {
605 lyxerr << "Releasing the server\n["
607 << "] GHOSTVIEW property"
608 " found. Waiting." << endl;
612 #warning What is this doing? (wouldn't a sleep(1); work too?')
616 signal(SIGALRM, waitalarm);
617 while (!alarmed) pause();
623 XChangeProperty(tempdisp,
624 fl_get_canvas_id(figinset_canvas),
625 XInternAtom(tempdisp, "GHOSTVIEW", false),
626 XInternAtom(tempdisp, "STRING", false),
628 reinterpret_cast<unsigned char*>(tbuf),
631 switch (p->data->flags & 3) {
632 case 0: tbuf[0] = 'H'; break; // Hidden
633 case 1: tbuf[0] = 'M'; break; // Mono
634 case 2: tbuf[0] = 'G'; break; // Gray
637 tbuf[0] = 'C'; // Color
639 tbuf[0] = 'G'; // Gray
644 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
645 DefaultScreenOfDisplay(fl_display)),
648 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
649 DefaultScreenOfDisplay(fl_display)),
653 XChangeProperty(tempdisp,
654 fl_get_canvas_id(figinset_canvas),
655 XInternAtom(tempdisp,
656 "GHOSTVIEW_COLORS", false),
657 XInternAtom(tempdisp, "STRING", false),
659 reinterpret_cast<unsigned char*>(tbuf),
661 XUngrabServer(tempdisp);
663 if (lyxerr.debugging()) {
664 lyxerr << "Releasing the server" << endl;
666 XCloseDisplay(tempdisp);
668 // set up environment
669 while (environ[ne]) ++ne;
670 env = static_cast<char **>
671 (malloc(sizeof(char*) * (ne + 2)));
673 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
676 // now make gs command
678 // close(1); do NOT close. If GS writes out
679 // errors it would hang. (Matthias 290596)
680 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
681 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
682 // now chdir into dir with .eps file, to be on the safe
684 chdir(OnlyPath(p->data->fname).c_str());
685 // make temp file name
686 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
688 if (lyxerr.debugging()) {
689 lyxerr << "starting gs " << tbuf << " "
691 << ", pid: " << getpid() << endl;
694 int err = execlp(lyxrc->ps_command.c_str(),
695 lyxrc->ps_command.c_str(),
697 "-dNOPAUSE", "-dQUIET",
700 p->data->fname.c_str(),
701 "showpage.ps", "quit.ps", "-", 0);
702 // if we are still there, an error occurred.
703 lyxerr << "Error executing ghostscript. "
704 << "Code: " << err << endl;
705 lyxerr.debug() << "Cmd: "
709 << p->data->fname << endl;
712 // normal process (parent)
713 if (lyxerr.debugging()) {
714 lyxerr << "GS [" << pid << "] started" << endl;
716 gsqueue = gsqueue->next;
718 p->data->gspid = pid;
724 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
726 // recompute the stuff and put in the queue
727 queue * p = new queue;
730 p->rx = (float(data->raw_wid) * 72.0) / pswid;
731 p->ry = (float(data->raw_hgh) * 72.0) / pshgh;
736 // now put into queue
737 queue * p2 = gsqueue;
738 if (!gsqueue) gsqueue = p;
740 while (p2->next) p2 = p2->next;
744 // if possible, run the queue
749 static figdata * getfigdata(int wid, int hgh, string const & fname,
750 int psx, int psy, int pswid, int pshgh,
751 int raw_wid, int raw_hgh, float angle, char flags)
753 /* first search for an exact match with fname and width/height */
755 if (fname.empty()) return 0;
758 while (i < bmpinsref) {
759 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
760 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
761 bitmaps[i]->angle == angle) {
767 /* not found -> create new record or return 0 if no record */
769 if (bmpinsref > bmparrsize) {
770 // allocate more space
771 bmparrsize += figallocchunk;
772 figdata ** tmp = static_cast<figdata**>
773 (malloc(sizeof(figdata*) * bmparrsize));
775 sizeof(figdata*) * (bmparrsize - figallocchunk));
779 figdata * p = new figdata;
780 bitmaps[bmpinsref-1] = p;
783 p->raw_wid = raw_wid;
784 p->raw_hgh = raw_hgh;
788 XWindowAttributes wa;
789 XGetWindowAttributes(fl_display, fl_get_canvas_id(
790 figinset_canvas), &wa);
792 if (lyxerr.debugging()) {
793 lyxerr << "Create pixmap disp:" << fl_display
794 << " scr:" << DefaultScreen(fl_display)
797 << " depth:" << wa.depth << endl;
805 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
806 figinset_canvas), wid, hgh, wa.depth);
808 // initialize reading of .eps file with correct sizes and stuff
809 addwait(psx, psy, pswid, pshgh, p);
820 static void getbitmap(figdata * p)
826 static void makeupdatelist(figdata * p)
828 for (int i = 0; i < figinsref; ++i)
829 if (figures[i]->data == p) {
830 if (lyxerr.debugging()) {
831 lyxerr << "Updating inset "
835 //UpdateInset(figures[i]->inset);
836 // add inset figures[i]->inset into to_update list
837 PutInsetIntoInsetUpdateList(figures[i]->inset);
842 void sigchldchecker(pid_t pid, int * status)
844 lyxerr.debug() << "Got pid = " << pid << endl;
845 bool pid_handled = false;
846 for (int i = bmpinsref - 1; i >= 0; --i) {
847 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
848 lyxerr.debug() << "Found pid in bitmaps" << endl;
849 // now read the file and remove it from disk
850 figdata * p = bitmaps[i];
852 if (bitmaps[i]->gsdone) *status = 0;
854 lyxerr.debug() << "GS [" << pid
855 << "] exit OK." << endl;
857 lyxerr << "GS [" << pid << "] error "
859 << WIFEXITED(*status)
860 << " " << WEXITSTATUS(*status)
861 << " S:" << WIFSIGNALED(*status)
862 << " " << WTERMSIG(*status) << endl;
865 bitmap_waiting = true;
868 // remove temporary files
870 sprintf(tmp, "%s/~lyxgs%d.ps",
871 system_tempdir.c_str(),
877 makeupdatelist(bitmaps[i]);
884 lyxerr.debug() << "Checking pid in pidwait" << endl;
885 pidwait * p = pw, * prev = 0;
888 lyxerr.debug() << "Found pid in pidwait" << endl;
889 lyxerr.debug() << "Caught child pid of recompute routine " << pid << endl;
891 prev->next = p->next;
903 lyxerr.debug() << "waitpid error" << endl;
906 lyxerr << "The process or process group specified by "
907 "pid does not exist or is not a child of "
908 "the calling process or can never be in the "
909 "states specified by options." << endl;
912 lyxerr << "waitpid() was interrupted due to the "
913 "receipt of a signal sent by the calling "
917 lyxerr << "An invalid value was specified for "
921 lyxerr << "Unknown error from waitpid" << endl;
924 } else if (pid == 0) {
925 lyxerr << "waitpid nohang" << endl;;
927 lyxerr.debug() << "normal exit from childhandler" << endl;
932 static void getbitmaps()
934 bitmap_waiting = false;
935 for (int i = 0; i < bmpinsref; ++i)
936 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
937 getbitmap(bitmaps[i]);
941 static void RegisterFigure(InsetFig *fi)
943 if (figinsref == 0) InitFigures();
946 if (figinsref > figarrsize) {
947 // allocate more space
948 figarrsize += figallocchunk;
949 Figref ** tmp = static_cast<Figref**>
950 (malloc(sizeof(Figref*)*figarrsize));
952 sizeof(Figref*)*(figarrsize-figallocchunk));
956 Figref * tmpfig = new Figref;
959 figures[figinsref-1] = tmpfig;
962 if (lyxerr.debugging()) {
963 lyxerr << "Register Figure: buffer:["
964 << current_view->buffer() << "]" << endl;
969 int FindFigIndex(Figref * tmpfig)
972 while (i < figinsref) {
973 if (figures[i] == tmpfig) return i;
980 static void UnregisterFigure(InsetFig * fi)
982 Figref * tmpfig = fi->figure;
984 if (tmpfig->data) freefigdata(tmpfig->data);
985 if (tmpfig->inset->form) {
986 if (tmpfig->inset->form->Figure->visible) {
987 fl_set_focus_object(tmpfig->inset->form->Figure,
988 tmpfig->inset->form->OkBtn);
989 fl_hide_form(tmpfig->inset->form->Figure);
991 #if FL_REVISION == 89
992 #warning Reactivate this free_form calls
994 fl_free_form(tmpfig->inset->form->Figure);
995 free(tmpfig->inset->form);
996 tmpfig->inset->form = 0;
999 int i = FindFigIndex(tmpfig);
1001 while (i < figinsref) {
1002 figures[i] = figures[i+1];
1007 if (figinsref == 0) DoneFigures();
1011 static string NextToken(istream & is)
1019 } while (!is.eof() && !isspace(c));
1020 token.erase(token.length() - 1); // remove the isspace
1026 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1036 psubfigure = subfigure = false;
1037 xwid = xhgh = angle = 0;
1039 raw_wid = raw_hgh = 0;
1040 changedfname = false;
1041 RegisterFigure(this);
1045 InsetFig::~InsetFig()
1047 if (lyxerr.debugging()) {
1048 lyxerr << "Figure destructor called" << endl;
1050 UnregisterFigure(this);
1054 int InsetFig::Ascent(LyXFont const &) const
1060 int InsetFig::Descent(LyXFont const &) const
1066 int InsetFig::Width(LyXFont const &) const
1072 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1074 if (bitmap_waiting) getbitmaps();
1076 // I wish that I didn't have to use this
1077 // but the figinset code is so complicated so
1078 // I don't want to fiddle with it now.
1079 unsigned long pm = scr.getForeground();
1081 if (figure && figure->data && figure->data->bitmap &&
1082 !figure->data->reading && !figure->data->broken) {
1084 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1085 0, 0, wid, hgh, int(x+1), baseline-hgh);
1087 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1088 int(x), baseline - hgh - 1,
1093 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1095 baseline - hgh - 1, wid+1, hgh+1);
1096 if (figure && figure->data) {
1097 if (figure->data->broken) msg = _("[render error]");
1098 else if (figure->data->reading) msg = _("[rendering ... ]");
1100 if (fname.empty()) msg = _("[no file]");
1101 else if ((flags & 3) == 0) msg = _("[not displayed]");
1102 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1104 if (!msg) msg = _("[unknown error]");
1106 font.setFamily (LyXFont::SANS_FAMILY);
1107 font.setSize (LyXFont::SIZE_FOOTNOTE);
1108 string justname = OnlyFilename (fname);
1109 font.drawString(justname, pm,
1110 baseline - font.maxAscent() - 4,
1112 font.setSize (LyXFont::SIZE_TINY);
1113 font.drawText (msg, strlen(msg), pm,
1118 x += Width(font); // ?
1122 void InsetFig::Write(ostream & os)
1125 os << "Figure size " << wid << " " << hgh << "\n";
1126 if (!fname.empty()) {
1127 string buf1 = OnlyPath(owner->fileName());
1128 string fname2 = MakeRelPath(fname, buf1);
1129 os << "file " << fname2 << "\n";
1131 if (!subcaption.empty())
1132 os << "subcaption " << subcaption << "\n";
1133 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1134 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1135 if (angle != 0) os << "angle " << angle << "\n";
1136 os << "flags " << flags << "\n";
1137 if (subfigure) os << "subfigure\n";
1141 void InsetFig::Read(LyXLex & lex)
1144 bool finished = false;
1146 while (lex.IsOK() && !finished) {
1149 string const token = lex.GetString();
1150 lyxerr.debug() << "Token: " << token << endl;
1154 else if (token == "\\end_inset") {
1156 } else if (token == "file") {
1158 buf = lex.GetString();
1159 string buf1 = OnlyPath(owner->fileName());
1160 fname = MakeAbsPath(buf, buf1);
1161 changedfname = true;
1163 } else if (token == "extra") {
1165 // kept for backwards compability. Delete in 0.13.x
1166 } else if (token == "subcaption") {
1168 subcaption = lex.GetString();
1169 } else if (token == "label") {
1171 // kept for backwards compability. Delete in 0.13.x
1172 } else if (token == "angle") {
1174 angle = lex.GetFloat();
1175 } else if (token == "size") {
1177 wid = lex.GetInteger();
1179 hgh = lex.GetInteger();
1180 } else if (token == "flags") {
1182 flags = pflags = lex.GetInteger();
1183 } else if (token == "subfigure") {
1184 subfigure = psubfigure = true;
1185 } else if (token == "width") {
1188 typ = lex.GetInteger();
1190 xwid = lex.GetFloat();
1192 case DEF: wtype = DEF; break;
1193 case CM: wtype = CM; break;
1194 case IN: wtype = IN; break;
1195 case PER_PAGE: wtype = PER_PAGE; break;
1196 case PER_COL: wtype = PER_COL; break;
1198 lyxerr.debug() << "Unknown type!" << endl;
1202 } else if (token == "height") {
1205 typ = lex.GetInteger();
1207 xhgh = lex.GetFloat();
1209 case DEF: htype = DEF; break;
1210 case CM: htype = CM; break;
1211 case IN: htype = IN; break;
1212 case PER_PAGE: htype = PER_PAGE; break;
1214 lyxerr.debug() << "Unknown type!" << endl;
1225 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1228 if (!cmd.empty()) os << cmd << " ";
1233 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1241 int InsetFig::Linuxdoc(string &/*file*/)
1247 int InsetFig::DocBook(string & file)
1249 string figurename = fname;
1251 if(suffixIs(figurename, ".eps"))
1252 figurename.erase(fname.length() - 5);
1254 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1259 void InsetFig::Validate(LaTeXFeatures & features) const
1261 features.graphics = true;
1262 if (subfigure) features.subfigure = true;
1266 unsigned char InsetFig::Editable() const
1272 bool InsetFig::Deletable() const
1278 void InsetFig::Edit(int, int)
1280 lyxerr.debug() << "Editing InsetFig." << endl;
1283 // We should have RO-versions of the form instead.
1284 // The actual prevention of altering a readonly doc
1285 // is done in CallbackFig()
1286 if(current_view->buffer()->isReadonly())
1287 WarnReadonly(current_view->buffer()->fileName());
1290 form = create_form_Figure();
1291 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1292 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1293 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1294 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1297 if (form->Figure->visible) {
1298 fl_raise_form(form->Figure);
1300 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1301 FL_FULLBORDER, _("Figure"));
1306 Inset * InsetFig::Clone() const
1308 InsetFig * tmp = new InsetFig(100, 100, owner);
1310 if (lyxerr.debugging()) {
1311 lyxerr << "Clone Figure: buffer:["
1312 << current_view->buffer()
1313 << "], cbuffer:[xx]" << endl;
1318 tmp->raw_wid = raw_wid;
1319 tmp->raw_hgh = raw_hgh;
1324 tmp->pflags = pflags;
1325 tmp->subfigure = subfigure;
1326 tmp->psubfigure = psubfigure;
1334 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1335 // do not display if there is
1336 // "do not display" chosen (Matthias 260696)
1337 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1338 pswid, pshgh, raw_wid, raw_hgh,
1339 angle, flags & (3|8));
1340 } else tmp->figure->data = 0;
1341 tmp->subcaption = subcaption;
1342 tmp->changedfname = false;
1349 Inset::Code InsetFig::LyxCode() const
1351 return Inset::GRAPHICS_CODE;
1355 void InsetFig::Regenerate()
1358 string resizeW, resizeH;
1359 string rotate, recmd;
1361 if (fname.empty()) {
1362 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1363 cmd += _("empty figure path");
1365 //if (form) fl_set_object_label(form->cmd, "");
1369 string buf1 = OnlyPath(owner->fileName());
1370 string fname2 = MakeRelPath(fname, buf1);
1372 string gcmd = "\\includegraphics{" + fname2 + '}';
1377 case CM:{// \resizebox*{h-length}{v-length}{text}
1379 sprintf(buf, "%g", xwid); // should find better
1386 sprintf(buf, "%g", xwid);
1393 sprintf(buf, "%g", xwid/100);
1395 resizeW += "\\textwidth";
1400 sprintf(buf, "%g", xwid/100);
1402 resizeW += "\\columnwidth";
1412 sprintf(buf, "%g", xhgh);
1419 sprintf(buf, "%g", xhgh);
1426 sprintf(buf, "%g", xhgh/100);
1428 resizeH += "\\textheight";
1432 // Doesn't occur; case exists to suppress compiler warnings.
1437 if (!resizeW.empty() || !resizeH.empty()) {
1438 recmd = "\\resizebox*{";
1439 if (!resizeW.empty())
1444 if (!resizeH.empty())
1454 sprintf(buf, "%g", angle);
1455 // \rotatebox{angle}{text}
1456 rotate = "\\rotatebox{";
1464 if (!rotate.empty()) cmdbuf += '}';
1465 if (!recmd.empty()) cmdbuf += '}';
1467 if (!subcaption.empty())
1468 cmdbuf = "\\subfigure[" + subcaption +
1469 "]{" + cmdbuf + "}";
1471 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1476 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1480 void InsetFig::TempRegenerate()
1483 string resizeW, resizeH;
1484 string rotate, recmd;
1486 char const * tfname = fl_get_input(form->EpsFile);
1487 string tsubcap = fl_get_input(form->Subcaption);
1488 float tangle = atof(fl_get_input(form->Angle));
1489 float txwid = atof(fl_get_input(form->Width));
1490 float txhgh = atof(fl_get_input(form->Height));
1492 if (!tfname || !*tfname) {
1493 //fl_set_object_label(form->cmd, "");
1494 //fl_redraw_object(form->cmd);
1495 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1496 cmd += _("empty figure path");
1501 string buf1 = OnlyPath(owner->fileName());
1502 string fname2 = MakeRelPath(tfname, buf1);
1503 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1504 string gcmd = "\\includegraphics{" + fname2 + '}';
1509 case CM: {// \resizebox*{h-length}{v-length}{text}
1511 sprintf(buf, "%g", txwid); // should find better
1518 sprintf(buf, "%g", txwid);
1525 sprintf(buf, "%g", txwid/100);
1527 resizeW += "\\textwidth";
1532 sprintf(buf, "%g", txwid/100);
1534 resizeW += "\\columnwidth";
1544 sprintf(buf, "%g", txhgh);
1551 sprintf(buf, "%g", txhgh);
1558 sprintf(buf, "%g", txhgh/100);
1560 resizeH += "\\textheight";
1564 // Doesn't occur; case exists to suppress compiler warnings.
1569 // \resizebox*{h-length}{v-length}{text}
1570 if (!resizeW.empty() || !resizeH.empty()) {
1571 recmd = "\\resizebox*{";
1572 if (!resizeW.empty())
1577 if (!resizeH.empty())
1586 sprintf(buf, "%g", tangle);
1587 // \rotatebox{angle}{text}
1588 rotate = "\\rotatebox{";
1596 if (!rotate.empty()) cmdbuf += '}';
1597 if (!recmd.empty()) cmdbuf += '}';
1598 if (psubfigure && !tsubcap.empty()) {
1599 cmdbuf = string("\\subfigure{") + tsubcap
1600 + string("}{") + cmdbuf + "}";
1605 void InsetFig::Recompute()
1607 bool changed = changedfname;
1608 int newx, newy, nraw_x, nraw_y;
1610 if (changed) GetPSSizes();
1612 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1613 float cos_a = cos (angle / DEG2PI);
1614 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1615 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1617 /* now recompute wid and hgh, and if that is changed, set changed */
1618 /* this depends on chosen size of the picture and its bbox */
1619 // This will be redone in 0.13 ... (hen)
1620 if (!fname.empty()) {
1621 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1629 newx = int(28.346 * xwid);
1632 newx = int(72 * xwid);
1634 case PER_PAGE: /* % of page */
1635 newx = int(5.95 * xwid);
1637 case PER_COL: /* % of col */
1638 newx = int(2.975 * xwid);
1642 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1646 //lyxerr << "This should not happen!" << endl;
1649 newy = int(28.346 * xhgh);
1652 newy = int(72 * xhgh);
1654 case PER_PAGE: /* % of page */
1655 newy = int(8.42 * xhgh);
1658 // Doesn't occur; case exists to suppress
1659 // compiler warnings.
1662 if (htype && !wtype && frame_hgh)
1663 newx = newy*frame_wid/frame_hgh;
1672 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1677 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1679 // cannot be zero, actually, set it to some minimum, so its clickable
1680 if (newx < 5) newx = 5;
1681 if (newy < 5) newy = 5;
1683 if (newx != wid || newy != hgh ||
1684 nraw_x != raw_wid || nraw_y != raw_hgh ||
1685 flags != pflags || subfigure != psubfigure)
1693 subfigure = psubfigure;
1696 figdata * pf = figure->data;
1699 if (!fname.empty() && (flags & 3)
1700 && !lyxrc->ps_command.empty()) {
1701 // do not display if there is "do not display"
1702 // chosen (Matthias 260696)
1703 figure->data = getfigdata(wid, hgh, fname,
1704 psx, psy, pswid, pshgh,
1706 angle, flags & (3|8));
1707 } else figure->data = 0;
1709 // free the old data
1710 if (pf) freefigdata(pf);
1713 changedfname = false;
1717 void InsetFig::GetPSSizes()
1719 /* get %%BoundingBox: from postscript file */
1721 /* defaults to associated size
1722 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1729 if (fname.empty()) return;
1731 ifstream ifs(fname.c_str());
1733 if (!ifs) return; // file not found !!!!
1735 /* defaults to A4 page */
1741 char lastchar = 0; ifs.get(lastchar);
1743 char c = 0; ifs.get(c);
1745 lyxerr.debug() << "End of (E)PS file reached and"
1746 " no BoundingBox!" << endl;
1749 if (c == '%' && lastchar == '%') {
1751 if (p.empty()) break;
1752 // we should not use this, with it we cannot
1753 // discover bounding box and end of file.
1754 //if (strcmp(p, "EndComments") == 0) break;
1755 lyxerr.debug() << "Token: `" << p << "'" << endl;
1756 if (p == "BoundingBox:") {
1757 float fpsx, fpsy, fpswid, fpshgh;
1758 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1761 pswid = int(fpswid);
1762 pshgh = int(fpshgh);
1764 if (lyxerr.debugging()) {
1765 lyxerr << "%%%%BoundingBox:"
1783 void InsetFig::CallbackFig(long arg)
1788 if (lyxerr.debugging()) {
1789 lyxerr << "Figure callback, arg " << arg << endl;
1795 case 12: /* width type */
1802 fl_deactivate_object(form->Width);
1807 fl_activate_object(form->Width);
1812 fl_activate_object(form->Width);
1817 fl_activate_object(form->Width);
1822 fl_activate_object(form->Width);
1825 lyxerr.debug() << "Unknown type!" << endl;
1832 case 22: /* height type */
1838 fl_deactivate_object(form->Height);
1843 fl_activate_object(form->Height);
1848 fl_activate_object(form->Height);
1853 fl_activate_object(form->Height);
1856 lyxerr.debug() << "Unknown type!" << endl;
1862 pflags = pflags & ~3; /* wysiwyg0 */
1865 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1868 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1871 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1874 pflags ^= 4; /* frame */
1877 pflags ^= 8; /* do translations */
1880 psubfigure = !psubfigure; /* This is a subfigure */
1883 regen = true; /* regenerate command */
1885 case 0: /* browse file */
1889 case 1: /* preview */
1890 p = fl_get_input(form->EpsFile);
1894 case 8: /* ok (apply and close) */
1895 if(!current_view->buffer()->isReadonly()) {
1898 xwid = atof(fl_get_input(form->Width));
1899 xhgh = atof(fl_get_input(form->Height));
1900 angle = atof(fl_get_input(form->Angle));
1901 p = fl_get_input(form->EpsFile);
1903 string buf1 = OnlyPath(owner->fileName());
1904 fname = MakeAbsPath(p, buf1);
1905 changedfname = true;
1907 if (!fname.empty()) {
1908 changedfname = true;
1912 subcaption = fl_get_input(form->Subcaption);
1916 /* now update inset */
1917 if (lyxerr.debugging()) {
1918 lyxerr << "Update: ["
1919 << wid << 'x' << hgh << ']' << endl;
1923 fl_set_focus_object(form->Figure, form->OkBtn);
1924 fl_hide_form(form->Figure);
1925 #if FL_REVISION == 89
1926 #warning Reactivate this free_form calls
1928 fl_free_form(form->Figure);
1935 // The user has already been informed about RO in ::Edit
1936 if(arg == 7) // if 'Apply'
1939 case 9: /* cancel = restore and close */
1940 fl_set_focus_object(form->Figure, form->OkBtn);
1941 fl_hide_form(form->Figure);
1942 #if FL_REVISION == 89
1943 #warning Reactivate this free_form calls
1944 #warning Jug, is this still a problem?
1946 fl_free_form(form->Figure);
1953 if (regen) TempRegenerate();
1957 inline void DisableFigurePanel(FD_Figure * const form)
1959 fl_deactivate_object(form->EpsFile);
1960 fl_deactivate_object(form->Browse);
1961 fl_deactivate_object(form->Width);
1962 fl_deactivate_object(form->Height);
1963 fl_deactivate_object(form->Frame);
1964 fl_deactivate_object(form->Translations);
1965 fl_deactivate_object(form->Angle);
1966 fl_deactivate_object(form->HeightGrp);
1967 fl_deactivate_object(form->page2);
1968 fl_deactivate_object(form->Default2);
1969 fl_deactivate_object(form->cm2);
1970 fl_deactivate_object(form->in2);
1971 fl_deactivate_object(form->HeightLabel);
1972 fl_deactivate_object(form->WidthLabel);
1973 fl_deactivate_object(form->DisplayGrp);
1974 fl_deactivate_object(form->Wysiwyg3);
1975 fl_deactivate_object(form->Wysiwyg0);
1976 fl_deactivate_object(form->Wysiwyg2);
1977 fl_deactivate_object(form->Wysiwyg1);
1978 fl_deactivate_object(form->WidthGrp);
1979 fl_deactivate_object(form->Default1);
1980 fl_deactivate_object(form->cm1);
1981 fl_deactivate_object(form->in1);
1982 fl_deactivate_object(form->page1);
1983 fl_deactivate_object(form->column1);
1984 fl_deactivate_object(form->Subcaption);
1985 fl_deactivate_object(form->Subfigure);
1986 fl_deactivate_object (form->OkBtn);
1987 fl_deactivate_object (form->ApplyBtn);
1988 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1989 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1993 inline void EnableFigurePanel(FD_Figure * const form)
1995 fl_activate_object(form->EpsFile);
1996 fl_activate_object(form->Browse);
1997 fl_activate_object(form->Width);
1998 fl_activate_object(form->Height);
1999 fl_activate_object(form->Frame);
2000 fl_activate_object(form->Translations);
2001 fl_activate_object(form->Angle);
2002 fl_activate_object(form->HeightGrp);
2003 fl_activate_object(form->page2);
2004 fl_activate_object(form->Default2);
2005 fl_activate_object(form->cm2);
2006 fl_activate_object(form->in2);
2007 fl_activate_object(form->HeightLabel);
2008 fl_activate_object(form->WidthLabel);
2009 fl_activate_object(form->DisplayGrp);
2010 fl_activate_object(form->Wysiwyg3);
2011 fl_activate_object(form->Wysiwyg0);
2012 fl_activate_object(form->Wysiwyg2);
2013 fl_activate_object(form->Wysiwyg1);
2014 fl_activate_object(form->WidthGrp);
2015 fl_activate_object(form->Default1);
2016 fl_activate_object(form->cm1);
2017 fl_activate_object(form->in1);
2018 fl_activate_object(form->page1);
2019 fl_activate_object(form->column1);
2020 fl_activate_object(form->Subcaption);
2021 fl_activate_object(form->Subfigure);
2022 fl_activate_object (form->OkBtn);
2023 fl_activate_object (form->ApplyBtn);
2024 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2025 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2029 void InsetFig::RestoreForm()
2033 EnableFigurePanel(form);
2036 fl_set_button(form->Default1, (wtype == 0));
2037 fl_set_button(form->cm1, (wtype == 1));
2038 fl_set_button(form->in1, (wtype == 2));
2039 fl_set_button(form->page1, (wtype == 3));
2040 fl_set_button(form->column1, (wtype == 4));
2042 fl_deactivate_object(form->Width);
2044 fl_activate_object(form->Width);
2047 // enable and disable should be put here.
2049 fl_set_button(form->Default2, (htype == 0));
2050 fl_set_button(form->cm2, (htype == 1));
2051 fl_set_button(form->in2, (htype == 2));
2052 fl_set_button(form->page2, (htype == 3));
2053 // enable and disable should be put here.
2055 fl_deactivate_object(form->Height);
2057 fl_activate_object(form->Height);
2060 int pflags = flags & 3;
2061 fl_set_button(form->Wysiwyg0, (pflags == 0));
2062 fl_set_button(form->Wysiwyg1, (pflags == 1));
2063 fl_set_button(form->Wysiwyg2, (pflags == 2));
2064 fl_set_button(form->Wysiwyg3, (pflags == 3));
2065 fl_set_button(form->Frame, ((flags & 4) != 0));
2066 fl_set_button(form->Translations, ((flags & 8) != 0));
2067 fl_set_button(form->Subfigure, (subfigure != 0));
2069 psubfigure = subfigure;
2070 sprintf(buf, "%g", xwid);
2071 fl_set_input(form->Width, buf);
2072 sprintf(buf, "%g", xhgh);
2073 fl_set_input(form->Height, buf);
2074 sprintf(buf, "%g", angle);
2075 fl_set_input(form->Angle, buf);
2076 if (!fname.empty()){
2077 string buf1 = OnlyPath(owner->fileName());
2078 string fname2 = MakeRelPath(fname, buf1);
2079 fl_set_input(form->EpsFile, fname2.c_str());
2081 else fl_set_input(form->EpsFile, "");
2082 fl_set_input(form->Subcaption, subcaption.c_str());
2083 if(current_view->buffer()->isReadonly())
2084 DisableFigurePanel(form);
2090 void InsetFig::Preview(char const * p)
2095 lyxerr << "Cannot fork process!" << endl;
2100 return; // parent process
2103 string buf1 = OnlyPath(owner->fileName());
2104 string buf2 = MakeAbsPath(p, buf1);
2106 lyxerr << "Error during rendering "
2107 << execlp(lyxrc->view_pspic_command.c_str(),
2108 lyxrc->view_pspic_command.c_str(),
2115 void InsetFig::BrowseFile()
2117 static string current_figure_path;
2118 static int once = 0;
2121 if (lyxerr.debugging()) {
2122 lyxerr << "Filename: "
2123 << owner->fileName() << endl;
2125 string p = fl_get_input(form->EpsFile);
2127 string buf = MakeAbsPath(owner->fileName());
2128 string buf2 = OnlyPath(buf);
2130 buf = MakeAbsPath(p, buf2);
2131 buf = OnlyPath(buf);
2133 buf = OnlyPath(owner->fileName().c_str());
2136 // Does user clipart directory exist?
2137 string bufclip = AddName (user_lyxdir, "clipart");
2138 FileInfo fileInfo(bufclip);
2139 if (!(fileInfo.isOK() && fileInfo.isDir()))
2140 // No - bail out to system clipart directory
2141 bufclip = AddName (system_lyxdir, "clipart");
2144 fileDlg.SetButton(0, _("Clipart"), bufclip);
2145 fileDlg.SetButton(1, _("Document"), buf);
2151 p = fileDlg.Select(_("EPS Figure"),
2152 current_figure_path,
2155 p = fileDlg.Select(_("EPS Figure"), buf,
2160 if (p.empty()) return;
2162 buf = MakeRelPath(p, buf2);
2163 current_figure_path = OnlyPath(p);
2166 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2167 || contains(p, "%") || contains(p, " "))
2169 WriteAlert(_("Filename can't contain any "
2170 "of these characters:"),
2171 // xgettext:no-c-format
2172 _("space, '#', '~', '$' or '%'."));
2177 if (form) fl_set_input(form->EpsFile, buf.c_str());
2181 void GraphicsCB(FL_OBJECT * obj, long arg)
2183 /* obj->form contains the form */
2185 if (lyxerr.debugging()) {
2186 lyxerr << "GraphicsCB callback: " << arg << endl;
2189 /* find inset we were reacting to */
2190 for (int i = 0; i < figinsref; ++i)
2191 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2194 if (lyxerr.debugging()) {
2195 lyxerr << "Calling back figure " << i << endl;
2197 figures[i]->inset->CallbackFig(arg);
2203 void HideFiguresPopups()
2205 for (int i = 0; i < figinsref; ++i)
2206 if (figures[i]->inset->form
2207 && figures[i]->inset->form->Figure->visible) {
2208 if (lyxerr.debugging()) {
2209 lyxerr << "Hiding figure " << i << endl;
2211 // hide and free the form
2212 figures[i]->inset->CallbackFig(9);