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
50 #include "support/filetools.h"
51 #include "LyXView.h" // just because of form_main
54 #include "LaTeXFeatures.h"
57 #include "lyx_gui_misc.h" // CancelCloseBoxCB
58 #include "support/FileInfo.h"
60 extern BufferView * current_view;
62 static volatile bool alarmed;
64 extern FL_OBJECT * figinset_canvas;
67 extern "C" void waitalarm(int)
73 extern char ** environ; // is this only redundtant on linux systems? Lgb.
74 extern void UpdateInset(Inset * inset, bool mark_dirty = true);
75 // better for asyncron updating:
76 void PutInsetIntoInsetUpdateList(Inset * inset);
77 extern void ProhibitInput();
78 extern void AllowInput();
80 static float const DEG2PI = 57.295779513;
81 static int const figallocchunk = 32;
83 static int figinsref = 0; /* number of figures */
84 static int figarrsize = 0; /* current max number of figures */
85 static int bmpinsref = 0; /* number of bitmaps */
86 static int bmparrsize = 0; /* current max number of bitmaps */
89 float rx, ry; /* resolution x and y */
90 int ofsx, ofsy; /* x and y translation */
91 figdata * data; /* we are doing it for this data */
92 queue * next; /* next item in queue */
96 int pid; /* pid to wait for */
97 pidwait * next; /* next */
100 static int const MAXGS = 3; /* maximum 3 gs's at a time */
102 static Figref ** figures; /* all the figures */
103 static figdata ** bitmaps; /* all the bitmaps */
104 static queue * gsqueue = 0; /* queue for ghostscripting */
105 static int gsrunning = 0; /* currently so many gs's are running */
106 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
107 static char bittable[256]; /* bit reversion table */
109 static bool gs_color; // do we allocate colors for gs?
110 static bool color_visual; // is the visual color?
111 static bool gs_xcolor = false; // allocated extended colors
112 static unsigned long gs_pixels[128]; // allocated pixels
113 static int gs_num_pixels; // number of pixels allocated
114 static int gs_spc; // shades per color
115 static bool gs_gray; // is grayscale?
116 static int gs_allcolors; // number of all colors
118 static pidwait * pw = 0; // pid wait list
121 extern Colormap color_map;
123 void addpidwait(int pid)
125 // adds pid to pid wait list
126 register pidwait * p = new pidwait;
132 if (lyxerr.debugging()) {
133 lyxerr << "Pids to wait for: " << p->pid << endl;
136 lyxerr << p->pid << endl;
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) {
198 if (lyxerr.debugging()) {
199 lyxerr << "Spawned child "
202 addpidwait(forkstat);
203 break; // in parent process
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 //cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
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 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 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 figures = static_cast<Figref**>
370 (malloc(sizeof(Figref*) * figallocchunk));
371 bitmaps = static_cast<figdata**>
372 (malloc(sizeof(figdata*) * figallocchunk));
375 for (unsigned int i = 0; i < 256; ++i) {
377 for (unsigned int j = 0; j < 8; ++j)
378 if (i & (1 << (7-j))) k |= 1 << j;
379 bittable[i] = char(~k);
382 fl_add_canvas_handler(figinset_canvas, ClientMessage,
383 GhostscriptMsg, current_view->owner()->getMainForm());
385 // now we have to init color_map
386 if (!color_map) color_map = DefaultColormap(fl_display,
387 DefaultScreen(fl_display));
388 // allocate color cube on pseudo-color display
392 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
393 if (lyxerr.debugging()) {
394 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
395 vi->visualid, vi->c_class,
396 vi->bits_per_rgb, vi->map_entries);
398 color_visual = ( (vi->c_class == StaticColor) ||
399 (vi->c_class == PseudoColor) ||
400 (vi->c_class == TrueColor) ||
401 (vi->c_class == DirectColor) );
402 if ((vi->c_class & 1) == 0) return;
403 // now allocate colors
404 if (vi->c_class == GrayScale) {
405 // allocate grayscale
406 AllocGrays(vi->map_entries/2);
408 // allocate normal color
410 while (i * i * i * 2 > vi->map_entries) --i;
413 gs_allcolors = vi->map_entries;
424 lyxerr.debug() << "Unregistering figures..." << endl;
426 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
430 lyxerr.debug() << "Freeing up the colors..." << endl;
431 XFreeColors(fl_display, color_map, gs_pixels,
433 /******????????????????? what's planes in this case ??????***/
438 int FindBmpIndex(figdata * tmpdata)
441 while (i < bmpinsref) {
442 if (bitmaps[i] == tmpdata) return i;
449 static void chpixmap(Pixmap, int, int)
452 Display * tempdisp = XOpenDisplay(XDisplayName(0));
454 // here read the pixmap and change all colors to those we
457 XCloseDisplay(tempdisp);
462 static void freefigdata(figdata * tmpdata)
465 if (tmpdata->ref) return;
467 if (tmpdata->gspid > 0) {
468 int pid = tmpdata->gspid;
470 // change Pixmap according to our allocated colormap
471 chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
472 // kill ghostscript and unlink it's files
475 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
479 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
481 int i = FindBmpIndex(tmpdata);
483 while (i < bmpinsref) {
484 bitmaps[i] = bitmaps[i + 1];
490 static void runqueue()
492 // run queued requests for ghostscript, if any
493 if (!gsrunning && gs_color && !gs_xcolor) {
494 // here alloc all colors, so that gs will use only
495 // those we allocated for it
500 while (gsrunning < MAXGS) {
501 char tbuf[384], tbuf2[80];
506 if (!gsrunning && gs_xcolor) {
507 // de-allocate rest of colors
523 if (lyxerr.debugging()) {
524 lyxerr << "GS start error! Cannot fork."
527 p->data->broken = true;
528 p->data->reading = false;
531 if (pid == 0) { // child
532 char ** env, rbuf[80], gbuf[40];
534 Display * tempdisp = XOpenDisplay(XDisplayName(0));
536 // create translation file
537 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
541 ofs << "gsave clippath pathbbox grestore\n"
543 << "/ury exch def /urx exch def /lly exch def "
545 << p->data->wid / 2.0 << " "
546 << p->data->hgh / 2.0 << " translate\n"
547 << p->data->angle << " rotate\n"
548 << -(p->data->raw_wid / 2.0) << " "
549 << -(p->data->raw_hgh / 2.0) << " translate\n"
550 << p->rx / 72.0 << " " << p->ry / 72.0
552 << -p->ofsx << " " << -p->ofsy << " translate\n"
554 ofs.close(); // Don't remove this.
556 // gs process - set ghostview environment first
557 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
558 figinset_canvas), p->data->bitmap);
560 // now set up ghostview property on a window
561 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
562 p->data->wid, p->data->hgh);
563 // #warning BUG seems that the only bug here
564 // might be the hardcoded dpi.. Bummer!
566 if (lyxerr.debugging()) {
567 lyxerr << "Will set GHOSTVIEW property to ["
568 << tbuf << "]" << endl;
570 // wait until property is deleted if executing multiple
573 // grab server to prevent other child
574 // interfering with setting GHOSTVIEW property
575 if (lyxerr.debugging()) {
576 lyxerr << "Grabbing the server"
579 XGrabServer(tempdisp);
580 prop = XListProperties(tempdisp,
582 figinset_canvas), &nprop);
586 for (i = 0; i < nprop; ++i) {
587 char * p = XGetAtomName(tempdisp,
589 if (strcmp(p, "GHOSTVIEW") == 0) {
595 XFree(reinterpret_cast<char *>(prop)); // jc:
597 // release the server
598 XUngrabServer(tempdisp);
600 // ok, property found, we must wait until
601 // ghostscript deletes it
602 if (lyxerr.debugging()) {
603 lyxerr << "Releasing the server\n["
605 << "] GHOSTVIEW property"
606 " found. Waiting." << endl;
610 #warning What is this doing? (wouldn't a sleep(1); work too?')
614 signal(SIGALRM, waitalarm);
615 while (!alarmed) pause();
621 XChangeProperty(tempdisp,
622 fl_get_canvas_id(figinset_canvas),
623 XInternAtom(tempdisp, "GHOSTVIEW", false),
624 XInternAtom(tempdisp, "STRING", false),
626 reinterpret_cast<unsigned char*>(tbuf),
629 switch (p->data->flags & 3) {
630 case 0: tbuf[0] = 'H'; break; // Hidden
631 case 1: tbuf[0] = 'M'; break; // Mono
632 case 2: tbuf[0] = 'G'; break; // Gray
635 tbuf[0] = 'C'; // Color
637 tbuf[0] = 'G'; // Gray
642 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
643 DefaultScreenOfDisplay(fl_display)),
646 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
647 DefaultScreenOfDisplay(fl_display)),
651 XChangeProperty(tempdisp,
652 fl_get_canvas_id(figinset_canvas),
653 XInternAtom(tempdisp,
654 "GHOSTVIEW_COLORS", false),
655 XInternAtom(tempdisp, "STRING", false),
657 reinterpret_cast<unsigned char*>(tbuf),
659 XUngrabServer(tempdisp);
661 if (lyxerr.debugging()) {
662 lyxerr << "Releasing the server" << endl;
664 XCloseDisplay(tempdisp);
666 // set up environment
667 while (environ[ne]) ++ne;
668 env = static_cast<char **>
669 (malloc(sizeof(char*) * (ne + 2)));
671 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
674 // now make gs command
676 // close(1); do NOT close. If GS writes out
677 // errors it would hang. (Matthias 290596)
678 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
679 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
680 // now chdir into dir with .eps file, to be on the safe
682 chdir(OnlyPath(p->data->fname).c_str());
683 // make temp file name
684 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
686 if (lyxerr.debugging()) {
687 lyxerr << "starting gs " << tbuf << " "
689 << ", pid: " << getpid() << endl;
692 int err = execlp(lyxrc->ps_command.c_str(),
693 lyxrc->ps_command.c_str(),
695 "-dNOPAUSE", "-dQUIET",
698 p->data->fname.c_str(),
699 "showpage.ps", "quit.ps", "-", 0);
700 // if we are still there, an error occurred.
701 lyxerr << "Error executing ghostscript. "
702 << "Code: " << err << endl;
703 lyxerr.debug() << "Cmd: "
707 << p->data->fname << endl;
710 // normal process (parent)
711 if (lyxerr.debugging()) {
712 lyxerr << "GS [" << pid << "] started" << endl;
714 gsqueue = gsqueue->next;
716 p->data->gspid = pid;
722 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
724 // recompute the stuff and put in the queue
725 queue * p = new queue;
728 p->rx = (float(data->raw_wid) * 72.0) / pswid;
729 p->ry = (float(data->raw_hgh) * 72.0) / pshgh;
734 // now put into queue
735 queue * p2 = gsqueue;
736 if (!gsqueue) gsqueue = p;
738 while (p2->next) p2 = p2->next;
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 figdata ** tmp = static_cast<figdata**>
771 (malloc(sizeof(figdata*) * bmparrsize));
773 sizeof(figdata*) * (bmparrsize - figallocchunk));
777 figdata * p = new figdata;
778 bitmaps[bmpinsref-1] = p;
781 p->raw_wid = raw_wid;
782 p->raw_hgh = raw_hgh;
786 XWindowAttributes wa;
787 XGetWindowAttributes(fl_display, fl_get_canvas_id(
788 figinset_canvas), &wa);
790 if (lyxerr.debugging()) {
791 lyxerr << "Create pixmap disp:" << fl_display
792 << " scr:" << DefaultScreen(fl_display)
795 << " depth:" << wa.depth << endl;
803 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
804 figinset_canvas), wid, hgh, wa.depth);
806 // initialize reading of .eps file with correct sizes and stuff
807 addwait(psx, psy, pswid, pshgh, p);
818 static void getbitmap(figdata * p)
824 static void makeupdatelist(figdata * p)
826 for (int i = 0; i < figinsref; ++i)
827 if (figures[i]->data == p) {
828 if (lyxerr.debugging()) {
829 lyxerr << "Updating inset "
833 //UpdateInset(figures[i]->inset);
834 // add inset figures[i]->inset into to_update list
835 PutInsetIntoInsetUpdateList(figures[i]->inset);
840 void sigchldchecker(pid_t pid, int * status)
842 lyxerr.debug() << "Got pid = " << pid << endl;
843 bool pid_handled = false;
844 for (int i = bmpinsref - 1; i >= 0; --i) {
845 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
846 lyxerr.debug() << "Found pid in bitmaps" << endl;
847 // now read the file and remove it from disk
848 figdata * p = bitmaps[i];
850 if (bitmaps[i]->gsdone) *status = 0;
852 lyxerr.debug() << "GS [" << pid
853 << "] exit OK." << endl;
855 lyxerr << "GS [" << pid << "] error "
857 << WIFEXITED(*status)
858 << " " << WEXITSTATUS(*status)
859 << " S:" << WIFSIGNALED(*status)
860 << " " << WTERMSIG(*status) << endl;
863 bitmap_waiting = true;
866 // remove temporary files
868 sprintf(tmp, "%s/~lyxgs%d.ps",
869 system_tempdir.c_str(),
875 makeupdatelist(bitmaps[i]);
882 lyxerr.debug() << "Checking pid in pidwait" << endl;
883 pidwait * p = pw, * prev = 0;
886 lyxerr.debug() << "Found pid in pidwait" << endl;
887 lyxerr.debug() << "Caught child pid of recompute routine " << pid << endl;
889 prev->next = p->next;
901 lyxerr.debug() << "waitpid error" << endl;
904 lyxerr << "The process or process group specified by "
905 "pid does not exist or is not a child of "
906 "the calling process or can never be in the "
907 "states specified by options." << endl;
910 lyxerr << "waitpid() was interrupted due to the "
911 "receipt of a signal sent by the calling "
915 lyxerr << "An invalid value was specified for "
919 lyxerr << "Unknown error from waitpid" << endl;
922 } else if (pid == 0) {
923 lyxerr << "waitpid nohang" << endl;;
925 lyxerr.debug() << "normal exit from childhandler" << endl;
930 static void getbitmaps()
932 bitmap_waiting = false;
933 for (int i = 0; i < bmpinsref; ++i)
934 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
935 getbitmap(bitmaps[i]);
939 static void RegisterFigure(InsetFig *fi)
941 if (figinsref == 0) InitFigures();
944 if (figinsref > figarrsize) {
945 // allocate more space
946 figarrsize += figallocchunk;
947 Figref ** tmp = static_cast<Figref**>
948 (malloc(sizeof(Figref*)*figarrsize));
950 sizeof(Figref*)*(figarrsize-figallocchunk));
954 Figref * tmpfig = new Figref;
957 figures[figinsref-1] = tmpfig;
960 if (lyxerr.debugging()) {
961 lyxerr << "Register Figure: buffer:["
962 << current_view->buffer() << "]" << endl;
967 int FindFigIndex(Figref * tmpfig)
970 while (i < figinsref) {
971 if (figures[i] == tmpfig) return i;
978 static void UnregisterFigure(InsetFig * fi)
980 Figref * tmpfig = fi->figure;
982 if (tmpfig->data) freefigdata(tmpfig->data);
983 if (tmpfig->inset->form) {
984 if (tmpfig->inset->form->Figure->visible) {
985 fl_set_focus_object(tmpfig->inset->form->Figure,
986 tmpfig->inset->form->OkBtn);
987 fl_hide_form(tmpfig->inset->form->Figure);
989 #if FL_REVISION == 89
990 #warning Reactivate this free_form calls
992 fl_free_form(tmpfig->inset->form->Figure);
993 free(tmpfig->inset->form);
994 tmpfig->inset->form = 0;
997 int i = FindFigIndex(tmpfig);
999 while (i < figinsref) {
1000 figures[i] = figures[i+1];
1005 if (figinsref == 0) DoneFigures();
1009 static string NextToken(istream & is)
1017 } while (!is.eof() && !isspace(c));
1018 token.erase(token.length() - 1); // remove the isspace
1024 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1034 psubfigure = subfigure = false;
1035 xwid = xhgh = angle = 0;
1037 raw_wid = raw_hgh = 0;
1038 changedfname = false;
1039 RegisterFigure(this);
1043 InsetFig::~InsetFig()
1045 if (lyxerr.debugging()) {
1046 lyxerr << "Figure destructor called" << endl;
1048 UnregisterFigure(this);
1052 int InsetFig::Ascent(LyXFont const &) const
1058 int InsetFig::Descent(LyXFont const &) const
1064 int InsetFig::Width(LyXFont const &) const
1070 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1072 if (bitmap_waiting) getbitmaps();
1074 // I wish that I didn't have to use this
1075 // but the figinset code is so complicated so
1076 // I don't want to fiddle with it now.
1077 unsigned long pm = scr.getForeground();
1079 if (figure && figure->data && figure->data->bitmap &&
1080 !figure->data->reading && !figure->data->broken) {
1082 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1083 0, 0, wid, hgh, int(x+1), baseline-hgh);
1085 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1086 int(x), baseline - hgh - 1,
1091 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1093 baseline - hgh - 1, wid+1, hgh+1);
1094 if (figure && figure->data) {
1095 if (figure->data->broken) msg = _("[render error]");
1096 else if (figure->data->reading) msg = _("[rendering ... ]");
1098 if (fname.empty()) msg = _("[no file]");
1099 else if ((flags & 3) == 0) msg = _("[not displayed]");
1100 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1102 if (!msg) msg = _("[unknown error]");
1104 font.setFamily (LyXFont::SANS_FAMILY);
1105 font.setSize (LyXFont::SIZE_FOOTNOTE);
1106 string justname = OnlyFilename (fname);
1107 font.drawString(justname, pm,
1108 baseline - font.maxAscent() - 4,
1110 font.setSize (LyXFont::SIZE_TINY);
1111 font.drawText (msg, strlen(msg), pm,
1116 x += Width(font); // ?
1120 void InsetFig::Write(ostream & os)
1123 os << "Figure size " << wid << " " << hgh << "\n";
1124 if (!fname.empty()) {
1125 string buf1 = OnlyPath(owner->fileName());
1126 string fname2 = MakeRelPath(fname, buf1);
1127 os << "file " << fname2 << "\n";
1129 if (!subcaption.empty())
1130 os << "subcaption " << subcaption << "\n";
1131 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1132 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1133 if (angle != 0) os << "angle " << angle << "\n";
1134 os << "flags " << flags << "\n";
1135 if (subfigure) os << "subfigure\n";
1139 void InsetFig::Read(LyXLex & lex)
1142 bool finished = false;
1144 while (lex.IsOK() && !finished) {
1147 string const token = lex.GetString();
1148 lyxerr.debug() << "Token: " << token << endl;
1152 else if (token == "\\end_inset") {
1154 } else if (token == "file") {
1156 buf = lex.GetString();
1157 string buf1 = OnlyPath(owner->fileName());
1158 fname = MakeAbsPath(buf, buf1);
1159 changedfname = true;
1161 } else if (token == "extra") {
1163 // kept for backwards compability. Delete in 0.13.x
1164 } else if (token == "subcaption") {
1166 subcaption = lex.GetString();
1167 } else if (token == "label") {
1169 // kept for backwards compability. Delete in 0.13.x
1170 } else if (token == "angle") {
1172 angle = lex.GetFloat();
1173 } else if (token == "size") {
1175 wid = lex.GetInteger();
1177 hgh = lex.GetInteger();
1178 } else if (token == "flags") {
1180 flags = pflags = lex.GetInteger();
1181 } else if (token == "subfigure") {
1182 subfigure = psubfigure = true;
1183 } else if (token == "width") {
1186 typ = lex.GetInteger();
1188 xwid = lex.GetFloat();
1190 case DEF: wtype = DEF; break;
1191 case CM: wtype = CM; break;
1192 case IN: wtype = IN; break;
1193 case PER_PAGE: wtype = PER_PAGE; break;
1194 case PER_COL: wtype = PER_COL; break;
1196 lyxerr.debug() << "Unknown type!" << endl;
1200 } else if (token == "height") {
1203 typ = lex.GetInteger();
1205 xhgh = lex.GetFloat();
1207 case DEF: htype = DEF; break;
1208 case CM: htype = CM; break;
1209 case IN: htype = IN; break;
1210 case PER_PAGE: htype = PER_PAGE; break;
1212 lyxerr.debug() << "Unknown type!" << endl;
1223 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1226 if (!cmd.empty()) os << cmd << " ";
1231 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1239 int InsetFig::Linuxdoc(string &/*file*/)
1245 int InsetFig::DocBook(string & file)
1247 string figurename = fname;
1249 if(suffixIs(figurename, ".eps"))
1250 figurename.erase(fname.length() - 5);
1252 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1257 void InsetFig::Validate(LaTeXFeatures & features) const
1259 features.graphics = true;
1260 if (subfigure) features.subfigure = true;
1264 unsigned char InsetFig::Editable() const
1270 bool InsetFig::Deletable() const
1276 void InsetFig::Edit(int, int)
1278 lyxerr.debug() << "Editing InsetFig." << endl;
1281 // We should have RO-versions of the form instead.
1282 // The actual prevention of altering a readonly doc
1283 // is done in CallbackFig()
1284 if(current_view->buffer()->isReadonly())
1285 WarnReadonly(current_view->buffer()->fileName());
1288 form = create_form_Figure();
1289 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1290 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1291 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1292 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1295 if (form->Figure->visible) {
1296 fl_raise_form(form->Figure);
1298 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1299 FL_FULLBORDER, _("Figure"));
1304 Inset * InsetFig::Clone() const
1306 InsetFig * tmp = new InsetFig(100, 100, owner);
1308 if (lyxerr.debugging()) {
1309 lyxerr << "Clone Figure: buffer:["
1310 << current_view->buffer()
1311 << "], cbuffer:[xx]" << endl;
1316 tmp->raw_wid = raw_wid;
1317 tmp->raw_hgh = raw_hgh;
1322 tmp->pflags = pflags;
1323 tmp->subfigure = subfigure;
1324 tmp->psubfigure = psubfigure;
1332 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1333 // do not display if there is
1334 // "do not display" chosen (Matthias 260696)
1335 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1336 pswid, pshgh, raw_wid, raw_hgh,
1337 angle, flags & (3|8));
1338 } else tmp->figure->data = 0;
1339 tmp->subcaption = subcaption;
1340 tmp->changedfname = false;
1347 Inset::Code InsetFig::LyxCode() const
1349 return Inset::GRAPHICS_CODE;
1353 void InsetFig::Regenerate()
1356 string resizeW, resizeH;
1357 string rotate, recmd;
1359 if (fname.empty()) {
1360 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1361 cmd += _("empty figure path");
1363 //if (form) fl_set_object_label(form->cmd, "");
1367 string buf1 = OnlyPath(owner->fileName());
1368 string fname2 = MakeRelPath(fname, buf1);
1370 string gcmd = "\\includegraphics{" + fname2 + '}';
1375 case CM:{// \resizebox*{h-length}{v-length}{text}
1377 sprintf(buf, "%g", xwid); // should find better
1384 sprintf(buf, "%g", xwid);
1391 sprintf(buf, "%g", xwid/100);
1393 resizeW += "\\textwidth";
1398 sprintf(buf, "%g", xwid/100);
1400 resizeW += "\\columnwidth";
1410 sprintf(buf, "%g", xhgh);
1417 sprintf(buf, "%g", xhgh);
1424 sprintf(buf, "%g", xhgh/100);
1426 resizeH += "\\textheight";
1430 // Doesn't occur; case exists to suppress compiler warnings.
1435 if (!resizeW.empty() || !resizeH.empty()) {
1436 recmd = "\\resizebox*{";
1437 if (!resizeW.empty())
1442 if (!resizeH.empty())
1452 sprintf(buf, "%g", angle);
1453 // \rotatebox{angle}{text}
1454 rotate = "\\rotatebox{";
1462 if (!rotate.empty()) cmdbuf += '}';
1463 if (!recmd.empty()) cmdbuf += '}';
1465 if (!subcaption.empty())
1466 cmdbuf = "\\subfigure[" + subcaption +
1467 "]{" + cmdbuf + "}";
1469 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1474 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1478 void InsetFig::TempRegenerate()
1481 string resizeW, resizeH;
1482 string rotate, recmd;
1484 char const * tfname = fl_get_input(form->EpsFile);
1485 string tsubcap = fl_get_input(form->Subcaption);
1486 float tangle = atof(fl_get_input(form->Angle));
1487 float txwid = atof(fl_get_input(form->Width));
1488 float txhgh = atof(fl_get_input(form->Height));
1490 if (!tfname || !*tfname) {
1491 //fl_set_object_label(form->cmd, "");
1492 //fl_redraw_object(form->cmd);
1493 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1494 cmd += _("empty figure path");
1499 string buf1 = OnlyPath(owner->fileName());
1500 string fname2 = MakeRelPath(tfname, buf1);
1501 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1502 string gcmd = "\\includegraphics{" + fname2 + '}';
1507 case CM: {// \resizebox*{h-length}{v-length}{text}
1509 sprintf(buf, "%g", txwid); // should find better
1516 sprintf(buf, "%g", txwid);
1523 sprintf(buf, "%g", txwid/100);
1525 resizeW += "\\textwidth";
1530 sprintf(buf, "%g", txwid/100);
1532 resizeW += "\\columnwidth";
1542 sprintf(buf, "%g", txhgh);
1549 sprintf(buf, "%g", txhgh);
1556 sprintf(buf, "%g", txhgh/100);
1558 resizeH += "\\textheight";
1562 // Doesn't occur; case exists to suppress compiler warnings.
1567 // \resizebox*{h-length}{v-length}{text}
1568 if (!resizeW.empty() || !resizeH.empty()) {
1569 recmd = "\\resizebox*{";
1570 if (!resizeW.empty())
1575 if (!resizeH.empty())
1584 sprintf(buf, "%g", tangle);
1585 // \rotatebox{angle}{text}
1586 rotate = "\\rotatebox{";
1594 if (!rotate.empty()) cmdbuf += '}';
1595 if (!recmd.empty()) cmdbuf += '}';
1596 if (psubfigure && !tsubcap.empty()) {
1597 cmdbuf = string("\\subfigure{") + tsubcap
1598 + string("}{") + cmdbuf + "}";
1603 void InsetFig::Recompute()
1605 bool changed = changedfname;
1606 int newx, newy, nraw_x, nraw_y;
1608 if (changed) GetPSSizes();
1610 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1611 float cos_a = cos (angle / DEG2PI);
1612 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1613 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1615 /* now recompute wid and hgh, and if that is changed, set changed */
1616 /* this depends on chosen size of the picture and its bbox */
1617 // This will be redone in 0.13 ... (hen)
1618 if (!fname.empty()) {
1619 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1627 newx = int(28.346 * xwid);
1630 newx = int(72 * xwid);
1632 case PER_PAGE: /* % of page */
1633 newx = int(5.95 * xwid);
1635 case PER_COL: /* % of col */
1636 newx = int(2.975 * xwid);
1640 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1644 //lyxerr << "This should not happen!" << endl;
1647 newy = int(28.346 * xhgh);
1650 newy = int(72 * xhgh);
1652 case PER_PAGE: /* % of page */
1653 newy = int(8.42 * xhgh);
1656 // Doesn't occur; case exists to suppress
1657 // compiler warnings.
1660 if (htype && !wtype && frame_hgh)
1661 newx = newy*frame_wid/frame_hgh;
1670 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1675 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1677 // cannot be zero, actually, set it to some minimum, so its clickable
1678 if (newx < 5) newx = 5;
1679 if (newy < 5) newy = 5;
1681 if (newx != wid || newy != hgh ||
1682 nraw_x != raw_wid || nraw_y != raw_hgh ||
1683 flags != pflags || subfigure != psubfigure)
1691 subfigure = psubfigure;
1694 figdata * pf = figure->data;
1697 if (!fname.empty() && (flags & 3)
1698 && !lyxrc->ps_command.empty()) {
1699 // do not display if there is "do not display"
1700 // chosen (Matthias 260696)
1701 figure->data = getfigdata(wid, hgh, fname,
1702 psx, psy, pswid, pshgh,
1704 angle, flags & (3|8));
1705 } else figure->data = 0;
1707 // free the old data
1708 if (pf) freefigdata(pf);
1711 changedfname = false;
1715 void InsetFig::GetPSSizes()
1717 /* get %%BoundingBox: from postscript file */
1719 /* defaults to associated size
1720 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1727 if (fname.empty()) return;
1729 ifstream ifs(fname.c_str());
1731 if (!ifs) return; // file not found !!!!
1733 /* defaults to A4 page */
1739 char lastchar = 0; ifs.get(lastchar);
1741 char c = 0; ifs.get(c);
1743 lyxerr.debug() << "End of (E)PS file reached and"
1744 " no BoundingBox!" << endl;
1747 if (c == '%' && lastchar == '%') {
1749 if (p.empty()) break;
1750 // we should not use this, with it we cannot
1751 // discover bounding box and end of file.
1752 //if (strcmp(p, "EndComments") == 0) break;
1753 lyxerr.debug() << "Token: `" << p << "'" << endl;
1754 if (p == "BoundingBox:") {
1755 float fpsx, fpsy, fpswid, fpshgh;
1756 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1759 pswid = int(fpswid);
1760 pshgh = int(fpshgh);
1762 if (lyxerr.debugging()) {
1763 lyxerr << "%%%%BoundingBox:"
1781 void InsetFig::CallbackFig(long arg)
1786 if (lyxerr.debugging()) {
1787 lyxerr << "Figure callback, arg " << arg << endl;
1793 case 12: /* width type */
1800 fl_deactivate_object(form->Width);
1805 fl_activate_object(form->Width);
1810 fl_activate_object(form->Width);
1815 fl_activate_object(form->Width);
1820 fl_activate_object(form->Width);
1823 lyxerr.debug() << "Unknown type!" << endl;
1830 case 22: /* height type */
1836 fl_deactivate_object(form->Height);
1841 fl_activate_object(form->Height);
1846 fl_activate_object(form->Height);
1851 fl_activate_object(form->Height);
1854 lyxerr.debug() << "Unknown type!" << endl;
1860 pflags = pflags & ~3; /* wysiwyg0 */
1863 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1866 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1869 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1872 pflags ^= 4; /* frame */
1875 pflags ^= 8; /* do translations */
1878 psubfigure = !psubfigure; /* This is a subfigure */
1881 regen = true; /* regenerate command */
1883 case 0: /* browse file */
1887 case 1: /* preview */
1888 p = fl_get_input(form->EpsFile);
1892 case 8: /* ok (apply and close) */
1893 if(!current_view->buffer()->isReadonly()) {
1896 xwid = atof(fl_get_input(form->Width));
1897 xhgh = atof(fl_get_input(form->Height));
1898 angle = atof(fl_get_input(form->Angle));
1899 p = fl_get_input(form->EpsFile);
1901 string buf1 = OnlyPath(owner->fileName());
1902 fname = MakeAbsPath(p, buf1);
1903 changedfname = true;
1905 if (!fname.empty()) {
1906 changedfname = true;
1910 subcaption = fl_get_input(form->Subcaption);
1914 /* now update inset */
1915 if (lyxerr.debugging()) {
1916 lyxerr << "Update: ["
1917 << wid << 'x' << hgh << ']' << endl;
1921 fl_set_focus_object(form->Figure, form->OkBtn);
1922 fl_hide_form(form->Figure);
1923 #if FL_REVISION == 89
1924 #warning Reactivate this free_form calls
1926 fl_free_form(form->Figure);
1933 // The user has already been informed about RO in ::Edit
1934 if(arg == 7) // if 'Apply'
1937 case 9: /* cancel = restore and close */
1938 fl_set_focus_object(form->Figure, form->OkBtn);
1939 fl_hide_form(form->Figure);
1940 #if FL_REVISION == 89
1941 #warning Reactivate this free_form calls
1942 #warning Jug, is this still a problem?
1944 fl_free_form(form->Figure);
1951 if (regen) TempRegenerate();
1955 inline void DisableFigurePanel(FD_Figure * const form)
1957 fl_deactivate_object(form->EpsFile);
1958 fl_deactivate_object(form->Browse);
1959 fl_deactivate_object(form->Width);
1960 fl_deactivate_object(form->Height);
1961 fl_deactivate_object(form->Frame);
1962 fl_deactivate_object(form->Translations);
1963 fl_deactivate_object(form->Angle);
1964 fl_deactivate_object(form->HeightGrp);
1965 fl_deactivate_object(form->page2);
1966 fl_deactivate_object(form->Default2);
1967 fl_deactivate_object(form->cm2);
1968 fl_deactivate_object(form->in2);
1969 fl_deactivate_object(form->HeightLabel);
1970 fl_deactivate_object(form->WidthLabel);
1971 fl_deactivate_object(form->DisplayGrp);
1972 fl_deactivate_object(form->Wysiwyg3);
1973 fl_deactivate_object(form->Wysiwyg0);
1974 fl_deactivate_object(form->Wysiwyg2);
1975 fl_deactivate_object(form->Wysiwyg1);
1976 fl_deactivate_object(form->WidthGrp);
1977 fl_deactivate_object(form->Default1);
1978 fl_deactivate_object(form->cm1);
1979 fl_deactivate_object(form->in1);
1980 fl_deactivate_object(form->page1);
1981 fl_deactivate_object(form->column1);
1982 fl_deactivate_object(form->Subcaption);
1983 fl_deactivate_object(form->Subfigure);
1984 fl_deactivate_object (form->OkBtn);
1985 fl_deactivate_object (form->ApplyBtn);
1986 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1987 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1991 inline void EnableFigurePanel(FD_Figure * const form)
1993 fl_activate_object(form->EpsFile);
1994 fl_activate_object(form->Browse);
1995 fl_activate_object(form->Width);
1996 fl_activate_object(form->Height);
1997 fl_activate_object(form->Frame);
1998 fl_activate_object(form->Translations);
1999 fl_activate_object(form->Angle);
2000 fl_activate_object(form->HeightGrp);
2001 fl_activate_object(form->page2);
2002 fl_activate_object(form->Default2);
2003 fl_activate_object(form->cm2);
2004 fl_activate_object(form->in2);
2005 fl_activate_object(form->HeightLabel);
2006 fl_activate_object(form->WidthLabel);
2007 fl_activate_object(form->DisplayGrp);
2008 fl_activate_object(form->Wysiwyg3);
2009 fl_activate_object(form->Wysiwyg0);
2010 fl_activate_object(form->Wysiwyg2);
2011 fl_activate_object(form->Wysiwyg1);
2012 fl_activate_object(form->WidthGrp);
2013 fl_activate_object(form->Default1);
2014 fl_activate_object(form->cm1);
2015 fl_activate_object(form->in1);
2016 fl_activate_object(form->page1);
2017 fl_activate_object(form->column1);
2018 fl_activate_object(form->Subcaption);
2019 fl_activate_object(form->Subfigure);
2020 fl_activate_object (form->OkBtn);
2021 fl_activate_object (form->ApplyBtn);
2022 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2023 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2027 void InsetFig::RestoreForm()
2031 EnableFigurePanel(form);
2034 fl_set_button(form->Default1, (wtype == 0));
2035 fl_set_button(form->cm1, (wtype == 1));
2036 fl_set_button(form->in1, (wtype == 2));
2037 fl_set_button(form->page1, (wtype == 3));
2038 fl_set_button(form->column1, (wtype == 4));
2040 fl_deactivate_object(form->Width);
2042 fl_activate_object(form->Width);
2045 // enable and disable should be put here.
2047 fl_set_button(form->Default2, (htype == 0));
2048 fl_set_button(form->cm2, (htype == 1));
2049 fl_set_button(form->in2, (htype == 2));
2050 fl_set_button(form->page2, (htype == 3));
2051 // enable and disable should be put here.
2053 fl_deactivate_object(form->Height);
2055 fl_activate_object(form->Height);
2058 int pflags = flags & 3;
2059 fl_set_button(form->Wysiwyg0, (pflags == 0));
2060 fl_set_button(form->Wysiwyg1, (pflags == 1));
2061 fl_set_button(form->Wysiwyg2, (pflags == 2));
2062 fl_set_button(form->Wysiwyg3, (pflags == 3));
2063 fl_set_button(form->Frame, ((flags & 4) != 0));
2064 fl_set_button(form->Translations, ((flags & 8) != 0));
2065 fl_set_button(form->Subfigure, (subfigure != 0));
2067 psubfigure = subfigure;
2068 sprintf(buf, "%g", xwid);
2069 fl_set_input(form->Width, buf);
2070 sprintf(buf, "%g", xhgh);
2071 fl_set_input(form->Height, buf);
2072 sprintf(buf, "%g", angle);
2073 fl_set_input(form->Angle, buf);
2074 if (!fname.empty()){
2075 string buf1 = OnlyPath(owner->fileName());
2076 string fname2 = MakeRelPath(fname, buf1);
2077 fl_set_input(form->EpsFile, fname2.c_str());
2079 else fl_set_input(form->EpsFile, "");
2080 fl_set_input(form->Subcaption, subcaption.c_str());
2081 if(current_view->buffer()->isReadonly())
2082 DisableFigurePanel(form);
2088 void InsetFig::Preview(char const * p)
2093 lyxerr << "Cannot fork process!" << endl;
2098 return; // parent process
2101 string buf1 = OnlyPath(owner->fileName());
2102 string buf2 = MakeAbsPath(p, buf1);
2104 lyxerr << "Error during rendering "
2105 << execlp(lyxrc->view_pspic_command.c_str(),
2106 lyxrc->view_pspic_command.c_str(),
2113 void InsetFig::BrowseFile()
2115 static string current_figure_path;
2116 static int once = 0;
2119 if (lyxerr.debugging()) {
2120 lyxerr << "Filename: "
2121 << owner->fileName() << endl;
2123 string p = fl_get_input(form->EpsFile);
2125 string buf = MakeAbsPath(owner->fileName());
2126 string buf2 = OnlyPath(buf);
2128 buf = MakeAbsPath(p, buf2);
2129 buf = OnlyPath(buf);
2131 buf = OnlyPath(owner->fileName().c_str());
2134 // Does user clipart directory exist?
2135 string bufclip = AddName (user_lyxdir, "clipart");
2136 FileInfo fileInfo(bufclip);
2137 if (!(fileInfo.isOK() && fileInfo.isDir()))
2138 // No - bail out to system clipart directory
2139 bufclip = AddName (system_lyxdir, "clipart");
2142 fileDlg.SetButton(0, _("Clipart"), bufclip);
2143 fileDlg.SetButton(1, _("Document"), buf);
2149 p = fileDlg.Select(_("EPS Figure"),
2150 current_figure_path,
2153 p = fileDlg.Select(_("EPS Figure"), buf,
2158 if (p.empty()) return;
2160 buf = MakeRelPath(p, buf2);
2161 current_figure_path = OnlyPath(p);
2164 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2165 || contains(p, "%") || contains(p, " "))
2167 WriteAlert(_("Filename can't contain any "
2168 "of these characters:"),
2169 // xgettext:no-c-format
2170 _("space, '#', '~', '$' or '%'."));
2175 if (form) fl_set_input(form->EpsFile, buf.c_str());
2179 void GraphicsCB(FL_OBJECT * obj, long arg)
2181 /* obj->form contains the form */
2183 if (lyxerr.debugging()) {
2184 lyxerr << "GraphicsCB callback: " << arg << endl;
2187 /* find inset we were reacting to */
2188 for (int i = 0; i < figinsref; ++i)
2189 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2192 if (lyxerr.debugging()) {
2193 lyxerr << "Calling back figure " << i << endl;
2195 figures[i]->inset->CallbackFig(arg);
2201 void HideFiguresPopups()
2203 for (int i = 0; i < figinsref; ++i)
2204 if (figures[i]->inset->form
2205 && figures[i]->inset->form->Figure->visible) {
2206 if (lyxerr.debugging()) {
2207 lyxerr << "Hiding figure " << i << endl;
2209 // hide and free the form
2210 figures[i]->inset->CallbackFig(9);