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 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 lyx::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 lyx::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 typedef Figref * Figref_p;
371 figures = new Figref_p[figallocchunk];
372 //figures = static_cast<Figref**>
373 // (malloc(sizeof(Figref*) * figallocchunk));
374 typedef figdata * figdata_p;
375 bitmaps = new figdata_p[figallocchunk];
376 //bitmaps = static_cast<figdata**>
377 //(malloc(sizeof(figdata*) * figallocchunk));
380 for (unsigned int i = 0; i < 256; ++i) {
382 for (unsigned int j = 0; j < 8; ++j)
383 if (i & (1 << (7-j))) k |= 1 << j;
384 bittable[i] = char(~k);
387 fl_add_canvas_handler(figinset_canvas, ClientMessage,
388 GhostscriptMsg, current_view->owner()->getMainForm());
390 // now we have to init color_map
391 if (!color_map) color_map = DefaultColormap(fl_display,
392 DefaultScreen(fl_display));
393 // allocate color cube on pseudo-color display
397 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
398 if (lyxerr.debugging()) {
399 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
400 vi->visualid, vi->c_class,
401 vi->bits_per_rgb, vi->map_entries);
403 color_visual = ( (vi->c_class == StaticColor) ||
404 (vi->c_class == PseudoColor) ||
405 (vi->c_class == TrueColor) ||
406 (vi->c_class == DirectColor) );
407 if ((vi->c_class & 1) == 0) return;
408 // now allocate colors
409 if (vi->c_class == GrayScale) {
410 // allocate grayscale
411 AllocGrays(vi->map_entries/2);
413 // allocate normal color
415 while (i * i * i * 2 > vi->map_entries) --i;
418 gs_allcolors = vi->map_entries;
431 lyxerr.debug() << "Unregistering figures..." << endl;
433 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
437 lyxerr.debug() << "Freeing up the colors..." << endl;
438 XFreeColors(fl_display, color_map, gs_pixels,
440 /******????????????????? what's planes in this case ??????***/
445 int FindBmpIndex(figdata * tmpdata)
448 while (i < bmpinsref) {
449 if (bitmaps[i] == tmpdata) return i;
456 static void chpixmap(Pixmap, int, int)
459 Display * tempdisp = XOpenDisplay(XDisplayName(0));
461 // here read the pixmap and change all colors to those we
464 XCloseDisplay(tempdisp);
469 static void freefigdata(figdata * tmpdata)
472 if (tmpdata->ref) return;
474 if (tmpdata->gspid > 0) {
475 int pid = tmpdata->gspid;
477 // change Pixmap according to our allocated colormap
478 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
479 // kill ghostscript and unlink it's files
481 lyx::kill(pid, SIGKILL);
482 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
486 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
488 int i = FindBmpIndex(tmpdata);
490 while (i < bmpinsref) {
491 bitmaps[i] = bitmaps[i + 1];
497 static void runqueue()
499 // run queued requests for ghostscript, if any
500 if (!gsrunning && gs_color && !gs_xcolor) {
501 // here alloc all colors, so that gs will use only
502 // those we allocated for it
507 while (gsrunning < MAXGS) {
508 char tbuf[384], tbuf2[80];
513 if (!gsrunning && gs_xcolor) {
514 // de-allocate rest of colors
530 if (lyxerr.debugging()) {
531 lyxerr << "GS start error! Cannot fork."
534 p->data->broken = true;
535 p->data->reading = false;
538 if (pid == 0) { // child
539 char ** env, rbuf[80], gbuf[40];
541 Display * tempdisp = XOpenDisplay(XDisplayName(0));
543 // create translation file
544 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
548 ofs << "gsave clippath pathbbox grestore\n"
550 << "/ury exch def /urx exch def /lly exch def "
552 << p->data->wid / 2.0 << " "
553 << p->data->hgh / 2.0 << " translate\n"
554 << p->data->angle << " rotate\n"
555 << -(p->data->raw_wid / 2.0) << " "
556 << -(p->data->raw_hgh / 2.0) << " translate\n"
557 << p->rx / 72.0 << " " << p->ry / 72.0
559 << -p->ofsx << " " << -p->ofsy << " translate\n"
561 ofs.close(); // Don't remove this.
563 // gs process - set ghostview environment first
564 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
565 figinset_canvas), p->data->bitmap);
567 // now set up ghostview property on a window
568 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
569 p->data->wid, p->data->hgh);
570 // #warning BUG seems that the only bug here
571 // might be the hardcoded dpi.. Bummer!
573 if (lyxerr.debugging()) {
574 lyxerr << "Will set GHOSTVIEW property to ["
575 << tbuf << "]" << endl;
577 // wait until property is deleted if executing multiple
580 // grab server to prevent other child
581 // interfering with setting GHOSTVIEW property
582 if (lyxerr.debugging()) {
583 lyxerr << "Grabbing the server"
586 XGrabServer(tempdisp);
587 prop = XListProperties(tempdisp,
589 figinset_canvas), &nprop);
593 for (i = 0; i < nprop; ++i) {
594 char * p = XGetAtomName(tempdisp,
596 if (strcmp(p, "GHOSTVIEW") == 0) {
602 XFree(reinterpret_cast<char *>(prop)); // jc:
604 // release the server
605 XUngrabServer(tempdisp);
607 // ok, property found, we must wait until
608 // ghostscript deletes it
609 if (lyxerr.debugging()) {
610 lyxerr << "Releasing the server\n["
612 << "] GHOSTVIEW property"
613 " found. Waiting." << endl;
617 #warning What is this doing? (wouldn't a sleep(1); work too?')
621 signal(SIGALRM, waitalarm);
622 while (!alarmed) pause();
628 XChangeProperty(tempdisp,
629 fl_get_canvas_id(figinset_canvas),
630 XInternAtom(tempdisp, "GHOSTVIEW", false),
631 XInternAtom(tempdisp, "STRING", false),
633 reinterpret_cast<unsigned char*>(tbuf),
636 switch (p->data->flags & 3) {
637 case 0: tbuf[0] = 'H'; break; // Hidden
638 case 1: tbuf[0] = 'M'; break; // Mono
639 case 2: tbuf[0] = 'G'; break; // Gray
642 tbuf[0] = 'C'; // Color
644 tbuf[0] = 'G'; // Gray
649 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
650 DefaultScreenOfDisplay(fl_display)),
653 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
654 DefaultScreenOfDisplay(fl_display)),
658 XChangeProperty(tempdisp,
659 fl_get_canvas_id(figinset_canvas),
660 XInternAtom(tempdisp,
661 "GHOSTVIEW_COLORS", false),
662 XInternAtom(tempdisp, "STRING", false),
664 reinterpret_cast<unsigned char*>(tbuf),
666 XUngrabServer(tempdisp);
668 if (lyxerr.debugging()) {
669 lyxerr << "Releasing the server" << endl;
671 XCloseDisplay(tempdisp);
673 // set up environment
674 while (environ[ne]) ++ne;
675 typedef char * char_p;
676 env = new char_p[ne + 2];
677 //env = static_cast<char **>
678 // (malloc(sizeof(char*) * (ne + 2)));
680 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
683 // now make gs command
685 // close(1); do NOT close. If GS writes out
686 // errors it would hang. (Matthias 290596)
687 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
688 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
689 // now chdir into dir with .eps file, to be on the safe
691 chdir(OnlyPath(p->data->fname).c_str());
692 // make temp file name
693 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
695 if (lyxerr.debugging()) {
696 lyxerr << "starting gs " << tbuf << " "
698 << ", pid: " << getpid() << endl;
701 int err = execlp(lyxrc->ps_command.c_str(),
702 lyxrc->ps_command.c_str(),
704 "-dNOPAUSE", "-dQUIET",
707 p->data->fname.c_str(),
708 "showpage.ps", "quit.ps", "-", 0);
709 // if we are still there, an error occurred.
710 lyxerr << "Error executing ghostscript. "
711 << "Code: " << err << endl;
712 lyxerr.debug() << "Cmd: "
716 << p->data->fname << endl;
719 // normal process (parent)
720 if (lyxerr.debugging()) {
721 lyxerr << "GS [" << pid << "] started" << endl;
723 gsqueue = gsqueue->next;
725 p->data->gspid = pid;
731 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
733 // recompute the stuff and put in the queue
734 queue * p = new queue;
737 p->rx = (float(data->raw_wid) * 72.0) / pswid;
738 p->ry = (float(data->raw_hgh) * 72.0) / pshgh;
743 // now put into queue
744 queue * p2 = gsqueue;
745 if (!gsqueue) gsqueue = p;
747 while (p2->next) p2 = p2->next;
751 // if possible, run the queue
756 static figdata * getfigdata(int wid, int hgh, string const & fname,
757 int psx, int psy, int pswid, int pshgh,
758 int raw_wid, int raw_hgh, float angle, char flags)
760 /* first search for an exact match with fname and width/height */
762 if (fname.empty()) return 0;
765 while (i < bmpinsref) {
766 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
767 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
768 bitmaps[i]->angle == angle) {
774 /* not found -> create new record or return 0 if no record */
776 if (bmpinsref > bmparrsize) {
777 // allocate more space
778 bmparrsize += figallocchunk;
779 typedef figdata * figdata_p;
780 figdata ** tmp = new figdata_p[bmparrsize];
781 //figdata ** tmp = static_cast<figdata**>
782 // (malloc(sizeof(figdata*) * bmparrsize));
784 sizeof(figdata*) * (bmparrsize - figallocchunk));
789 figdata * p = new figdata;
790 bitmaps[bmpinsref-1] = p;
793 p->raw_wid = raw_wid;
794 p->raw_hgh = raw_hgh;
798 XWindowAttributes wa;
799 XGetWindowAttributes(fl_display, fl_get_canvas_id(
800 figinset_canvas), &wa);
802 if (lyxerr.debugging()) {
803 lyxerr << "Create pixmap disp:" << fl_display
804 << " scr:" << DefaultScreen(fl_display)
807 << " depth:" << wa.depth << endl;
815 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
816 figinset_canvas), wid, hgh, wa.depth);
818 // initialize reading of .eps file with correct sizes and stuff
819 addwait(psx, psy, pswid, pshgh, p);
830 static void getbitmap(figdata * p)
836 static void makeupdatelist(figdata * p)
838 for (int i = 0; i < figinsref; ++i)
839 if (figures[i]->data == p) {
840 if (lyxerr.debugging()) {
841 lyxerr << "Updating inset "
845 //UpdateInset(figures[i]->inset);
846 // add inset figures[i]->inset into to_update list
847 PutInsetIntoInsetUpdateList(figures[i]->inset);
852 void sigchldchecker(pid_t pid, int * status)
854 lyxerr.debug() << "Got pid = " << pid << endl;
855 bool pid_handled = false;
856 for (int i = bmpinsref - 1; i >= 0; --i) {
857 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
858 lyxerr.debug() << "Found pid in bitmaps" << endl;
859 // now read the file and remove it from disk
860 figdata * p = bitmaps[i];
862 if (bitmaps[i]->gsdone) *status = 0;
864 lyxerr.debug() << "GS [" << pid
865 << "] exit OK." << endl;
867 lyxerr << "GS [" << pid << "] error "
869 << WIFEXITED(*status)
870 << " " << WEXITSTATUS(*status)
871 << " S:" << WIFSIGNALED(*status)
872 << " " << WTERMSIG(*status) << endl;
875 bitmap_waiting = true;
878 // remove temporary files
880 sprintf(tmp, "%s/~lyxgs%d.ps",
881 system_tempdir.c_str(),
887 makeupdatelist(bitmaps[i]);
894 lyxerr.debug() << "Checking pid in pidwait" << endl;
895 pidwait * p = pw, * prev = 0;
898 lyxerr.debug() << "Found pid in pidwait" << endl;
899 lyxerr.debug() << "Caught child pid of recompute routine " << pid << endl;
901 prev->next = p->next;
913 lyxerr.debug() << "waitpid error" << endl;
916 lyxerr << "The process or process group specified by "
917 "pid does not exist or is not a child of "
918 "the calling process or can never be in the "
919 "states specified by options." << endl;
922 lyxerr << "waitpid() was interrupted due to the "
923 "receipt of a signal sent by the calling "
927 lyxerr << "An invalid value was specified for "
931 lyxerr << "Unknown error from waitpid" << endl;
934 } else if (pid == 0) {
935 lyxerr << "waitpid nohang" << endl;;
937 lyxerr.debug() << "normal exit from childhandler" << endl;
942 static void getbitmaps()
944 bitmap_waiting = false;
945 for (int i = 0; i < bmpinsref; ++i)
946 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
947 getbitmap(bitmaps[i]);
951 static void RegisterFigure(InsetFig * fi)
953 if (figinsref == 0) InitFigures();
956 if (figinsref > figarrsize) {
957 // allocate more space
958 figarrsize += figallocchunk;
959 typedef Figref * Figref_p;
960 Figref ** tmp = new Figref_p[figarrsize];
961 //Figref ** tmp = static_cast<Figref**>
962 // (malloc(sizeof(Figref*)*figarrsize));
964 sizeof(Figref*)*(figarrsize-figallocchunk));
969 Figref * tmpfig = new Figref;
972 figures[figinsref-1] = tmpfig;
975 if (lyxerr.debugging()) {
976 lyxerr << "Register Figure: buffer:["
977 << current_view->buffer() << "]" << endl;
982 int FindFigIndex(Figref * tmpfig)
985 while (i < figinsref) {
986 if (figures[i] == tmpfig) return i;
993 static void UnregisterFigure(InsetFig * fi)
995 Figref * tmpfig = fi->figure;
997 if (tmpfig->data) freefigdata(tmpfig->data);
998 if (tmpfig->inset->form) {
999 if (tmpfig->inset->form->Figure->visible) {
1000 fl_set_focus_object(tmpfig->inset->form->Figure,
1001 tmpfig->inset->form->OkBtn);
1002 fl_hide_form(tmpfig->inset->form->Figure);
1004 #if FL_REVISION == 89
1005 #warning Reactivate this free_form calls
1007 fl_free_form(tmpfig->inset->form->Figure);
1008 free(tmpfig->inset->form); // Why free?
1009 tmpfig->inset->form = 0;
1012 int i = FindFigIndex(tmpfig);
1014 while (i < figinsref) {
1015 figures[i] = figures[i+1];
1020 if (figinsref == 0) DoneFigures();
1024 static string NextToken(istream & is)
1032 } while (!is.eof() && !isspace(c));
1033 token.erase(token.length() - 1); // remove the isspace
1039 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1049 psubfigure = subfigure = false;
1050 xwid = xhgh = angle = 0;
1052 raw_wid = raw_hgh = 0;
1053 changedfname = false;
1054 RegisterFigure(this);
1058 InsetFig::~InsetFig()
1060 if (lyxerr.debugging()) {
1061 lyxerr << "Figure destructor called" << endl;
1063 UnregisterFigure(this);
1067 int InsetFig::Ascent(LyXFont const &) const
1073 int InsetFig::Descent(LyXFont const &) const
1079 int InsetFig::Width(LyXFont const &) const
1085 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1087 if (bitmap_waiting) getbitmaps();
1089 // I wish that I didn't have to use this
1090 // but the figinset code is so complicated so
1091 // I don't want to fiddle with it now.
1092 unsigned long pm = scr.getForeground();
1094 if (figure && figure->data && figure->data->bitmap &&
1095 !figure->data->reading && !figure->data->broken) {
1097 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1098 0, 0, wid, hgh, int(x+1), baseline-hgh);
1100 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1101 int(x), baseline - hgh - 1,
1106 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1108 baseline - hgh - 1, wid+1, hgh+1);
1109 if (figure && figure->data) {
1110 if (figure->data->broken) msg = _("[render error]");
1111 else if (figure->data->reading) msg = _("[rendering ... ]");
1113 if (fname.empty()) msg = _("[no file]");
1114 else if ((flags & 3) == 0) msg = _("[not displayed]");
1115 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1117 if (!msg) msg = _("[unknown error]");
1119 font.setFamily (LyXFont::SANS_FAMILY);
1120 font.setSize (LyXFont::SIZE_FOOTNOTE);
1121 string justname = OnlyFilename (fname);
1122 font.drawString(justname, pm,
1123 baseline - font.maxAscent() - 4,
1125 font.setSize (LyXFont::SIZE_TINY);
1126 font.drawText (msg, strlen(msg), pm,
1131 x += Width(font); // ?
1135 void InsetFig::Write(ostream & os)
1138 os << "Figure size " << wid << " " << hgh << "\n";
1139 if (!fname.empty()) {
1140 string buf1 = OnlyPath(owner->fileName());
1141 string fname2 = MakeRelPath(fname, buf1);
1142 os << "file " << fname2 << "\n";
1144 if (!subcaption.empty())
1145 os << "subcaption " << subcaption << "\n";
1146 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1147 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1148 if (angle != 0) os << "angle " << angle << "\n";
1149 os << "flags " << flags << "\n";
1150 if (subfigure) os << "subfigure\n";
1154 void InsetFig::Read(LyXLex & lex)
1157 bool finished = false;
1159 while (lex.IsOK() && !finished) {
1162 string const token = lex.GetString();
1163 lyxerr.debug() << "Token: " << token << endl;
1167 else if (token == "\\end_inset") {
1169 } else if (token == "file") {
1171 buf = lex.GetString();
1172 string buf1 = OnlyPath(owner->fileName());
1173 fname = MakeAbsPath(buf, buf1);
1174 changedfname = true;
1176 } else if (token == "extra") {
1178 // kept for backwards compability. Delete in 0.13.x
1179 } else if (token == "subcaption") {
1181 subcaption = lex.GetString();
1182 } else if (token == "label") {
1184 // kept for backwards compability. Delete in 0.13.x
1185 } else if (token == "angle") {
1187 angle = lex.GetFloat();
1188 } else if (token == "size") {
1190 wid = lex.GetInteger();
1192 hgh = lex.GetInteger();
1193 } else if (token == "flags") {
1195 flags = pflags = lex.GetInteger();
1196 } else if (token == "subfigure") {
1197 subfigure = psubfigure = true;
1198 } else if (token == "width") {
1201 typ = lex.GetInteger();
1203 xwid = lex.GetFloat();
1205 case DEF: wtype = DEF; break;
1206 case CM: wtype = CM; break;
1207 case IN: wtype = IN; break;
1208 case PER_PAGE: wtype = PER_PAGE; break;
1209 case PER_COL: wtype = PER_COL; break;
1211 lyxerr.debug() << "Unknown type!" << endl;
1215 } else if (token == "height") {
1218 typ = lex.GetInteger();
1220 xhgh = lex.GetFloat();
1222 case DEF: htype = DEF; break;
1223 case CM: htype = CM; break;
1224 case IN: htype = IN; break;
1225 case PER_PAGE: htype = PER_PAGE; break;
1227 lyxerr.debug() << "Unknown type!" << endl;
1238 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1241 if (!cmd.empty()) os << cmd << " ";
1246 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1254 int InsetFig::Linuxdoc(string &/*file*/)
1260 int InsetFig::DocBook(string & file)
1262 string figurename = fname;
1264 if(suffixIs(figurename, ".eps"))
1265 figurename.erase(fname.length() - 5);
1267 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1272 void InsetFig::Validate(LaTeXFeatures & features) const
1274 features.graphics = true;
1275 if (subfigure) features.subfigure = true;
1279 unsigned char InsetFig::Editable() const
1285 bool InsetFig::Deletable() const
1291 void InsetFig::Edit(int, int)
1293 lyxerr.debug() << "Editing InsetFig." << endl;
1296 // We should have RO-versions of the form instead.
1297 // The actual prevention of altering a readonly doc
1298 // is done in CallbackFig()
1299 if(current_view->buffer()->isReadonly())
1300 WarnReadonly(current_view->buffer()->fileName());
1303 form = create_form_Figure();
1304 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1305 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1306 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1307 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1310 if (form->Figure->visible) {
1311 fl_raise_form(form->Figure);
1313 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1314 FL_FULLBORDER, _("Figure"));
1319 Inset * InsetFig::Clone() const
1321 InsetFig * tmp = new InsetFig(100, 100, owner);
1323 if (lyxerr.debugging()) {
1324 lyxerr << "Clone Figure: buffer:["
1325 << current_view->buffer()
1326 << "], cbuffer:[xx]" << endl;
1331 tmp->raw_wid = raw_wid;
1332 tmp->raw_hgh = raw_hgh;
1337 tmp->pflags = pflags;
1338 tmp->subfigure = subfigure;
1339 tmp->psubfigure = psubfigure;
1347 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1348 // do not display if there is
1349 // "do not display" chosen (Matthias 260696)
1350 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1351 pswid, pshgh, raw_wid, raw_hgh,
1352 angle, flags & (3|8));
1353 } else tmp->figure->data = 0;
1354 tmp->subcaption = subcaption;
1355 tmp->changedfname = false;
1362 Inset::Code InsetFig::LyxCode() const
1364 return Inset::GRAPHICS_CODE;
1368 void InsetFig::Regenerate()
1371 string resizeW, resizeH;
1372 string rotate, recmd;
1374 if (fname.empty()) {
1375 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1376 cmd += _("empty figure path");
1378 //if (form) fl_set_object_label(form->cmd, "");
1382 string buf1 = OnlyPath(owner->fileName());
1383 string fname2 = MakeRelPath(fname, buf1);
1385 string gcmd = "\\includegraphics{" + fname2 + '}';
1390 case CM:{// \resizebox*{h-length}{v-length}{text}
1392 sprintf(buf, "%g", xwid); // should find better
1399 sprintf(buf, "%g", xwid);
1406 sprintf(buf, "%g", xwid/100);
1408 resizeW += "\\textwidth";
1413 sprintf(buf, "%g", xwid/100);
1415 resizeW += "\\columnwidth";
1425 sprintf(buf, "%g", xhgh);
1432 sprintf(buf, "%g", xhgh);
1439 sprintf(buf, "%g", xhgh/100);
1441 resizeH += "\\textheight";
1445 // Doesn't occur; case exists to suppress compiler warnings.
1450 if (!resizeW.empty() || !resizeH.empty()) {
1451 recmd = "\\resizebox*{";
1452 if (!resizeW.empty())
1457 if (!resizeH.empty())
1467 sprintf(buf, "%g", angle);
1468 // \rotatebox{angle}{text}
1469 rotate = "\\rotatebox{";
1477 if (!rotate.empty()) cmdbuf += '}';
1478 if (!recmd.empty()) cmdbuf += '}';
1480 if (!subcaption.empty())
1481 cmdbuf = "\\subfigure[" + subcaption +
1482 "]{" + cmdbuf + "}";
1484 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1489 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1493 void InsetFig::TempRegenerate()
1496 string resizeW, resizeH;
1497 string rotate, recmd;
1499 char const * tfname = fl_get_input(form->EpsFile);
1500 string tsubcap = fl_get_input(form->Subcaption);
1501 float tangle = atof(fl_get_input(form->Angle));
1502 float txwid = atof(fl_get_input(form->Width));
1503 float txhgh = atof(fl_get_input(form->Height));
1505 if (!tfname || !*tfname) {
1506 //fl_set_object_label(form->cmd, "");
1507 //fl_redraw_object(form->cmd);
1508 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1509 cmd += _("empty figure path");
1514 string buf1 = OnlyPath(owner->fileName());
1515 string fname2 = MakeRelPath(tfname, buf1);
1516 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1517 string gcmd = "\\includegraphics{" + fname2 + '}';
1522 case CM: {// \resizebox*{h-length}{v-length}{text}
1524 sprintf(buf, "%g", txwid); // should find better
1531 sprintf(buf, "%g", txwid);
1538 sprintf(buf, "%g", txwid/100);
1540 resizeW += "\\textwidth";
1545 sprintf(buf, "%g", txwid/100);
1547 resizeW += "\\columnwidth";
1557 sprintf(buf, "%g", txhgh);
1564 sprintf(buf, "%g", txhgh);
1571 sprintf(buf, "%g", txhgh/100);
1573 resizeH += "\\textheight";
1577 // Doesn't occur; case exists to suppress compiler warnings.
1582 // \resizebox*{h-length}{v-length}{text}
1583 if (!resizeW.empty() || !resizeH.empty()) {
1584 recmd = "\\resizebox*{";
1585 if (!resizeW.empty())
1590 if (!resizeH.empty())
1599 sprintf(buf, "%g", tangle);
1600 // \rotatebox{angle}{text}
1601 rotate = "\\rotatebox{";
1609 if (!rotate.empty()) cmdbuf += '}';
1610 if (!recmd.empty()) cmdbuf += '}';
1611 if (psubfigure && !tsubcap.empty()) {
1612 cmdbuf = string("\\subfigure{") + tsubcap
1613 + string("}{") + cmdbuf + "}";
1618 void InsetFig::Recompute()
1620 bool changed = changedfname;
1621 int newx, newy, nraw_x, nraw_y;
1623 if (changed) GetPSSizes();
1625 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1626 float cos_a = cos (angle / DEG2PI);
1627 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1628 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1630 /* now recompute wid and hgh, and if that is changed, set changed */
1631 /* this depends on chosen size of the picture and its bbox */
1632 // This will be redone in 0.13 ... (hen)
1633 if (!fname.empty()) {
1634 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1642 newx = int(28.346 * xwid);
1645 newx = int(72 * xwid);
1647 case PER_PAGE: /* % of page */
1648 newx = int(5.95 * xwid);
1650 case PER_COL: /* % of col */
1651 newx = int(2.975 * xwid);
1655 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1659 //lyxerr << "This should not happen!" << endl;
1662 newy = int(28.346 * xhgh);
1665 newy = int(72 * xhgh);
1667 case PER_PAGE: /* % of page */
1668 newy = int(8.42 * xhgh);
1671 // Doesn't occur; case exists to suppress
1672 // compiler warnings.
1675 if (htype && !wtype && frame_hgh)
1676 newx = newy*frame_wid/frame_hgh;
1685 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1690 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1692 // cannot be zero, actually, set it to some minimum, so its clickable
1693 if (newx < 5) newx = 5;
1694 if (newy < 5) newy = 5;
1696 if (newx != wid || newy != hgh ||
1697 nraw_x != raw_wid || nraw_y != raw_hgh ||
1698 flags != pflags || subfigure != psubfigure)
1706 subfigure = psubfigure;
1709 figdata * pf = figure->data;
1712 if (!fname.empty() && (flags & 3)
1713 && !lyxrc->ps_command.empty()) {
1714 // do not display if there is "do not display"
1715 // chosen (Matthias 260696)
1716 figure->data = getfigdata(wid, hgh, fname,
1717 psx, psy, pswid, pshgh,
1719 angle, flags & (3|8));
1720 } else figure->data = 0;
1722 // free the old data
1723 if (pf) freefigdata(pf);
1726 changedfname = false;
1730 void InsetFig::GetPSSizes()
1732 /* get %%BoundingBox: from postscript file */
1734 /* defaults to associated size
1735 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1742 if (fname.empty()) return;
1744 ifstream ifs(fname.c_str());
1746 if (!ifs) return; // file not found !!!!
1748 /* defaults to A4 page */
1754 char lastchar = 0; ifs.get(lastchar);
1756 char c = 0; ifs.get(c);
1758 lyxerr.debug() << "End of (E)PS file reached and"
1759 " no BoundingBox!" << endl;
1762 if (c == '%' && lastchar == '%') {
1764 if (p.empty()) break;
1765 // we should not use this, with it we cannot
1766 // discover bounding box and end of file.
1767 //if (strcmp(p, "EndComments") == 0) break;
1768 lyxerr.debug() << "Token: `" << p << "'" << endl;
1769 if (p == "BoundingBox:") {
1770 float fpsx, fpsy, fpswid, fpshgh;
1771 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1774 pswid = int(fpswid);
1775 pshgh = int(fpshgh);
1777 if (lyxerr.debugging()) {
1778 lyxerr << "%%%%BoundingBox:"
1796 void InsetFig::CallbackFig(long arg)
1801 if (lyxerr.debugging()) {
1802 lyxerr << "Figure callback, arg " << arg << endl;
1808 case 12: /* width type */
1815 fl_deactivate_object(form->Width);
1820 fl_activate_object(form->Width);
1825 fl_activate_object(form->Width);
1830 fl_activate_object(form->Width);
1835 fl_activate_object(form->Width);
1838 lyxerr.debug() << "Unknown type!" << endl;
1845 case 22: /* height type */
1851 fl_deactivate_object(form->Height);
1856 fl_activate_object(form->Height);
1861 fl_activate_object(form->Height);
1866 fl_activate_object(form->Height);
1869 lyxerr.debug() << "Unknown type!" << endl;
1875 pflags = pflags & ~3; /* wysiwyg0 */
1878 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1881 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1884 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1887 pflags ^= 4; /* frame */
1890 pflags ^= 8; /* do translations */
1893 psubfigure = !psubfigure; /* This is a subfigure */
1896 regen = true; /* regenerate command */
1898 case 0: /* browse file */
1902 case 1: /* preview */
1903 p = fl_get_input(form->EpsFile);
1907 case 8: /* ok (apply and close) */
1908 if(!current_view->buffer()->isReadonly()) {
1911 xwid = atof(fl_get_input(form->Width));
1912 xhgh = atof(fl_get_input(form->Height));
1913 angle = atof(fl_get_input(form->Angle));
1914 p = fl_get_input(form->EpsFile);
1916 string buf1 = OnlyPath(owner->fileName());
1917 fname = MakeAbsPath(p, buf1);
1918 changedfname = true;
1920 if (!fname.empty()) {
1921 changedfname = true;
1925 subcaption = fl_get_input(form->Subcaption);
1929 /* now update inset */
1930 if (lyxerr.debugging()) {
1931 lyxerr << "Update: ["
1932 << wid << 'x' << hgh << ']' << endl;
1936 fl_set_focus_object(form->Figure, form->OkBtn);
1937 fl_hide_form(form->Figure);
1938 #if FL_REVISION == 89
1939 #warning Reactivate this free_form calls
1941 fl_free_form(form->Figure);
1942 free(form); // Why free?
1948 // The user has already been informed about RO in ::Edit
1949 if(arg == 7) // if 'Apply'
1952 case 9: /* cancel = restore and close */
1953 fl_set_focus_object(form->Figure, form->OkBtn);
1954 fl_hide_form(form->Figure);
1955 #if FL_REVISION == 89
1956 #warning Reactivate this free_form calls
1957 #warning Jug, is this still a problem?
1959 fl_free_form(form->Figure);
1960 free(form); // Why free?
1966 if (regen) TempRegenerate();
1970 inline void DisableFigurePanel(FD_Figure * const form)
1972 fl_deactivate_object(form->EpsFile);
1973 fl_deactivate_object(form->Browse);
1974 fl_deactivate_object(form->Width);
1975 fl_deactivate_object(form->Height);
1976 fl_deactivate_object(form->Frame);
1977 fl_deactivate_object(form->Translations);
1978 fl_deactivate_object(form->Angle);
1979 fl_deactivate_object(form->HeightGrp);
1980 fl_deactivate_object(form->page2);
1981 fl_deactivate_object(form->Default2);
1982 fl_deactivate_object(form->cm2);
1983 fl_deactivate_object(form->in2);
1984 fl_deactivate_object(form->HeightLabel);
1985 fl_deactivate_object(form->WidthLabel);
1986 fl_deactivate_object(form->DisplayGrp);
1987 fl_deactivate_object(form->Wysiwyg3);
1988 fl_deactivate_object(form->Wysiwyg0);
1989 fl_deactivate_object(form->Wysiwyg2);
1990 fl_deactivate_object(form->Wysiwyg1);
1991 fl_deactivate_object(form->WidthGrp);
1992 fl_deactivate_object(form->Default1);
1993 fl_deactivate_object(form->cm1);
1994 fl_deactivate_object(form->in1);
1995 fl_deactivate_object(form->page1);
1996 fl_deactivate_object(form->column1);
1997 fl_deactivate_object(form->Subcaption);
1998 fl_deactivate_object(form->Subfigure);
1999 fl_deactivate_object (form->OkBtn);
2000 fl_deactivate_object (form->ApplyBtn);
2001 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
2002 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
2006 inline void EnableFigurePanel(FD_Figure * const form)
2008 fl_activate_object(form->EpsFile);
2009 fl_activate_object(form->Browse);
2010 fl_activate_object(form->Width);
2011 fl_activate_object(form->Height);
2012 fl_activate_object(form->Frame);
2013 fl_activate_object(form->Translations);
2014 fl_activate_object(form->Angle);
2015 fl_activate_object(form->HeightGrp);
2016 fl_activate_object(form->page2);
2017 fl_activate_object(form->Default2);
2018 fl_activate_object(form->cm2);
2019 fl_activate_object(form->in2);
2020 fl_activate_object(form->HeightLabel);
2021 fl_activate_object(form->WidthLabel);
2022 fl_activate_object(form->DisplayGrp);
2023 fl_activate_object(form->Wysiwyg3);
2024 fl_activate_object(form->Wysiwyg0);
2025 fl_activate_object(form->Wysiwyg2);
2026 fl_activate_object(form->Wysiwyg1);
2027 fl_activate_object(form->WidthGrp);
2028 fl_activate_object(form->Default1);
2029 fl_activate_object(form->cm1);
2030 fl_activate_object(form->in1);
2031 fl_activate_object(form->page1);
2032 fl_activate_object(form->column1);
2033 fl_activate_object(form->Subcaption);
2034 fl_activate_object(form->Subfigure);
2035 fl_activate_object (form->OkBtn);
2036 fl_activate_object (form->ApplyBtn);
2037 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2038 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2042 void InsetFig::RestoreForm()
2046 EnableFigurePanel(form);
2049 fl_set_button(form->Default1, (wtype == 0));
2050 fl_set_button(form->cm1, (wtype == 1));
2051 fl_set_button(form->in1, (wtype == 2));
2052 fl_set_button(form->page1, (wtype == 3));
2053 fl_set_button(form->column1, (wtype == 4));
2055 fl_deactivate_object(form->Width);
2057 fl_activate_object(form->Width);
2060 // enable and disable should be put here.
2062 fl_set_button(form->Default2, (htype == 0));
2063 fl_set_button(form->cm2, (htype == 1));
2064 fl_set_button(form->in2, (htype == 2));
2065 fl_set_button(form->page2, (htype == 3));
2066 // enable and disable should be put here.
2068 fl_deactivate_object(form->Height);
2070 fl_activate_object(form->Height);
2073 int pflags = flags & 3;
2074 fl_set_button(form->Wysiwyg0, (pflags == 0));
2075 fl_set_button(form->Wysiwyg1, (pflags == 1));
2076 fl_set_button(form->Wysiwyg2, (pflags == 2));
2077 fl_set_button(form->Wysiwyg3, (pflags == 3));
2078 fl_set_button(form->Frame, ((flags & 4) != 0));
2079 fl_set_button(form->Translations, ((flags & 8) != 0));
2080 fl_set_button(form->Subfigure, (subfigure != 0));
2082 psubfigure = subfigure;
2083 sprintf(buf, "%g", xwid);
2084 fl_set_input(form->Width, buf);
2085 sprintf(buf, "%g", xhgh);
2086 fl_set_input(form->Height, buf);
2087 sprintf(buf, "%g", angle);
2088 fl_set_input(form->Angle, buf);
2089 if (!fname.empty()){
2090 string buf1 = OnlyPath(owner->fileName());
2091 string fname2 = MakeRelPath(fname, buf1);
2092 fl_set_input(form->EpsFile, fname2.c_str());
2094 else fl_set_input(form->EpsFile, "");
2095 fl_set_input(form->Subcaption, subcaption.c_str());
2096 if(current_view->buffer()->isReadonly())
2097 DisableFigurePanel(form);
2103 void InsetFig::Preview(char const * p)
2108 lyxerr << "Cannot fork process!" << endl;
2113 return; // parent process
2116 string buf1 = OnlyPath(owner->fileName());
2117 string buf2 = MakeAbsPath(p, buf1);
2119 lyxerr << "Error during rendering "
2120 << execlp(lyxrc->view_pspic_command.c_str(),
2121 lyxrc->view_pspic_command.c_str(),
2128 void InsetFig::BrowseFile()
2130 static string current_figure_path;
2131 static int once = 0;
2134 if (lyxerr.debugging()) {
2135 lyxerr << "Filename: "
2136 << owner->fileName() << endl;
2138 string p = fl_get_input(form->EpsFile);
2140 string buf = MakeAbsPath(owner->fileName());
2141 string buf2 = OnlyPath(buf);
2143 buf = MakeAbsPath(p, buf2);
2144 buf = OnlyPath(buf);
2146 buf = OnlyPath(owner->fileName().c_str());
2149 // Does user clipart directory exist?
2150 string bufclip = AddName (user_lyxdir, "clipart");
2151 FileInfo fileInfo(bufclip);
2152 if (!(fileInfo.isOK() && fileInfo.isDir()))
2153 // No - bail out to system clipart directory
2154 bufclip = AddName (system_lyxdir, "clipart");
2157 fileDlg.SetButton(0, _("Clipart"), bufclip);
2158 fileDlg.SetButton(1, _("Document"), buf);
2164 p = fileDlg.Select(_("EPS Figure"),
2165 current_figure_path,
2168 p = fileDlg.Select(_("EPS Figure"), buf,
2173 if (p.empty()) return;
2175 buf = MakeRelPath(p, buf2);
2176 current_figure_path = OnlyPath(p);
2179 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2180 || contains(p, "%") || contains(p, " "))
2182 WriteAlert(_("Filename can't contain any "
2183 "of these characters:"),
2184 // xgettext:no-c-format
2185 _("space, '#', '~', '$' or '%'."));
2190 if (form) fl_set_input(form->EpsFile, buf.c_str());
2194 void GraphicsCB(FL_OBJECT * obj, long arg)
2196 /* obj->form contains the form */
2198 if (lyxerr.debugging()) {
2199 lyxerr << "GraphicsCB callback: " << arg << endl;
2202 /* find inset we were reacting to */
2203 for (int i = 0; i < figinsref; ++i)
2204 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2207 if (lyxerr.debugging()) {
2208 lyxerr << "Calling back figure " << i << endl;
2210 figures[i]->inset->CallbackFig(arg);
2216 void HideFiguresPopups()
2218 for (int i = 0; i < figinsref; ++i)
2219 if (figures[i]->inset->form
2220 && figures[i]->inset->form->Figure->visible) {
2221 if (lyxerr.debugging()) {
2222 lyxerr << "Hiding figure " << i << endl;
2224 // hide and free the form
2225 figures[i]->inset->CallbackFig(9);