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
57 #include "support/filetools.h"
58 #include "LyXView.h" // just because of form_main
61 #include "LaTeXFeatures.h"
64 #include "lyx_gui_misc.h" // CancelCloseBoxCB
65 #include "support/FileInfo.h"
66 #include "support/lyxlib.h"
68 extern BufferView * current_view;
70 static volatile bool alarmed;
72 extern FL_OBJECT * figinset_canvas;
75 extern "C" void waitalarm(int)
81 extern char ** environ; // is this only redundtant on linux systems? Lgb.
82 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
83 // better for asyncron updating:
84 void PutInsetIntoInsetUpdateList(Inset * inset);
85 extern void ProhibitInput();
86 extern void AllowInput();
88 static float const DEG2PI = 57.295779513;
89 static int const figallocchunk = 32;
91 static int figinsref = 0; /* number of figures */
92 static int figarrsize = 0; /* current max number of figures */
93 static int bmpinsref = 0; /* number of bitmaps */
94 static int bmparrsize = 0; /* current max number of bitmaps */
96 struct queue_element {
97 float rx, ry; // resolution x and y
98 int ofsx, ofsy; // x and y translation
99 figdata * data; // we are doing it for this data
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 */
107 static queue<queue_element> gsqueue; // queue for ghostscripting
109 static int gsrunning = 0; /* currently so many gs's are running */
110 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
111 static char bittable[256]; /* bit reversion table */
113 static bool gs_color; // do we allocate colors for gs?
114 static bool color_visual; // is the visual color?
115 static bool gs_xcolor = false; // allocated extended colors
116 static unsigned long gs_pixels[128]; // allocated pixels
117 static int gs_num_pixels; // number of pixels allocated
118 static int gs_spc; // shades per color
119 static bool gs_gray; // is grayscale?
120 static int gs_allcolors; // number of all colors
122 static list<int> pidwaitlist; // pid wait list
124 extern Colormap color_map;
126 void addpidwait(int pid)
128 // adds pid to pid wait list
129 pidwaitlist.push_back(pid);
131 if (lyxerr.debugging()) {
132 lyxerr << "Pids to wait for: \n";
133 for (list<int>::const_iterator cit = pidwaitlist.begin();
134 cit != pidwaitlist.end(); ++cit) {
135 lyxerr << (*cit) << '\n';
142 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
147 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
149 if(lyxerr.debugging()) {
150 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
151 << "] pm:[" << e->data.l[1] << "]" << endl;
154 // just kill gs, that way it will work for sure
155 // This loop looks like S**T so it probably is...
156 for (int i = 0; i < bmpinsref; ++i)
157 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
159 figdata * p = bitmaps[i];
162 // first update p->bitmap, if necessary
163 if (p->bitmap != None
164 && p->flags > (1|8) && gs_color && p->wid) {
165 // query current colormap and re-render
166 // the pixmap with proper colors
168 XWindowAttributes wa;
169 register XImage * im;
170 int i, y, wid1, spc1 = gs_spc-1,
171 spc2 = gs_spc * gs_spc, wid = p->wid,
174 GC gc = getGC(gc_copy);
176 XGetWindowAttributes(fl_display,
181 if (lyxerr.debugging()) {
182 lyxerr << "Starting image translation "
185 << p->wid << "x" << p->hgh
187 << " " << XYPixmap << endl;
189 // now fork rendering process
191 if (forkstat == -1) {
193 << "Cannot fork, using slow "
194 "method for pixmap translation." << endl;
195 tmpdisp = fl_display;
196 } else if (forkstat > 0) { // parent
198 if (lyxerr.debugging()) {
199 lyxerr << "Spawned child "
202 addpidwait(forkstat);
205 tmpdisp = XOpenDisplay(XDisplayName(0));
208 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
209 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
211 if (lyxerr.debugging()) {
212 lyxerr << "Got the image" << endl;
215 if (lyxerr.debugging()) {
216 lyxerr << "Error getting the image" << endl;
221 // query current colormap
222 XColor * cmap = new XColor[gs_allcolors];
223 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
224 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
227 // now we process all the image
228 for (y = 0; y < p->hgh; ++y) {
229 for (int x = 0; x < wid; ++x) {
234 gs_pixels[((pc->red+6553)*
235 spc1/65535)*spc2+((pc->green+6553)*
236 spc1/65535)*gs_spc+((pc->blue+6553)*
241 // This must be correct.
243 if (lyxerr.debugging()) {
244 lyxerr << "Putting image back"
247 XPutImage(tmpdisp, p->bitmap,
249 0, 0, p->wid, p->hgh);
251 if (lyxerr.debugging()) {
252 lyxerr << "Done translation"
257 if (lyxerr.debugging()) {
258 lyxerr << "Killing gs "
261 lyx::kill(p->gspid, SIGHUP);
263 sprintf(tmp, "%s/~lyxgs%d.ps",
264 system_tempdir.c_str(),
268 XCloseDisplay(tmpdisp);
272 if (lyxerr.debugging()) {
273 lyxerr << "Killing gs "
276 lyx::kill(p->gspid, SIGHUP);
278 sprintf(tmp, "%s/~lyxgs%d.ps",
279 system_tempdir.c_str(),
289 static void AllocColors(int num)
290 // allocate color cube numxnumxnum, if possible
292 if (lyxerr.debugging()) {
293 lyxerr << "Allocating color cube " << num
294 << 'x' << num << 'x' << num << endl;
298 lyxerr << "Error allocating color colormap." << endl;
302 if (num > 5) num = 5;
304 for (int i = 0; i < num * num * num; ++i) {
305 xcol.red = 65535 * (i / (num * num)) / (num - 1);
306 xcol.green = 65535 * ((i / num) % num) / (num - 1);
307 xcol.blue = 65535 * (i % num) / (num - 1);
308 xcol.flags = DoRed | DoGreen | DoBlue;
309 if (!XAllocColor(fl_display, color_map, &xcol)) {
310 if (i) XFreeColors(fl_display, color_map,
312 if(lyxerr.debugging()) {
313 lyxerr << "Cannot allocate color cube "
316 AllocColors(num - 1);
319 gs_pixels[i] = xcol.pixel;
324 gs_num_pixels = num * num * num;
328 // allocate grayscale ramp
330 void AllocGrays(int num)
332 if (lyxerr.debugging()) {
333 lyxerr << "Allocating grayscale colormap "
338 lyxerr << "Error allocating grayscale colormap." << endl;
342 if (num > 128) num = 128;
344 for (int i = 0; i < num; ++i) {
345 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
346 xcol.flags = DoRed | DoGreen | DoBlue;
347 if (!XAllocColor(fl_display, color_map, &xcol)) {
348 if (i) XFreeColors(fl_display, color_map,
350 if (lyxerr.debugging()) {
351 lyxerr << "Cannot allocate grayscale "
357 gs_pixels[i] = xcol.pixel;
367 bmparrsize = figarrsize = figallocchunk;
368 typedef Figref * Figref_p;
369 figures = new Figref_p[figallocchunk];
370 //figures = static_cast<Figref**>
371 // (malloc(sizeof(Figref*) * figallocchunk));
372 typedef figdata * figdata_p;
373 bitmaps = new figdata_p[figallocchunk];
374 //bitmaps = static_cast<figdata**>
375 //(malloc(sizeof(figdata*) * figallocchunk));
378 for (unsigned int i = 0; i < 256; ++i) {
380 for (unsigned int j = 0; j < 8; ++j)
381 if (i & (1 << (7-j))) k |= 1 << j;
382 bittable[i] = char(~k);
385 fl_add_canvas_handler(figinset_canvas, ClientMessage,
386 GhostscriptMsg, current_view->owner()->getMainForm());
388 // now we have to init color_map
389 if (!color_map) color_map = DefaultColormap(fl_display,
390 DefaultScreen(fl_display));
391 // allocate color cube on pseudo-color display
395 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
396 if (lyxerr.debugging()) {
397 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
398 vi->visualid, vi->c_class,
399 vi->bits_per_rgb, vi->map_entries);
401 color_visual = ( (vi->c_class == StaticColor) ||
402 (vi->c_class == PseudoColor) ||
403 (vi->c_class == TrueColor) ||
404 (vi->c_class == DirectColor) );
405 if ((vi->c_class & 1) == 0) return;
406 // now allocate colors
407 if (vi->c_class == GrayScale) {
408 // allocate grayscale
409 AllocGrays(vi->map_entries/2);
411 // allocate normal color
413 while (i * i * i * 2 > vi->map_entries) --i;
416 gs_allcolors = vi->map_entries;
429 lyxerr.debug() << "Unregistering figures..." << endl;
431 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
435 lyxerr.debug() << "Freeing up the colors..." << endl;
436 XFreeColors(fl_display, color_map, gs_pixels,
438 /******????????????????? what's planes in this case ??????***/
443 int FindBmpIndex(figdata * tmpdata)
446 while (i < bmpinsref) {
447 if (bitmaps[i] == tmpdata) return i;
454 static void chpixmap(Pixmap, int, int)
457 Display * tempdisp = XOpenDisplay(XDisplayName(0));
459 // here read the pixmap and change all colors to those we
462 XCloseDisplay(tempdisp);
467 static void freefigdata(figdata * tmpdata)
470 if (tmpdata->ref) return;
472 if (tmpdata->gspid > 0) {
473 int pid = tmpdata->gspid;
475 // change Pixmap according to our allocated colormap
476 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
477 // kill ghostscript and unlink it's files
479 lyx::kill(pid, SIGKILL);
480 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
484 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
486 int i = FindBmpIndex(tmpdata);
488 while (i < bmpinsref) {
489 bitmaps[i] = bitmaps[i + 1];
495 static void runqueue()
497 // run queued requests for ghostscript, if any
498 if (!gsrunning && gs_color && !gs_xcolor) {
499 // here alloc all colors, so that gs will use only
500 // those we allocated for it
505 while (gsrunning < MAXGS) {
506 char tbuf[384], tbuf2[80];
510 if (gsqueue.empty()) {
511 if (!gsrunning && gs_xcolor) {
512 // de-allocate rest of colors
518 queue_element * p = &gsqueue.front();
527 if (lyxerr.debugging()) {
528 lyxerr << "GS start error! Cannot fork."
531 p->data->broken = true;
532 p->data->reading = false;
535 if (pid == 0) { // child
536 char ** env, rbuf[80], gbuf[40];
538 Display * tempdisp = XOpenDisplay(XDisplayName(0));
540 // create translation file
541 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
545 ofs << "gsave clippath pathbbox grestore\n"
547 << "/ury exch def /urx exch def /lly exch def "
549 << p->data->wid / 2.0 << " "
550 << p->data->hgh / 2.0 << " translate\n"
551 << p->data->angle << " rotate\n"
552 << -(p->data->raw_wid / 2.0) << " "
553 << -(p->data->raw_hgh / 2.0) << " translate\n"
554 << p->rx / 72.0 << " " << p->ry / 72.0
556 << -p->ofsx << " " << -p->ofsy << " translate\n"
558 ofs.close(); // Don't remove this.
560 // gs process - set ghostview environment first
561 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
562 figinset_canvas), p->data->bitmap);
564 // now set up ghostview property on a window
565 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
566 p->data->wid, p->data->hgh);
567 // #warning BUG seems that the only bug here
568 // might be the hardcoded dpi.. Bummer!
570 if (lyxerr.debugging()) {
571 lyxerr << "Will set GHOSTVIEW property to ["
572 << tbuf << "]" << endl;
574 // wait until property is deleted if executing multiple
577 // grab server to prevent other child
578 // interfering with setting GHOSTVIEW property
579 if (lyxerr.debugging()) {
580 lyxerr << "Grabbing the server"
583 XGrabServer(tempdisp);
584 prop = XListProperties(tempdisp,
586 figinset_canvas), &nprop);
590 for (i = 0; i < nprop; ++i) {
591 char * p = XGetAtomName(tempdisp,
593 if (strcmp(p, "GHOSTVIEW") == 0) {
599 XFree(reinterpret_cast<char *>(prop)); // jc:
601 // release the server
602 XUngrabServer(tempdisp);
604 // ok, property found, we must wait until
605 // ghostscript deletes it
606 if (lyxerr.debugging()) {
607 lyxerr << "Releasing the server\n["
609 << "] GHOSTVIEW property"
610 " found. Waiting." << endl;
614 #warning What is this doing? (wouldn't a sleep(1); work too?')
618 signal(SIGALRM, waitalarm);
619 while (!alarmed) pause();
625 XChangeProperty(tempdisp,
626 fl_get_canvas_id(figinset_canvas),
627 XInternAtom(tempdisp, "GHOSTVIEW", false),
628 XInternAtom(tempdisp, "STRING", false),
630 reinterpret_cast<unsigned char*>(tbuf),
633 switch (p->data->flags & 3) {
634 case 0: tbuf[0] = 'H'; break; // Hidden
635 case 1: tbuf[0] = 'M'; break; // Mono
636 case 2: tbuf[0] = 'G'; break; // Gray
639 tbuf[0] = 'C'; // Color
641 tbuf[0] = 'G'; // Gray
646 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
647 DefaultScreenOfDisplay(fl_display)),
650 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
651 DefaultScreenOfDisplay(fl_display)),
655 XChangeProperty(tempdisp,
656 fl_get_canvas_id(figinset_canvas),
657 XInternAtom(tempdisp,
658 "GHOSTVIEW_COLORS", false),
659 XInternAtom(tempdisp, "STRING", false),
661 reinterpret_cast<unsigned char*>(tbuf),
663 XUngrabServer(tempdisp);
665 if (lyxerr.debugging()) {
666 lyxerr << "Releasing the server" << endl;
668 XCloseDisplay(tempdisp);
670 // set up environment
671 while (environ[ne]) ++ne;
672 typedef char * char_p;
673 env = new char_p[ne + 2];
674 //env = static_cast<char **>
675 // (malloc(sizeof(char*) * (ne + 2)));
677 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
680 // now make gs command
682 // close(1); do NOT close. If GS writes out
683 // errors it would hang. (Matthias 290596)
684 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
685 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
686 // now chdir into dir with .eps file, to be on the safe
688 chdir(OnlyPath(p->data->fname).c_str());
689 // make temp file name
690 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
692 if (lyxerr.debugging()) {
693 lyxerr << "starting gs " << tbuf << " "
695 << ", pid: " << getpid() << endl;
698 int err = execlp(lyxrc->ps_command.c_str(),
699 lyxrc->ps_command.c_str(),
701 "-dNOPAUSE", "-dQUIET",
704 p->data->fname.c_str(),
705 "showpage.ps", "quit.ps", "-", 0);
706 // if we are still there, an error occurred.
707 lyxerr << "Error executing ghostscript. "
708 << "Code: " << err << endl;
709 lyxerr.debug() << "Cmd: "
713 << p->data->fname << endl;
716 // normal process (parent)
717 if (lyxerr.debugging()) {
718 lyxerr << "GS [" << pid << "] started" << endl;
721 p->data->gspid = pid;
728 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
730 // recompute the stuff and put in the queue
734 p.rx = (float(data->raw_wid) * 72.0) / pswid;
735 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
741 // if possible, run the queue
746 static figdata * getfigdata(int wid, int hgh, string const & fname,
747 int psx, int psy, int pswid, int pshgh,
748 int raw_wid, int raw_hgh, float angle, char flags)
750 /* first search for an exact match with fname and width/height */
752 if (fname.empty()) return 0;
755 while (i < bmpinsref) {
756 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
757 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
758 bitmaps[i]->angle == angle) {
764 /* not found -> create new record or return 0 if no record */
766 if (bmpinsref > bmparrsize) {
767 // allocate more space
768 bmparrsize += figallocchunk;
769 typedef figdata * figdata_p;
770 figdata ** tmp = new figdata_p[bmparrsize];
771 //figdata ** tmp = static_cast<figdata**>
772 // (malloc(sizeof(figdata*) * bmparrsize));
774 sizeof(figdata*) * (bmparrsize - figallocchunk));
779 figdata * p = new figdata;
780 bitmaps[bmpinsref-1] = p;
783 p->raw_wid = raw_wid;
784 p->raw_hgh = raw_hgh;
788 XWindowAttributes wa;
789 XGetWindowAttributes(fl_display, fl_get_canvas_id(
790 figinset_canvas), &wa);
792 if (lyxerr.debugging()) {
793 lyxerr << "Create pixmap disp:" << fl_display
794 << " scr:" << DefaultScreen(fl_display)
797 << " depth:" << wa.depth << endl;
805 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
806 figinset_canvas), wid, hgh, wa.depth);
808 // initialize reading of .eps file with correct sizes and stuff
809 addwait(psx, psy, pswid, pshgh, p);
820 static void getbitmap(figdata * p)
826 static void makeupdatelist(figdata * p)
828 for (int i = 0; i < figinsref; ++i)
829 if (figures[i]->data == p) {
830 if (lyxerr.debugging()) {
831 lyxerr << "Updating inset "
835 //UpdateInset(figures[i]->inset);
836 // add inset figures[i]->inset into to_update list
837 PutInsetIntoInsetUpdateList(figures[i]->inset);
842 void sigchldchecker(pid_t pid, int * status)
844 lyxerr.debug() << "Got pid = " << pid << endl;
845 bool pid_handled = false;
846 for (int i = bmpinsref - 1; i >= 0; --i) {
847 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
848 lyxerr.debug() << "Found pid in bitmaps" << endl;
849 // now read the file and remove it from disk
850 figdata * p = bitmaps[i];
852 if (bitmaps[i]->gsdone) *status = 0;
854 lyxerr.debug() << "GS [" << pid
855 << "] exit OK." << endl;
857 lyxerr << "GS [" << pid << "] error "
859 << WIFEXITED(*status)
860 << " " << WEXITSTATUS(*status)
861 << " S:" << WIFSIGNALED(*status)
862 << " " << WTERMSIG(*status) << endl;
865 bitmap_waiting = true;
868 // remove temporary files
870 sprintf(tmp, "%s/~lyxgs%d.ps",
871 system_tempdir.c_str(),
877 makeupdatelist(bitmaps[i]);
884 lyxerr.debug() << "Checking pid in pidwait" << endl;
885 list<int>::iterator it = find(pidwaitlist.begin(),
886 pidwaitlist.end(), pid);
887 if (it != pidwaitlist.end()) {
888 lyxerr.debug() << "Found pid in pidwait\n"
889 << "Caught child pid of recompute "
890 "routine" << pid << endl;
891 pidwaitlist.erase(it);
895 lyxerr.debug() << "waitpid error" << endl;
898 lyxerr << "The process or process group specified by "
899 "pid does not exist or is not a child of "
900 "the calling process or can never be in the "
901 "states specified by options." << endl;
904 lyxerr << "waitpid() was interrupted due to the "
905 "receipt of a signal sent by the calling "
909 lyxerr << "An invalid value was specified for "
913 lyxerr << "Unknown error from waitpid" << endl;
916 } else if (pid == 0) {
917 lyxerr << "waitpid nohang" << endl;;
919 lyxerr.debug() << "normal exit from childhandler" << endl;
924 static void getbitmaps()
926 bitmap_waiting = false;
927 for (int i = 0; i < bmpinsref; ++i)
928 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
929 getbitmap(bitmaps[i]);
933 static void RegisterFigure(InsetFig * fi)
935 if (figinsref == 0) InitFigures();
938 if (figinsref > figarrsize) {
939 // allocate more space
940 figarrsize += figallocchunk;
941 typedef Figref * Figref_p;
942 Figref ** tmp = new Figref_p[figarrsize];
943 //Figref ** tmp = static_cast<Figref**>
944 // (malloc(sizeof(Figref*)*figarrsize));
946 sizeof(Figref*)*(figarrsize-figallocchunk));
951 Figref * tmpfig = new Figref;
954 figures[figinsref-1] = tmpfig;
957 if (lyxerr.debugging()) {
958 lyxerr << "Register Figure: buffer:["
959 << current_view->buffer() << "]" << endl;
964 int FindFigIndex(Figref * tmpfig)
967 while (i < figinsref) {
968 if (figures[i] == tmpfig) return i;
975 static void UnregisterFigure(InsetFig * fi)
977 Figref * tmpfig = fi->figure;
979 if (tmpfig->data) freefigdata(tmpfig->data);
980 if (tmpfig->inset->form) {
981 if (tmpfig->inset->form->Figure->visible) {
982 fl_set_focus_object(tmpfig->inset->form->Figure,
983 tmpfig->inset->form->OkBtn);
984 fl_hide_form(tmpfig->inset->form->Figure);
986 #if FL_REVISION == 89
987 #warning Reactivate this free_form calls
989 fl_free_form(tmpfig->inset->form->Figure);
990 free(tmpfig->inset->form); // Why free?
991 tmpfig->inset->form = 0;
994 int i = FindFigIndex(tmpfig);
996 while (i < figinsref) {
997 figures[i] = figures[i+1];
1002 if (figinsref == 0) DoneFigures();
1006 static string NextToken(istream & is)
1014 } while (!is.eof() && !isspace(c));
1015 token.erase(token.length() - 1); // remove the isspace
1021 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1031 psubfigure = subfigure = false;
1032 xwid = xhgh = angle = 0;
1034 raw_wid = raw_hgh = 0;
1035 changedfname = false;
1036 RegisterFigure(this);
1040 InsetFig::~InsetFig()
1042 if (lyxerr.debugging()) {
1043 lyxerr << "Figure destructor called" << endl;
1045 UnregisterFigure(this);
1049 int InsetFig::Ascent(LyXFont const &) const
1055 int InsetFig::Descent(LyXFont const &) const
1061 int InsetFig::Width(LyXFont const &) const
1067 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1069 if (bitmap_waiting) getbitmaps();
1071 // I wish that I didn't have to use this
1072 // but the figinset code is so complicated so
1073 // I don't want to fiddle with it now.
1074 unsigned long pm = scr.getForeground();
1076 if (figure && figure->data && figure->data->bitmap &&
1077 !figure->data->reading && !figure->data->broken) {
1079 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1080 0, 0, wid, hgh, int(x+1), baseline-hgh);
1082 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1083 int(x), baseline - hgh - 1,
1088 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1090 baseline - hgh - 1, wid+1, hgh+1);
1091 if (figure && figure->data) {
1092 if (figure->data->broken) msg = _("[render error]");
1093 else if (figure->data->reading) msg = _("[rendering ... ]");
1095 if (fname.empty()) msg = _("[no file]");
1096 else if ((flags & 3) == 0) msg = _("[not displayed]");
1097 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1099 if (!msg) msg = _("[unknown error]");
1101 font.setFamily (LyXFont::SANS_FAMILY);
1102 font.setSize (LyXFont::SIZE_FOOTNOTE);
1103 string justname = OnlyFilename (fname);
1104 font.drawString(justname, pm,
1105 baseline - font.maxAscent() - 4,
1107 font.setSize (LyXFont::SIZE_TINY);
1108 font.drawText (msg, strlen(msg), pm,
1113 x += Width(font); // ?
1117 void InsetFig::Write(ostream & os)
1120 os << "Figure size " << wid << " " << hgh << "\n";
1121 if (!fname.empty()) {
1122 string buf1 = OnlyPath(owner->fileName());
1123 string fname2 = MakeRelPath(fname, buf1);
1124 os << "file " << fname2 << "\n";
1126 if (!subcaption.empty())
1127 os << "subcaption " << subcaption << "\n";
1128 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1129 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1130 if (angle != 0) os << "angle " << angle << "\n";
1131 os << "flags " << flags << "\n";
1132 if (subfigure) os << "subfigure\n";
1136 void InsetFig::Read(LyXLex & lex)
1139 bool finished = false;
1141 while (lex.IsOK() && !finished) {
1144 string const token = lex.GetString();
1145 lyxerr.debug() << "Token: " << token << endl;
1149 else if (token == "\\end_inset") {
1151 } else if (token == "file") {
1153 buf = lex.GetString();
1154 string buf1 = OnlyPath(owner->fileName());
1155 fname = MakeAbsPath(buf, buf1);
1156 changedfname = true;
1158 } else if (token == "extra") {
1160 // kept for backwards compability. Delete in 0.13.x
1161 } else if (token == "subcaption") {
1163 subcaption = lex.GetString();
1164 } else if (token == "label") {
1166 // kept for backwards compability. Delete in 0.13.x
1167 } else if (token == "angle") {
1169 angle = lex.GetFloat();
1170 } else if (token == "size") {
1172 wid = lex.GetInteger();
1174 hgh = lex.GetInteger();
1175 } else if (token == "flags") {
1177 flags = pflags = lex.GetInteger();
1178 } else if (token == "subfigure") {
1179 subfigure = psubfigure = true;
1180 } else if (token == "width") {
1183 typ = lex.GetInteger();
1185 xwid = lex.GetFloat();
1187 case DEF: wtype = DEF; break;
1188 case CM: wtype = CM; break;
1189 case IN: wtype = IN; break;
1190 case PER_PAGE: wtype = PER_PAGE; break;
1191 case PER_COL: wtype = PER_COL; break;
1193 lyxerr.debug() << "Unknown type!" << endl;
1197 } else if (token == "height") {
1200 typ = lex.GetInteger();
1202 xhgh = lex.GetFloat();
1204 case DEF: htype = DEF; break;
1205 case CM: htype = CM; break;
1206 case IN: htype = IN; break;
1207 case PER_PAGE: htype = PER_PAGE; break;
1209 lyxerr.debug() << "Unknown type!" << endl;
1220 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1223 if (!cmd.empty()) os << cmd << " ";
1228 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1236 int InsetFig::Linuxdoc(string &/*file*/)
1242 int InsetFig::DocBook(string & file)
1244 string figurename = fname;
1246 if(suffixIs(figurename, ".eps"))
1247 figurename.erase(fname.length() - 5);
1249 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1254 void InsetFig::Validate(LaTeXFeatures & features) const
1256 features.graphics = true;
1257 if (subfigure) features.subfigure = true;
1261 unsigned char InsetFig::Editable() const
1267 bool InsetFig::Deletable() const
1273 void InsetFig::Edit(int, int)
1275 lyxerr.debug() << "Editing InsetFig." << endl;
1278 // We should have RO-versions of the form instead.
1279 // The actual prevention of altering a readonly doc
1280 // is done in CallbackFig()
1281 if(current_view->buffer()->isReadonly())
1282 WarnReadonly(current_view->buffer()->fileName());
1285 form = create_form_Figure();
1286 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1287 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1288 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1289 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1292 if (form->Figure->visible) {
1293 fl_raise_form(form->Figure);
1295 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1296 FL_FULLBORDER, _("Figure"));
1301 Inset * InsetFig::Clone() const
1303 InsetFig * tmp = new InsetFig(100, 100, owner);
1305 if (lyxerr.debugging()) {
1306 lyxerr << "Clone Figure: buffer:["
1307 << current_view->buffer()
1308 << "], cbuffer:[xx]" << endl;
1313 tmp->raw_wid = raw_wid;
1314 tmp->raw_hgh = raw_hgh;
1319 tmp->pflags = pflags;
1320 tmp->subfigure = subfigure;
1321 tmp->psubfigure = psubfigure;
1329 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1330 // do not display if there is
1331 // "do not display" chosen (Matthias 260696)
1332 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1333 pswid, pshgh, raw_wid, raw_hgh,
1334 angle, flags & (3|8));
1335 } else tmp->figure->data = 0;
1336 tmp->subcaption = subcaption;
1337 tmp->changedfname = false;
1344 Inset::Code InsetFig::LyxCode() const
1346 return Inset::GRAPHICS_CODE;
1350 void InsetFig::Regenerate()
1353 string resizeW, resizeH;
1354 string rotate, recmd;
1356 if (fname.empty()) {
1357 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1358 cmd += _("empty figure path");
1360 //if (form) fl_set_object_label(form->cmd, "");
1364 string buf1 = OnlyPath(owner->fileName());
1365 string fname2 = MakeRelPath(fname, buf1);
1367 string gcmd = "\\includegraphics{" + fname2 + '}';
1372 case CM:{// \resizebox*{h-length}{v-length}{text}
1374 sprintf(buf, "%g", xwid); // should find better
1381 sprintf(buf, "%g", xwid);
1388 sprintf(buf, "%g", xwid/100);
1390 resizeW += "\\textwidth";
1395 sprintf(buf, "%g", xwid/100);
1397 resizeW += "\\columnwidth";
1407 sprintf(buf, "%g", xhgh);
1414 sprintf(buf, "%g", xhgh);
1421 sprintf(buf, "%g", xhgh/100);
1423 resizeH += "\\textheight";
1427 // Doesn't occur; case exists to suppress compiler warnings.
1432 if (!resizeW.empty() || !resizeH.empty()) {
1433 recmd = "\\resizebox*{";
1434 if (!resizeW.empty())
1439 if (!resizeH.empty())
1449 sprintf(buf, "%g", angle);
1450 // \rotatebox{angle}{text}
1451 rotate = "\\rotatebox{";
1459 if (!rotate.empty()) cmdbuf += '}';
1460 if (!recmd.empty()) cmdbuf += '}';
1462 if (!subcaption.empty())
1463 cmdbuf = "\\subfigure[" + subcaption +
1464 "]{" + cmdbuf + "}";
1466 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1471 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1475 void InsetFig::TempRegenerate()
1478 string resizeW, resizeH;
1479 string rotate, recmd;
1481 char const * tfname = fl_get_input(form->EpsFile);
1482 string tsubcap = fl_get_input(form->Subcaption);
1483 float tangle = atof(fl_get_input(form->Angle));
1484 float txwid = atof(fl_get_input(form->Width));
1485 float txhgh = atof(fl_get_input(form->Height));
1487 if (!tfname || !*tfname) {
1488 //fl_set_object_label(form->cmd, "");
1489 //fl_redraw_object(form->cmd);
1490 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1491 cmd += _("empty figure path");
1496 string buf1 = OnlyPath(owner->fileName());
1497 string fname2 = MakeRelPath(tfname, buf1);
1498 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1499 string gcmd = "\\includegraphics{" + fname2 + '}';
1504 case CM: {// \resizebox*{h-length}{v-length}{text}
1506 sprintf(buf, "%g", txwid); // should find better
1513 sprintf(buf, "%g", txwid);
1520 sprintf(buf, "%g", txwid/100);
1522 resizeW += "\\textwidth";
1527 sprintf(buf, "%g", txwid/100);
1529 resizeW += "\\columnwidth";
1539 sprintf(buf, "%g", txhgh);
1546 sprintf(buf, "%g", txhgh);
1553 sprintf(buf, "%g", txhgh/100);
1555 resizeH += "\\textheight";
1559 // Doesn't occur; case exists to suppress compiler warnings.
1564 // \resizebox*{h-length}{v-length}{text}
1565 if (!resizeW.empty() || !resizeH.empty()) {
1566 recmd = "\\resizebox*{";
1567 if (!resizeW.empty())
1572 if (!resizeH.empty())
1581 sprintf(buf, "%g", tangle);
1582 // \rotatebox{angle}{text}
1583 rotate = "\\rotatebox{";
1591 if (!rotate.empty()) cmdbuf += '}';
1592 if (!recmd.empty()) cmdbuf += '}';
1593 if (psubfigure && !tsubcap.empty()) {
1594 cmdbuf = string("\\subfigure{") + tsubcap
1595 + string("}{") + cmdbuf + "}";
1600 void InsetFig::Recompute()
1602 bool changed = changedfname;
1603 int newx, newy, nraw_x, nraw_y;
1605 if (changed) GetPSSizes();
1607 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1608 float cos_a = cos (angle / DEG2PI);
1609 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1610 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1612 /* now recompute wid and hgh, and if that is changed, set changed */
1613 /* this depends on chosen size of the picture and its bbox */
1614 // This will be redone in 0.13 ... (hen)
1615 if (!fname.empty()) {
1616 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1624 newx = int(28.346 * xwid);
1627 newx = int(72 * xwid);
1629 case PER_PAGE: /* % of page */
1630 newx = int(5.95 * xwid);
1632 case PER_COL: /* % of col */
1633 newx = int(2.975 * xwid);
1637 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1641 //lyxerr << "This should not happen!" << endl;
1644 newy = int(28.346 * xhgh);
1647 newy = int(72 * xhgh);
1649 case PER_PAGE: /* % of page */
1650 newy = int(8.42 * xhgh);
1653 // Doesn't occur; case exists to suppress
1654 // compiler warnings.
1657 if (htype && !wtype && frame_hgh)
1658 newx = newy*frame_wid/frame_hgh;
1667 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1672 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1674 // cannot be zero, actually, set it to some minimum, so its clickable
1675 if (newx < 5) newx = 5;
1676 if (newy < 5) newy = 5;
1678 if (newx != wid || newy != hgh ||
1679 nraw_x != raw_wid || nraw_y != raw_hgh ||
1680 flags != pflags || subfigure != psubfigure)
1688 subfigure = psubfigure;
1691 figdata * pf = figure->data;
1694 if (!fname.empty() && (flags & 3)
1695 && !lyxrc->ps_command.empty()) {
1696 // do not display if there is "do not display"
1697 // chosen (Matthias 260696)
1698 figure->data = getfigdata(wid, hgh, fname,
1699 psx, psy, pswid, pshgh,
1701 angle, flags & (3|8));
1702 } else figure->data = 0;
1704 // free the old data
1705 if (pf) freefigdata(pf);
1708 changedfname = false;
1712 void InsetFig::GetPSSizes()
1714 /* get %%BoundingBox: from postscript file */
1716 /* defaults to associated size
1717 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1724 if (fname.empty()) return;
1726 ifstream ifs(fname.c_str());
1728 if (!ifs) return; // file not found !!!!
1730 /* defaults to A4 page */
1736 char lastchar = 0; ifs.get(lastchar);
1738 char c = 0; ifs.get(c);
1740 lyxerr.debug() << "End of (E)PS file reached and"
1741 " no BoundingBox!" << endl;
1744 if (c == '%' && lastchar == '%') {
1746 if (p.empty()) break;
1747 // we should not use this, with it we cannot
1748 // discover bounding box and end of file.
1749 //if (strcmp(p, "EndComments") == 0) break;
1750 lyxerr.debug() << "Token: `" << p << "'" << endl;
1751 if (p == "BoundingBox:") {
1752 float fpsx, fpsy, fpswid, fpshgh;
1753 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1756 pswid = int(fpswid);
1757 pshgh = int(fpshgh);
1759 if (lyxerr.debugging()) {
1760 lyxerr << "%%%%BoundingBox:"
1778 void InsetFig::CallbackFig(long arg)
1783 if (lyxerr.debugging()) {
1784 lyxerr << "Figure callback, arg " << arg << endl;
1790 case 12: /* width type */
1797 fl_deactivate_object(form->Width);
1802 fl_activate_object(form->Width);
1807 fl_activate_object(form->Width);
1812 fl_activate_object(form->Width);
1817 fl_activate_object(form->Width);
1820 lyxerr.debug() << "Unknown type!" << endl;
1827 case 22: /* height type */
1833 fl_deactivate_object(form->Height);
1838 fl_activate_object(form->Height);
1843 fl_activate_object(form->Height);
1848 fl_activate_object(form->Height);
1851 lyxerr.debug() << "Unknown type!" << endl;
1857 pflags = pflags & ~3; /* wysiwyg0 */
1860 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1863 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1866 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1869 pflags ^= 4; /* frame */
1872 pflags ^= 8; /* do translations */
1875 psubfigure = !psubfigure; /* This is a subfigure */
1878 regen = true; /* regenerate command */
1880 case 0: /* browse file */
1884 case 1: /* preview */
1885 p = fl_get_input(form->EpsFile);
1889 case 8: /* ok (apply and close) */
1890 if(!current_view->buffer()->isReadonly()) {
1893 xwid = atof(fl_get_input(form->Width));
1894 xhgh = atof(fl_get_input(form->Height));
1895 angle = atof(fl_get_input(form->Angle));
1896 p = fl_get_input(form->EpsFile);
1898 string buf1 = OnlyPath(owner->fileName());
1899 fname = MakeAbsPath(p, buf1);
1900 changedfname = true;
1902 if (!fname.empty()) {
1903 changedfname = true;
1907 subcaption = fl_get_input(form->Subcaption);
1911 /* now update inset */
1912 if (lyxerr.debugging()) {
1913 lyxerr << "Update: ["
1914 << wid << 'x' << hgh << ']' << endl;
1918 fl_set_focus_object(form->Figure, form->OkBtn);
1919 fl_hide_form(form->Figure);
1920 #if FL_REVISION == 89
1921 #warning Reactivate this free_form calls
1923 fl_free_form(form->Figure);
1924 free(form); // Why free?
1930 // The user has already been informed about RO in ::Edit
1931 if(arg == 7) // if 'Apply'
1934 case 9: /* cancel = restore and close */
1935 fl_set_focus_object(form->Figure, form->OkBtn);
1936 fl_hide_form(form->Figure);
1937 #if FL_REVISION == 89
1938 #warning Reactivate this free_form calls
1939 #warning Jug, is this still a problem?
1941 fl_free_form(form->Figure);
1942 free(form); // Why free?
1948 if (regen) TempRegenerate();
1952 inline void DisableFigurePanel(FD_Figure * const form)
1954 fl_deactivate_object(form->EpsFile);
1955 fl_deactivate_object(form->Browse);
1956 fl_deactivate_object(form->Width);
1957 fl_deactivate_object(form->Height);
1958 fl_deactivate_object(form->Frame);
1959 fl_deactivate_object(form->Translations);
1960 fl_deactivate_object(form->Angle);
1961 fl_deactivate_object(form->HeightGrp);
1962 fl_deactivate_object(form->page2);
1963 fl_deactivate_object(form->Default2);
1964 fl_deactivate_object(form->cm2);
1965 fl_deactivate_object(form->in2);
1966 fl_deactivate_object(form->HeightLabel);
1967 fl_deactivate_object(form->WidthLabel);
1968 fl_deactivate_object(form->DisplayGrp);
1969 fl_deactivate_object(form->Wysiwyg3);
1970 fl_deactivate_object(form->Wysiwyg0);
1971 fl_deactivate_object(form->Wysiwyg2);
1972 fl_deactivate_object(form->Wysiwyg1);
1973 fl_deactivate_object(form->WidthGrp);
1974 fl_deactivate_object(form->Default1);
1975 fl_deactivate_object(form->cm1);
1976 fl_deactivate_object(form->in1);
1977 fl_deactivate_object(form->page1);
1978 fl_deactivate_object(form->column1);
1979 fl_deactivate_object(form->Subcaption);
1980 fl_deactivate_object(form->Subfigure);
1981 fl_deactivate_object (form->OkBtn);
1982 fl_deactivate_object (form->ApplyBtn);
1983 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1984 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1988 inline void EnableFigurePanel(FD_Figure * const form)
1990 fl_activate_object(form->EpsFile);
1991 fl_activate_object(form->Browse);
1992 fl_activate_object(form->Width);
1993 fl_activate_object(form->Height);
1994 fl_activate_object(form->Frame);
1995 fl_activate_object(form->Translations);
1996 fl_activate_object(form->Angle);
1997 fl_activate_object(form->HeightGrp);
1998 fl_activate_object(form->page2);
1999 fl_activate_object(form->Default2);
2000 fl_activate_object(form->cm2);
2001 fl_activate_object(form->in2);
2002 fl_activate_object(form->HeightLabel);
2003 fl_activate_object(form->WidthLabel);
2004 fl_activate_object(form->DisplayGrp);
2005 fl_activate_object(form->Wysiwyg3);
2006 fl_activate_object(form->Wysiwyg0);
2007 fl_activate_object(form->Wysiwyg2);
2008 fl_activate_object(form->Wysiwyg1);
2009 fl_activate_object(form->WidthGrp);
2010 fl_activate_object(form->Default1);
2011 fl_activate_object(form->cm1);
2012 fl_activate_object(form->in1);
2013 fl_activate_object(form->page1);
2014 fl_activate_object(form->column1);
2015 fl_activate_object(form->Subcaption);
2016 fl_activate_object(form->Subfigure);
2017 fl_activate_object (form->OkBtn);
2018 fl_activate_object (form->ApplyBtn);
2019 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2020 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2024 void InsetFig::RestoreForm()
2028 EnableFigurePanel(form);
2031 fl_set_button(form->Default1, (wtype == 0));
2032 fl_set_button(form->cm1, (wtype == 1));
2033 fl_set_button(form->in1, (wtype == 2));
2034 fl_set_button(form->page1, (wtype == 3));
2035 fl_set_button(form->column1, (wtype == 4));
2037 fl_deactivate_object(form->Width);
2039 fl_activate_object(form->Width);
2042 // enable and disable should be put here.
2044 fl_set_button(form->Default2, (htype == 0));
2045 fl_set_button(form->cm2, (htype == 1));
2046 fl_set_button(form->in2, (htype == 2));
2047 fl_set_button(form->page2, (htype == 3));
2048 // enable and disable should be put here.
2050 fl_deactivate_object(form->Height);
2052 fl_activate_object(form->Height);
2055 int pflags = flags & 3;
2056 fl_set_button(form->Wysiwyg0, (pflags == 0));
2057 fl_set_button(form->Wysiwyg1, (pflags == 1));
2058 fl_set_button(form->Wysiwyg2, (pflags == 2));
2059 fl_set_button(form->Wysiwyg3, (pflags == 3));
2060 fl_set_button(form->Frame, ((flags & 4) != 0));
2061 fl_set_button(form->Translations, ((flags & 8) != 0));
2062 fl_set_button(form->Subfigure, (subfigure != 0));
2064 psubfigure = subfigure;
2065 sprintf(buf, "%g", xwid);
2066 fl_set_input(form->Width, buf);
2067 sprintf(buf, "%g", xhgh);
2068 fl_set_input(form->Height, buf);
2069 sprintf(buf, "%g", angle);
2070 fl_set_input(form->Angle, buf);
2071 if (!fname.empty()){
2072 string buf1 = OnlyPath(owner->fileName());
2073 string fname2 = MakeRelPath(fname, buf1);
2074 fl_set_input(form->EpsFile, fname2.c_str());
2076 else fl_set_input(form->EpsFile, "");
2077 fl_set_input(form->Subcaption, subcaption.c_str());
2078 if(current_view->buffer()->isReadonly())
2079 DisableFigurePanel(form);
2085 void InsetFig::Preview(char const * p)
2090 lyxerr << "Cannot fork process!" << endl;
2095 return; // parent process
2098 string buf1 = OnlyPath(owner->fileName());
2099 string buf2 = MakeAbsPath(p, buf1);
2101 lyxerr << "Error during rendering "
2102 << execlp(lyxrc->view_pspic_command.c_str(),
2103 lyxrc->view_pspic_command.c_str(),
2110 void InsetFig::BrowseFile()
2112 static string current_figure_path;
2113 static int once = 0;
2116 if (lyxerr.debugging()) {
2117 lyxerr << "Filename: "
2118 << owner->fileName() << endl;
2120 string p = fl_get_input(form->EpsFile);
2122 string buf = MakeAbsPath(owner->fileName());
2123 string buf2 = OnlyPath(buf);
2125 buf = MakeAbsPath(p, buf2);
2126 buf = OnlyPath(buf);
2128 buf = OnlyPath(owner->fileName().c_str());
2131 // Does user clipart directory exist?
2132 string bufclip = AddName (user_lyxdir, "clipart");
2133 FileInfo fileInfo(bufclip);
2134 if (!(fileInfo.isOK() && fileInfo.isDir()))
2135 // No - bail out to system clipart directory
2136 bufclip = AddName (system_lyxdir, "clipart");
2139 fileDlg.SetButton(0, _("Clipart"), bufclip);
2140 fileDlg.SetButton(1, _("Document"), buf);
2146 p = fileDlg.Select(_("EPS Figure"),
2147 current_figure_path,
2150 p = fileDlg.Select(_("EPS Figure"), buf,
2155 if (p.empty()) return;
2157 buf = MakeRelPath(p, buf2);
2158 current_figure_path = OnlyPath(p);
2161 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2162 || contains(p, "%") || contains(p, " "))
2164 WriteAlert(_("Filename can't contain any "
2165 "of these characters:"),
2166 // xgettext:no-c-format
2167 _("space, '#', '~', '$' or '%'."));
2172 if (form) fl_set_input(form->EpsFile, buf.c_str());
2176 void GraphicsCB(FL_OBJECT * obj, long arg)
2178 /* obj->form contains the form */
2180 if (lyxerr.debugging()) {
2181 lyxerr << "GraphicsCB callback: " << arg << endl;
2184 /* find inset we were reacting to */
2185 for (int i = 0; i < figinsref; ++i)
2186 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2189 if (lyxerr.debugging()) {
2190 lyxerr << "Calling back figure " << i << endl;
2192 figures[i]->inset->CallbackFig(arg);
2198 void HideFiguresPopups()
2200 for (int i = 0; i < figinsref; ++i)
2201 if (figures[i]->inset->form
2202 && figures[i]->inset->form->Figure->visible) {
2203 if (lyxerr.debugging()) {
2204 lyxerr << "Hiding figure " << i << endl;
2206 // hide and free the form
2207 figures[i]->inset->CallbackFig(9);