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
58 #include "support/filetools.h"
59 #include "LyXView.h" // just because of form_main
62 #include "LaTeXFeatures.h"
65 #include "lyx_gui_misc.h" // CancelCloseBoxCB
66 #include "support/FileInfo.h"
67 #include "support/lyxlib.h"
69 extern BufferView * current_view;
71 static volatile bool alarmed;
73 extern FL_OBJECT * figinset_canvas;
76 extern "C" void waitalarm(int)
82 extern char ** environ; // is this only redundtant on linux systems? Lgb.
83 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
84 // better for asyncron updating:
85 void PutInsetIntoInsetUpdateList(Inset * inset);
86 extern void ProhibitInput();
87 extern void AllowInput();
89 static float const DEG2PI = 57.295779513;
90 static int const figallocchunk = 32;
92 static int figinsref = 0; /* number of figures */
93 static int figarrsize = 0; /* current max number of figures */
94 static int bmpinsref = 0; /* number of bitmaps */
95 static int bmparrsize = 0; /* current max number of bitmaps */
97 struct queue_element {
98 float rx, ry; // resolution x and y
99 int ofsx, ofsy; // x and y translation
100 figdata * data; // we are doing it for this data
103 static int const MAXGS = 3; /* maximum 3 gs's at a time */
105 static Figref ** figures; /* all the figures */
106 static figdata ** bitmaps; /* all the bitmaps */
108 static queue<queue_element> gsqueue; // queue for ghostscripting
110 static int gsrunning = 0; /* currently so many gs's are running */
111 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
112 static char bittable[256]; /* bit reversion table */
114 static bool gs_color; // do we allocate colors for gs?
115 static bool color_visual; // is the visual color?
116 static bool gs_xcolor = false; // allocated extended colors
117 static unsigned long gs_pixels[128]; // allocated pixels
118 static int gs_num_pixels; // number of pixels allocated
119 static int gs_spc; // shades per color
120 static bool gs_gray; // is grayscale?
121 static int gs_allcolors; // number of all colors
123 static list<int> pidwaitlist; // pid wait list
125 extern Colormap color_map;
127 void addpidwait(int pid)
129 // adds pid to pid wait list
130 pidwaitlist.push_back(pid);
132 if (lyxerr.debugging()) {
133 lyxerr << "Pids to wait for: \n";
134 for (list<int>::const_iterator cit = pidwaitlist.begin();
135 cit != pidwaitlist.end(); ++cit) {
136 lyxerr << (*cit) << '\n';
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) { // parent
199 if (lyxerr.debugging()) {
200 lyxerr << "Spawned child "
203 addpidwait(forkstat);
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 XColor * cmap = new XColor[gs_allcolors];
224 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
225 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
228 // now we process all the image
229 for (y = 0; y < p->hgh; ++y) {
230 for (int x = 0; x < wid; ++x) {
235 gs_pixels[((pc->red+6553)*
236 spc1/65535)*spc2+((pc->green+6553)*
237 spc1/65535)*gs_spc+((pc->blue+6553)*
242 // This must be correct.
244 if (lyxerr.debugging()) {
245 lyxerr << "Putting image back"
248 XPutImage(tmpdisp, p->bitmap,
250 0, 0, p->wid, p->hgh);
252 if (lyxerr.debugging()) {
253 lyxerr << "Done translation"
258 if (lyxerr.debugging()) {
259 lyxerr << "Killing gs "
262 lyx::kill(p->gspid, SIGHUP);
264 sprintf(tmp, "%s/~lyxgs%d.ps",
265 system_tempdir.c_str(),
269 XCloseDisplay(tmpdisp);
273 if (lyxerr.debugging()) {
274 lyxerr << "Killing gs "
277 lyx::kill(p->gspid, SIGHUP);
279 sprintf(tmp, "%s/~lyxgs%d.ps",
280 system_tempdir.c_str(),
290 static void AllocColors(int num)
291 // allocate color cube numxnumxnum, if possible
293 if (lyxerr.debugging()) {
294 lyxerr << "Allocating color cube " << num
295 << 'x' << num << 'x' << num << endl;
299 lyxerr << "Error allocating color colormap." << endl;
303 if (num > 5) num = 5;
305 for (int i = 0; i < num * num * num; ++i) {
306 xcol.red = 65535 * (i / (num * num)) / (num - 1);
307 xcol.green = 65535 * ((i / num) % num) / (num - 1);
308 xcol.blue = 65535 * (i % num) / (num - 1);
309 xcol.flags = DoRed | DoGreen | DoBlue;
310 if (!XAllocColor(fl_display, color_map, &xcol)) {
311 if (i) XFreeColors(fl_display, color_map,
313 if(lyxerr.debugging()) {
314 lyxerr << "Cannot allocate color cube "
317 AllocColors(num - 1);
320 gs_pixels[i] = xcol.pixel;
325 gs_num_pixels = num * num * num;
329 // allocate grayscale ramp
331 void AllocGrays(int num)
333 if (lyxerr.debugging()) {
334 lyxerr << "Allocating grayscale colormap "
339 lyxerr << "Error allocating grayscale colormap." << endl;
343 if (num > 128) num = 128;
345 for (int i = 0; i < num; ++i) {
346 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
347 xcol.flags = DoRed | DoGreen | DoBlue;
348 if (!XAllocColor(fl_display, color_map, &xcol)) {
349 if (i) XFreeColors(fl_display, color_map,
351 if (lyxerr.debugging()) {
352 lyxerr << "Cannot allocate grayscale "
358 gs_pixels[i] = xcol.pixel;
368 bmparrsize = figarrsize = figallocchunk;
369 typedef Figref * Figref_p;
370 figures = new Figref_p[figallocchunk];
371 //figures = static_cast<Figref**>
372 // (malloc(sizeof(Figref*) * figallocchunk));
373 typedef figdata * figdata_p;
374 bitmaps = new figdata_p[figallocchunk];
375 //bitmaps = static_cast<figdata**>
376 //(malloc(sizeof(figdata*) * figallocchunk));
379 for (unsigned int i = 0; i < 256; ++i) {
381 for (unsigned int j = 0; j < 8; ++j)
382 if (i & (1 << (7-j))) k |= 1 << j;
383 bittable[i] = char(~k);
386 fl_add_canvas_handler(figinset_canvas, ClientMessage,
387 GhostscriptMsg, current_view->owner()->getMainForm());
389 // now we have to init color_map
390 if (!color_map) color_map = DefaultColormap(fl_display,
391 DefaultScreen(fl_display));
392 // allocate color cube on pseudo-color display
396 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
397 if (lyxerr.debugging()) {
398 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
399 vi->visualid, vi->c_class,
400 vi->bits_per_rgb, vi->map_entries);
402 color_visual = ( (vi->c_class == StaticColor) ||
403 (vi->c_class == PseudoColor) ||
404 (vi->c_class == TrueColor) ||
405 (vi->c_class == DirectColor) );
406 if ((vi->c_class & 1) == 0) return;
407 // now allocate colors
408 if (vi->c_class == GrayScale) {
409 // allocate grayscale
410 AllocGrays(vi->map_entries/2);
412 // allocate normal color
414 while (i * i * i * 2 > vi->map_entries) --i;
417 gs_allcolors = vi->map_entries;
430 lyxerr.debug() << "Unregistering figures..." << endl;
432 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
436 lyxerr.debug() << "Freeing up the colors..." << endl;
437 XFreeColors(fl_display, color_map, gs_pixels,
439 /******????????????????? what's planes in this case ??????***/
444 int FindBmpIndex(figdata * tmpdata)
447 while (i < bmpinsref) {
448 if (bitmaps[i] == tmpdata) return i;
455 static void chpixmap(Pixmap, int, int)
458 Display * tempdisp = XOpenDisplay(XDisplayName(0));
460 // here read the pixmap and change all colors to those we
463 XCloseDisplay(tempdisp);
468 static void freefigdata(figdata * tmpdata)
471 if (tmpdata->ref) return;
473 if (tmpdata->gspid > 0) {
474 int pid = tmpdata->gspid;
476 // change Pixmap according to our allocated colormap
477 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
478 // kill ghostscript and unlink it's files
480 lyx::kill(pid, SIGKILL);
481 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
485 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
487 int i = FindBmpIndex(tmpdata);
489 while (i < bmpinsref) {
490 bitmaps[i] = bitmaps[i + 1];
496 static void runqueue()
498 // run queued requests for ghostscript, if any
499 if (!gsrunning && gs_color && !gs_xcolor) {
500 // here alloc all colors, so that gs will use only
501 // those we allocated for it
506 while (gsrunning < MAXGS) {
507 char tbuf[384], tbuf2[80];
511 if (gsqueue.empty()) {
512 if (!gsrunning && gs_xcolor) {
513 // de-allocate rest of colors
519 queue_element * p = &gsqueue.front();
528 if (lyxerr.debugging()) {
529 lyxerr << "GS start error! Cannot fork."
532 p->data->broken = true;
533 p->data->reading = false;
536 if (pid == 0) { // child
537 char ** env, rbuf[80], gbuf[40];
539 Display * tempdisp = XOpenDisplay(XDisplayName(0));
541 // create translation file
542 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
546 ofs << "gsave clippath pathbbox grestore\n"
548 << "/ury exch def /urx exch def /lly exch def "
550 << p->data->wid / 2.0 << " "
551 << p->data->hgh / 2.0 << " translate\n"
552 << p->data->angle << " rotate\n"
553 << -(p->data->raw_wid / 2.0) << " "
554 << -(p->data->raw_hgh / 2.0) << " translate\n"
555 << p->rx / 72.0 << " " << p->ry / 72.0
557 << -p->ofsx << " " << -p->ofsy << " translate\n"
559 ofs.close(); // Don't remove this.
561 // gs process - set ghostview environment first
562 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
563 figinset_canvas), p->data->bitmap);
565 // now set up ghostview property on a window
566 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
567 p->data->wid, p->data->hgh);
568 // #warning BUG seems that the only bug here
569 // might be the hardcoded dpi.. Bummer!
571 if (lyxerr.debugging()) {
572 lyxerr << "Will set GHOSTVIEW property to ["
573 << tbuf << "]" << endl;
575 // wait until property is deleted if executing multiple
578 // grab server to prevent other child
579 // interfering with setting GHOSTVIEW property
580 if (lyxerr.debugging()) {
581 lyxerr << "Grabbing the server"
584 XGrabServer(tempdisp);
585 prop = XListProperties(tempdisp,
587 figinset_canvas), &nprop);
591 for (i = 0; i < nprop; ++i) {
592 char * p = XGetAtomName(tempdisp,
594 if (strcmp(p, "GHOSTVIEW") == 0) {
600 XFree(reinterpret_cast<char *>(prop)); // jc:
602 // release the server
603 XUngrabServer(tempdisp);
605 // ok, property found, we must wait until
606 // ghostscript deletes it
607 if (lyxerr.debugging()) {
608 lyxerr << "Releasing the server\n["
610 << "] GHOSTVIEW property"
611 " found. Waiting." << endl;
615 #warning What is this doing? (wouldn't a sleep(1); work too?')
619 signal(SIGALRM, waitalarm);
620 while (!alarmed) pause();
626 XChangeProperty(tempdisp,
627 fl_get_canvas_id(figinset_canvas),
628 XInternAtom(tempdisp, "GHOSTVIEW", false),
629 XInternAtom(tempdisp, "STRING", false),
631 reinterpret_cast<unsigned char*>(tbuf),
634 switch (p->data->flags & 3) {
635 case 0: tbuf[0] = 'H'; break; // Hidden
636 case 1: tbuf[0] = 'M'; break; // Mono
637 case 2: tbuf[0] = 'G'; break; // Gray
640 tbuf[0] = 'C'; // Color
642 tbuf[0] = 'G'; // Gray
647 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
648 DefaultScreenOfDisplay(fl_display)),
651 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
652 DefaultScreenOfDisplay(fl_display)),
656 XChangeProperty(tempdisp,
657 fl_get_canvas_id(figinset_canvas),
658 XInternAtom(tempdisp,
659 "GHOSTVIEW_COLORS", false),
660 XInternAtom(tempdisp, "STRING", false),
662 reinterpret_cast<unsigned char*>(tbuf),
664 XUngrabServer(tempdisp);
666 if (lyxerr.debugging()) {
667 lyxerr << "Releasing the server" << endl;
669 XCloseDisplay(tempdisp);
671 // set up environment
672 while (environ[ne]) ++ne;
673 typedef char * char_p;
674 env = new char_p[ne + 2];
675 //env = static_cast<char **>
676 // (malloc(sizeof(char*) * (ne + 2)));
678 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
681 // now make gs command
683 // close(1); do NOT close. If GS writes out
684 // errors it would hang. (Matthias 290596)
685 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
686 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
687 // now chdir into dir with .eps file, to be on the safe
689 chdir(OnlyPath(p->data->fname).c_str());
690 // make temp file name
691 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
693 if (lyxerr.debugging()) {
694 lyxerr << "starting gs " << tbuf << " "
696 << ", pid: " << getpid() << endl;
699 int err = execlp(lyxrc->ps_command.c_str(),
700 lyxrc->ps_command.c_str(),
702 "-dNOPAUSE", "-dQUIET",
705 p->data->fname.c_str(),
706 "showpage.ps", "quit.ps", "-", 0);
707 // if we are still there, an error occurred.
708 lyxerr << "Error executing ghostscript. "
709 << "Code: " << err << endl;
710 lyxerr.debug() << "Cmd: "
714 << p->data->fname << endl;
717 // normal process (parent)
718 if (lyxerr.debugging()) {
719 lyxerr << "GS [" << pid << "] started" << endl;
722 p->data->gspid = pid;
729 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
731 // recompute the stuff and put in the queue
735 p.rx = (float(data->raw_wid) * 72.0) / pswid;
736 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
742 // if possible, run the queue
747 static figdata * getfigdata(int wid, int hgh, string const & fname,
748 int psx, int psy, int pswid, int pshgh,
749 int raw_wid, int raw_hgh, float angle, char flags)
751 /* first search for an exact match with fname and width/height */
753 if (fname.empty()) return 0;
756 while (i < bmpinsref) {
757 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
758 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
759 bitmaps[i]->angle == angle) {
765 /* not found -> create new record or return 0 if no record */
767 if (bmpinsref > bmparrsize) {
768 // allocate more space
769 bmparrsize += figallocchunk;
770 typedef figdata * figdata_p;
771 figdata ** tmp = new figdata_p[bmparrsize];
772 //figdata ** tmp = static_cast<figdata**>
773 // (malloc(sizeof(figdata*) * bmparrsize));
775 sizeof(figdata*) * (bmparrsize - figallocchunk));
780 figdata * p = new figdata;
781 bitmaps[bmpinsref-1] = p;
784 p->raw_wid = raw_wid;
785 p->raw_hgh = raw_hgh;
789 XWindowAttributes wa;
790 XGetWindowAttributes(fl_display, fl_get_canvas_id(
791 figinset_canvas), &wa);
793 if (lyxerr.debugging()) {
794 lyxerr << "Create pixmap disp:" << fl_display
795 << " scr:" << DefaultScreen(fl_display)
798 << " depth:" << wa.depth << endl;
806 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
807 figinset_canvas), wid, hgh, wa.depth);
809 // initialize reading of .eps file with correct sizes and stuff
810 addwait(psx, psy, pswid, pshgh, p);
821 static void getbitmap(figdata * p)
827 static void makeupdatelist(figdata * p)
829 for (int i = 0; i < figinsref; ++i)
830 if (figures[i]->data == p) {
831 if (lyxerr.debugging()) {
832 lyxerr << "Updating inset "
836 //UpdateInset(figures[i]->inset);
837 // add inset figures[i]->inset into to_update list
838 PutInsetIntoInsetUpdateList(figures[i]->inset);
843 void sigchldchecker(pid_t pid, int * status)
845 lyxerr.debug() << "Got pid = " << pid << endl;
846 bool pid_handled = false;
847 for (int i = bmpinsref - 1; i >= 0; --i) {
848 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
849 lyxerr.debug() << "Found pid in bitmaps" << endl;
850 // now read the file and remove it from disk
851 figdata * p = bitmaps[i];
853 if (bitmaps[i]->gsdone) *status = 0;
855 lyxerr.debug() << "GS [" << pid
856 << "] exit OK." << endl;
858 lyxerr << "GS [" << pid << "] error "
860 << WIFEXITED(*status)
861 << " " << WEXITSTATUS(*status)
862 << " S:" << WIFSIGNALED(*status)
863 << " " << WTERMSIG(*status) << endl;
866 bitmap_waiting = true;
869 // remove temporary files
871 sprintf(tmp, "%s/~lyxgs%d.ps",
872 system_tempdir.c_str(),
878 makeupdatelist(bitmaps[i]);
885 lyxerr.debug() << "Checking pid in pidwait" << endl;
886 list<int>::iterator it = find(pidwaitlist.begin(),
887 pidwaitlist.end(), pid);
888 if (it != pidwaitlist.end()) {
889 lyxerr.debug() << "Found pid in pidwait\n"
890 << "Caught child pid of recompute "
891 "routine" << pid << endl;
892 pidwaitlist.erase(it);
896 lyxerr.debug() << "waitpid error" << endl;
899 lyxerr << "The process or process group specified by "
900 "pid does not exist or is not a child of "
901 "the calling process or can never be in the "
902 "states specified by options." << endl;
905 lyxerr << "waitpid() was interrupted due to the "
906 "receipt of a signal sent by the calling "
910 lyxerr << "An invalid value was specified for "
914 lyxerr << "Unknown error from waitpid" << endl;
917 } else if (pid == 0) {
918 lyxerr << "waitpid nohang" << endl;;
920 lyxerr.debug() << "normal exit from childhandler" << endl;
925 static void getbitmaps()
927 bitmap_waiting = false;
928 for (int i = 0; i < bmpinsref; ++i)
929 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
930 getbitmap(bitmaps[i]);
934 static void RegisterFigure(InsetFig * fi)
936 if (figinsref == 0) InitFigures();
939 if (figinsref > figarrsize) {
940 // allocate more space
941 figarrsize += figallocchunk;
942 typedef Figref * Figref_p;
943 Figref ** tmp = new Figref_p[figarrsize];
944 //Figref ** tmp = static_cast<Figref**>
945 // (malloc(sizeof(Figref*)*figarrsize));
947 sizeof(Figref*)*(figarrsize-figallocchunk));
952 Figref * tmpfig = new Figref;
955 figures[figinsref-1] = tmpfig;
958 if (lyxerr.debugging()) {
959 lyxerr << "Register Figure: buffer:["
960 << current_view->buffer() << "]" << endl;
965 int FindFigIndex(Figref * tmpfig)
968 while (i < figinsref) {
969 if (figures[i] == tmpfig) return i;
976 static void UnregisterFigure(InsetFig * fi)
978 Figref * tmpfig = fi->figure;
980 if (tmpfig->data) freefigdata(tmpfig->data);
981 if (tmpfig->inset->form) {
982 if (tmpfig->inset->form->Figure->visible) {
983 fl_set_focus_object(tmpfig->inset->form->Figure,
984 tmpfig->inset->form->OkBtn);
985 fl_hide_form(tmpfig->inset->form->Figure);
987 #if FL_REVISION == 89
988 #warning Reactivate this free_form calls
990 fl_free_form(tmpfig->inset->form->Figure);
991 free(tmpfig->inset->form); // Why free?
992 tmpfig->inset->form = 0;
995 int i = FindFigIndex(tmpfig);
997 while (i < figinsref) {
998 figures[i] = figures[i+1];
1003 if (figinsref == 0) DoneFigures();
1007 static string NextToken(istream & is)
1015 } while (!is.eof() && !isspace(c));
1016 token.erase(token.length() - 1); // remove the isspace
1022 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1032 psubfigure = subfigure = false;
1033 xwid = xhgh = angle = 0;
1035 raw_wid = raw_hgh = 0;
1036 changedfname = false;
1037 RegisterFigure(this);
1041 InsetFig::~InsetFig()
1043 if (lyxerr.debugging()) {
1044 lyxerr << "Figure destructor called" << endl;
1046 UnregisterFigure(this);
1050 int InsetFig::Ascent(LyXFont const &) const
1056 int InsetFig::Descent(LyXFont const &) const
1062 int InsetFig::Width(LyXFont const &) const
1068 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1070 if (bitmap_waiting) getbitmaps();
1072 // I wish that I didn't have to use this
1073 // but the figinset code is so complicated so
1074 // I don't want to fiddle with it now.
1075 unsigned long pm = scr.getForeground();
1077 if (figure && figure->data && figure->data->bitmap &&
1078 !figure->data->reading && !figure->data->broken) {
1080 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1081 0, 0, wid, hgh, int(x+1), baseline-hgh);
1083 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1084 int(x), baseline - hgh - 1,
1089 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1091 baseline - hgh - 1, wid+1, hgh+1);
1092 if (figure && figure->data) {
1093 if (figure->data->broken) msg = _("[render error]");
1094 else if (figure->data->reading) msg = _("[rendering ... ]");
1096 if (fname.empty()) msg = _("[no file]");
1097 else if ((flags & 3) == 0) msg = _("[not displayed]");
1098 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1100 if (!msg) msg = _("[unknown error]");
1102 font.setFamily (LyXFont::SANS_FAMILY);
1103 font.setSize (LyXFont::SIZE_FOOTNOTE);
1104 string justname = OnlyFilename (fname);
1105 font.drawString(justname, pm,
1106 baseline - font.maxAscent() - 4,
1108 font.setSize (LyXFont::SIZE_TINY);
1109 font.drawText (msg, strlen(msg), pm,
1114 x += Width(font); // ?
1118 void InsetFig::Write(ostream & os)
1121 os << "Figure size " << wid << " " << hgh << "\n";
1122 if (!fname.empty()) {
1123 string buf1 = OnlyPath(owner->fileName());
1124 string fname2 = MakeRelPath(fname, buf1);
1125 os << "file " << fname2 << "\n";
1127 if (!subcaption.empty())
1128 os << "subcaption " << subcaption << "\n";
1129 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1130 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1131 if (angle != 0) os << "angle " << angle << "\n";
1132 os << "flags " << flags << "\n";
1133 if (subfigure) os << "subfigure\n";
1137 void InsetFig::Read(LyXLex & lex)
1140 bool finished = false;
1142 while (lex.IsOK() && !finished) {
1145 string const token = lex.GetString();
1146 lyxerr.debug() << "Token: " << token << endl;
1150 else if (token == "\\end_inset") {
1152 } else if (token == "file") {
1154 buf = lex.GetString();
1155 string buf1 = OnlyPath(owner->fileName());
1156 fname = MakeAbsPath(buf, buf1);
1157 changedfname = true;
1159 } else if (token == "extra") {
1161 // kept for backwards compability. Delete in 0.13.x
1162 } else if (token == "subcaption") {
1164 subcaption = lex.GetString();
1165 } else if (token == "label") {
1167 // kept for backwards compability. Delete in 0.13.x
1168 } else if (token == "angle") {
1170 angle = lex.GetFloat();
1171 } else if (token == "size") {
1173 wid = lex.GetInteger();
1175 hgh = lex.GetInteger();
1176 } else if (token == "flags") {
1178 flags = pflags = lex.GetInteger();
1179 } else if (token == "subfigure") {
1180 subfigure = psubfigure = true;
1181 } else if (token == "width") {
1184 typ = lex.GetInteger();
1186 xwid = lex.GetFloat();
1188 case DEF: wtype = DEF; break;
1189 case CM: wtype = CM; break;
1190 case IN: wtype = IN; break;
1191 case PER_PAGE: wtype = PER_PAGE; break;
1192 case PER_COL: wtype = PER_COL; break;
1194 lyxerr.debug() << "Unknown type!" << endl;
1198 } else if (token == "height") {
1201 typ = lex.GetInteger();
1203 xhgh = lex.GetFloat();
1205 case DEF: htype = DEF; break;
1206 case CM: htype = CM; break;
1207 case IN: htype = IN; break;
1208 case PER_PAGE: htype = PER_PAGE; break;
1210 lyxerr.debug() << "Unknown type!" << endl;
1221 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1224 if (!cmd.empty()) os << cmd << " ";
1229 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1237 int InsetFig::Linuxdoc(string &/*file*/)
1243 int InsetFig::DocBook(string & file)
1245 string figurename = fname;
1247 if(suffixIs(figurename, ".eps"))
1248 figurename.erase(fname.length() - 5);
1250 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1255 void InsetFig::Validate(LaTeXFeatures & features) const
1257 features.graphics = true;
1258 if (subfigure) features.subfigure = true;
1262 unsigned char InsetFig::Editable() const
1268 bool InsetFig::Deletable() const
1274 void InsetFig::Edit(int, int)
1276 lyxerr.debug() << "Editing InsetFig." << endl;
1279 // We should have RO-versions of the form instead.
1280 // The actual prevention of altering a readonly doc
1281 // is done in CallbackFig()
1282 if(current_view->buffer()->isReadonly())
1283 WarnReadonly(current_view->buffer()->fileName());
1286 form = create_form_Figure();
1287 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1288 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1289 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1290 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1293 if (form->Figure->visible) {
1294 fl_raise_form(form->Figure);
1296 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1297 FL_FULLBORDER, _("Figure"));
1302 Inset * InsetFig::Clone() const
1304 InsetFig * tmp = new InsetFig(100, 100, owner);
1306 if (lyxerr.debugging()) {
1307 lyxerr << "Clone Figure: buffer:["
1308 << current_view->buffer()
1309 << "], cbuffer:[xx]" << endl;
1314 tmp->raw_wid = raw_wid;
1315 tmp->raw_hgh = raw_hgh;
1320 tmp->pflags = pflags;
1321 tmp->subfigure = subfigure;
1322 tmp->psubfigure = psubfigure;
1330 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1331 // do not display if there is
1332 // "do not display" chosen (Matthias 260696)
1333 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1334 pswid, pshgh, raw_wid, raw_hgh,
1335 angle, flags & (3|8));
1336 } else tmp->figure->data = 0;
1337 tmp->subcaption = subcaption;
1338 tmp->changedfname = false;
1345 Inset::Code InsetFig::LyxCode() const
1347 return Inset::GRAPHICS_CODE;
1351 void InsetFig::Regenerate()
1354 string resizeW, resizeH;
1355 string rotate, recmd;
1357 if (fname.empty()) {
1358 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1359 cmd += _("empty figure path");
1361 //if (form) fl_set_object_label(form->cmd, "");
1365 string buf1 = OnlyPath(owner->fileName());
1366 string fname2 = MakeRelPath(fname, buf1);
1368 string gcmd = "\\includegraphics{" + fname2 + '}';
1373 case CM:{// \resizebox*{h-length}{v-length}{text}
1375 sprintf(buf, "%g", xwid); // should find better
1382 sprintf(buf, "%g", xwid);
1389 sprintf(buf, "%g", xwid/100);
1391 resizeW += "\\textwidth";
1396 sprintf(buf, "%g", xwid/100);
1398 resizeW += "\\columnwidth";
1408 sprintf(buf, "%g", xhgh);
1415 sprintf(buf, "%g", xhgh);
1422 sprintf(buf, "%g", xhgh/100);
1424 resizeH += "\\textheight";
1428 // Doesn't occur; case exists to suppress compiler warnings.
1433 if (!resizeW.empty() || !resizeH.empty()) {
1434 recmd = "\\resizebox*{";
1435 if (!resizeW.empty())
1440 if (!resizeH.empty())
1450 sprintf(buf, "%g", angle);
1451 // \rotatebox{angle}{text}
1452 rotate = "\\rotatebox{";
1460 if (!rotate.empty()) cmdbuf += '}';
1461 if (!recmd.empty()) cmdbuf += '}';
1463 if (!subcaption.empty())
1464 cmdbuf = "\\subfigure[" + subcaption +
1465 "]{" + cmdbuf + "}";
1467 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1472 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1476 void InsetFig::TempRegenerate()
1479 string resizeW, resizeH;
1480 string rotate, recmd;
1482 char const * tfname = fl_get_input(form->EpsFile);
1483 string tsubcap = fl_get_input(form->Subcaption);
1484 float tangle = atof(fl_get_input(form->Angle));
1485 float txwid = atof(fl_get_input(form->Width));
1486 float txhgh = atof(fl_get_input(form->Height));
1488 if (!tfname || !*tfname) {
1489 //fl_set_object_label(form->cmd, "");
1490 //fl_redraw_object(form->cmd);
1491 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1492 cmd += _("empty figure path");
1497 string buf1 = OnlyPath(owner->fileName());
1498 string fname2 = MakeRelPath(tfname, buf1);
1499 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1500 string gcmd = "\\includegraphics{" + fname2 + '}';
1505 case CM: {// \resizebox*{h-length}{v-length}{text}
1507 sprintf(buf, "%g", txwid); // should find better
1514 sprintf(buf, "%g", txwid);
1521 sprintf(buf, "%g", txwid/100);
1523 resizeW += "\\textwidth";
1528 sprintf(buf, "%g", txwid/100);
1530 resizeW += "\\columnwidth";
1540 sprintf(buf, "%g", txhgh);
1547 sprintf(buf, "%g", txhgh);
1554 sprintf(buf, "%g", txhgh/100);
1556 resizeH += "\\textheight";
1560 // Doesn't occur; case exists to suppress compiler warnings.
1565 // \resizebox*{h-length}{v-length}{text}
1566 if (!resizeW.empty() || !resizeH.empty()) {
1567 recmd = "\\resizebox*{";
1568 if (!resizeW.empty())
1573 if (!resizeH.empty())
1582 sprintf(buf, "%g", tangle);
1583 // \rotatebox{angle}{text}
1584 rotate = "\\rotatebox{";
1592 if (!rotate.empty()) cmdbuf += '}';
1593 if (!recmd.empty()) cmdbuf += '}';
1594 if (psubfigure && !tsubcap.empty()) {
1595 cmdbuf = string("\\subfigure{") + tsubcap
1596 + string("}{") + cmdbuf + "}";
1601 void InsetFig::Recompute()
1603 bool changed = changedfname;
1604 int newx, newy, nraw_x, nraw_y;
1606 if (changed) GetPSSizes();
1608 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1609 float cos_a = cos (angle / DEG2PI);
1610 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1611 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1613 /* now recompute wid and hgh, and if that is changed, set changed */
1614 /* this depends on chosen size of the picture and its bbox */
1615 // This will be redone in 0.13 ... (hen)
1616 if (!fname.empty()) {
1617 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1625 newx = int(28.346 * xwid);
1628 newx = int(72 * xwid);
1630 case PER_PAGE: /* % of page */
1631 newx = int(5.95 * xwid);
1633 case PER_COL: /* % of col */
1634 newx = int(2.975 * xwid);
1638 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1642 //lyxerr << "This should not happen!" << endl;
1645 newy = int(28.346 * xhgh);
1648 newy = int(72 * xhgh);
1650 case PER_PAGE: /* % of page */
1651 newy = int(8.42 * xhgh);
1654 // Doesn't occur; case exists to suppress
1655 // compiler warnings.
1658 if (htype && !wtype && frame_hgh)
1659 newx = newy*frame_wid/frame_hgh;
1668 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1673 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1675 // cannot be zero, actually, set it to some minimum, so its clickable
1676 if (newx < 5) newx = 5;
1677 if (newy < 5) newy = 5;
1679 if (newx != wid || newy != hgh ||
1680 nraw_x != raw_wid || nraw_y != raw_hgh ||
1681 flags != pflags || subfigure != psubfigure)
1689 subfigure = psubfigure;
1692 figdata * pf = figure->data;
1695 if (!fname.empty() && (flags & 3)
1696 && !lyxrc->ps_command.empty()) {
1697 // do not display if there is "do not display"
1698 // chosen (Matthias 260696)
1699 figure->data = getfigdata(wid, hgh, fname,
1700 psx, psy, pswid, pshgh,
1702 angle, flags & (3|8));
1703 } else figure->data = 0;
1705 // free the old data
1706 if (pf) freefigdata(pf);
1709 changedfname = false;
1713 void InsetFig::GetPSSizes()
1715 /* get %%BoundingBox: from postscript file */
1717 /* defaults to associated size
1718 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1725 if (fname.empty()) return;
1727 ifstream ifs(fname.c_str());
1729 if (!ifs) return; // file not found !!!!
1731 /* defaults to A4 page */
1737 char lastchar = 0; ifs.get(lastchar);
1739 char c = 0; ifs.get(c);
1741 lyxerr.debug() << "End of (E)PS file reached and"
1742 " no BoundingBox!" << endl;
1745 if (c == '%' && lastchar == '%') {
1747 if (p.empty()) break;
1748 // we should not use this, with it we cannot
1749 // discover bounding box and end of file.
1750 //if (strcmp(p, "EndComments") == 0) break;
1751 lyxerr.debug() << "Token: `" << p << "'" << endl;
1752 if (p == "BoundingBox:") {
1753 float fpsx, fpsy, fpswid, fpshgh;
1754 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1757 pswid = int(fpswid);
1758 pshgh = int(fpshgh);
1760 if (lyxerr.debugging()) {
1761 lyxerr << "%%%%BoundingBox:"
1779 void InsetFig::CallbackFig(long arg)
1784 if (lyxerr.debugging()) {
1785 lyxerr << "Figure callback, arg " << arg << endl;
1791 case 12: /* width type */
1798 fl_deactivate_object(form->Width);
1803 fl_activate_object(form->Width);
1808 fl_activate_object(form->Width);
1813 fl_activate_object(form->Width);
1818 fl_activate_object(form->Width);
1821 lyxerr.debug() << "Unknown type!" << endl;
1828 case 22: /* height type */
1834 fl_deactivate_object(form->Height);
1839 fl_activate_object(form->Height);
1844 fl_activate_object(form->Height);
1849 fl_activate_object(form->Height);
1852 lyxerr.debug() << "Unknown type!" << endl;
1858 pflags = pflags & ~3; /* wysiwyg0 */
1861 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1864 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1867 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1870 pflags ^= 4; /* frame */
1873 pflags ^= 8; /* do translations */
1876 psubfigure = !psubfigure; /* This is a subfigure */
1879 regen = true; /* regenerate command */
1881 case 0: /* browse file */
1885 case 1: /* preview */
1886 p = fl_get_input(form->EpsFile);
1890 case 8: /* ok (apply and close) */
1891 if(!current_view->buffer()->isReadonly()) {
1894 xwid = atof(fl_get_input(form->Width));
1895 xhgh = atof(fl_get_input(form->Height));
1896 angle = atof(fl_get_input(form->Angle));
1897 p = fl_get_input(form->EpsFile);
1899 string buf1 = OnlyPath(owner->fileName());
1900 fname = MakeAbsPath(p, buf1);
1901 changedfname = true;
1903 if (!fname.empty()) {
1904 changedfname = true;
1908 subcaption = fl_get_input(form->Subcaption);
1912 /* now update inset */
1913 if (lyxerr.debugging()) {
1914 lyxerr << "Update: ["
1915 << wid << 'x' << hgh << ']' << endl;
1919 fl_set_focus_object(form->Figure, form->OkBtn);
1920 fl_hide_form(form->Figure);
1921 #if FL_REVISION == 89
1922 #warning Reactivate this free_form calls
1924 fl_free_form(form->Figure);
1925 free(form); // Why free?
1931 // The user has already been informed about RO in ::Edit
1932 if(arg == 7) // if 'Apply'
1935 case 9: /* cancel = restore and close */
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
1940 #warning Jug, is this still a problem?
1942 fl_free_form(form->Figure);
1943 free(form); // Why free?
1949 if (regen) TempRegenerate();
1953 inline void DisableFigurePanel(FD_Figure * const form)
1955 fl_deactivate_object(form->EpsFile);
1956 fl_deactivate_object(form->Browse);
1957 fl_deactivate_object(form->Width);
1958 fl_deactivate_object(form->Height);
1959 fl_deactivate_object(form->Frame);
1960 fl_deactivate_object(form->Translations);
1961 fl_deactivate_object(form->Angle);
1962 fl_deactivate_object(form->HeightGrp);
1963 fl_deactivate_object(form->page2);
1964 fl_deactivate_object(form->Default2);
1965 fl_deactivate_object(form->cm2);
1966 fl_deactivate_object(form->in2);
1967 fl_deactivate_object(form->HeightLabel);
1968 fl_deactivate_object(form->WidthLabel);
1969 fl_deactivate_object(form->DisplayGrp);
1970 fl_deactivate_object(form->Wysiwyg3);
1971 fl_deactivate_object(form->Wysiwyg0);
1972 fl_deactivate_object(form->Wysiwyg2);
1973 fl_deactivate_object(form->Wysiwyg1);
1974 fl_deactivate_object(form->WidthGrp);
1975 fl_deactivate_object(form->Default1);
1976 fl_deactivate_object(form->cm1);
1977 fl_deactivate_object(form->in1);
1978 fl_deactivate_object(form->page1);
1979 fl_deactivate_object(form->column1);
1980 fl_deactivate_object(form->Subcaption);
1981 fl_deactivate_object(form->Subfigure);
1982 fl_deactivate_object (form->OkBtn);
1983 fl_deactivate_object (form->ApplyBtn);
1984 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1985 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1989 inline void EnableFigurePanel(FD_Figure * const form)
1991 fl_activate_object(form->EpsFile);
1992 fl_activate_object(form->Browse);
1993 fl_activate_object(form->Width);
1994 fl_activate_object(form->Height);
1995 fl_activate_object(form->Frame);
1996 fl_activate_object(form->Translations);
1997 fl_activate_object(form->Angle);
1998 fl_activate_object(form->HeightGrp);
1999 fl_activate_object(form->page2);
2000 fl_activate_object(form->Default2);
2001 fl_activate_object(form->cm2);
2002 fl_activate_object(form->in2);
2003 fl_activate_object(form->HeightLabel);
2004 fl_activate_object(form->WidthLabel);
2005 fl_activate_object(form->DisplayGrp);
2006 fl_activate_object(form->Wysiwyg3);
2007 fl_activate_object(form->Wysiwyg0);
2008 fl_activate_object(form->Wysiwyg2);
2009 fl_activate_object(form->Wysiwyg1);
2010 fl_activate_object(form->WidthGrp);
2011 fl_activate_object(form->Default1);
2012 fl_activate_object(form->cm1);
2013 fl_activate_object(form->in1);
2014 fl_activate_object(form->page1);
2015 fl_activate_object(form->column1);
2016 fl_activate_object(form->Subcaption);
2017 fl_activate_object(form->Subfigure);
2018 fl_activate_object (form->OkBtn);
2019 fl_activate_object (form->ApplyBtn);
2020 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2021 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2025 void InsetFig::RestoreForm()
2029 EnableFigurePanel(form);
2032 fl_set_button(form->Default1, (wtype == 0));
2033 fl_set_button(form->cm1, (wtype == 1));
2034 fl_set_button(form->in1, (wtype == 2));
2035 fl_set_button(form->page1, (wtype == 3));
2036 fl_set_button(form->column1, (wtype == 4));
2038 fl_deactivate_object(form->Width);
2040 fl_activate_object(form->Width);
2043 // enable and disable should be put here.
2045 fl_set_button(form->Default2, (htype == 0));
2046 fl_set_button(form->cm2, (htype == 1));
2047 fl_set_button(form->in2, (htype == 2));
2048 fl_set_button(form->page2, (htype == 3));
2049 // enable and disable should be put here.
2051 fl_deactivate_object(form->Height);
2053 fl_activate_object(form->Height);
2056 int pflags = flags & 3;
2057 fl_set_button(form->Wysiwyg0, (pflags == 0));
2058 fl_set_button(form->Wysiwyg1, (pflags == 1));
2059 fl_set_button(form->Wysiwyg2, (pflags == 2));
2060 fl_set_button(form->Wysiwyg3, (pflags == 3));
2061 fl_set_button(form->Frame, ((flags & 4) != 0));
2062 fl_set_button(form->Translations, ((flags & 8) != 0));
2063 fl_set_button(form->Subfigure, (subfigure != 0));
2065 psubfigure = subfigure;
2066 sprintf(buf, "%g", xwid);
2067 fl_set_input(form->Width, buf);
2068 sprintf(buf, "%g", xhgh);
2069 fl_set_input(form->Height, buf);
2070 sprintf(buf, "%g", angle);
2071 fl_set_input(form->Angle, buf);
2072 if (!fname.empty()){
2073 string buf1 = OnlyPath(owner->fileName());
2074 string fname2 = MakeRelPath(fname, buf1);
2075 fl_set_input(form->EpsFile, fname2.c_str());
2077 else fl_set_input(form->EpsFile, "");
2078 fl_set_input(form->Subcaption, subcaption.c_str());
2079 if(current_view->buffer()->isReadonly())
2080 DisableFigurePanel(form);
2086 void InsetFig::Preview(char const * p)
2091 lyxerr << "Cannot fork process!" << endl;
2096 return; // parent process
2099 string buf1 = OnlyPath(owner->fileName());
2100 string buf2 = MakeAbsPath(p, buf1);
2102 lyxerr << "Error during rendering "
2103 << execlp(lyxrc->view_pspic_command.c_str(),
2104 lyxrc->view_pspic_command.c_str(),
2111 void InsetFig::BrowseFile()
2113 static string current_figure_path;
2114 static int once = 0;
2117 if (lyxerr.debugging()) {
2118 lyxerr << "Filename: "
2119 << owner->fileName() << endl;
2121 string p = fl_get_input(form->EpsFile);
2123 string buf = MakeAbsPath(owner->fileName());
2124 string buf2 = OnlyPath(buf);
2126 buf = MakeAbsPath(p, buf2);
2127 buf = OnlyPath(buf);
2129 buf = OnlyPath(owner->fileName().c_str());
2132 // Does user clipart directory exist?
2133 string bufclip = AddName (user_lyxdir, "clipart");
2134 FileInfo fileInfo(bufclip);
2135 if (!(fileInfo.isOK() && fileInfo.isDir()))
2136 // No - bail out to system clipart directory
2137 bufclip = AddName (system_lyxdir, "clipart");
2140 fileDlg.SetButton(0, _("Clipart"), bufclip);
2141 fileDlg.SetButton(1, _("Document"), buf);
2147 p = fileDlg.Select(_("EPS Figure"),
2148 current_figure_path,
2151 p = fileDlg.Select(_("EPS Figure"), buf,
2156 if (p.empty()) return;
2158 buf = MakeRelPath(p, buf2);
2159 current_figure_path = OnlyPath(p);
2162 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2163 || contains(p, "%") || contains(p, " "))
2165 WriteAlert(_("Filename can't contain any "
2166 "of these characters:"),
2167 // xgettext:no-c-format
2168 _("space, '#', '~', '$' or '%'."));
2173 if (form) fl_set_input(form->EpsFile, buf.c_str());
2177 void GraphicsCB(FL_OBJECT * obj, long arg)
2179 /* obj->form contains the form */
2181 if (lyxerr.debugging()) {
2182 lyxerr << "GraphicsCB callback: " << arg << endl;
2185 /* find inset we were reacting to */
2186 for (int i = 0; i < figinsref; ++i)
2187 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2190 if (lyxerr.debugging()) {
2191 lyxerr << "Calling back figure " << i << endl;
2193 figures[i]->inset->CallbackFig(arg);
2199 void HideFiguresPopups()
2201 for (int i = 0; i < figinsref; ++i)
2202 if (figures[i]->inset->form
2203 && figures[i]->inset->form->Figure->visible) {
2204 if (lyxerr.debugging()) {
2205 lyxerr << "Hiding figure " << i << endl;
2207 // hide and free the form
2208 figures[i]->inset->CallbackFig(9);