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;
70 extern FL_OBJECT * figinset_canvas;
72 extern char ** environ; // is this only redundtant on linux systems? Lgb.
73 extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
74 // better for asyncron updating:
75 void PutInsetIntoInsetUpdateList(Inset * inset);
76 extern void ProhibitInput();
77 extern void AllowInput();
79 static float const DEG2PI = 57.295779513;
80 static int const figallocchunk = 32;
82 static int figinsref = 0; /* number of figures */
83 static int figarrsize = 0; /* current max number of figures */
84 static int bmpinsref = 0; /* number of bitmaps */
85 static int bmparrsize = 0; /* current max number of bitmaps */
87 struct queue_element {
88 float rx, ry; // resolution x and y
89 int ofsx, ofsy; // x and y translation
90 figdata * data; // we are doing it for this data
93 static int const MAXGS = 3; /* maximum 3 gs's at a time */
95 static Figref ** figures; /* all the figures */
96 static figdata ** bitmaps; /* all the bitmaps */
98 static queue<queue_element> gsqueue; // queue for ghostscripting
100 static int gsrunning = 0; /* currently so many gs's are running */
101 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
102 static char bittable[256]; /* bit reversion table */
104 static bool gs_color; // do we allocate colors for gs?
105 static bool color_visual; // is the visual color?
106 static bool gs_xcolor = false; // allocated extended colors
107 static unsigned long gs_pixels[128]; // allocated pixels
108 static int gs_num_pixels; // number of pixels allocated
109 static int gs_spc; // shades per color
110 static bool gs_gray; // is grayscale?
111 static int gs_allcolors; // number of all colors
113 static list<int> pidwaitlist; // pid wait list
115 extern Colormap color_map;
117 void addpidwait(int pid)
119 // adds pid to pid wait list
120 pidwaitlist.push_back(pid);
122 if (lyxerr.debugging()) {
123 lyxerr << "Pids to wait for: \n";
124 for (list<int>::const_iterator cit = pidwaitlist.begin();
125 cit != pidwaitlist.end(); ++cit) {
126 lyxerr << (*cit) << '\n';
133 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
138 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
140 if(lyxerr.debugging()) {
141 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
142 << "] pm:[" << e->data.l[1] << "]" << endl;
145 // just kill gs, that way it will work for sure
146 // This loop looks like S**T so it probably is...
147 for (int i = 0; i < bmpinsref; ++i)
148 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
150 figdata * p = bitmaps[i];
153 // first update p->bitmap, if necessary
154 if (p->bitmap != None
155 && p->flags > (1|8) && gs_color && p->wid) {
156 // query current colormap and re-render
157 // the pixmap with proper colors
159 XWindowAttributes wa;
160 register XImage * im;
161 int i, y, wid1, spc1 = gs_spc-1,
162 spc2 = gs_spc * gs_spc, wid = p->wid,
165 GC gc = getGC(gc_copy);
167 XGetWindowAttributes(fl_display,
172 if (lyxerr.debugging()) {
173 lyxerr << "Starting image translation "
176 << p->wid << "x" << p->hgh
178 << " " << XYPixmap << endl;
180 // now fork rendering process
182 if (forkstat == -1) {
184 << "Cannot fork, using slow "
185 "method for pixmap translation." << endl;
186 tmpdisp = fl_display;
187 } else if (forkstat > 0) { // parent
189 if (lyxerr.debugging()) {
190 lyxerr << "Spawned child "
193 addpidwait(forkstat);
196 tmpdisp = XOpenDisplay(XDisplayName(0));
199 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
200 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
202 if (lyxerr.debugging()) {
203 lyxerr << "Got the image" << endl;
206 if (lyxerr.debugging()) {
207 lyxerr << "Error getting the image" << endl;
212 // query current colormap
213 XColor * cmap = new XColor[gs_allcolors];
214 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
215 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
218 // now we process all the image
219 for (y = 0; y < p->hgh; ++y) {
220 for (int x = 0; x < wid; ++x) {
225 gs_pixels[((pc->red+6553)*
226 spc1/65535)*spc2+((pc->green+6553)*
227 spc1/65535)*gs_spc+((pc->blue+6553)*
232 // This must be correct.
234 if (lyxerr.debugging()) {
235 lyxerr << "Putting image back"
238 XPutImage(tmpdisp, p->bitmap,
240 0, 0, p->wid, p->hgh);
242 if (lyxerr.debugging()) {
243 lyxerr << "Done translation"
248 if (lyxerr.debugging()) {
249 lyxerr << "Killing gs "
252 lyx::kill(p->gspid, SIGHUP);
254 sprintf(tmp, "%s/~lyxgs%d.ps",
255 system_tempdir.c_str(),
259 XCloseDisplay(tmpdisp);
263 if (lyxerr.debugging()) {
264 lyxerr << "Killing gs "
267 lyx::kill(p->gspid, SIGHUP);
269 sprintf(tmp, "%s/~lyxgs%d.ps",
270 system_tempdir.c_str(),
280 static void AllocColors(int num)
281 // allocate color cube numxnumxnum, if possible
283 if (lyxerr.debugging()) {
284 lyxerr << "Allocating color cube " << num
285 << 'x' << num << 'x' << num << endl;
289 lyxerr << "Error allocating color colormap." << endl;
293 if (num > 5) num = 5;
295 for (int i = 0; i < num * num * num; ++i) {
296 xcol.red = 65535 * (i / (num * num)) / (num - 1);
297 xcol.green = 65535 * ((i / num) % num) / (num - 1);
298 xcol.blue = 65535 * (i % num) / (num - 1);
299 xcol.flags = DoRed | DoGreen | DoBlue;
300 if (!XAllocColor(fl_display, color_map, &xcol)) {
301 if (i) XFreeColors(fl_display, color_map,
303 if(lyxerr.debugging()) {
304 lyxerr << "Cannot allocate color cube "
307 AllocColors(num - 1);
310 gs_pixels[i] = xcol.pixel;
315 gs_num_pixels = num * num * num;
319 // allocate grayscale ramp
321 void AllocGrays(int num)
323 if (lyxerr.debugging()) {
324 lyxerr << "Allocating grayscale colormap "
329 lyxerr << "Error allocating grayscale colormap." << endl;
333 if (num > 128) num = 128;
335 for (int i = 0; i < num; ++i) {
336 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
337 xcol.flags = DoRed | DoGreen | DoBlue;
338 if (!XAllocColor(fl_display, color_map, &xcol)) {
339 if (i) XFreeColors(fl_display, color_map,
341 if (lyxerr.debugging()) {
342 lyxerr << "Cannot allocate grayscale "
348 gs_pixels[i] = xcol.pixel;
358 bmparrsize = figarrsize = figallocchunk;
359 typedef Figref * Figref_p;
360 figures = new Figref_p[figallocchunk];
361 //figures = static_cast<Figref**>
362 // (malloc(sizeof(Figref*) * figallocchunk));
363 typedef figdata * figdata_p;
364 bitmaps = new figdata_p[figallocchunk];
365 //bitmaps = static_cast<figdata**>
366 //(malloc(sizeof(figdata*) * figallocchunk));
369 for (unsigned int i = 0; i < 256; ++i) {
371 for (unsigned int j = 0; j < 8; ++j)
372 if (i & (1 << (7-j))) k |= 1 << j;
373 bittable[i] = char(~k);
376 fl_add_canvas_handler(figinset_canvas, ClientMessage,
377 GhostscriptMsg, current_view->owner()->getMainForm());
379 // now we have to init color_map
380 if (!color_map) color_map = DefaultColormap(fl_display,
381 DefaultScreen(fl_display));
382 // allocate color cube on pseudo-color display
386 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
387 if (lyxerr.debugging()) {
388 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
389 vi->visualid, vi->c_class,
390 vi->bits_per_rgb, vi->map_entries);
392 color_visual = ( (vi->c_class == StaticColor) ||
393 (vi->c_class == PseudoColor) ||
394 (vi->c_class == TrueColor) ||
395 (vi->c_class == DirectColor) );
396 if ((vi->c_class & 1) == 0) return;
397 // now allocate colors
398 if (vi->c_class == GrayScale) {
399 // allocate grayscale
400 AllocGrays(vi->map_entries/2);
402 // allocate normal color
404 while (i * i * i * 2 > vi->map_entries) --i;
407 gs_allcolors = vi->map_entries;
420 lyxerr.debug() << "Unregistering figures..." << endl;
422 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
426 lyxerr.debug() << "Freeing up the colors..." << endl;
427 XFreeColors(fl_display, color_map, gs_pixels,
429 /******????????????????? what's planes in this case ??????***/
434 int FindBmpIndex(figdata * tmpdata)
437 while (i < bmpinsref) {
438 if (bitmaps[i] == tmpdata) return i;
445 static void freefigdata(figdata * tmpdata)
448 if (tmpdata->ref) return;
450 if (tmpdata->gspid > 0) {
451 int pid = tmpdata->gspid;
453 // kill ghostscript and unlink it's files
455 lyx::kill(pid, SIGKILL);
456 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
460 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
462 int i = FindBmpIndex(tmpdata);
464 while (i < bmpinsref) {
465 bitmaps[i] = bitmaps[i + 1];
471 static void runqueue()
473 // run queued requests for ghostscript, if any
474 if (!gsrunning && gs_color && !gs_xcolor) {
475 // here alloc all colors, so that gs will use only
476 // those we allocated for it
481 while (gsrunning < MAXGS) {
482 char tbuf[384], tbuf2[80];
486 if (gsqueue.empty()) {
487 if (!gsrunning && gs_xcolor) {
488 // de-allocate rest of colors
494 queue_element * p = &gsqueue.front();
503 if (lyxerr.debugging()) {
504 lyxerr << "GS start error! Cannot fork."
507 p->data->broken = true;
508 p->data->reading = false;
511 if (pid == 0) { // child
512 char ** env, rbuf[80], gbuf[40];
514 Display * tempdisp = XOpenDisplay(XDisplayName(0));
516 // create translation file
517 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
521 ofs << "gsave clippath pathbbox grestore\n"
523 << "/ury exch def /urx exch def /lly exch def "
525 << p->data->wid / 2.0 << " "
526 << p->data->hgh / 2.0 << " translate\n"
527 << p->data->angle << " rotate\n"
528 << -(p->data->raw_wid / 2.0) << " "
529 << -(p->data->raw_hgh / 2.0) << " translate\n"
530 << p->rx / 72.0 << " " << p->ry / 72.0
532 << -p->ofsx << " " << -p->ofsy << " translate\n"
534 ofs.close(); // Don't remove this.
536 // gs process - set ghostview environment first
537 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
538 figinset_canvas), p->data->bitmap);
540 // now set up ghostview property on a window
541 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
542 p->data->wid, p->data->hgh);
543 // #warning BUG seems that the only bug here
544 // might be the hardcoded dpi.. Bummer!
546 if (lyxerr.debugging()) {
547 lyxerr << "Will set GHOSTVIEW property to ["
548 << tbuf << "]" << endl;
550 // wait until property is deleted if executing multiple
553 // grab server to prevent other child
554 // interfering with setting GHOSTVIEW property
555 if (lyxerr.debugging()) {
556 lyxerr << "Grabbing the server"
559 XGrabServer(tempdisp);
560 prop = XListProperties(tempdisp,
562 figinset_canvas), &nprop);
566 for (i = 0; i < nprop; ++i) {
567 char * p = XGetAtomName(tempdisp,
569 if (strcmp(p, "GHOSTVIEW") == 0) {
575 XFree(reinterpret_cast<char *>(prop)); // jc:
577 // release the server
578 XUngrabServer(tempdisp);
580 // ok, property found, we must wait until
581 // ghostscript deletes it
582 if (lyxerr.debugging()) {
583 lyxerr << "Releasing the server\n["
585 << "] GHOSTVIEW property"
586 " found. Waiting." << endl;
592 XChangeProperty(tempdisp,
593 fl_get_canvas_id(figinset_canvas),
594 XInternAtom(tempdisp, "GHOSTVIEW", false),
595 XInternAtom(tempdisp, "STRING", false),
597 reinterpret_cast<unsigned char*>(tbuf),
600 switch (p->data->flags & 3) {
601 case 0: tbuf[0] = 'H'; break; // Hidden
602 case 1: tbuf[0] = 'M'; break; // Mono
603 case 2: tbuf[0] = 'G'; break; // Gray
606 tbuf[0] = 'C'; // Color
608 tbuf[0] = 'G'; // Gray
613 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
614 DefaultScreenOfDisplay(fl_display)),
617 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
618 DefaultScreenOfDisplay(fl_display)),
622 XChangeProperty(tempdisp,
623 fl_get_canvas_id(figinset_canvas),
624 XInternAtom(tempdisp,
625 "GHOSTVIEW_COLORS", false),
626 XInternAtom(tempdisp, "STRING", false),
628 reinterpret_cast<unsigned char*>(tbuf),
630 XUngrabServer(tempdisp);
632 if (lyxerr.debugging()) {
633 lyxerr << "Releasing the server" << endl;
635 XCloseDisplay(tempdisp);
637 // set up environment
638 while (environ[ne]) ++ne;
639 typedef char * char_p;
640 env = new char_p[ne + 2];
641 //env = static_cast<char **>
642 // (malloc(sizeof(char*) * (ne + 2)));
644 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
647 // now make gs command
649 // close(1); do NOT close. If GS writes out
650 // errors it would hang. (Matthias 290596)
651 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
652 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
653 // now chdir into dir with .eps file, to be on the safe
655 chdir(OnlyPath(p->data->fname).c_str());
656 // make temp file name
657 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
659 if (lyxerr.debugging()) {
660 lyxerr << "starting gs " << tbuf << " "
662 << ", pid: " << getpid() << endl;
665 int err = execlp(lyxrc->ps_command.c_str(),
666 lyxrc->ps_command.c_str(),
668 "-dNOPAUSE", "-dQUIET",
671 p->data->fname.c_str(),
672 "showpage.ps", "quit.ps", "-", 0);
673 // if we are still there, an error occurred.
674 lyxerr << "Error executing ghostscript. "
675 << "Code: " << err << endl;
676 lyxerr.debug() << "Cmd: "
680 << p->data->fname << endl;
683 // normal process (parent)
684 if (lyxerr.debugging()) {
685 lyxerr << "GS [" << pid << "] started" << endl;
688 p->data->gspid = pid;
695 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
697 // recompute the stuff and put in the queue
701 p.rx = (float(data->raw_wid) * 72.0) / pswid;
702 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
708 // if possible, run the queue
713 static figdata * getfigdata(int wid, int hgh, string const & fname,
714 int psx, int psy, int pswid, int pshgh,
715 int raw_wid, int raw_hgh, float angle, char flags)
717 /* first search for an exact match with fname and width/height */
719 if (fname.empty()) return 0;
722 while (i < bmpinsref) {
723 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
724 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
725 bitmaps[i]->angle == angle) {
731 /* not found -> create new record or return 0 if no record */
733 if (bmpinsref > bmparrsize) {
734 // allocate more space
735 bmparrsize += figallocchunk;
736 typedef figdata * figdata_p;
737 figdata ** tmp = new figdata_p[bmparrsize];
738 //figdata ** tmp = static_cast<figdata**>
739 // (malloc(sizeof(figdata*) * bmparrsize));
741 sizeof(figdata*) * (bmparrsize - figallocchunk));
746 figdata * p = new figdata;
747 bitmaps[bmpinsref-1] = p;
750 p->raw_wid = raw_wid;
751 p->raw_hgh = raw_hgh;
755 XWindowAttributes wa;
756 XGetWindowAttributes(fl_display, fl_get_canvas_id(
757 figinset_canvas), &wa);
759 if (lyxerr.debugging()) {
760 lyxerr << "Create pixmap disp:" << fl_display
761 << " scr:" << DefaultScreen(fl_display)
764 << " depth:" << wa.depth << endl;
772 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
773 figinset_canvas), wid, hgh, wa.depth);
775 // initialize reading of .eps file with correct sizes and stuff
776 addwait(psx, psy, pswid, pshgh, p);
787 static void getbitmap(figdata * p)
793 static void makeupdatelist(figdata * p)
795 for (int i = 0; i < figinsref; ++i)
796 if (figures[i]->data == p) {
797 if (lyxerr.debugging()) {
798 lyxerr << "Updating inset "
802 //UpdateInset(figures[i]->inset);
803 // add inset figures[i]->inset into to_update list
804 PutInsetIntoInsetUpdateList(figures[i]->inset);
809 void sigchldchecker(pid_t pid, int * status)
811 lyxerr.debug() << "Got pid = " << pid << endl;
812 bool pid_handled = false;
813 for (int i = bmpinsref - 1; i >= 0; --i) {
814 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
815 lyxerr.debug() << "Found pid in bitmaps" << endl;
816 // now read the file and remove it from disk
817 figdata * p = bitmaps[i];
819 if (bitmaps[i]->gsdone) *status = 0;
821 lyxerr.debug() << "GS [" << pid
822 << "] exit OK." << endl;
824 lyxerr << "GS [" << pid << "] error "
826 << WIFEXITED(*status)
827 << " " << WEXITSTATUS(*status)
828 << " S:" << WIFSIGNALED(*status)
829 << " " << WTERMSIG(*status) << endl;
832 bitmap_waiting = true;
835 // remove temporary files
837 sprintf(tmp, "%s/~lyxgs%d.ps",
838 system_tempdir.c_str(),
844 makeupdatelist(bitmaps[i]);
851 lyxerr.debug() << "Checking pid in pidwait" << endl;
852 list<int>::iterator it = find(pidwaitlist.begin(),
853 pidwaitlist.end(), pid);
854 if (it != pidwaitlist.end()) {
855 lyxerr.debug() << "Found pid in pidwait\n"
856 << "Caught child pid of recompute "
857 "routine" << pid << endl;
858 pidwaitlist.erase(it);
862 lyxerr.debug() << "waitpid error" << endl;
865 lyxerr << "The process or process group specified by "
866 "pid does not exist or is not a child of "
867 "the calling process or can never be in the "
868 "states specified by options." << endl;
871 lyxerr << "waitpid() was interrupted due to the "
872 "receipt of a signal sent by the calling "
876 lyxerr << "An invalid value was specified for "
880 lyxerr << "Unknown error from waitpid" << endl;
883 } else if (pid == 0) {
884 lyxerr << "waitpid nohang" << endl;;
886 lyxerr.debug() << "normal exit from childhandler" << endl;
891 static void getbitmaps()
893 bitmap_waiting = false;
894 for (int i = 0; i < bmpinsref; ++i)
895 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
896 getbitmap(bitmaps[i]);
900 static void RegisterFigure(InsetFig * fi)
902 if (figinsref == 0) InitFigures();
905 if (figinsref > figarrsize) {
906 // allocate more space
907 figarrsize += figallocchunk;
908 typedef Figref * Figref_p;
909 Figref ** tmp = new Figref_p[figarrsize];
910 //Figref ** tmp = static_cast<Figref**>
911 // (malloc(sizeof(Figref*)*figarrsize));
913 sizeof(Figref*)*(figarrsize-figallocchunk));
918 Figref * tmpfig = new Figref;
921 figures[figinsref-1] = tmpfig;
924 if (lyxerr.debugging()) {
925 lyxerr << "Register Figure: buffer:["
926 << current_view->buffer() << "]" << endl;
931 int FindFigIndex(Figref * tmpfig)
934 while (i < figinsref) {
935 if (figures[i] == tmpfig) return i;
942 static void UnregisterFigure(InsetFig * fi)
944 Figref * tmpfig = fi->figure;
946 if (tmpfig->data) freefigdata(tmpfig->data);
947 if (tmpfig->inset->form) {
948 if (tmpfig->inset->form->Figure->visible) {
949 fl_set_focus_object(tmpfig->inset->form->Figure,
950 tmpfig->inset->form->OkBtn);
951 fl_hide_form(tmpfig->inset->form->Figure);
953 #if FL_REVISION == 89
954 #warning Reactivate this free_form calls
956 fl_free_form(tmpfig->inset->form->Figure);
957 free(tmpfig->inset->form); // Why free?
958 tmpfig->inset->form = 0;
961 int i = FindFigIndex(tmpfig);
963 while (i < figinsref) {
964 figures[i] = figures[i+1];
969 if (figinsref == 0) DoneFigures();
973 static string NextToken(istream & is)
981 } while (!is.eof() && !isspace(c));
982 token.erase(token.length() - 1); // remove the isspace
988 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
998 psubfigure = subfigure = false;
999 xwid = xhgh = angle = 0;
1001 raw_wid = raw_hgh = 0;
1002 changedfname = false;
1003 RegisterFigure(this);
1007 InsetFig::~InsetFig()
1009 if (lyxerr.debugging()) {
1010 lyxerr << "Figure destructor called" << endl;
1012 UnregisterFigure(this);
1016 int InsetFig::Ascent(LyXFont const &) const
1022 int InsetFig::Descent(LyXFont const &) const
1028 int InsetFig::Width(LyXFont const &) const
1034 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1036 if (bitmap_waiting) getbitmaps();
1038 // I wish that I didn't have to use this
1039 // but the figinset code is so complicated so
1040 // I don't want to fiddle with it now.
1041 unsigned long pm = scr.getForeground();
1043 if (figure && figure->data && figure->data->bitmap &&
1044 !figure->data->reading && !figure->data->broken) {
1046 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1047 0, 0, wid, hgh, int(x+1), baseline-hgh);
1049 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1050 int(x), baseline - hgh - 1,
1055 XDrawRectangle(fl_display, pm, getGC(gc_copy),
1057 baseline - hgh - 1, wid+1, hgh+1);
1058 if (figure && figure->data) {
1059 if (figure->data->broken) msg = _("[render error]");
1060 else if (figure->data->reading) msg = _("[rendering ... ]");
1062 if (fname.empty()) msg = _("[no file]");
1063 else if ((flags & 3) == 0) msg = _("[not displayed]");
1064 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1066 if (!msg) msg = _("[unknown error]");
1068 font.setFamily (LyXFont::SANS_FAMILY);
1069 font.setSize (LyXFont::SIZE_FOOTNOTE);
1070 string justname = OnlyFilename (fname);
1071 font.drawString(justname, pm,
1072 baseline - font.maxAscent() - 4,
1074 font.setSize (LyXFont::SIZE_TINY);
1075 font.drawText (msg, strlen(msg), pm,
1080 x += Width(font); // ?
1084 void InsetFig::Write(ostream & os)
1087 os << "Figure size " << wid << " " << hgh << "\n";
1088 if (!fname.empty()) {
1089 string buf1 = OnlyPath(owner->fileName());
1090 string fname2 = MakeRelPath(fname, buf1);
1091 os << "file " << fname2 << "\n";
1093 if (!subcaption.empty())
1094 os << "subcaption " << subcaption << "\n";
1095 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1096 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1097 if (angle != 0) os << "angle " << angle << "\n";
1098 os << "flags " << flags << "\n";
1099 if (subfigure) os << "subfigure\n";
1103 void InsetFig::Read(LyXLex & lex)
1106 bool finished = false;
1108 while (lex.IsOK() && !finished) {
1111 string const token = lex.GetString();
1112 lyxerr.debug() << "Token: " << token << endl;
1116 else if (token == "\\end_inset") {
1118 } else if (token == "file") {
1120 buf = lex.GetString();
1121 string buf1 = OnlyPath(owner->fileName());
1122 fname = MakeAbsPath(buf, buf1);
1123 changedfname = true;
1125 } else if (token == "extra") {
1127 // kept for backwards compability. Delete in 0.13.x
1128 } else if (token == "subcaption") {
1130 subcaption = lex.GetString();
1131 } else if (token == "label") {
1133 // kept for backwards compability. Delete in 0.13.x
1134 } else if (token == "angle") {
1136 angle = lex.GetFloat();
1137 } else if (token == "size") {
1139 wid = lex.GetInteger();
1141 hgh = lex.GetInteger();
1142 } else if (token == "flags") {
1144 flags = pflags = lex.GetInteger();
1145 } else if (token == "subfigure") {
1146 subfigure = psubfigure = true;
1147 } else if (token == "width") {
1150 typ = lex.GetInteger();
1152 xwid = lex.GetFloat();
1154 case DEF: wtype = DEF; break;
1155 case CM: wtype = CM; break;
1156 case IN: wtype = IN; break;
1157 case PER_PAGE: wtype = PER_PAGE; break;
1158 case PER_COL: wtype = PER_COL; break;
1160 lyxerr.debug() << "Unknown type!" << endl;
1164 } else if (token == "height") {
1167 typ = lex.GetInteger();
1169 xhgh = lex.GetFloat();
1171 case DEF: htype = DEF; break;
1172 case CM: htype = CM; break;
1173 case IN: htype = IN; break;
1174 case PER_PAGE: htype = PER_PAGE; break;
1176 lyxerr.debug() << "Unknown type!" << endl;
1187 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1190 if (!cmd.empty()) os << cmd << " ";
1195 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1203 int InsetFig::Linuxdoc(string &/*file*/)
1209 int InsetFig::DocBook(string & file)
1211 string figurename = fname;
1213 if(suffixIs(figurename, ".eps"))
1214 figurename.erase(fname.length() - 5);
1216 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1221 void InsetFig::Validate(LaTeXFeatures & features) const
1223 features.graphics = true;
1224 if (subfigure) features.subfigure = true;
1228 unsigned char InsetFig::Editable() const
1234 bool InsetFig::Deletable() const
1240 void InsetFig::Edit(int, int)
1242 lyxerr.debug() << "Editing InsetFig." << endl;
1245 // We should have RO-versions of the form instead.
1246 // The actual prevention of altering a readonly doc
1247 // is done in CallbackFig()
1248 if(current_view->buffer()->isReadonly())
1249 WarnReadonly(current_view->buffer()->fileName());
1252 form = create_form_Figure();
1253 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1254 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1255 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1256 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1259 if (form->Figure->visible) {
1260 fl_raise_form(form->Figure);
1262 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1263 FL_FULLBORDER, _("Figure"));
1268 Inset * InsetFig::Clone() const
1270 InsetFig * tmp = new InsetFig(100, 100, owner);
1272 if (lyxerr.debugging()) {
1273 lyxerr << "Clone Figure: buffer:["
1274 << current_view->buffer()
1275 << "], cbuffer:[xx]" << endl;
1280 tmp->raw_wid = raw_wid;
1281 tmp->raw_hgh = raw_hgh;
1286 tmp->pflags = pflags;
1287 tmp->subfigure = subfigure;
1288 tmp->psubfigure = psubfigure;
1296 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1297 // do not display if there is
1298 // "do not display" chosen (Matthias 260696)
1299 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1300 pswid, pshgh, raw_wid, raw_hgh,
1301 angle, flags & (3|8));
1302 } else tmp->figure->data = 0;
1303 tmp->subcaption = subcaption;
1304 tmp->changedfname = false;
1311 Inset::Code InsetFig::LyxCode() const
1313 return Inset::GRAPHICS_CODE;
1317 void InsetFig::Regenerate()
1320 string resizeW, resizeH;
1321 string rotate, recmd;
1323 if (fname.empty()) {
1324 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1325 cmd += _("empty figure path");
1327 //if (form) fl_set_object_label(form->cmd, "");
1331 string buf1 = OnlyPath(owner->fileName());
1332 string fname2 = MakeRelPath(fname, buf1);
1334 string gcmd = "\\includegraphics{" + fname2 + '}';
1339 case CM:{// \resizebox*{h-length}{v-length}{text}
1341 sprintf(buf, "%g", xwid); // should find better
1348 sprintf(buf, "%g", xwid);
1355 sprintf(buf, "%g", xwid/100);
1357 resizeW += "\\textwidth";
1362 sprintf(buf, "%g", xwid/100);
1364 resizeW += "\\columnwidth";
1374 sprintf(buf, "%g", xhgh);
1381 sprintf(buf, "%g", xhgh);
1388 sprintf(buf, "%g", xhgh/100);
1390 resizeH += "\\textheight";
1394 // Doesn't occur; case exists to suppress compiler warnings.
1399 if (!resizeW.empty() || !resizeH.empty()) {
1400 recmd = "\\resizebox*{";
1401 if (!resizeW.empty())
1406 if (!resizeH.empty())
1416 sprintf(buf, "%g", angle);
1417 // \rotatebox{angle}{text}
1418 rotate = "\\rotatebox{";
1426 if (!rotate.empty()) cmdbuf += '}';
1427 if (!recmd.empty()) cmdbuf += '}';
1429 if (!subcaption.empty())
1430 cmdbuf = "\\subfigure[" + subcaption +
1431 "]{" + cmdbuf + "}";
1433 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1438 //if (form) fl_set_object_label(form->cmd, cmd.c_str());
1442 void InsetFig::TempRegenerate()
1445 string resizeW, resizeH;
1446 string rotate, recmd;
1448 char const * tfname = fl_get_input(form->EpsFile);
1449 string tsubcap = fl_get_input(form->Subcaption);
1450 float tangle = atof(fl_get_input(form->Angle));
1451 float txwid = atof(fl_get_input(form->Width));
1452 float txhgh = atof(fl_get_input(form->Height));
1454 if (!tfname || !*tfname) {
1455 //fl_set_object_label(form->cmd, "");
1456 //fl_redraw_object(form->cmd);
1457 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1458 cmd += _("empty figure path");
1463 string buf1 = OnlyPath(owner->fileName());
1464 string fname2 = MakeRelPath(tfname, buf1);
1465 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1466 string gcmd = "\\includegraphics{" + fname2 + '}';
1471 case CM: {// \resizebox*{h-length}{v-length}{text}
1473 sprintf(buf, "%g", txwid); // should find better
1480 sprintf(buf, "%g", txwid);
1487 sprintf(buf, "%g", txwid/100);
1489 resizeW += "\\textwidth";
1494 sprintf(buf, "%g", txwid/100);
1496 resizeW += "\\columnwidth";
1506 sprintf(buf, "%g", txhgh);
1513 sprintf(buf, "%g", txhgh);
1520 sprintf(buf, "%g", txhgh/100);
1522 resizeH += "\\textheight";
1526 // Doesn't occur; case exists to suppress compiler warnings.
1531 // \resizebox*{h-length}{v-length}{text}
1532 if (!resizeW.empty() || !resizeH.empty()) {
1533 recmd = "\\resizebox*{";
1534 if (!resizeW.empty())
1539 if (!resizeH.empty())
1548 sprintf(buf, "%g", tangle);
1549 // \rotatebox{angle}{text}
1550 rotate = "\\rotatebox{";
1558 if (!rotate.empty()) cmdbuf += '}';
1559 if (!recmd.empty()) cmdbuf += '}';
1560 if (psubfigure && !tsubcap.empty()) {
1561 cmdbuf = string("\\subfigure{") + tsubcap
1562 + string("}{") + cmdbuf + "}";
1567 void InsetFig::Recompute()
1569 bool changed = changedfname;
1570 int newx, newy, nraw_x, nraw_y;
1572 if (changed) GetPSSizes();
1574 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1575 float cos_a = cos (angle / DEG2PI);
1576 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1577 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1579 /* now recompute wid and hgh, and if that is changed, set changed */
1580 /* this depends on chosen size of the picture and its bbox */
1581 // This will be redone in 0.13 ... (hen)
1582 if (!fname.empty()) {
1583 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1591 newx = int(28.346 * xwid);
1594 newx = int(72 * xwid);
1596 case PER_PAGE: /* % of page */
1597 newx = int(5.95 * xwid);
1599 case PER_COL: /* % of col */
1600 newx = int(2.975 * xwid);
1604 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1608 //lyxerr << "This should not happen!" << endl;
1611 newy = int(28.346 * xhgh);
1614 newy = int(72 * xhgh);
1616 case PER_PAGE: /* % of page */
1617 newy = int(8.42 * xhgh);
1620 // Doesn't occur; case exists to suppress
1621 // compiler warnings.
1624 if (htype && !wtype && frame_hgh)
1625 newx = newy*frame_wid/frame_hgh;
1634 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1639 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1641 // cannot be zero, actually, set it to some minimum, so its clickable
1642 if (newx < 5) newx = 5;
1643 if (newy < 5) newy = 5;
1645 if (newx != wid || newy != hgh ||
1646 nraw_x != raw_wid || nraw_y != raw_hgh ||
1647 flags != pflags || subfigure != psubfigure)
1655 subfigure = psubfigure;
1658 figdata * pf = figure->data;
1661 if (!fname.empty() && (flags & 3)
1662 && !lyxrc->ps_command.empty()) {
1663 // do not display if there is "do not display"
1664 // chosen (Matthias 260696)
1665 figure->data = getfigdata(wid, hgh, fname,
1666 psx, psy, pswid, pshgh,
1668 angle, flags & (3|8));
1669 } else figure->data = 0;
1671 // free the old data
1672 if (pf) freefigdata(pf);
1675 changedfname = false;
1679 void InsetFig::GetPSSizes()
1681 /* get %%BoundingBox: from postscript file */
1683 /* defaults to associated size
1684 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1691 if (fname.empty()) return;
1693 ifstream ifs(fname.c_str());
1695 if (!ifs) return; // file not found !!!!
1697 /* defaults to A4 page */
1703 char lastchar = 0; ifs.get(lastchar);
1705 char c = 0; ifs.get(c);
1707 lyxerr.debug() << "End of (E)PS file reached and"
1708 " no BoundingBox!" << endl;
1711 if (c == '%' && lastchar == '%') {
1713 if (p.empty()) break;
1714 // we should not use this, with it we cannot
1715 // discover bounding box and end of file.
1716 //if (strcmp(p, "EndComments") == 0) break;
1717 lyxerr.debug() << "Token: `" << p << "'" << endl;
1718 if (p == "BoundingBox:") {
1719 float fpsx, fpsy, fpswid, fpshgh;
1720 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1723 pswid = int(fpswid);
1724 pshgh = int(fpshgh);
1726 if (lyxerr.debugging()) {
1727 lyxerr << "%%%%BoundingBox:"
1745 void InsetFig::CallbackFig(long arg)
1750 if (lyxerr.debugging()) {
1751 lyxerr << "Figure callback, arg " << arg << endl;
1757 case 12: /* width type */
1764 fl_deactivate_object(form->Width);
1769 fl_activate_object(form->Width);
1774 fl_activate_object(form->Width);
1779 fl_activate_object(form->Width);
1784 fl_activate_object(form->Width);
1787 lyxerr.debug() << "Unknown type!" << endl;
1794 case 22: /* height type */
1800 fl_deactivate_object(form->Height);
1805 fl_activate_object(form->Height);
1810 fl_activate_object(form->Height);
1815 fl_activate_object(form->Height);
1818 lyxerr.debug() << "Unknown type!" << endl;
1824 pflags = pflags & ~3; /* wysiwyg0 */
1827 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1830 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1833 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1836 pflags ^= 4; /* frame */
1839 pflags ^= 8; /* do translations */
1842 psubfigure = !psubfigure; /* This is a subfigure */
1845 regen = true; /* regenerate command */
1847 case 0: /* browse file */
1851 case 1: /* preview */
1852 p = fl_get_input(form->EpsFile);
1856 case 8: /* ok (apply and close) */
1857 if(!current_view->buffer()->isReadonly()) {
1860 xwid = atof(fl_get_input(form->Width));
1861 xhgh = atof(fl_get_input(form->Height));
1862 angle = atof(fl_get_input(form->Angle));
1863 p = fl_get_input(form->EpsFile);
1865 string buf1 = OnlyPath(owner->fileName());
1866 fname = MakeAbsPath(p, buf1);
1867 changedfname = true;
1869 if (!fname.empty()) {
1870 changedfname = true;
1874 subcaption = fl_get_input(form->Subcaption);
1878 /* now update inset */
1879 if (lyxerr.debugging()) {
1880 lyxerr << "Update: ["
1881 << wid << 'x' << hgh << ']' << endl;
1883 UpdateInset(current_view, this);
1885 fl_set_focus_object(form->Figure, form->OkBtn);
1886 fl_hide_form(form->Figure);
1887 #if FL_REVISION == 89
1888 #warning Reactivate this free_form calls
1890 fl_free_form(form->Figure);
1891 free(form); // Why free?
1897 // The user has already been informed about RO in ::Edit
1898 if(arg == 7) // if 'Apply'
1901 case 9: /* cancel = restore and close */
1902 fl_set_focus_object(form->Figure, form->OkBtn);
1903 fl_hide_form(form->Figure);
1904 #if FL_REVISION == 89
1905 #warning Reactivate this free_form calls
1906 #warning Jug, is this still a problem?
1908 fl_free_form(form->Figure);
1909 free(form); // Why free?
1915 if (regen) TempRegenerate();
1919 inline void DisableFigurePanel(FD_Figure * const form)
1921 fl_deactivate_object(form->EpsFile);
1922 fl_deactivate_object(form->Browse);
1923 fl_deactivate_object(form->Width);
1924 fl_deactivate_object(form->Height);
1925 fl_deactivate_object(form->Frame);
1926 fl_deactivate_object(form->Translations);
1927 fl_deactivate_object(form->Angle);
1928 fl_deactivate_object(form->HeightGrp);
1929 fl_deactivate_object(form->page2);
1930 fl_deactivate_object(form->Default2);
1931 fl_deactivate_object(form->cm2);
1932 fl_deactivate_object(form->in2);
1933 fl_deactivate_object(form->HeightLabel);
1934 fl_deactivate_object(form->WidthLabel);
1935 fl_deactivate_object(form->DisplayGrp);
1936 fl_deactivate_object(form->Wysiwyg3);
1937 fl_deactivate_object(form->Wysiwyg0);
1938 fl_deactivate_object(form->Wysiwyg2);
1939 fl_deactivate_object(form->Wysiwyg1);
1940 fl_deactivate_object(form->WidthGrp);
1941 fl_deactivate_object(form->Default1);
1942 fl_deactivate_object(form->cm1);
1943 fl_deactivate_object(form->in1);
1944 fl_deactivate_object(form->page1);
1945 fl_deactivate_object(form->column1);
1946 fl_deactivate_object(form->Subcaption);
1947 fl_deactivate_object(form->Subfigure);
1948 fl_deactivate_object (form->OkBtn);
1949 fl_deactivate_object (form->ApplyBtn);
1950 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
1951 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
1955 inline void EnableFigurePanel(FD_Figure * const form)
1957 fl_activate_object(form->EpsFile);
1958 fl_activate_object(form->Browse);
1959 fl_activate_object(form->Width);
1960 fl_activate_object(form->Height);
1961 fl_activate_object(form->Frame);
1962 fl_activate_object(form->Translations);
1963 fl_activate_object(form->Angle);
1964 fl_activate_object(form->HeightGrp);
1965 fl_activate_object(form->page2);
1966 fl_activate_object(form->Default2);
1967 fl_activate_object(form->cm2);
1968 fl_activate_object(form->in2);
1969 fl_activate_object(form->HeightLabel);
1970 fl_activate_object(form->WidthLabel);
1971 fl_activate_object(form->DisplayGrp);
1972 fl_activate_object(form->Wysiwyg3);
1973 fl_activate_object(form->Wysiwyg0);
1974 fl_activate_object(form->Wysiwyg2);
1975 fl_activate_object(form->Wysiwyg1);
1976 fl_activate_object(form->WidthGrp);
1977 fl_activate_object(form->Default1);
1978 fl_activate_object(form->cm1);
1979 fl_activate_object(form->in1);
1980 fl_activate_object(form->page1);
1981 fl_activate_object(form->column1);
1982 fl_activate_object(form->Subcaption);
1983 fl_activate_object(form->Subfigure);
1984 fl_activate_object (form->OkBtn);
1985 fl_activate_object (form->ApplyBtn);
1986 fl_set_object_lcol (form->OkBtn, FL_BLACK);
1987 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
1991 void InsetFig::RestoreForm()
1995 EnableFigurePanel(form);
1998 fl_set_button(form->Default1, (wtype == 0));
1999 fl_set_button(form->cm1, (wtype == 1));
2000 fl_set_button(form->in1, (wtype == 2));
2001 fl_set_button(form->page1, (wtype == 3));
2002 fl_set_button(form->column1, (wtype == 4));
2004 fl_deactivate_object(form->Width);
2006 fl_activate_object(form->Width);
2009 // enable and disable should be put here.
2011 fl_set_button(form->Default2, (htype == 0));
2012 fl_set_button(form->cm2, (htype == 1));
2013 fl_set_button(form->in2, (htype == 2));
2014 fl_set_button(form->page2, (htype == 3));
2015 // enable and disable should be put here.
2017 fl_deactivate_object(form->Height);
2019 fl_activate_object(form->Height);
2022 int pflags = flags & 3;
2023 fl_set_button(form->Wysiwyg0, (pflags == 0));
2024 fl_set_button(form->Wysiwyg1, (pflags == 1));
2025 fl_set_button(form->Wysiwyg2, (pflags == 2));
2026 fl_set_button(form->Wysiwyg3, (pflags == 3));
2027 fl_set_button(form->Frame, ((flags & 4) != 0));
2028 fl_set_button(form->Translations, ((flags & 8) != 0));
2029 fl_set_button(form->Subfigure, (subfigure != 0));
2031 psubfigure = subfigure;
2032 sprintf(buf, "%g", xwid);
2033 fl_set_input(form->Width, buf);
2034 sprintf(buf, "%g", xhgh);
2035 fl_set_input(form->Height, buf);
2036 sprintf(buf, "%g", angle);
2037 fl_set_input(form->Angle, buf);
2038 if (!fname.empty()){
2039 string buf1 = OnlyPath(owner->fileName());
2040 string fname2 = MakeRelPath(fname, buf1);
2041 fl_set_input(form->EpsFile, fname2.c_str());
2043 else fl_set_input(form->EpsFile, "");
2044 fl_set_input(form->Subcaption, subcaption.c_str());
2045 if(current_view->buffer()->isReadonly())
2046 DisableFigurePanel(form);
2052 void InsetFig::Preview(char const * p)
2057 lyxerr << "Cannot fork process!" << endl;
2062 return; // parent process
2065 string buf1 = OnlyPath(owner->fileName());
2066 string buf2 = MakeAbsPath(p, buf1);
2068 lyxerr << "Error during rendering "
2069 << execlp(lyxrc->view_pspic_command.c_str(),
2070 lyxrc->view_pspic_command.c_str(),
2077 void InsetFig::BrowseFile()
2079 static string current_figure_path;
2080 static int once = 0;
2083 if (lyxerr.debugging()) {
2084 lyxerr << "Filename: "
2085 << owner->fileName() << endl;
2087 string p = fl_get_input(form->EpsFile);
2089 string buf = MakeAbsPath(owner->fileName());
2090 string buf2 = OnlyPath(buf);
2092 buf = MakeAbsPath(p, buf2);
2093 buf = OnlyPath(buf);
2095 buf = OnlyPath(owner->fileName().c_str());
2098 // Does user clipart directory exist?
2099 string bufclip = AddName (user_lyxdir, "clipart");
2100 FileInfo fileInfo(bufclip);
2101 if (!(fileInfo.isOK() && fileInfo.isDir()))
2102 // No - bail out to system clipart directory
2103 bufclip = AddName (system_lyxdir, "clipart");
2106 fileDlg.SetButton(0, _("Clipart"), bufclip);
2107 fileDlg.SetButton(1, _("Document"), buf);
2113 p = fileDlg.Select(_("EPS Figure"),
2114 current_figure_path,
2117 p = fileDlg.Select(_("EPS Figure"), buf,
2122 if (p.empty()) return;
2124 buf = MakeRelPath(p, buf2);
2125 current_figure_path = OnlyPath(p);
2128 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2129 || contains(p, "%") || contains(p, " "))
2131 WriteAlert(_("Filename can't contain any "
2132 "of these characters:"),
2133 // xgettext:no-c-format
2134 _("space, '#', '~', '$' or '%'."));
2139 if (form) fl_set_input(form->EpsFile, buf.c_str());
2143 void GraphicsCB(FL_OBJECT * obj, long arg)
2145 /* obj->form contains the form */
2147 if (lyxerr.debugging()) {
2148 lyxerr << "GraphicsCB callback: " << arg << endl;
2151 /* find inset we were reacting to */
2152 for (int i = 0; i < figinsref; ++i)
2153 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2156 if (lyxerr.debugging()) {
2157 lyxerr << "Calling back figure " << i << endl;
2159 figures[i]->inset->CallbackFig(arg);
2165 void HideFiguresPopups()
2167 for (int i = 0; i < figinsref; ++i)
2168 if (figures[i]->inset->form
2169 && figures[i]->inset->form->Figure->visible) {
2170 if (lyxerr.debugging()) {
2171 lyxerr << "Hiding figure " << i << endl;
2173 // hide and free the form
2174 figures[i]->inset->CallbackFig(9);