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"
61 extern BufferView * current_view;
63 static volatile bool alarmed;
65 extern FL_OBJECT * figinset_canvas;
68 extern "C" void waitalarm(int)
74 extern char ** environ; // is this only redundtant on linux systems? Lgb.
75 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
76 // better for asyncron updating:
77 void PutInsetIntoInsetUpdateList(Inset * inset);
78 extern void ProhibitInput();
79 extern void AllowInput();
81 #define DEG2PI 57.295779513
82 #define figallocchunk 32
84 static int figinsref = 0; /* number of figures */
85 static int figarrsize = 0; /* current max number of figures */
86 static int bmpinsref = 0; /* number of bitmaps */
87 static int bmparrsize = 0; /* current max number of bitmaps */
90 float rx, ry; /* resolution x and y */
91 int ofsx, ofsy; /* x and y translation */
92 figdata * data; /* we are doing it for this data */
93 queue * next; /* next item in queue */
97 int pid; /* pid to wait for */
98 pidwait * next; /* next */
101 #define MAXGS 3 /* maximum 3 gs's at a time */
103 static Figref ** figures; /* all the figures */
104 static figdata ** bitmaps; /* all the bitmaps */
105 static queue * gsqueue = 0; /* queue for ghostscripting */
106 static int gsrunning = 0; /* currently so many gs's are running */
107 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
108 static char bittable[256]; /* bit reversion table */
110 static bool gs_color; // do we allocate colors for gs?
111 static bool color_visual; // is the visual color?
112 static bool gs_xcolor = false; // allocated extended colors
113 static unsigned long gs_pixels[128]; // allocated pixels
114 static int gs_num_pixels; // number of pixels allocated
115 static int gs_spc; // shades per color
116 static bool gs_gray; // is grayscale?
117 static int gs_allcolors; // number of all colors
119 static pidwait * pw = 0; // pid wait list
122 extern FD_form_main * fd_form_main;
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 for (int i = 0; i < bmpinsref; ++i)
158 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
160 figdata * p = bitmaps[i];
163 // first update p->bitmap, if necessary
164 if (p->bitmap != None && p->flags > (1|8) && gs_color && p->wid) {
165 // query current colormap and re-render
166 // the pixmap with proper colors
168 XWindowAttributes wa;
169 register XImage * im;
170 int i, y, wid1, spc1 = gs_spc-1,
171 spc2 = gs_spc * gs_spc, wid = p->wid,
174 GC gc = getGC(gc_copy);
176 XGetWindowAttributes(fl_display, fl_get_canvas_id(
177 figinset_canvas), &wa);
179 if (lyxerr.debugging()) {
180 lyxerr << "Starting image translation "
183 << p->wid << "x" << p->hgh
185 << " " << XYPixmap << endl;
187 // now fork rendering process
189 if (forkstat == -1) {
191 << "Cannot fork, using slow "
192 "method for pixmap translation." << endl;
193 tmpdisp = fl_display;
194 } else if (forkstat > 0) {
196 if (lyxerr.debugging()) {
197 lyxerr << "Spawned child "
200 addpidwait(forkstat);
201 break; // in parent process
203 tmpdisp = XOpenDisplay(XDisplayName(0));
206 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
207 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
209 if (lyxerr.debugging()) {
210 lyxerr << "Got the image" << endl;
213 if (lyxerr.debugging()) {
214 lyxerr << "Error getting the image" << endl;
219 // query current colormap
220 //cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
221 XColor * cmap = new XColor[gs_allcolors];
222 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
223 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
226 // now we process all the image
227 for (y = 0; y < p->hgh; ++y) {
228 for (int x = 0; x < wid; ++x) {
233 gs_pixels[((pc->red+6553)*
234 spc1/65535)*spc2+((pc->green+6553)*
235 spc1/65535)*gs_spc+((pc->blue+6553)*
240 // This must be correct.
242 if (lyxerr.debugging()) {
243 lyxerr << "Putting image back" << endl;
245 XPutImage(tmpdisp, p->bitmap, gc, im, 0, 0,
246 0, 0, p->wid, p->hgh);
248 if (lyxerr.debugging()) {
249 lyxerr << "Done translation" << endl;
253 if (lyxerr.debugging()) {
254 lyxerr << "Killing gs "
257 kill(p->gspid, SIGHUP);
259 sprintf(tmp, "%s/~lyxgs%d.ps",
260 system_tempdir.c_str(),
264 XCloseDisplay(tmpdisp);
268 if (lyxerr.debugging()) {
269 lyxerr << "Killing gs "
272 kill(p->gspid, SIGHUP);
274 sprintf(tmp, "%s/~lyxgs%d.ps",
275 system_tempdir.c_str(),
285 static void AllocColors(int num)
286 // allocate color cube numxnumxnum, if possible
291 if (lyxerr.debugging()) {
292 lyxerr << "Allocating color cube " << num
293 << 'x' << num << 'x' << num << endl;
297 lyxerr << "Error allocating color colormap." << endl;
301 if (num > 5) num = 5;
302 for (i = 0; i < num*num*num; ++i) {
303 xcol.red = 65535*(i/(num*num))/(num-1);
304 xcol.green = 65535*((i/num) % num)/(num-1);
305 xcol.blue = 65535*(i % num)/(num-1);
306 xcol.flags = DoRed | DoGreen | DoBlue;
307 if (!XAllocColor(fl_display, color_map, &xcol)) {
308 if (i) XFreeColors(fl_display, color_map,
310 if(lyxerr.debugging()) {
311 lyxerr << "Cannot allocate color cube "
317 gs_pixels[i] = xcol.pixel;
322 gs_num_pixels = num*num*num;
326 static void AllocGrays(int num)
327 // allocate grayscale ramp
332 if (lyxerr.debugging()) {
333 lyxerr << "Allocating grayscale ramp "
338 lyxerr << "Error allocating grayscale colormap." << endl;
342 if (num > 128) num = 128;
343 for (i = 0; i < num; ++i) {
344 xcol.red = xcol.green = xcol.blue = 65535*i/(num-1);
345 xcol.flags = DoRed | DoGreen | DoBlue;
346 if (!XAllocColor(fl_display, color_map, &xcol)) {
347 if (i) XFreeColors(fl_display, color_map,
349 if (lyxerr.debugging()) {
350 lyxerr << "Cannot allocate grayscale "
356 gs_pixels[i] = xcol.pixel;
366 unsigned int i, j, k;
369 bmparrsize = figarrsize = figallocchunk;
370 figures = static_cast<Figref**>(malloc(sizeof(Figref*)*figallocchunk));
371 bitmaps = static_cast<figdata**>(malloc(sizeof(figdata*)*figallocchunk));
373 for (i = 0; i < 256; ++i) {
375 for (j = 0; j < 8; ++j)
376 if (i & (1 << (7-j))) k |= 1 << j;
377 bittable[i] = char(~k);
380 fl_add_canvas_handler(figinset_canvas, ClientMessage,
381 GhostscriptMsg, fd_form_main);
383 // now we have to init color_map
384 if (!color_map) color_map = DefaultColormap(fl_display,
385 DefaultScreen(fl_display));
386 // allocate color cube on pseudo-color display
390 vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
391 if (lyxerr.debugging()) {
392 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
393 vi->visualid, vi->c_class,
394 vi->bits_per_rgb, vi->map_entries);
396 color_visual = ( (vi->c_class == StaticColor) ||
397 (vi->c_class == PseudoColor) ||
398 (vi->c_class == TrueColor) ||
399 (vi->c_class == DirectColor) );
400 if ((vi->c_class & 1) == 0) return;
401 // now allocate colors
402 if (vi->c_class == GrayScale) {
403 // allocate grayscale
404 AllocGrays(vi->map_entries/2);
406 // allocate normal color
408 while (i*i*i*2 > vi->map_entries) --i;
411 gs_allcolors = vi->map_entries;
422 lyxerr.debug() << "Unregistering figures..." << endl;
424 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
428 lyxerr.debug() << "Freeing up the colors..." << endl;
429 XFreeColors(fl_display, color_map, gs_pixels,
431 /******????????????????? what's planes in this case ??????***/
436 int FindBmpIndex(figdata *tmpdata)
439 while (i < bmpinsref) {
440 if (bitmaps[i] == tmpdata) return i;
447 static void chpixmap(Pixmap, int, int)
450 Display * tempdisp = XOpenDisplay(XDisplayName(0));
452 // here read the pixmap and change all colors to those we
455 XCloseDisplay(tempdisp);
460 static void freefigdata(figdata *tmpdata)
463 if (tmpdata->ref) return;
465 if (tmpdata->gspid > 0) {
466 int pid = tmpdata->gspid;
468 // change Pixmap according to our allocated colormap
469 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
470 // kill ghostscript and unlink it's files
473 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
477 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
479 int i = FindBmpIndex(tmpdata);
481 while (i < bmpinsref) {
482 bitmaps[i] = bitmaps[i+1];
488 static void runqueue()
490 // run queued requests for ghostscript, if any
491 if (!gsrunning && gs_color && !gs_xcolor) {
492 // here alloc all colors, so that gs will use only
493 // those we allocated for it
498 while (gsrunning < MAXGS) {
499 char tbuf[384], tbuf2[80];
504 if (!gsrunning && gs_xcolor) {
505 // de-allocate rest of colors
521 if (lyxerr.debugging()) {
522 lyxerr << "GS start error! Cannot fork."
525 p->data->broken = true;
526 p->data->reading = false;
529 if (pid == 0) { // child
530 char ** env, rbuf[80], gbuf[40];
532 Display * tempdisp = XOpenDisplay(XDisplayName(0));
534 // create translation file
535 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
539 ofs << "gsave clippath pathbbox grestore\n"
541 << "/ury exch def /urx exch def /lly exch def "
543 << p->data->wid / 2.0 << " "
544 << p->data->hgh / 2.0 << " translate\n"
545 << p->data->angle << " rotate\n"
546 << -(p->data->raw_wid / 2.0) << " "
547 << -(p->data->raw_hgh / 2.0) << " translate\n"
548 << p->rx / 72.0 << " " << p->ry / 72.0
550 << -p->ofsx << " " << -p->ofsy << " translate\n"
552 ofs.close(); // Don't remove this.
554 // gs process - set ghostview environment first
555 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
556 figinset_canvas), p->data->bitmap);
558 // now set up ghostview property on a window
559 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
560 p->data->wid, p->data->hgh);
561 //#warning BUG seems that the only bug here might be the hardcoded dpi.. Bummer!
563 if (lyxerr.debugging()) {
564 lyxerr << "Will set GHOSTVIEW property to ["
565 << tbuf << "]" << endl;
567 // wait until property is deleted if executing multiple
570 // grab server to prevent other child interfering
571 // with setting GHOSTVIEW property
572 if (lyxerr.debugging()) {
573 lyxerr << "Grabbing the server" << endl;
575 XGrabServer(tempdisp);
576 prop = XListProperties(tempdisp, fl_get_canvas_id(
577 figinset_canvas), &nprop);
581 for (i = 0; i < nprop; ++i) {
582 char * p = XGetAtomName(tempdisp, prop[i]);
583 if (strcmp(p, "GHOSTVIEW") == 0) {
589 XFree(reinterpret_cast<char *>(prop)); /* jc: */
591 // release the server
592 XUngrabServer(tempdisp);
594 // ok, property found, we must wait until ghostscript
596 if (lyxerr.debugging()) {
597 lyxerr << "Releasing the server" << endl;
600 << "] GHOSTVIEW property"
601 " found. Waiting." << endl;
605 #warning What is this doing? (wouldn't a sleep(1); work too?')
609 signal(SIGALRM, waitalarm);
610 while (!alarmed) pause();
616 XChangeProperty(tempdisp,
617 fl_get_canvas_id(figinset_canvas),
618 XInternAtom(tempdisp, "GHOSTVIEW", false),
619 XInternAtom(tempdisp, "STRING", false),
621 reinterpret_cast<unsigned char*>(tbuf),
624 switch (p->data->flags & 3) {
625 case 0: tbuf[0] = 'H'; break; // Hidden
626 case 1: tbuf[0] = 'M'; break; // Mono
627 case 2: tbuf[0] = 'G'; break; // Gray
630 tbuf[0] = 'C'; // Color
632 tbuf[0] = 'G'; // Gray
637 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
638 DefaultScreenOfDisplay(fl_display)),
641 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
642 DefaultScreenOfDisplay(fl_display)),
646 XChangeProperty(tempdisp,
647 fl_get_canvas_id(figinset_canvas),
648 XInternAtom(tempdisp, "GHOSTVIEW_COLORS", false),
649 XInternAtom(tempdisp, "STRING", false),
651 reinterpret_cast<unsigned char*>(tbuf),
653 XUngrabServer(tempdisp);
655 if (lyxerr.debugging()) {
656 lyxerr << "Releasing the server" << endl;
658 XCloseDisplay(tempdisp);
660 // set up environment
661 while (environ[ne]) ++ne;
662 env = static_cast<char **>(malloc(sizeof(char*)*(ne+2)));
664 memcpy(&env[1], environ, sizeof(char*)*(ne+1));
667 // now make gs command
669 // close(1); do NOT close. If GS writes out
670 // errors it would hang. (Matthias 290596)
671 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
672 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
673 // now chdir into dir with .eps file, to be on the safe
675 chdir(OnlyPath(p->data->fname).c_str());
676 // make temp file name
677 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
679 if (lyxerr.debugging()) {
680 printf("starting gs %s %s, pid: %d\n", tbuf,
681 p->data->fname.c_str(), int(getpid()));
684 int err = execlp(lyxrc->ps_command.c_str(),
685 lyxrc->ps_command.c_str(),
687 "-dNOPAUSE", "-dQUIET",
690 p->data->fname.c_str(),
691 "showpage.ps", "quit.ps", "-", 0);
692 // if we are still there, an error occurred.
693 lyxerr << "Error executing ghostscript. "
694 << "Code: " << err << endl;
695 lyxerr.debug() << "Cmd: "
699 << p->data->fname << endl;
702 // normal process (parent)
703 if (lyxerr.debugging()) {
704 lyxerr << "GS [" << pid << "] started" << endl;
706 gsqueue = gsqueue->next;
708 p->data->gspid = pid;
714 static void addwait(int psx, int psy, int pswid, int pshgh, figdata *data)
716 // recompute the stuff and put in the queue
717 queue * p = new queue;
720 p->rx = (float(data->raw_wid) * 72.0)/pswid;
721 p->ry = (float(data->raw_hgh) * 72.0)/pshgh;
726 // now put into queue
727 queue * p2 = gsqueue;
728 if (!gsqueue) gsqueue = p;
730 while (p2->next) p2 = p2->next;
734 // if possible, run the queue
739 static figdata * getfigdata(int wid, int hgh, string const & fname,
740 int psx, int psy, int pswid, int pshgh,
741 int raw_wid, int raw_hgh, float angle, char flags)
743 /* first search for an exact match with fname and width/height */
745 if (fname.empty()) return 0;
748 while (i < bmpinsref) {
749 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
750 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
751 bitmaps[i]->angle == angle) {
757 /* not found -> create new record or return 0 if no record */
759 if (bmpinsref > bmparrsize) {
760 // allocate more space
761 bmparrsize += figallocchunk;
762 figdata ** tmp = static_cast<figdata**>(malloc(sizeof(figdata*)*bmparrsize));
763 memcpy(tmp, bitmaps, sizeof(figdata*)*(bmparrsize-figallocchunk));
767 figdata * p = new figdata;
768 bitmaps[bmpinsref-1] = p;
771 p->raw_wid = raw_wid;
772 p->raw_hgh = raw_hgh;
776 XWindowAttributes wa;
777 XGetWindowAttributes(fl_display, fl_get_canvas_id(
778 figinset_canvas), &wa);
780 if (lyxerr.debugging()) {
781 lyxerr << "Create pixmap disp:" << fl_display
782 << " scr:" << DefaultScreen(fl_display)
785 << " depth:" << wa.depth << endl;
793 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
794 figinset_canvas), wid, hgh, wa.depth);
796 // initialize reading of .eps file with correct sizes and stuff
797 addwait(psx, psy, pswid, pshgh, p);
808 static void getbitmap(figdata *p)
814 static void makeupdatelist(figdata *p)
816 for (int i = 0; i < figinsref; ++i)
817 if (figures[i]->data == p) {
818 if (lyxerr.debugging()) {
819 lyxerr << "Updating inset "
823 //UpdateInset(figures[i]->inset);
824 // add inset figures[i]->inset into to_update list
825 PutInsetIntoInsetUpdateList(figures[i]->inset);
830 void sigchldchecker(pid_t pid, int * status)
832 lyxerr.debug() << "Got pid = " << pid << endl;
833 bool pid_handled = false;
834 for (int 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
838 figdata * p = bitmaps[i];
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()
922 bitmap_waiting = false;
923 for (int i = 0; i < bmpinsref; ++i)
924 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
925 getbitmap(bitmaps[i]);
929 static void RegisterFigure(InsetFig *fi)
931 if (figinsref == 0) InitFigures();
934 if (figinsref > figarrsize) {
935 // allocate more space
936 figarrsize += figallocchunk;
937 Figref **tmp = static_cast<Figref**>(malloc(sizeof(Figref*)*figarrsize));
938 memcpy(tmp, figures, sizeof(Figref*)*(figarrsize-figallocchunk));
942 Figref * tmpfig = new Figref;
945 figures[figinsref-1] = tmpfig;
948 if (lyxerr.debugging()) {
949 lyxerr << "Register Figure: buffer:["
950 << current_view->buffer() << "]" << endl;
955 int FindFigIndex(Figref * tmpfig)
958 while (i < figinsref) {
959 if (figures[i] == tmpfig) return i;
966 static void UnregisterFigure(InsetFig * fi)
968 Figref * tmpfig = fi->figure;
970 if (tmpfig->data) freefigdata(tmpfig->data);
971 if (tmpfig->inset->form) {
972 if (tmpfig->inset->form->Figure->visible) {
973 fl_set_focus_object(tmpfig->inset->form->Figure,
974 tmpfig->inset->form->OkBtn);
975 fl_hide_form(tmpfig->inset->form->Figure);
977 #if FL_REVISION == 89
978 #warning Reactivate this free_form calls
980 fl_free_form(tmpfig->inset->form->Figure);
981 free(tmpfig->inset->form);
982 tmpfig->inset->form = 0;
985 int i = FindFigIndex(tmpfig);
987 while (i < figinsref) {
988 figures[i] = figures[i+1];
993 if (figinsref == 0) DoneFigures();
997 static char * NextToken(FILE * myfile)
1003 if (!feof(myfile)) {
1004 token = new char[256];
1008 } while (!feof(myfile) && !isspace(c));
1010 token[i-1]= '\0'; /* just the end of a command */
1016 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1026 psubfigure = subfigure = false;
1027 xwid = xhgh = angle = 0;
1028 raw_wid = raw_hgh = 0;
1029 changedfname = false;
1030 RegisterFigure(this);
1034 InsetFig::~InsetFig()
1036 if (lyxerr.debugging()) {
1037 lyxerr << "Figure destructor called" << endl;
1039 UnregisterFigure(this);
1043 int InsetFig::Ascent(LyXFont const &) const
1049 int InsetFig::Descent(LyXFont const &) const
1055 int InsetFig::Width(LyXFont const &) const
1061 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1063 if (bitmap_waiting) getbitmaps();
1065 // I wish that I didn't have to use this
1066 // but the figinset code is so complicated so
1067 // I don't want to fiddle with it now.
1068 unsigned long pm = scr.getForeground();
1070 if (figure && figure->data && figure->data->bitmap &&
1071 !figure->data->reading && !figure->data->broken) {
1073 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1074 0, 0, wid, hgh, int(x+1), baseline-hgh);
1076 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1077 int(x), baseline - hgh - 1,
1082 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1084 baseline - hgh - 1, wid+1, hgh+1);
1085 if (figure && figure->data) {
1086 if (figure->data->broken) msg = _("[render error]");
1087 else if (figure->data->reading) msg = _("[rendering ... ]");
1089 if (fname.empty()) msg = _("[no file]");
1090 else if ((flags & 3) == 0) msg = _("[not displayed]");
1091 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1093 if (!msg) msg = _("[unknown error]");
1095 font.setFamily (LyXFont::SANS_FAMILY);
1096 font.setSize (LyXFont::SIZE_FOOTNOTE);
1097 string justname = OnlyFilename (fname);
1098 font.drawString(justname, pm,
1099 baseline - font.maxAscent() - 4,
1101 font.setSize (LyXFont::SIZE_TINY);
1102 font.drawText (msg, strlen(msg), pm,
1107 x += Width(font); // ?
1111 void InsetFig::Write(ostream & os)
1114 os << "Figure size " << wid << " " << hgh << "\n";
1115 if (!fname.empty()) {
1116 string buf1 = OnlyPath(owner->fileName());
1117 string fname2 = MakeRelPath(fname, buf1);
1118 os << "file " << fname2 << "\n";
1120 if (!subcaption.empty())
1121 os << "subcaption " << subcaption << "\n";
1122 if (wtype) os << "width " << wtype << " " << xwid << "\n";
1123 if (htype) os << "height " << htype << " " << xhgh << "\n";
1124 if (angle != 0) os << "angle " << angle << "\n";
1125 os << "flags " << flags << "\n";
1126 if (subfigure) os << "subfigure\n";
1130 void InsetFig::Read(LyXLex & lex)
1133 bool finished = false;
1135 while (lex.IsOK() && !finished) {
1138 string const token = lex.GetString();
1139 lyxerr.debug() << "Token: " << token << endl;
1143 else if (token == "\\end_inset") {
1145 } else if (token == "file") {
1147 buf = lex.GetString();
1148 string buf1 = OnlyPath(owner->fileName());
1149 fname = MakeAbsPath(buf, buf1);
1150 changedfname = true;
1152 } else if (token == "extra") {
1154 // kept for backwards compability. Delete in 0.13.x
1155 } else if (token == "subcaption") {
1157 subcaption = lex.GetString();
1158 } else if (token == "label") {
1160 // kept for backwards compability. Delete in 0.13.x
1161 } else if (token == "angle") {
1163 angle = lex.GetFloat();
1164 } else if (token == "size") {
1166 wid = lex.GetInteger();
1168 hgh = lex.GetInteger();
1169 } else if (token == "flags") {
1171 flags = pflags = lex.GetInteger();
1172 } else if (token == "subfigure") {
1173 subfigure = psubfigure = true;
1174 } else if (token == "width") {
1177 typ = lex.GetInteger();
1179 xwid = lex.GetFloat();
1181 case DEF: wtype = DEF; break;
1182 case CM: wtype = CM; break;
1183 case IN: wtype = IN; break;
1184 case PER_PAGE: wtype = PER_PAGE; break;
1185 case PER_COL: wtype = PER_COL; break;
1187 lyxerr.debug() << "Unknown type!" << endl;
1191 } else if (token == "height") {
1194 typ = lex.GetInteger();
1196 xhgh = lex.GetFloat();
1198 case DEF: htype = DEF; break;
1199 case CM: htype = CM; break;
1200 case IN: htype = IN; break;
1201 case PER_PAGE: htype = PER_PAGE; break;
1203 lyxerr.debug() << "Unknown type!" << endl;
1214 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1217 if (!cmd.empty()) os << cmd << " ";
1222 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1230 int InsetFig::Linuxdoc(string &/*file*/)
1236 int InsetFig::DocBook(string & file)
1238 string figurename= fname;
1240 if(suffixIs(figurename, ".eps"))
1241 figurename.erase(fname.length() - 5);
1243 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1248 void InsetFig::Validate(LaTeXFeatures & features) const
1250 features.graphics = true;
1251 if (subfigure) features.subfigure = true;
1255 unsigned char InsetFig::Editable() const
1261 bool InsetFig::Deletable() const
1267 void InsetFig::Edit(int, int)
1269 lyxerr.debug() << "Editing InsetFig." << endl;
1272 // We should have RO-versions of the form instead.
1273 // The actual prevention of altering a readonly doc
1274 // is done in CallbackFig()
1275 if(current_view->buffer()->isReadonly())
1279 form = create_form_Figure();
1280 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1281 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1282 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1283 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1286 if (form->Figure->visible) {
1287 fl_raise_form(form->Figure);
1289 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1290 FL_FULLBORDER, _("Figure"));
1295 Inset * InsetFig::Clone() const
1297 InsetFig * tmp = new InsetFig(100, 100, owner);
1299 if (lyxerr.debugging()) {
1300 lyxerr << "Clone Figure: buffer:["
1301 << current_view->buffer()
1302 << "], cbuffer:[xx]" << endl;
1307 tmp->raw_wid = raw_wid;
1308 tmp->raw_hgh = raw_hgh;
1313 tmp->pflags = pflags;
1314 tmp->subfigure = subfigure;
1315 tmp->psubfigure = psubfigure;
1323 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1324 // do not display if there is "do not display" chosen (Matthias 260696)
1325 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1326 pswid, pshgh, raw_wid, raw_hgh,
1327 angle, flags & (3|8));
1328 } else tmp->figure->data = 0;
1329 tmp->subcaption = subcaption;
1330 tmp->changedfname = false;
1337 Inset::Code InsetFig::LyxCode() const
1339 return Inset::GRAPHICS_CODE;
1343 void InsetFig::Regenerate()
1346 string resizeW, resizeH;
1347 string rotate, recmd;
1349 if (fname.empty()) {
1350 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1351 cmd += _("empty figure path");
1353 //if (form) fl_set_object_label(form->cmd, "");
1357 string buf1 = OnlyPath(owner->fileName());
1358 string fname2 = MakeRelPath(fname, buf1);
1360 string gcmd = "\\includegraphics{" + fname2 + '}';
1365 case CM:{// \resizebox*{h-length}{v-length}{text}
1367 sprintf(buf, "%g", xwid); // should find better
1374 sprintf(buf, "%g", xwid);
1381 sprintf(buf, "%g", xwid/100);
1383 resizeW += "\\textwidth";
1388 sprintf(buf, "%g", xwid/100);
1390 resizeW += "\\columnwidth";
1400 sprintf(buf, "%g", xhgh);
1407 sprintf(buf, "%g", xhgh);
1414 sprintf(buf, "%g", xhgh/100);
1416 resizeH += "\\textheight";
1420 // Doesn't occur; case exists to suppress compiler warnings.
1425 if (!resizeW.empty() || !resizeH.empty()) {
1426 recmd = "\\resizebox*{";
1427 if (!resizeW.empty())
1432 if (!resizeH.empty())
1442 sprintf(buf, "%g", angle);
1443 // \rotatebox{angle}{text}
1444 rotate = "\\rotatebox{";
1452 if (!rotate.empty()) cmdbuf += '}';
1453 if (!recmd.empty()) cmdbuf += '}';
1455 if (!subcaption.empty())
1456 cmdbuf = "\\subfigure[" + subcaption +
1457 "]{" + cmdbuf + "}";
1459 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1464 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1468 void InsetFig::TempRegenerate()
1471 string resizeW, resizeH;
1472 string rotate, recmd;
1474 char const * tfname = fl_get_input(form->EpsFile);
1475 string tsubcap = fl_get_input(form->Subcaption);
1476 float tangle = atof(fl_get_input(form->Angle));
1477 float txwid = atof(fl_get_input(form->Width));
1478 float txhgh = atof(fl_get_input(form->Height));
1480 if (!tfname || !*tfname) {
1481 //fl_set_object_label(form->cmd, "");
1482 //fl_redraw_object(form->cmd);
1483 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1484 cmd += _("empty figure path");
1489 string buf1 = OnlyPath(owner->fileName());
1490 string fname2 = MakeRelPath(tfname, buf1);
1491 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1492 string gcmd = "\\includegraphics{" + fname2 + '}';
1497 case CM: {// \resizebox*{h-length}{v-length}{text}
1499 sprintf(buf, "%g", txwid); // should find better
1506 sprintf(buf, "%g", txwid);
1513 sprintf(buf, "%g", txwid/100);
1515 resizeW += "\\textwidth";
1520 sprintf(buf, "%g", txwid/100);
1522 resizeW += "\\columnwidth";
1532 sprintf(buf, "%g", txhgh);
1539 sprintf(buf, "%g", txhgh);
1546 sprintf(buf, "%g", txhgh/100);
1548 resizeH += "\\textheight";
1552 // Doesn't occur; case exists to suppress compiler warnings.
1557 // \resizebox*{h-length}{v-length}{text}
1558 if (!resizeW.empty() || !resizeH.empty()) {
1559 recmd = "\\resizebox*{";
1560 if (!resizeW.empty())
1565 if (!resizeH.empty())
1574 sprintf(buf, "%g", tangle);
1575 // \rotatebox{angle}{text}
1576 rotate = "\\rotatebox{";
1584 if (!rotate.empty()) cmdbuf += '}';
1585 if (!recmd.empty()) cmdbuf += '}';
1586 if (psubfigure && !tsubcap.empty()) {
1587 cmdbuf = string("\\subfigure{") + tsubcap
1588 + string("}{") + cmdbuf + "}";
1593 void InsetFig::Recompute()
1595 bool changed = changedfname;
1596 int newx, newy, nraw_x, nraw_y;
1598 if (changed) GetPSSizes();
1600 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1601 float cos_a = cos (angle / DEG2PI);
1602 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1603 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1605 /* now recompute wid and hgh, and if that is changed, set changed */
1606 /* this depends on chosen size of the picture and its bbox */
1607 // This will be redone in 0.13 ... (hen)
1608 if (!fname.empty()) {
1609 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1617 newx = int(28.346 * xwid);
1620 newx = int(72 * xwid);
1622 case PER_PAGE: /* % of page */
1623 newx = int(5.95 * xwid);
1625 case PER_COL: /* % of col */
1626 newx = int(2.975 * xwid);
1630 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1634 //lyxerr << "This should not happen!" << endl;
1637 newy = int(28.346 * xhgh);
1640 newy = int(72 * xhgh);
1642 case PER_PAGE: /* % of page */
1643 newy = int(8.42 * xhgh);
1646 // Doesn't occur; case exists to suppress
1647 // compiler warnings.
1650 if (htype && !wtype && frame_hgh) newx = newy*frame_wid/frame_hgh;
1659 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1664 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1666 // cannot be zero, actually, set it to some minimum, so its clickable
1667 if (newx < 5) newx = 5;
1668 if (newy < 5) newy = 5;
1670 if (newx != wid || newy != hgh ||
1671 nraw_x != raw_wid || nraw_y != raw_hgh ||
1672 flags != pflags || subfigure != psubfigure)
1680 subfigure = psubfigure;
1683 figdata * pf = figure->data;
1686 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1687 // do not display if there is "do not display"
1688 // chosen (Matthias 260696)
1689 figure->data = getfigdata(wid, hgh, fname,
1690 psx, psy, pswid, pshgh,
1692 angle, flags & (3|8));
1693 } else figure->data = 0;
1695 // free the old data
1696 if (pf) freefigdata(pf);
1699 changedfname = false;
1703 void InsetFig::GetPSSizes()
1705 #ifdef WITH_WARNINGS
1706 #warning rewrite this method to use ifstream
1708 /* get %%BoundingBox: from postscript file */
1711 /* defaults to associated size
1712 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1719 if (fname.empty()) return;
1721 FilePtr f(fname, FilePtr::read);
1723 if (!f()) return; // file not found !!!!
1725 /* defaults to A4 page */
1731 int lastchar = fgetc(f);
1735 lyxerr.debug() << "End of (E)PS file reached and"
1736 " no BoundingBox!" << endl;
1739 if (c == '%' && lastchar == '%') {
1742 // we should not use this, with it we cannot
1743 // discover bounding box and end of file.
1744 //if (strcmp(p, "EndComments") == 0) break;
1745 if (strcmp(p, "BoundingBox:") == 0) {
1746 float fpsx, fpsy, fpswid, fpshgh;
1747 if (fscanf(f, "%f %f %f %f", &fpsx, &fpsy,
1748 &fpswid, &fpshgh) == 4) {
1751 pswid = int(fpswid);
1752 pshgh = int(fpshgh);
1755 if (lyxerr.debugging()) {
1756 lyxerr << "%%%%BoundingBox:"
1777 void InsetFig::CallbackFig(long arg)
1782 if (lyxerr.debugging()) {
1783 printf("Figure callback, arg %ld\n", arg);
1789 case 12: /* width type */
1796 fl_deactivate_object(form->Width);
1801 fl_activate_object(form->Width);
1806 fl_activate_object(form->Width);
1811 fl_activate_object(form->Width);
1816 fl_activate_object(form->Width);
1819 lyxerr.debug() << "Unknown type!" << endl;
1826 case 22: /* height type */
1832 fl_deactivate_object(form->Height);
1837 fl_activate_object(form->Height);
1842 fl_activate_object(form->Height);
1847 fl_activate_object(form->Height);
1850 lyxerr.debug() << "Unknown type!" << endl;
1856 pflags = pflags & ~3; /* wysiwyg0 */
1859 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1862 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1865 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1868 pflags ^= 4; /* frame */
1871 pflags ^= 8; /* do translations */
1874 psubfigure = !psubfigure; /* This is a subfigure */
1877 regen = true; /* regenerate command */
1879 case 0: /* browse file */
1883 case 1: /* preview */
1884 p = fl_get_input(form->EpsFile);
1888 case 8: /* ok (apply and close) */
1889 if(!current_view->buffer()->isReadonly()) {
1892 xwid = atof(fl_get_input(form->Width));
1893 xhgh = atof(fl_get_input(form->Height));
1894 angle = atof(fl_get_input(form->Angle));
1895 p = fl_get_input(form->EpsFile);
1897 string buf1 = OnlyPath(owner->fileName());
1898 fname = MakeAbsPath(p, buf1);
1899 changedfname = true;
1901 if (!fname.empty()) {
1902 changedfname = true;
1906 subcaption = fl_get_input(form->Subcaption);
1910 /* now update inset */
1911 if (lyxerr.debugging()) {
1912 lyxerr << "Update: ["
1913 << wid << 'x' << hgh << ']' << endl;
1917 fl_set_focus_object(form->Figure, form->OkBtn);
1918 fl_hide_form(form->Figure);
1919 #if FL_REVISION == 89
1920 #warning Reactivate this free_form calls
1922 fl_free_form(form->Figure);
1929 // The user has already been informed about RO in ::Edit
1930 if(arg == 7) // if 'Apply'
1933 case 9: /* cancel = restore and close */
1934 fl_set_focus_object(form->Figure, form->OkBtn);
1935 fl_hide_form(form->Figure);
1936 #if FL_REVISION == 89
1937 #warning Reactivate this free_form calls
1938 #warning Jug, is this still a problem?
1940 fl_free_form(form->Figure);
1947 if (regen) TempRegenerate();
1951 inline void DisableFigurePanel(FD_Figure * const form)
1953 fl_deactivate_object(form->EpsFile);
1954 fl_deactivate_object(form->Browse);
1955 fl_deactivate_object(form->Width);
1956 fl_deactivate_object(form->Height);
1957 fl_deactivate_object(form->Frame);
1958 fl_deactivate_object(form->Translations);
1959 fl_deactivate_object(form->Angle);
1960 fl_deactivate_object(form->HeightGrp);
1961 fl_deactivate_object(form->page2);
1962 fl_deactivate_object(form->Default2);
1963 fl_deactivate_object(form->cm2);
1964 fl_deactivate_object(form->in2);
1965 fl_deactivate_object(form->HeightLabel);
1966 fl_deactivate_object(form->WidthLabel);
1967 fl_deactivate_object(form->DisplayGrp);
1968 fl_deactivate_object(form->Wysiwyg3);
1969 fl_deactivate_object(form->Wysiwyg0);
1970 fl_deactivate_object(form->Wysiwyg2);
1971 fl_deactivate_object(form->Wysiwyg1);
1972 fl_deactivate_object(form->WidthGrp);
1973 fl_deactivate_object(form->Default1);
1974 fl_deactivate_object(form->cm1);
1975 fl_deactivate_object(form->in1);
1976 fl_deactivate_object(form->page1);
1977 fl_deactivate_object(form->column1);
1978 fl_deactivate_object(form->Subcaption);
1979 fl_deactivate_object(form->Subfigure);
1980 fl_deactivate_object (form->OkBtn);
1981 fl_deactivate_object (form->ApplyBtn);
1982 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1983 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1987 inline void EnableFigurePanel(FD_Figure * const form)
1989 fl_activate_object(form->EpsFile);
1990 fl_activate_object(form->Browse);
1991 fl_activate_object(form->Width);
1992 fl_activate_object(form->Height);
1993 fl_activate_object(form->Frame);
1994 fl_activate_object(form->Translations);
1995 fl_activate_object(form->Angle);
1996 fl_activate_object(form->HeightGrp);
1997 fl_activate_object(form->page2);
1998 fl_activate_object(form->Default2);
1999 fl_activate_object(form->cm2);
2000 fl_activate_object(form->in2);
2001 fl_activate_object(form->HeightLabel);
2002 fl_activate_object(form->WidthLabel);
2003 fl_activate_object(form->DisplayGrp);
2004 fl_activate_object(form->Wysiwyg3);
2005 fl_activate_object(form->Wysiwyg0);
2006 fl_activate_object(form->Wysiwyg2);
2007 fl_activate_object(form->Wysiwyg1);
2008 fl_activate_object(form->WidthGrp);
2009 fl_activate_object(form->Default1);
2010 fl_activate_object(form->cm1);
2011 fl_activate_object(form->in1);
2012 fl_activate_object(form->page1);
2013 fl_activate_object(form->column1);
2014 fl_activate_object(form->Subcaption);
2015 fl_activate_object(form->Subfigure);
2016 fl_activate_object (form->OkBtn);
2017 fl_activate_object (form->ApplyBtn);
2018 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2019 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2023 void InsetFig::RestoreForm()
2027 EnableFigurePanel(form);
2030 fl_set_button(form->Default1, (wtype == 0));
2031 fl_set_button(form->cm1, (wtype == 1));
2032 fl_set_button(form->in1, (wtype == 2));
2033 fl_set_button(form->page1, (wtype == 3));
2034 fl_set_button(form->column1, (wtype == 4));
2036 fl_deactivate_object(form->Width);
2038 fl_activate_object(form->Width);
2041 // enable and disable should be put here.
2043 fl_set_button(form->Default2, (htype == 0));
2044 fl_set_button(form->cm2, (htype == 1));
2045 fl_set_button(form->in2, (htype == 2));
2046 fl_set_button(form->page2, (htype == 3));
2047 // enable and disable should be put here.
2049 fl_deactivate_object(form->Height);
2051 fl_activate_object(form->Height);
2054 int pflags = flags & 3;
2055 fl_set_button(form->Wysiwyg0, (pflags == 0));
2056 fl_set_button(form->Wysiwyg1, (pflags == 1));
2057 fl_set_button(form->Wysiwyg2, (pflags == 2));
2058 fl_set_button(form->Wysiwyg3, (pflags == 3));
2059 fl_set_button(form->Frame, ((flags & 4) != 0));
2060 fl_set_button(form->Translations, ((flags & 8) != 0));
2061 fl_set_button(form->Subfigure, (subfigure != 0));
2063 psubfigure = subfigure;
2064 sprintf(buf, "%g", xwid);
2065 fl_set_input(form->Width, buf);
2066 sprintf(buf, "%g", xhgh);
2067 fl_set_input(form->Height, buf);
2068 sprintf(buf, "%g", angle);
2069 fl_set_input(form->Angle, buf);
2070 if (!fname.empty()){
2071 string buf1 = OnlyPath(owner->fileName());
2072 string fname2 = MakeRelPath(fname, buf1);
2073 fl_set_input(form->EpsFile, fname2.c_str());
2075 else fl_set_input(form->EpsFile, "");
2076 fl_set_input(form->Subcaption, subcaption.c_str());
2077 if(current_view->buffer()->isReadonly())
2078 DisableFigurePanel(form);
2084 void InsetFig::Preview(char const * p)
2089 lyxerr << "Cannot fork process!" << endl;
2094 return; // parent process
2097 string buf1 = OnlyPath(owner->fileName());
2098 string buf2 = MakeAbsPath(p, buf1);
2100 lyxerr << "Error during rendering "
2101 << execlp(lyxrc->view_pspic_command.c_str(),
2102 lyxrc->view_pspic_command.c_str(),
2109 void InsetFig::BrowseFile()
2111 static string current_figure_path;
2112 static int once = 0;
2115 if (lyxerr.debugging()) {
2116 lyxerr << "Filename: "
2117 << owner->fileName() << endl;
2119 string p = fl_get_input(form->EpsFile);
2121 string buf = MakeAbsPath(owner->fileName());
2122 string buf2 = OnlyPath(buf);
2124 buf = MakeAbsPath(p, buf2);
2125 buf = OnlyPath(buf);
2127 buf = OnlyPath(owner->fileName().c_str());
2130 // Does user clipart directory exist?
2131 string bufclip = AddName (user_lyxdir, "clipart");
2132 FileInfo fileInfo(bufclip);
2133 if (!(fileInfo.isOK() && fileInfo.isDir()))
2134 // No - bail out to system clipart directory
2135 bufclip = AddName (system_lyxdir, "clipart");
2138 fileDlg.SetButton(0, _("Clipart"), bufclip);
2139 fileDlg.SetButton(1, _("Document"), buf);
2145 p = fileDlg.Select(_("EPS Figure"), current_figure_path,
2148 p = fileDlg.Select(_("EPS Figure"), buf,
2153 if (p.empty()) return;
2155 buf = MakeRelPath(p, buf2);
2156 current_figure_path = OnlyPath(p);
2159 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2160 || contains(p, "%") || contains(p, " "))
2162 WriteAlert(_("Filename can't contain any of these characters:"), // xgettext:no-c-format
2163 _("space, '#', '~', '$' or '%'."));
2168 if (form) fl_set_input(form->EpsFile, buf.c_str());
2172 void GraphicsCB(FL_OBJECT * obj, long arg)
2174 /* obj->form contains the form */
2176 if (lyxerr.debugging()) {
2177 lyxerr << "GraphicsCB callback: " << arg << endl;
2180 /* find inset we were reacting to */
2181 for (int i = 0; i < figinsref; ++i)
2182 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2185 if (lyxerr.debugging()) {
2186 lyxerr << "Calling back figure " << i << endl;
2188 figures[i]->inset->CallbackFig(arg);
2194 void HideFiguresPopups()
2196 for (int i = 0; i < figinsref; ++i)
2197 if (figures[i]->inset->form
2198 && figures[i]->inset->form->Figure->visible) {
2199 if (lyxerr.debugging()) {
2200 lyxerr << "Hiding figure " << i << endl;
2202 // hide and free the form
2203 figures[i]->inset->CallbackFig(9);