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 static float const DEG2PI = 57.295779513;
82 static int const 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 static int const 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 Colormap color_map;
124 void addpidwait(int pid)
126 // adds pid to pid wait list
127 register pidwait * p = new pidwait;
133 if (lyxerr.debugging()) {
134 lyxerr << "Pids to wait for: " << p->pid << endl;
137 lyxerr << p->pid << endl;
143 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
148 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
150 if(lyxerr.debugging()) {
151 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
152 << "] pm:[" << e->data.l[1] << "]" << endl;
155 // just kill gs, that way it will work for sure
156 // This loop looks like S**T so it probably is...
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
165 && p->flags > (1|8) && gs_color && p->wid) {
166 // query current colormap and re-render
167 // the pixmap with proper colors
169 XWindowAttributes wa;
170 register XImage * im;
171 int i, y, wid1, spc1 = gs_spc-1,
172 spc2 = gs_spc * gs_spc, wid = p->wid,
175 GC gc = getGC(gc_copy);
177 XGetWindowAttributes(fl_display,
182 if (lyxerr.debugging()) {
183 lyxerr << "Starting image translation "
186 << p->wid << "x" << p->hgh
188 << " " << XYPixmap << endl;
190 // now fork rendering process
192 if (forkstat == -1) {
194 << "Cannot fork, using slow "
195 "method for pixmap translation." << endl;
196 tmpdisp = fl_display;
197 } else if (forkstat > 0) {
199 if (lyxerr.debugging()) {
200 lyxerr << "Spawned child "
203 addpidwait(forkstat);
204 break; // in parent process
206 tmpdisp = XOpenDisplay(XDisplayName(0));
209 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
210 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
212 if (lyxerr.debugging()) {
213 lyxerr << "Got the image" << endl;
216 if (lyxerr.debugging()) {
217 lyxerr << "Error getting the image" << endl;
222 // query current colormap
223 //cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
224 XColor * cmap = new XColor[gs_allcolors];
225 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
226 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
229 // now we process all the image
230 for (y = 0; y < p->hgh; ++y) {
231 for (int x = 0; x < wid; ++x) {
236 gs_pixels[((pc->red+6553)*
237 spc1/65535)*spc2+((pc->green+6553)*
238 spc1/65535)*gs_spc+((pc->blue+6553)*
243 // This must be correct.
245 if (lyxerr.debugging()) {
246 lyxerr << "Putting image back"
249 XPutImage(tmpdisp, p->bitmap,
251 0, 0, p->wid, p->hgh);
253 if (lyxerr.debugging()) {
254 lyxerr << "Done translation"
259 if (lyxerr.debugging()) {
260 lyxerr << "Killing gs "
263 kill(p->gspid, SIGHUP);
265 sprintf(tmp, "%s/~lyxgs%d.ps",
266 system_tempdir.c_str(),
270 XCloseDisplay(tmpdisp);
274 if (lyxerr.debugging()) {
275 lyxerr << "Killing gs "
278 kill(p->gspid, SIGHUP);
280 sprintf(tmp, "%s/~lyxgs%d.ps",
281 system_tempdir.c_str(),
291 static void AllocColors(int num)
292 // allocate color cube numxnumxnum, if possible
294 if (lyxerr.debugging()) {
295 lyxerr << "Allocating color cube " << num
296 << 'x' << num << 'x' << num << endl;
300 lyxerr << "Error allocating color colormap." << endl;
304 if (num > 5) num = 5;
306 for (int i = 0; i < num * num * num; ++i) {
307 xcol.red = 65535 * (i / (num * num)) / (num - 1);
308 xcol.green = 65535 * ((i / num) % num) / (num - 1);
309 xcol.blue = 65535 * (i % num) / (num - 1);
310 xcol.flags = DoRed | DoGreen | DoBlue;
311 if (!XAllocColor(fl_display, color_map, &xcol)) {
312 if (i) XFreeColors(fl_display, color_map,
314 if(lyxerr.debugging()) {
315 lyxerr << "Cannot allocate color cube "
318 AllocColors(num - 1);
321 gs_pixels[i] = xcol.pixel;
326 gs_num_pixels = num * num * num;
330 // allocate grayscale ramp
332 void AllocGrays(int num)
334 if (lyxerr.debugging()) {
335 lyxerr << "Allocating grayscale colormap "
340 lyxerr << "Error allocating grayscale colormap." << endl;
344 if (num > 128) num = 128;
346 for (int i = 0; i < num; ++i) {
347 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
348 xcol.flags = DoRed | DoGreen | DoBlue;
349 if (!XAllocColor(fl_display, color_map, &xcol)) {
350 if (i) XFreeColors(fl_display, color_map,
352 if (lyxerr.debugging()) {
353 lyxerr << "Cannot allocate grayscale "
359 gs_pixels[i] = xcol.pixel;
369 bmparrsize = figarrsize = figallocchunk;
370 figures = static_cast<Figref**>
371 (malloc(sizeof(Figref*) * figallocchunk));
372 bitmaps = static_cast<figdata**>
373 (malloc(sizeof(figdata*) * figallocchunk));
376 for (unsigned int i = 0; i < 256; ++i) {
378 for (unsigned int j = 0; j < 8; ++j)
379 if (i & (1 << (7-j))) k |= 1 << j;
380 bittable[i] = char(~k);
383 fl_add_canvas_handler(figinset_canvas, ClientMessage,
384 GhostscriptMsg, current_view->owner()->getMainForm());
386 // now we have to init color_map
387 if (!color_map) color_map = DefaultColormap(fl_display,
388 DefaultScreen(fl_display));
389 // allocate color cube on pseudo-color display
393 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
394 if (lyxerr.debugging()) {
395 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
396 vi->visualid, vi->c_class,
397 vi->bits_per_rgb, vi->map_entries);
399 color_visual = ( (vi->c_class == StaticColor) ||
400 (vi->c_class == PseudoColor) ||
401 (vi->c_class == TrueColor) ||
402 (vi->c_class == DirectColor) );
403 if ((vi->c_class & 1) == 0) return;
404 // now allocate colors
405 if (vi->c_class == GrayScale) {
406 // allocate grayscale
407 AllocGrays(vi->map_entries/2);
409 // allocate normal color
411 while (i * i * i * 2 > vi->map_entries) --i;
414 gs_allcolors = vi->map_entries;
425 lyxerr.debug() << "Unregistering figures..." << endl;
427 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
431 lyxerr.debug() << "Freeing up the colors..." << endl;
432 XFreeColors(fl_display, color_map, gs_pixels,
434 /******????????????????? what's planes in this case ??????***/
439 int FindBmpIndex(figdata * tmpdata)
442 while (i < bmpinsref) {
443 if (bitmaps[i] == tmpdata) return i;
450 static void chpixmap(Pixmap, int, int)
453 Display * tempdisp = XOpenDisplay(XDisplayName(0));
455 // here read the pixmap and change all colors to those we
458 XCloseDisplay(tempdisp);
463 static void freefigdata(figdata * tmpdata)
466 if (tmpdata->ref) return;
468 if (tmpdata->gspid > 0) {
469 int pid = tmpdata->gspid;
471 // change Pixmap according to our allocated colormap
472 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
473 // kill ghostscript and unlink it's files
476 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
480 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
482 int i = FindBmpIndex(tmpdata);
484 while (i < bmpinsref) {
485 bitmaps[i] = bitmaps[i + 1];
491 static void runqueue()
493 // run queued requests for ghostscript, if any
494 if (!gsrunning && gs_color && !gs_xcolor) {
495 // here alloc all colors, so that gs will use only
496 // those we allocated for it
501 while (gsrunning < MAXGS) {
502 char tbuf[384], tbuf2[80];
507 if (!gsrunning && gs_xcolor) {
508 // de-allocate rest of colors
524 if (lyxerr.debugging()) {
525 lyxerr << "GS start error! Cannot fork."
528 p->data->broken = true;
529 p->data->reading = false;
532 if (pid == 0) { // child
533 char ** env, rbuf[80], gbuf[40];
535 Display * tempdisp = XOpenDisplay(XDisplayName(0));
537 // create translation file
538 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
542 ofs << "gsave clippath pathbbox grestore\n"
544 << "/ury exch def /urx exch def /lly exch def "
546 << p->data->wid / 2.0 << " "
547 << p->data->hgh / 2.0 << " translate\n"
548 << p->data->angle << " rotate\n"
549 << -(p->data->raw_wid / 2.0) << " "
550 << -(p->data->raw_hgh / 2.0) << " translate\n"
551 << p->rx / 72.0 << " " << p->ry / 72.0
553 << -p->ofsx << " " << -p->ofsy << " translate\n"
555 ofs.close(); // Don't remove this.
557 // gs process - set ghostview environment first
558 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
559 figinset_canvas), p->data->bitmap);
561 // now set up ghostview property on a window
562 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
563 p->data->wid, p->data->hgh);
564 // #warning BUG seems that the only bug here
565 // might be the hardcoded dpi.. Bummer!
567 if (lyxerr.debugging()) {
568 lyxerr << "Will set GHOSTVIEW property to ["
569 << tbuf << "]" << endl;
571 // wait until property is deleted if executing multiple
574 // grab server to prevent other child
575 // interfering with setting GHOSTVIEW property
576 if (lyxerr.debugging()) {
577 lyxerr << "Grabbing the server"
580 XGrabServer(tempdisp);
581 prop = XListProperties(tempdisp,
583 figinset_canvas), &nprop);
587 for (i = 0; i < nprop; ++i) {
588 char * p = XGetAtomName(tempdisp,
590 if (strcmp(p, "GHOSTVIEW") == 0) {
596 XFree(reinterpret_cast<char *>(prop)); // jc:
598 // release the server
599 XUngrabServer(tempdisp);
601 // ok, property found, we must wait until
602 // ghostscript deletes it
603 if (lyxerr.debugging()) {
604 lyxerr << "Releasing the server\n["
606 << "] GHOSTVIEW property"
607 " found. Waiting." << endl;
611 #warning What is this doing? (wouldn't a sleep(1); work too?')
615 signal(SIGALRM, waitalarm);
616 while (!alarmed) pause();
622 XChangeProperty(tempdisp,
623 fl_get_canvas_id(figinset_canvas),
624 XInternAtom(tempdisp, "GHOSTVIEW", false),
625 XInternAtom(tempdisp, "STRING", false),
627 reinterpret_cast<unsigned char*>(tbuf),
630 switch (p->data->flags & 3) {
631 case 0: tbuf[0] = 'H'; break; // Hidden
632 case 1: tbuf[0] = 'M'; break; // Mono
633 case 2: tbuf[0] = 'G'; break; // Gray
636 tbuf[0] = 'C'; // Color
638 tbuf[0] = 'G'; // Gray
643 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
644 DefaultScreenOfDisplay(fl_display)),
647 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
648 DefaultScreenOfDisplay(fl_display)),
652 XChangeProperty(tempdisp,
653 fl_get_canvas_id(figinset_canvas),
654 XInternAtom(tempdisp,
655 "GHOSTVIEW_COLORS", false),
656 XInternAtom(tempdisp, "STRING", false),
658 reinterpret_cast<unsigned char*>(tbuf),
660 XUngrabServer(tempdisp);
662 if (lyxerr.debugging()) {
663 lyxerr << "Releasing the server" << endl;
665 XCloseDisplay(tempdisp);
667 // set up environment
668 while (environ[ne]) ++ne;
669 env = static_cast<char **>
670 (malloc(sizeof(char*) * (ne + 2)));
672 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
675 // now make gs command
677 // close(1); do NOT close. If GS writes out
678 // errors it would hang. (Matthias 290596)
679 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
680 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
681 // now chdir into dir with .eps file, to be on the safe
683 chdir(OnlyPath(p->data->fname).c_str());
684 // make temp file name
685 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
687 if (lyxerr.debugging()) {
688 lyxerr << "starting gs " << tbuf << " "
690 << ", pid: " << getpid() << endl;
693 int err = execlp(lyxrc->ps_command.c_str(),
694 lyxrc->ps_command.c_str(),
696 "-dNOPAUSE", "-dQUIET",
699 p->data->fname.c_str(),
700 "showpage.ps", "quit.ps", "-", 0);
701 // if we are still there, an error occurred.
702 lyxerr << "Error executing ghostscript. "
703 << "Code: " << err << endl;
704 lyxerr.debug() << "Cmd: "
708 << p->data->fname << endl;
711 // normal process (parent)
712 if (lyxerr.debugging()) {
713 lyxerr << "GS [" << pid << "] started" << endl;
715 gsqueue = gsqueue->next;
717 p->data->gspid = pid;
723 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
725 // recompute the stuff and put in the queue
726 queue * p = new queue;
729 p->rx = (float(data->raw_wid) * 72.0) / pswid;
730 p->ry = (float(data->raw_hgh) * 72.0) / pshgh;
735 // now put into queue
736 queue * p2 = gsqueue;
737 if (!gsqueue) gsqueue = p;
739 while (p2->next) p2 = p2->next;
743 // if possible, run the queue
748 static figdata * getfigdata(int wid, int hgh, string const & fname,
749 int psx, int psy, int pswid, int pshgh,
750 int raw_wid, int raw_hgh, float angle, char flags)
752 /* first search for an exact match with fname and width/height */
754 if (fname.empty()) return 0;
757 while (i < bmpinsref) {
758 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
759 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
760 bitmaps[i]->angle == angle) {
766 /* not found -> create new record or return 0 if no record */
768 if (bmpinsref > bmparrsize) {
769 // allocate more space
770 bmparrsize += figallocchunk;
771 figdata ** tmp = static_cast<figdata**>
772 (malloc(sizeof(figdata*) * bmparrsize));
774 sizeof(figdata*) * (bmparrsize - figallocchunk));
778 figdata * p = new figdata;
779 bitmaps[bmpinsref-1] = p;
782 p->raw_wid = raw_wid;
783 p->raw_hgh = raw_hgh;
787 XWindowAttributes wa;
788 XGetWindowAttributes(fl_display, fl_get_canvas_id(
789 figinset_canvas), &wa);
791 if (lyxerr.debugging()) {
792 lyxerr << "Create pixmap disp:" << fl_display
793 << " scr:" << DefaultScreen(fl_display)
796 << " depth:" << wa.depth << endl;
804 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
805 figinset_canvas), wid, hgh, wa.depth);
807 // initialize reading of .eps file with correct sizes and stuff
808 addwait(psx, psy, pswid, pshgh, p);
819 static void getbitmap(figdata * p)
825 static void makeupdatelist(figdata * p)
827 for (int i = 0; i < figinsref; ++i)
828 if (figures[i]->data == p) {
829 if (lyxerr.debugging()) {
830 lyxerr << "Updating inset "
834 //UpdateInset(figures[i]->inset);
835 // add inset figures[i]->inset into to_update list
836 PutInsetIntoInsetUpdateList(figures[i]->inset);
841 void sigchldchecker(pid_t pid, int * status)
843 lyxerr.debug() << "Got pid = " << pid << endl;
844 bool pid_handled = false;
845 for (int i = bmpinsref - 1; i >= 0; --i) {
846 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
847 lyxerr.debug() << "Found pid in bitmaps" << endl;
848 // now read the file and remove it from disk
849 figdata * p = bitmaps[i];
851 if (bitmaps[i]->gsdone) *status = 0;
853 lyxerr.debug() << "GS [" << pid
854 << "] exit OK." << endl;
856 lyxerr << "GS [" << pid << "] error "
858 << WIFEXITED(*status)
859 << " " << WEXITSTATUS(*status)
860 << " S:" << WIFSIGNALED(*status)
861 << " " << WTERMSIG(*status) << endl;
864 bitmap_waiting = true;
867 // remove temporary files
869 sprintf(tmp, "%s/~lyxgs%d.ps",
870 system_tempdir.c_str(),
876 makeupdatelist(bitmaps[i]);
883 lyxerr.debug() << "Checking pid in pidwait" << endl;
884 pidwait * p = pw, * prev = 0;
887 lyxerr.debug() << "Found pid in pidwait" << endl;
888 lyxerr.debug() << "Caught child pid of recompute routine " << pid << endl;
890 prev->next = p->next;
902 lyxerr.debug() << "waitpid error" << endl;
905 lyxerr << "The process or process group specified by "
906 "pid does not exist or is not a child of "
907 "the calling process or can never be in the "
908 "states specified by options." << endl;
911 lyxerr << "waitpid() was interrupted due to the "
912 "receipt of a signal sent by the calling "
916 lyxerr << "An invalid value was specified for "
920 lyxerr << "Unknown error from waitpid" << endl;
923 } else if (pid == 0) {
924 lyxerr << "waitpid nohang" << endl;;
926 lyxerr.debug() << "normal exit from childhandler" << endl;
931 static void getbitmaps()
933 bitmap_waiting = false;
934 for (int i = 0; i < bmpinsref; ++i)
935 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
936 getbitmap(bitmaps[i]);
940 static void RegisterFigure(InsetFig *fi)
942 if (figinsref == 0) InitFigures();
945 if (figinsref > figarrsize) {
946 // allocate more space
947 figarrsize += figallocchunk;
948 Figref ** tmp = static_cast<Figref**>
949 (malloc(sizeof(Figref*)*figarrsize));
951 sizeof(Figref*)*(figarrsize-figallocchunk));
955 Figref * tmpfig = new Figref;
958 figures[figinsref-1] = tmpfig;
961 if (lyxerr.debugging()) {
962 lyxerr << "Register Figure: buffer:["
963 << current_view->buffer() << "]" << endl;
968 int FindFigIndex(Figref * tmpfig)
971 while (i < figinsref) {
972 if (figures[i] == tmpfig) return i;
979 static void UnregisterFigure(InsetFig * fi)
981 Figref * tmpfig = fi->figure;
983 if (tmpfig->data) freefigdata(tmpfig->data);
984 if (tmpfig->inset->form) {
985 if (tmpfig->inset->form->Figure->visible) {
986 fl_set_focus_object(tmpfig->inset->form->Figure,
987 tmpfig->inset->form->OkBtn);
988 fl_hide_form(tmpfig->inset->form->Figure);
990 #if FL_REVISION == 89
991 #warning Reactivate this free_form calls
993 fl_free_form(tmpfig->inset->form->Figure);
994 free(tmpfig->inset->form);
995 tmpfig->inset->form = 0;
998 int i = FindFigIndex(tmpfig);
1000 while (i < figinsref) {
1001 figures[i] = figures[i+1];
1006 if (figinsref == 0) DoneFigures();
1010 static string NextToken(istream & is)
1018 } while (!is.eof() && !isspace(c));
1019 token.erase(token.length() - 1); // remove the isspace
1025 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1035 psubfigure = subfigure = false;
1036 xwid = xhgh = angle = 0;
1038 raw_wid = raw_hgh = 0;
1039 changedfname = false;
1040 RegisterFigure(this);
1044 InsetFig::~InsetFig()
1046 if (lyxerr.debugging()) {
1047 lyxerr << "Figure destructor called" << endl;
1049 UnregisterFigure(this);
1053 int InsetFig::Ascent(LyXFont const &) const
1059 int InsetFig::Descent(LyXFont const &) const
1065 int InsetFig::Width(LyXFont const &) const
1071 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1073 if (bitmap_waiting) getbitmaps();
1075 // I wish that I didn't have to use this
1076 // but the figinset code is so complicated so
1077 // I don't want to fiddle with it now.
1078 unsigned long pm = scr.getForeground();
1080 if (figure && figure->data && figure->data->bitmap &&
1081 !figure->data->reading && !figure->data->broken) {
1083 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1084 0, 0, wid, hgh, int(x+1), baseline-hgh);
1086 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1087 int(x), baseline - hgh - 1,
1092 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1094 baseline - hgh - 1, wid+1, hgh+1);
1095 if (figure && figure->data) {
1096 if (figure->data->broken) msg = _("[render error]");
1097 else if (figure->data->reading) msg = _("[rendering ... ]");
1099 if (fname.empty()) msg = _("[no file]");
1100 else if ((flags & 3) == 0) msg = _("[not displayed]");
1101 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1103 if (!msg) msg = _("[unknown error]");
1105 font.setFamily (LyXFont::SANS_FAMILY);
1106 font.setSize (LyXFont::SIZE_FOOTNOTE);
1107 string justname = OnlyFilename (fname);
1108 font.drawString(justname, pm,
1109 baseline - font.maxAscent() - 4,
1111 font.setSize (LyXFont::SIZE_TINY);
1112 font.drawText (msg, strlen(msg), pm,
1117 x += Width(font); // ?
1121 void InsetFig::Write(ostream & os)
1124 os << "Figure size " << wid << " " << hgh << "\n";
1125 if (!fname.empty()) {
1126 string buf1 = OnlyPath(owner->fileName());
1127 string fname2 = MakeRelPath(fname, buf1);
1128 os << "file " << fname2 << "\n";
1130 if (!subcaption.empty())
1131 os << "subcaption " << subcaption << "\n";
1132 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1133 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1134 if (angle != 0) os << "angle " << angle << "\n";
1135 os << "flags " << flags << "\n";
1136 if (subfigure) os << "subfigure\n";
1140 void InsetFig::Read(LyXLex & lex)
1143 bool finished = false;
1145 while (lex.IsOK() && !finished) {
1148 string const token = lex.GetString();
1149 lyxerr.debug() << "Token: " << token << endl;
1153 else if (token == "\\end_inset") {
1155 } else if (token == "file") {
1157 buf = lex.GetString();
1158 string buf1 = OnlyPath(owner->fileName());
1159 fname = MakeAbsPath(buf, buf1);
1160 changedfname = true;
1162 } else if (token == "extra") {
1164 // kept for backwards compability. Delete in 0.13.x
1165 } else if (token == "subcaption") {
1167 subcaption = lex.GetString();
1168 } else if (token == "label") {
1170 // kept for backwards compability. Delete in 0.13.x
1171 } else if (token == "angle") {
1173 angle = lex.GetFloat();
1174 } else if (token == "size") {
1176 wid = lex.GetInteger();
1178 hgh = lex.GetInteger();
1179 } else if (token == "flags") {
1181 flags = pflags = lex.GetInteger();
1182 } else if (token == "subfigure") {
1183 subfigure = psubfigure = true;
1184 } else if (token == "width") {
1187 typ = lex.GetInteger();
1189 xwid = lex.GetFloat();
1191 case DEF: wtype = DEF; break;
1192 case CM: wtype = CM; break;
1193 case IN: wtype = IN; break;
1194 case PER_PAGE: wtype = PER_PAGE; break;
1195 case PER_COL: wtype = PER_COL; break;
1197 lyxerr.debug() << "Unknown type!" << endl;
1201 } else if (token == "height") {
1204 typ = lex.GetInteger();
1206 xhgh = lex.GetFloat();
1208 case DEF: htype = DEF; break;
1209 case CM: htype = CM; break;
1210 case IN: htype = IN; break;
1211 case PER_PAGE: htype = PER_PAGE; break;
1213 lyxerr.debug() << "Unknown type!" << endl;
1224 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1227 if (!cmd.empty()) os << cmd << " ";
1232 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1240 int InsetFig::Linuxdoc(string &/*file*/)
1246 int InsetFig::DocBook(string & file)
1248 string figurename = fname;
1250 if(suffixIs(figurename, ".eps"))
1251 figurename.erase(fname.length() - 5);
1253 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1258 void InsetFig::Validate(LaTeXFeatures & features) const
1260 features.graphics = true;
1261 if (subfigure) features.subfigure = true;
1265 unsigned char InsetFig::Editable() const
1271 bool InsetFig::Deletable() const
1277 void InsetFig::Edit(int, int)
1279 lyxerr.debug() << "Editing InsetFig." << endl;
1282 // We should have RO-versions of the form instead.
1283 // The actual prevention of altering a readonly doc
1284 // is done in CallbackFig()
1285 if(current_view->buffer()->isReadonly())
1286 WarnReadonly(current_view->buffer()->fileName());
1289 form = create_form_Figure();
1290 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1291 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1292 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1293 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1296 if (form->Figure->visible) {
1297 fl_raise_form(form->Figure);
1299 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1300 FL_FULLBORDER, _("Figure"));
1305 Inset * InsetFig::Clone() const
1307 InsetFig * tmp = new InsetFig(100, 100, owner);
1309 if (lyxerr.debugging()) {
1310 lyxerr << "Clone Figure: buffer:["
1311 << current_view->buffer()
1312 << "], cbuffer:[xx]" << endl;
1317 tmp->raw_wid = raw_wid;
1318 tmp->raw_hgh = raw_hgh;
1323 tmp->pflags = pflags;
1324 tmp->subfigure = subfigure;
1325 tmp->psubfigure = psubfigure;
1333 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1334 // do not display if there is
1335 // "do not display" chosen (Matthias 260696)
1336 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1337 pswid, pshgh, raw_wid, raw_hgh,
1338 angle, flags & (3|8));
1339 } else tmp->figure->data = 0;
1340 tmp->subcaption = subcaption;
1341 tmp->changedfname = false;
1348 Inset::Code InsetFig::LyxCode() const
1350 return Inset::GRAPHICS_CODE;
1354 void InsetFig::Regenerate()
1357 string resizeW, resizeH;
1358 string rotate, recmd;
1360 if (fname.empty()) {
1361 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1362 cmd += _("empty figure path");
1364 //if (form) fl_set_object_label(form->cmd, "");
1368 string buf1 = OnlyPath(owner->fileName());
1369 string fname2 = MakeRelPath(fname, buf1);
1371 string gcmd = "\\includegraphics{" + fname2 + '}';
1376 case CM:{// \resizebox*{h-length}{v-length}{text}
1378 sprintf(buf, "%g", xwid); // should find better
1385 sprintf(buf, "%g", xwid);
1392 sprintf(buf, "%g", xwid/100);
1394 resizeW += "\\textwidth";
1399 sprintf(buf, "%g", xwid/100);
1401 resizeW += "\\columnwidth";
1411 sprintf(buf, "%g", xhgh);
1418 sprintf(buf, "%g", xhgh);
1425 sprintf(buf, "%g", xhgh/100);
1427 resizeH += "\\textheight";
1431 // Doesn't occur; case exists to suppress compiler warnings.
1436 if (!resizeW.empty() || !resizeH.empty()) {
1437 recmd = "\\resizebox*{";
1438 if (!resizeW.empty())
1443 if (!resizeH.empty())
1453 sprintf(buf, "%g", angle);
1454 // \rotatebox{angle}{text}
1455 rotate = "\\rotatebox{";
1463 if (!rotate.empty()) cmdbuf += '}';
1464 if (!recmd.empty()) cmdbuf += '}';
1466 if (!subcaption.empty())
1467 cmdbuf = "\\subfigure[" + subcaption +
1468 "]{" + cmdbuf + "}";
1470 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1475 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1479 void InsetFig::TempRegenerate()
1482 string resizeW, resizeH;
1483 string rotate, recmd;
1485 char const * tfname = fl_get_input(form->EpsFile);
1486 string tsubcap = fl_get_input(form->Subcaption);
1487 float tangle = atof(fl_get_input(form->Angle));
1488 float txwid = atof(fl_get_input(form->Width));
1489 float 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->fileName());
1501 string fname2 = MakeRelPath(tfname, buf1);
1502 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1503 string 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 + "}";
1604 void InsetFig::Recompute()
1606 bool changed = changedfname;
1607 int newx, newy, nraw_x, nraw_y;
1609 if (changed) GetPSSizes();
1611 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1612 float cos_a = cos (angle / DEG2PI);
1613 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1614 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1616 /* now recompute wid and hgh, and if that is changed, set changed */
1617 /* this depends on chosen size of the picture and its bbox */
1618 // This will be redone in 0.13 ... (hen)
1619 if (!fname.empty()) {
1620 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1628 newx = int(28.346 * xwid);
1631 newx = int(72 * xwid);
1633 case PER_PAGE: /* % of page */
1634 newx = int(5.95 * xwid);
1636 case PER_COL: /* % of col */
1637 newx = int(2.975 * xwid);
1641 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1645 //lyxerr << "This should not happen!" << endl;
1648 newy = int(28.346 * xhgh);
1651 newy = int(72 * xhgh);
1653 case PER_PAGE: /* % of page */
1654 newy = int(8.42 * xhgh);
1657 // Doesn't occur; case exists to suppress
1658 // compiler warnings.
1661 if (htype && !wtype && frame_hgh)
1662 newx = newy*frame_wid/frame_hgh;
1671 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1676 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1678 // cannot be zero, actually, set it to some minimum, so its clickable
1679 if (newx < 5) newx = 5;
1680 if (newy < 5) newy = 5;
1682 if (newx != wid || newy != hgh ||
1683 nraw_x != raw_wid || nraw_y != raw_hgh ||
1684 flags != pflags || subfigure != psubfigure)
1692 subfigure = psubfigure;
1695 figdata * pf = figure->data;
1698 if (!fname.empty() && (flags & 3)
1699 && !lyxrc->ps_command.empty()) {
1700 // do not display if there is "do not display"
1701 // chosen (Matthias 260696)
1702 figure->data = getfigdata(wid, hgh, fname,
1703 psx, psy, pswid, pshgh,
1705 angle, flags & (3|8));
1706 } else figure->data = 0;
1708 // free the old data
1709 if (pf) freefigdata(pf);
1712 changedfname = false;
1716 void InsetFig::GetPSSizes()
1718 /* get %%BoundingBox: from postscript file */
1720 /* defaults to associated size
1721 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1728 if (fname.empty()) return;
1730 ifstream ifs(fname.c_str());
1732 if (!ifs) return; // file not found !!!!
1734 /* defaults to A4 page */
1740 char lastchar = 0; ifs.get(lastchar);
1742 char c = 0; ifs.get(c);
1744 lyxerr.debug() << "End of (E)PS file reached and"
1745 " no BoundingBox!" << endl;
1748 if (c == '%' && lastchar == '%') {
1750 if (p.empty()) break;
1751 // we should not use this, with it we cannot
1752 // discover bounding box and end of file.
1753 //if (strcmp(p, "EndComments") == 0) break;
1754 lyxerr.debug() << "Token: `" << p << "'" << endl;
1755 if (p == "BoundingBox:") {
1756 float fpsx, fpsy, fpswid, fpshgh;
1757 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1760 pswid = int(fpswid);
1761 pshgh = int(fpshgh);
1763 if (lyxerr.debugging()) {
1764 lyxerr << "%%%%BoundingBox:"
1782 void InsetFig::CallbackFig(long arg)
1787 if (lyxerr.debugging()) {
1788 lyxerr << "Figure callback, arg " << arg << endl;
1794 case 12: /* width type */
1801 fl_deactivate_object(form->Width);
1806 fl_activate_object(form->Width);
1811 fl_activate_object(form->Width);
1816 fl_activate_object(form->Width);
1821 fl_activate_object(form->Width);
1824 lyxerr.debug() << "Unknown type!" << endl;
1831 case 22: /* height type */
1837 fl_deactivate_object(form->Height);
1842 fl_activate_object(form->Height);
1847 fl_activate_object(form->Height);
1852 fl_activate_object(form->Height);
1855 lyxerr.debug() << "Unknown type!" << endl;
1861 pflags = pflags & ~3; /* wysiwyg0 */
1864 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1867 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1870 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1873 pflags ^= 4; /* frame */
1876 pflags ^= 8; /* do translations */
1879 psubfigure = !psubfigure; /* This is a subfigure */
1882 regen = true; /* regenerate command */
1884 case 0: /* browse file */
1888 case 1: /* preview */
1889 p = fl_get_input(form->EpsFile);
1893 case 8: /* ok (apply and close) */
1894 if(!current_view->buffer()->isReadonly()) {
1897 xwid = atof(fl_get_input(form->Width));
1898 xhgh = atof(fl_get_input(form->Height));
1899 angle = atof(fl_get_input(form->Angle));
1900 p = fl_get_input(form->EpsFile);
1902 string buf1 = OnlyPath(owner->fileName());
1903 fname = MakeAbsPath(p, buf1);
1904 changedfname = true;
1906 if (!fname.empty()) {
1907 changedfname = true;
1911 subcaption = fl_get_input(form->Subcaption);
1915 /* now update inset */
1916 if (lyxerr.debugging()) {
1917 lyxerr << "Update: ["
1918 << wid << 'x' << hgh << ']' << endl;
1922 fl_set_focus_object(form->Figure, form->OkBtn);
1923 fl_hide_form(form->Figure);
1924 #if FL_REVISION == 89
1925 #warning Reactivate this free_form calls
1927 fl_free_form(form->Figure);
1934 // The user has already been informed about RO in ::Edit
1935 if(arg == 7) // if 'Apply'
1938 case 9: /* cancel = restore and close */
1939 fl_set_focus_object(form->Figure, form->OkBtn);
1940 fl_hide_form(form->Figure);
1941 #if FL_REVISION == 89
1942 #warning Reactivate this free_form calls
1943 #warning Jug, is this still a problem?
1945 fl_free_form(form->Figure);
1952 if (regen) TempRegenerate();
1956 inline void DisableFigurePanel(FD_Figure * const form)
1958 fl_deactivate_object(form->EpsFile);
1959 fl_deactivate_object(form->Browse);
1960 fl_deactivate_object(form->Width);
1961 fl_deactivate_object(form->Height);
1962 fl_deactivate_object(form->Frame);
1963 fl_deactivate_object(form->Translations);
1964 fl_deactivate_object(form->Angle);
1965 fl_deactivate_object(form->HeightGrp);
1966 fl_deactivate_object(form->page2);
1967 fl_deactivate_object(form->Default2);
1968 fl_deactivate_object(form->cm2);
1969 fl_deactivate_object(form->in2);
1970 fl_deactivate_object(form->HeightLabel);
1971 fl_deactivate_object(form->WidthLabel);
1972 fl_deactivate_object(form->DisplayGrp);
1973 fl_deactivate_object(form->Wysiwyg3);
1974 fl_deactivate_object(form->Wysiwyg0);
1975 fl_deactivate_object(form->Wysiwyg2);
1976 fl_deactivate_object(form->Wysiwyg1);
1977 fl_deactivate_object(form->WidthGrp);
1978 fl_deactivate_object(form->Default1);
1979 fl_deactivate_object(form->cm1);
1980 fl_deactivate_object(form->in1);
1981 fl_deactivate_object(form->page1);
1982 fl_deactivate_object(form->column1);
1983 fl_deactivate_object(form->Subcaption);
1984 fl_deactivate_object(form->Subfigure);
1985 fl_deactivate_object (form->OkBtn);
1986 fl_deactivate_object (form->ApplyBtn);
1987 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1988 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1992 inline void EnableFigurePanel(FD_Figure * const form)
1994 fl_activate_object(form->EpsFile);
1995 fl_activate_object(form->Browse);
1996 fl_activate_object(form->Width);
1997 fl_activate_object(form->Height);
1998 fl_activate_object(form->Frame);
1999 fl_activate_object(form->Translations);
2000 fl_activate_object(form->Angle);
2001 fl_activate_object(form->HeightGrp);
2002 fl_activate_object(form->page2);
2003 fl_activate_object(form->Default2);
2004 fl_activate_object(form->cm2);
2005 fl_activate_object(form->in2);
2006 fl_activate_object(form->HeightLabel);
2007 fl_activate_object(form->WidthLabel);
2008 fl_activate_object(form->DisplayGrp);
2009 fl_activate_object(form->Wysiwyg3);
2010 fl_activate_object(form->Wysiwyg0);
2011 fl_activate_object(form->Wysiwyg2);
2012 fl_activate_object(form->Wysiwyg1);
2013 fl_activate_object(form->WidthGrp);
2014 fl_activate_object(form->Default1);
2015 fl_activate_object(form->cm1);
2016 fl_activate_object(form->in1);
2017 fl_activate_object(form->page1);
2018 fl_activate_object(form->column1);
2019 fl_activate_object(form->Subcaption);
2020 fl_activate_object(form->Subfigure);
2021 fl_activate_object (form->OkBtn);
2022 fl_activate_object (form->ApplyBtn);
2023 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2024 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2028 void InsetFig::RestoreForm()
2032 EnableFigurePanel(form);
2035 fl_set_button(form->Default1, (wtype == 0));
2036 fl_set_button(form->cm1, (wtype == 1));
2037 fl_set_button(form->in1, (wtype == 2));
2038 fl_set_button(form->page1, (wtype == 3));
2039 fl_set_button(form->column1, (wtype == 4));
2041 fl_deactivate_object(form->Width);
2043 fl_activate_object(form->Width);
2046 // enable and disable should be put here.
2048 fl_set_button(form->Default2, (htype == 0));
2049 fl_set_button(form->cm2, (htype == 1));
2050 fl_set_button(form->in2, (htype == 2));
2051 fl_set_button(form->page2, (htype == 3));
2052 // enable and disable should be put here.
2054 fl_deactivate_object(form->Height);
2056 fl_activate_object(form->Height);
2059 int pflags = flags & 3;
2060 fl_set_button(form->Wysiwyg0, (pflags == 0));
2061 fl_set_button(form->Wysiwyg1, (pflags == 1));
2062 fl_set_button(form->Wysiwyg2, (pflags == 2));
2063 fl_set_button(form->Wysiwyg3, (pflags == 3));
2064 fl_set_button(form->Frame, ((flags & 4) != 0));
2065 fl_set_button(form->Translations, ((flags & 8) != 0));
2066 fl_set_button(form->Subfigure, (subfigure != 0));
2068 psubfigure = subfigure;
2069 sprintf(buf, "%g", xwid);
2070 fl_set_input(form->Width, buf);
2071 sprintf(buf, "%g", xhgh);
2072 fl_set_input(form->Height, buf);
2073 sprintf(buf, "%g", angle);
2074 fl_set_input(form->Angle, buf);
2075 if (!fname.empty()){
2076 string buf1 = OnlyPath(owner->fileName());
2077 string fname2 = MakeRelPath(fname, buf1);
2078 fl_set_input(form->EpsFile, fname2.c_str());
2080 else fl_set_input(form->EpsFile, "");
2081 fl_set_input(form->Subcaption, subcaption.c_str());
2082 if(current_view->buffer()->isReadonly())
2083 DisableFigurePanel(form);
2089 void InsetFig::Preview(char const * p)
2094 lyxerr << "Cannot fork process!" << endl;
2099 return; // parent process
2102 string buf1 = OnlyPath(owner->fileName());
2103 string buf2 = MakeAbsPath(p, buf1);
2105 lyxerr << "Error during rendering "
2106 << execlp(lyxrc->view_pspic_command.c_str(),
2107 lyxrc->view_pspic_command.c_str(),
2114 void InsetFig::BrowseFile()
2116 static string current_figure_path;
2117 static int once = 0;
2120 if (lyxerr.debugging()) {
2121 lyxerr << "Filename: "
2122 << owner->fileName() << endl;
2124 string p = fl_get_input(form->EpsFile);
2126 string buf = MakeAbsPath(owner->fileName());
2127 string buf2 = OnlyPath(buf);
2129 buf = MakeAbsPath(p, buf2);
2130 buf = OnlyPath(buf);
2132 buf = OnlyPath(owner->fileName().c_str());
2135 // Does user clipart directory exist?
2136 string bufclip = AddName (user_lyxdir, "clipart");
2137 FileInfo fileInfo(bufclip);
2138 if (!(fileInfo.isOK() && fileInfo.isDir()))
2139 // No - bail out to system clipart directory
2140 bufclip = AddName (system_lyxdir, "clipart");
2143 fileDlg.SetButton(0, _("Clipart"), bufclip);
2144 fileDlg.SetButton(1, _("Document"), buf);
2150 p = fileDlg.Select(_("EPS Figure"),
2151 current_figure_path,
2154 p = fileDlg.Select(_("EPS Figure"), buf,
2159 if (p.empty()) return;
2161 buf = MakeRelPath(p, buf2);
2162 current_figure_path = OnlyPath(p);
2165 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2166 || contains(p, "%") || contains(p, " "))
2168 WriteAlert(_("Filename can't contain any "
2169 "of these characters:"),
2170 // xgettext:no-c-format
2171 _("space, '#', '~', '$' or '%'."));
2176 if (form) fl_set_input(form->EpsFile, buf.c_str());
2180 void GraphicsCB(FL_OBJECT * obj, long arg)
2182 /* obj->form contains the form */
2184 if (lyxerr.debugging()) {
2185 lyxerr << "GraphicsCB callback: " << arg << endl;
2188 /* find inset we were reacting to */
2189 for (int i = 0; i < figinsref; ++i)
2190 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2193 if (lyxerr.debugging()) {
2194 lyxerr << "Calling back figure " << i << endl;
2196 figures[i]->inset->CallbackFig(arg);
2202 void HideFiguresPopups()
2204 for (int i = 0; i < figinsref; ++i)
2205 if (figures[i]->inset->form
2206 && figures[i]->inset->form->Figure->visible) {
2207 if (lyxerr.debugging()) {
2208 lyxerr << "Hiding figure " << i << endl;
2210 // hide and free the form
2211 figures[i]->inset->CallbackFig(9);