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"
70 extern BufferView * current_view;
71 extern FL_OBJECT * figinset_canvas;
73 extern char ** environ; // is this only redundtant on linux systems? Lgb.
74 extern void UpdateInset(BufferView *, 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 */
88 struct queue_element {
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
94 static int const MAXGS = 3; /* maximum 3 gs's at a time */
96 static Figref ** figures; /* all the figures */
97 static figdata ** bitmaps; /* all the bitmaps */
99 static queue<queue_element> gsqueue; // queue for ghostscripting
101 static int gsrunning = 0; /* currently so many gs's are running */
102 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
103 static char bittable[256]; /* bit reversion table */
105 static bool gs_color; // do we allocate colors for gs?
106 static bool color_visual; // is the visual color?
107 static bool gs_xcolor = false; // allocated extended colors
108 static unsigned long gs_pixels[128]; // allocated pixels
109 static int gs_num_pixels; // number of pixels allocated
110 static int gs_spc; // shades per color
111 static bool gs_gray; // is grayscale?
112 static int gs_allcolors; // number of all colors
114 static list<int> pidwaitlist; // pid wait list
116 //extern Colormap color_map;
124 val.foreground = BlackPixel(fl_display,
125 DefaultScreen(fl_display));
128 val.graphics_exposures = false;
129 val.line_style = LineSolid;
131 return XCreateGC(fl_display, RootWindow(fl_display, 0),
132 GCForeground | GCFunction | GCGraphicsExposures
133 | GCLineWidth | GCLineStyle , &val);
140 void addpidwait(int pid)
142 // adds pid to pid wait list
143 pidwaitlist.push_back(pid);
145 if (lyxerr.debugging()) {
146 lyxerr << "Pids to wait for: \n";
147 for (list<int>::const_iterator cit = pidwaitlist.begin();
148 cit != pidwaitlist.end(); ++cit) {
149 lyxerr << (*cit) << '\n';
156 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
161 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
163 if(lyxerr.debugging()) {
164 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
165 << "] pm:[" << e->data.l[1] << "]" << endl;
168 // just kill gs, that way it will work for sure
169 // This loop looks like S**T so it probably is...
170 for (int i = 0; i < bmpinsref; ++i)
171 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
173 figdata * p = bitmaps[i];
176 // first update p->bitmap, if necessary
177 if (p->bitmap != None
178 && p->flags > (1|8) && gs_color && p->wid) {
179 // query current colormap and re-render
180 // the pixmap with proper colors
182 XWindowAttributes wa;
183 register XImage * im;
188 int spc2 = gs_spc * gs_spc;
192 GC gc = local_gc_copy;
194 XGetWindowAttributes(fl_display,
199 if (lyxerr.debugging()) {
200 lyxerr << "Starting image translation "
203 << p->wid << "x" << p->hgh
205 << " " << XYPixmap << endl;
207 // now fork rendering process
209 if (forkstat == -1) {
211 << "Cannot fork, using slow "
212 "method for pixmap translation." << endl;
213 tmpdisp = fl_display;
214 } else if (forkstat > 0) { // parent
216 if (lyxerr.debugging()) {
217 lyxerr << "Spawned child "
220 addpidwait(forkstat);
223 tmpdisp = XOpenDisplay(XDisplayName(0));
226 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
227 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
229 if (lyxerr.debugging()) {
230 lyxerr << "Got the image" << endl;
233 if (lyxerr.debugging()) {
234 lyxerr << "Error getting the image" << endl;
239 // query current colormap
240 XColor * cmap = new XColor[gs_allcolors];
241 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
243 XQueryColors(tmpdisp, fl_state[fl_get_vclass()].colormap, cmap, gs_allcolors);
245 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
249 // now we process all the image
250 for (y = 0; y < p->hgh; ++y) {
251 for (int x = 0; x < wid; ++x) {
256 gs_pixels[((pc->red+6553)*
257 spc1/65535)*spc2+((pc->green+6553)*
258 spc1/65535)*gs_spc+((pc->blue+6553)*
263 // This must be correct.
265 if (lyxerr.debugging()) {
266 lyxerr << "Putting image back"
269 XPutImage(tmpdisp, p->bitmap,
271 0, 0, p->wid, p->hgh);
273 if (lyxerr.debugging()) {
274 lyxerr << "Done translation"
279 if (lyxerr.debugging()) {
280 lyxerr << "Killing gs "
283 lyx::kill(p->gspid, SIGHUP);
285 sprintf(tmp, "%s/~lyxgs%d.ps",
286 system_tempdir.c_str(),
290 XCloseDisplay(tmpdisp);
294 if (lyxerr.debugging()) {
295 lyxerr << "Killing gs "
298 lyx::kill(p->gspid, SIGHUP);
300 sprintf(tmp, "%s/~lyxgs%d.ps",
301 system_tempdir.c_str(),
311 static void AllocColors(int num)
312 // allocate color cube numxnumxnum, if possible
314 if (lyxerr.debugging()) {
315 lyxerr << "Allocating color cube " << num
316 << 'x' << num << 'x' << num << endl;
320 lyxerr << "Error allocating color colormap." << endl;
324 if (num > 5) num = 5;
326 for (int i = 0; i < num * num * num; ++i) {
327 xcol.red = 65535 * (i / (num * num)) / (num - 1);
328 xcol.green = 65535 * ((i / num) % num) / (num - 1);
329 xcol.blue = 65535 * (i % num) / (num - 1);
330 xcol.flags = DoRed | DoGreen | DoBlue;
331 if (!XAllocColor(fl_display,
332 fl_state[fl_get_vclass()].colormap, &xcol)) {
333 if (i) XFreeColors(fl_display,
334 fl_state[fl_get_vclass()].colormap,
336 if(lyxerr.debugging()) {
337 lyxerr << "Cannot allocate color cube "
340 AllocColors(num - 1);
343 gs_pixels[i] = xcol.pixel;
348 gs_num_pixels = num * num * num;
352 // allocate grayscale ramp
354 void AllocGrays(int num)
356 if (lyxerr.debugging()) {
357 lyxerr << "Allocating grayscale colormap "
362 lyxerr << "Error allocating grayscale colormap." << endl;
366 if (num > 128) num = 128;
368 for (int i = 0; i < num; ++i) {
369 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
370 xcol.flags = DoRed | DoGreen | DoBlue;
371 if (!XAllocColor(fl_display,
372 fl_state[fl_get_vclass()].colormap, &xcol)) {
373 if (i) XFreeColors(fl_display,
374 fl_state[fl_get_vclass()].colormap,
376 if (lyxerr.debugging()) {
377 lyxerr << "Cannot allocate grayscale "
383 gs_pixels[i] = xcol.pixel;
393 bmparrsize = figarrsize = figallocchunk;
394 typedef Figref * Figref_p;
395 figures = new Figref_p[figallocchunk];
396 typedef figdata * figdata_p;
397 bitmaps = new figdata_p[figallocchunk];
400 for (unsigned int i = 0; i < 256; ++i) {
402 for (unsigned int j = 0; j < 8; ++j)
403 if (i & (1 << (7-j))) k |= 1 << j;
404 bittable[i] = char(~k);
407 fl_add_canvas_handler(figinset_canvas, ClientMessage,
408 GhostscriptMsg, current_view->owner()->getMainForm());
411 // now we have to init color_map
412 if (!color_map) color_map = DefaultColormap(fl_display,
413 DefaultScreen(fl_display));
415 // allocate color cube on pseudo-color display
418 local_gc_copy = createGC();
420 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
421 if (lyxerr.debugging()) {
422 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
423 vi->visualid, vi->c_class,
424 vi->bits_per_rgb, vi->map_entries);
426 color_visual = ( (vi->c_class == StaticColor) ||
427 (vi->c_class == PseudoColor) ||
428 (vi->c_class == TrueColor) ||
429 (vi->c_class == DirectColor) );
430 if ((vi->c_class & 1) == 0) return;
431 // now allocate colors
432 if (vi->c_class == GrayScale) {
433 // allocate grayscale
434 AllocGrays(vi->map_entries/2);
436 // allocate normal color
438 while (i * i * i * 2 > vi->map_entries) --i;
441 gs_allcolors = vi->map_entries;
452 lyxerr.debug() << "Unregistering figures..." << endl;
454 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
459 lyxerr.debug() << "Freeing up the colors..." << endl;
460 XFreeColors(fl_display, color_map, gs_pixels,
462 /******????????????????? what's planes in this case ??????***/
468 int FindBmpIndex(figdata * tmpdata)
471 while (i < bmpinsref) {
472 if (bitmaps[i] == tmpdata) return i;
479 static void freefigdata(figdata * tmpdata)
482 if (tmpdata->ref) return;
484 if (tmpdata->gspid > 0) {
485 int pid = tmpdata->gspid;
487 // kill ghostscript and unlink it's files
489 lyx::kill(pid, SIGKILL);
490 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
494 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
496 int i = FindBmpIndex(tmpdata);
498 while (i < bmpinsref) {
499 bitmaps[i] = bitmaps[i + 1];
505 static void runqueue()
507 // run queued requests for ghostscript, if any
508 if (!gsrunning && gs_color && !gs_xcolor) {
509 // here alloc all colors, so that gs will use only
510 // those we allocated for it
515 while (gsrunning < MAXGS) {
516 char tbuf[384], tbuf2[80];
520 if (gsqueue.empty()) {
521 if (!gsrunning && gs_xcolor) {
522 // de-allocate rest of colors
528 queue_element * p = &gsqueue.front();
537 if (lyxerr.debugging()) {
538 lyxerr << "GS start error! Cannot fork."
541 p->data->broken = true;
542 p->data->reading = false;
545 if (pid == 0) { // child
546 char ** env, rbuf[80], gbuf[40];
548 Display * tempdisp = XOpenDisplay(XDisplayName(0));
550 // create translation file
551 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
555 ofs << "gsave clippath pathbbox grestore\n"
557 << "/ury exch def /urx exch def /lly exch def "
559 << p->data->wid / 2.0 << " "
560 << p->data->hgh / 2.0 << " translate\n"
561 << p->data->angle << " rotate\n"
562 << -(p->data->raw_wid / 2.0) << " "
563 << -(p->data->raw_hgh / 2.0) << " translate\n"
564 << p->rx / 72.0 << " " << p->ry / 72.0
566 << -p->ofsx << " " << -p->ofsy << " translate\n"
568 ofs.close(); // Don't remove this.
570 // gs process - set ghostview environment first
571 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
572 figinset_canvas), p->data->bitmap);
574 // now set up ghostview property on a window
575 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
576 p->data->wid, p->data->hgh);
577 // #warning BUG seems that the only bug here
578 // might be the hardcoded dpi.. Bummer!
580 if (lyxerr.debugging()) {
581 lyxerr << "Will set GHOSTVIEW property to ["
582 << tbuf << "]" << endl;
584 // wait until property is deleted if executing multiple
587 // grab server to prevent other child
588 // interfering with setting GHOSTVIEW property
589 if (lyxerr.debugging()) {
590 lyxerr << "Grabbing the server"
593 XGrabServer(tempdisp);
594 prop = XListProperties(tempdisp,
596 figinset_canvas), &nprop);
600 for (i = 0; i < nprop; ++i) {
601 char * p = XGetAtomName(tempdisp,
603 if (strcmp(p, "GHOSTVIEW") == 0) {
609 XFree(reinterpret_cast<char *>(prop)); // jc:
611 // release the server
612 XUngrabServer(tempdisp);
614 // ok, property found, we must wait until
615 // ghostscript deletes it
616 if (lyxerr.debugging()) {
617 lyxerr << "Releasing the server\n["
619 << "] GHOSTVIEW property"
620 " found. Waiting." << endl;
626 XChangeProperty(tempdisp,
627 fl_get_canvas_id(figinset_canvas),
628 XInternAtom(tempdisp, "GHOSTVIEW", false),
629 XInternAtom(tempdisp, "STRING", false),
631 reinterpret_cast<unsigned char*>(tbuf),
634 switch (p->data->flags & 3) {
635 case 0: tbuf[0] = 'H'; break; // Hidden
636 case 1: tbuf[0] = 'M'; break; // Mono
637 case 2: tbuf[0] = 'G'; break; // Gray
640 tbuf[0] = 'C'; // Color
642 tbuf[0] = 'G'; // Gray
648 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
649 DefaultScreenOfDisplay(fl_display)),
650 fl_get_pixel(FL_BLACK));
652 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
653 DefaultScreenOfDisplay(fl_display)),
654 fl_get_pixel(FL_WHITE));
658 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
659 DefaultScreenOfDisplay(fl_display)),
662 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
663 DefaultScreenOfDisplay(fl_display)),
668 XChangeProperty(tempdisp,
669 fl_get_canvas_id(figinset_canvas),
670 XInternAtom(tempdisp,
671 "GHOSTVIEW_COLORS", false),
672 XInternAtom(tempdisp, "STRING", false),
674 reinterpret_cast<unsigned char*>(tbuf),
676 XUngrabServer(tempdisp);
678 if (lyxerr.debugging()) {
679 lyxerr << "Releasing the server" << endl;
681 XCloseDisplay(tempdisp);
683 // set up environment
684 while (environ[ne]) ++ne;
685 typedef char * char_p;
686 env = new char_p[ne + 2];
688 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
691 // now make gs command
693 // close(1); do NOT close. If GS writes out
694 // errors it would hang. (Matthias 290596)
695 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
696 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
697 // now chdir into dir with .eps file, to be on the safe
699 chdir(OnlyPath(p->data->fname).c_str());
700 // make temp file name
701 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
703 if (lyxerr.debugging()) {
704 lyxerr << "starting gs " << tbuf << " "
706 << ", pid: " << getpid() << endl;
709 int err = execlp(lyxrc->ps_command.c_str(),
710 lyxrc->ps_command.c_str(),
712 "-dNOPAUSE", "-dQUIET",
715 p->data->fname.c_str(),
716 "showpage.ps", "quit.ps", "-", 0);
717 // if we are still there, an error occurred.
718 lyxerr << "Error executing ghostscript. "
719 << "Code: " << err << endl;
720 lyxerr.debug() << "Cmd: "
724 << p->data->fname << endl;
727 // normal process (parent)
728 if (lyxerr.debugging()) {
729 lyxerr << "GS [" << pid << "] started" << endl;
732 p->data->gspid = pid;
739 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
741 // recompute the stuff and put in the queue
745 p.rx = (float(data->raw_wid) * 72.0) / pswid;
746 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
752 // if possible, run the queue
757 static figdata * getfigdata(int wid, int hgh, string const & fname,
758 int psx, int psy, int pswid, int pshgh,
759 int raw_wid, int raw_hgh, float angle, char flags)
761 /* first search for an exact match with fname and width/height */
763 if (fname.empty()) return 0;
766 while (i < bmpinsref) {
767 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
768 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
769 bitmaps[i]->angle == angle) {
775 /* not found -> create new record or return 0 if no record */
777 if (bmpinsref > bmparrsize) {
778 // allocate more space
779 bmparrsize += figallocchunk;
780 typedef figdata * figdata_p;
781 figdata ** tmp = new figdata_p[bmparrsize];
783 sizeof(figdata*) * (bmparrsize - figallocchunk));
787 figdata * p = new figdata;
788 bitmaps[bmpinsref-1] = p;
791 p->raw_wid = raw_wid;
792 p->raw_hgh = raw_hgh;
796 XWindowAttributes wa;
797 XGetWindowAttributes(fl_display, fl_get_canvas_id(
798 figinset_canvas), &wa);
800 if (lyxerr.debugging()) {
801 lyxerr << "Create pixmap disp:" << fl_display
802 << " scr:" << DefaultScreen(fl_display)
805 << " depth:" << wa.depth << endl;
813 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
814 figinset_canvas), wid, hgh, wa.depth);
816 // initialize reading of .eps file with correct sizes and stuff
817 addwait(psx, psy, pswid, pshgh, p);
828 static void getbitmap(figdata * p)
834 static void makeupdatelist(figdata * p)
836 for (int i = 0; i < figinsref; ++i)
837 if (figures[i]->data == p) {
838 if (lyxerr.debugging()) {
839 lyxerr << "Updating inset "
843 // add inset figures[i]->inset into to_update list
844 PutInsetIntoInsetUpdateList(figures[i]->inset);
849 void sigchldchecker(pid_t pid, int * status)
851 lyxerr.debug() << "Got pid = " << pid << endl;
852 bool pid_handled = false;
853 for (int i = bmpinsref - 1; i >= 0; --i) {
854 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
855 lyxerr.debug() << "Found pid in bitmaps" << endl;
856 // now read the file and remove it from disk
857 figdata * p = bitmaps[i];
859 if (bitmaps[i]->gsdone) *status = 0;
861 lyxerr.debug() << "GS [" << pid
862 << "] exit OK." << endl;
864 lyxerr << "GS [" << pid << "] error "
866 << WIFEXITED(*status)
867 << " " << WEXITSTATUS(*status)
868 << " S:" << WIFSIGNALED(*status)
869 << " " << WTERMSIG(*status) << endl;
872 bitmap_waiting = true;
875 // remove temporary files
877 sprintf(tmp, "%s/~lyxgs%d.ps",
878 system_tempdir.c_str(),
884 makeupdatelist(bitmaps[i]);
891 lyxerr.debug() << "Checking pid in pidwait" << endl;
892 list<int>::iterator it = find(pidwaitlist.begin(),
893 pidwaitlist.end(), pid);
894 if (it != pidwaitlist.end()) {
895 lyxerr.debug() << "Found pid in pidwait\n"
896 << "Caught child pid of recompute "
897 "routine" << pid << endl;
898 pidwaitlist.erase(it);
902 lyxerr.debug() << "waitpid error" << endl;
905 lyxerr << "The process or process group specified by "
906 "pid does not exist or is not a child of "
907 "the calling process or can never be in the "
908 "states specified by options." << endl;
911 lyxerr << "waitpid() was interrupted due to the "
912 "receipt of a signal sent by the calling "
916 lyxerr << "An invalid value was specified for "
920 lyxerr << "Unknown error from waitpid" << endl;
923 } else if (pid == 0) {
924 lyxerr << "waitpid nohang" << endl;;
926 lyxerr.debug() << "normal exit from childhandler" << endl;
931 static void getbitmaps()
933 bitmap_waiting = false;
934 for (int i = 0; i < bmpinsref; ++i)
935 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
936 getbitmap(bitmaps[i]);
940 static void RegisterFigure(InsetFig * fi)
942 if (figinsref == 0) InitFigures();
945 if (figinsref > figarrsize) {
946 // allocate more space
947 figarrsize += figallocchunk;
948 typedef Figref * Figref_p;
949 Figref ** tmp = new Figref_p[figarrsize];
951 sizeof(Figref*)*(figarrsize-figallocchunk));
955 Figref * tmpfig = new Figref;
958 figures[figinsref-1] = tmpfig;
961 if (lyxerr.debugging()) {
962 lyxerr << "Register Figure: buffer:["
963 << current_view->buffer() << "]" << endl;
968 int FindFigIndex(Figref * tmpfig)
971 while (i < figinsref) {
972 if (figures[i] == tmpfig) return i;
979 static void UnregisterFigure(InsetFig * fi)
981 Figref * tmpfig = fi->figure;
983 if (tmpfig->data) freefigdata(tmpfig->data);
984 if (tmpfig->inset->form) {
985 if (tmpfig->inset->form->Figure->visible) {
986 fl_set_focus_object(tmpfig->inset->form->Figure,
987 tmpfig->inset->form->OkBtn);
988 fl_hide_form(tmpfig->inset->form->Figure);
990 #if FL_REVISION == 89
991 #warning Reactivate this free_form calls
993 fl_free_form(tmpfig->inset->form->Figure);
994 free(tmpfig->inset->form); // Why free?
995 tmpfig->inset->form = 0;
998 int i = FindFigIndex(tmpfig);
1000 while (i < figinsref) {
1001 figures[i] = figures[i+1];
1006 if (figinsref == 0) DoneFigures();
1010 static string NextToken(istream & is)
1018 } while (!is.eof() && !isspace(c));
1019 token.erase(token.length() - 1); // remove the isspace
1025 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1035 psubfigure = subfigure = false;
1036 xwid = xhgh = angle = 0;
1038 raw_wid = raw_hgh = 0;
1039 changedfname = false;
1040 RegisterFigure(this);
1044 InsetFig::~InsetFig()
1046 if (lyxerr.debugging()) {
1047 lyxerr << "Figure destructor called" << endl;
1049 UnregisterFigure(this);
1054 int InsetFig::ascent(Painter &, LyXFont const &) const
1059 int InsetFig::Ascent(LyXFont const &) const
1067 int InsetFig::descent(Painter &, LyXFont const &) const
1072 int InsetFig::Descent(LyXFont const &) const
1080 int InsetFig::width(Painter &, LyXFont const &) const
1085 int InsetFig::Width(LyXFont const &) const
1093 void InsetFig::draw(Painter & pain, LyXFont const & f,
1094 int baseline, float & x) const
1098 if (bitmap_waiting) getbitmaps();
1100 // I wish that I didn't have to use this
1101 // but the figinset code is so complicated so
1102 // I don't want to fiddle with it now.
1105 unsigned long pm = pain.getScreen()->getForeground();
1106 if (figure && figure->data && figure->data->bitmap &&
1107 !figure->data->reading && !figure->data->broken) {
1109 XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
1110 0, 0, wid, hgh, int(x+1), baseline-hgh);
1112 if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
1113 int(x), baseline - hgh - 1,
1119 pain.rectangle(x, baseline - hgh - 1, wid + 1, hgh + 1);
1121 if (figure && figure->data) {
1122 if (figure->data->broken) msg = _("[render error]");
1123 else if (figure->data->reading) msg = _("[rendering ... ]");
1125 if (fname.empty()) msg = _("[no file]");
1126 else if ((flags & 3) == 0) msg = _("[not displayed]");
1127 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1129 if (!msg) msg = _("[unknown error]");
1131 font.setFamily(LyXFont::SANS_FAMILY);
1132 font.setSize(LyXFont::SIZE_FOOTNOTE);
1133 string justname = OnlyFilename (fname);
1134 pain.text(int(x + 8), baseline - font.maxAscent() - 4,
1137 font.setSize(LyXFont::SIZE_TINY);
1138 pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
1142 x += width(pain, font); // ?
1145 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1147 if (bitmap_waiting) getbitmaps();
1149 // I wish that I didn't have to use this
1150 // but the figinset code is so complicated so
1151 // I don't want to fiddle with it now.
1152 unsigned long pm = scr.getForeground();
1154 if (figure && figure->data && figure->data->bitmap &&
1155 !figure->data->reading && !figure->data->broken) {
1157 XCopyArea(fl_display, figure->data->bitmap, pm, local_gc_copy,
1158 0, 0, wid, hgh, int(x+1), baseline-hgh);
1160 if (flags & 4) XDrawRectangle(fl_display, pm, local_gc_copy,
1161 int(x), baseline - hgh - 1,
1166 XDrawRectangle(fl_display, pm, local_gc_copy,
1168 baseline - hgh - 1, wid+1, hgh+1);
1169 if (figure && figure->data) {
1170 if (figure->data->broken) msg = _("[render error]");
1171 else if (figure->data->reading) msg = _("[rendering ... ]");
1173 if (fname.empty()) msg = _("[no file]");
1174 else if ((flags & 3) == 0) msg = _("[not displayed]");
1175 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1177 if (!msg) msg = _("[unknown error]");
1179 font.setFamily (LyXFont::SANS_FAMILY);
1180 font.setSize (LyXFont::SIZE_FOOTNOTE);
1181 string justname = OnlyFilename (fname);
1182 font.drawString(justname, pm,
1183 baseline - font.maxAscent() - 4,
1185 font.setSize (LyXFont::SIZE_TINY);
1186 font.drawText (msg, strlen(msg), pm,
1191 x += Width(font); // ?
1196 void InsetFig::Write(ostream & os)
1199 os << "Figure size " << wid << " " << hgh << "\n";
1200 if (!fname.empty()) {
1201 string buf1 = OnlyPath(owner->fileName());
1202 string fname2 = MakeRelPath(fname, buf1);
1203 os << "file " << fname2 << "\n";
1205 if (!subcaption.empty())
1206 os << "subcaption " << subcaption << "\n";
1207 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1208 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1209 if (angle != 0) os << "angle " << angle << "\n";
1210 os << "flags " << flags << "\n";
1211 if (subfigure) os << "subfigure\n";
1215 void InsetFig::Read(LyXLex & lex)
1218 bool finished = false;
1220 while (lex.IsOK() && !finished) {
1223 string const token = lex.GetString();
1224 lyxerr.debug() << "Token: " << token << endl;
1228 else if (token == "\\end_inset") {
1230 } else if (token == "file") {
1232 buf = lex.GetString();
1233 string buf1 = OnlyPath(owner->fileName());
1234 fname = MakeAbsPath(buf, buf1);
1235 changedfname = true;
1237 } else if (token == "extra") {
1239 // kept for backwards compability. Delete in 0.13.x
1240 } else if (token == "subcaption") {
1242 subcaption = lex.GetString();
1243 } else if (token == "label") {
1245 // kept for backwards compability. Delete in 0.13.x
1246 } else if (token == "angle") {
1248 angle = lex.GetFloat();
1249 } else if (token == "size") {
1251 wid = lex.GetInteger();
1253 hgh = lex.GetInteger();
1254 } else if (token == "flags") {
1256 flags = pflags = lex.GetInteger();
1257 } else if (token == "subfigure") {
1258 subfigure = psubfigure = true;
1259 } else if (token == "width") {
1262 typ = lex.GetInteger();
1264 xwid = lex.GetFloat();
1266 case DEF: wtype = DEF; break;
1267 case CM: wtype = CM; break;
1268 case IN: wtype = IN; break;
1269 case PER_PAGE: wtype = PER_PAGE; break;
1270 case PER_COL: wtype = PER_COL; break;
1272 lyxerr.debug() << "Unknown type!" << endl;
1276 } else if (token == "height") {
1279 typ = lex.GetInteger();
1281 xhgh = lex.GetFloat();
1283 case DEF: htype = DEF; break;
1284 case CM: htype = CM; break;
1285 case IN: htype = IN; break;
1286 case PER_PAGE: htype = PER_PAGE; break;
1288 lyxerr.debug() << "Unknown type!" << endl;
1299 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1302 if (!cmd.empty()) os << cmd << " ";
1307 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1315 int InsetFig::Linuxdoc(string &/*file*/)
1321 int InsetFig::DocBook(string & file)
1323 string figurename = fname;
1325 if(suffixIs(figurename, ".eps"))
1326 figurename.erase(fname.length() - 5);
1328 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1333 void InsetFig::Validate(LaTeXFeatures & features) const
1335 features.graphics = true;
1336 if (subfigure) features.subfigure = true;
1340 unsigned char InsetFig::Editable() const
1346 bool InsetFig::Deletable() const
1352 void InsetFig::Edit(int, int)
1354 lyxerr.debug() << "Editing InsetFig." << endl;
1357 // We should have RO-versions of the form instead.
1358 // The actual prevention of altering a readonly doc
1359 // is done in CallbackFig()
1360 if(current_view->buffer()->isReadonly())
1361 WarnReadonly(current_view->buffer()->fileName());
1364 form = create_form_Figure();
1365 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1366 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1367 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1368 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1371 if (form->Figure->visible) {
1372 fl_raise_form(form->Figure);
1374 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1375 FL_FULLBORDER, _("Figure"));
1380 Inset * InsetFig::Clone() const
1382 InsetFig * tmp = new InsetFig(100, 100, owner);
1384 if (lyxerr.debugging()) {
1385 lyxerr << "Clone Figure: buffer:["
1386 << current_view->buffer()
1387 << "], cbuffer:[xx]" << endl;
1392 tmp->raw_wid = raw_wid;
1393 tmp->raw_hgh = raw_hgh;
1398 tmp->pflags = pflags;
1399 tmp->subfigure = subfigure;
1400 tmp->psubfigure = psubfigure;
1408 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1409 // do not display if there is
1410 // "do not display" chosen (Matthias 260696)
1411 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1412 pswid, pshgh, raw_wid, raw_hgh,
1413 angle, flags & (3|8));
1414 } else tmp->figure->data = 0;
1415 tmp->subcaption = subcaption;
1416 tmp->changedfname = false;
1423 Inset::Code InsetFig::LyxCode() const
1425 return Inset::GRAPHICS_CODE;
1429 void InsetFig::Regenerate()
1432 string resizeW, resizeH;
1433 string rotate, recmd;
1435 if (fname.empty()) {
1436 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1437 cmd += _("empty figure path");
1442 string buf1 = OnlyPath(owner->fileName());
1443 string fname2 = MakeRelPath(fname, buf1);
1445 string gcmd = "\\includegraphics{" + fname2 + '}';
1450 case CM:{// \resizebox*{h-length}{v-length}{text}
1452 sprintf(buf, "%g", xwid); // should find better
1459 sprintf(buf, "%g", xwid);
1466 sprintf(buf, "%g", xwid/100);
1468 resizeW += "\\textwidth";
1473 sprintf(buf, "%g", xwid/100);
1475 resizeW += "\\columnwidth";
1485 sprintf(buf, "%g", xhgh);
1492 sprintf(buf, "%g", xhgh);
1499 sprintf(buf, "%g", xhgh/100);
1501 resizeH += "\\textheight";
1505 // Doesn't occur; case exists to suppress compiler warnings.
1510 if (!resizeW.empty() || !resizeH.empty()) {
1511 recmd = "\\resizebox*{";
1512 if (!resizeW.empty())
1517 if (!resizeH.empty())
1527 sprintf(buf, "%g", angle);
1528 // \rotatebox{angle}{text}
1529 rotate = "\\rotatebox{";
1537 if (!rotate.empty()) cmdbuf += '}';
1538 if (!recmd.empty()) cmdbuf += '}';
1540 if (!subcaption.empty())
1541 cmdbuf = "\\subfigure[" + subcaption +
1542 "]{" + cmdbuf + "}";
1544 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1551 void InsetFig::TempRegenerate()
1554 string resizeW, resizeH;
1555 string rotate, recmd;
1557 char const * tfname = fl_get_input(form->EpsFile);
1558 string tsubcap = fl_get_input(form->Subcaption);
1559 float tangle = atof(fl_get_input(form->Angle));
1560 float txwid = atof(fl_get_input(form->Width));
1561 float txhgh = atof(fl_get_input(form->Height));
1563 if (!tfname || !*tfname) {
1564 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1565 cmd += _("empty figure path");
1570 string buf1 = OnlyPath(owner->fileName());
1571 string fname2 = MakeRelPath(tfname, buf1);
1572 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1573 string gcmd = "\\includegraphics{" + fname2 + '}';
1578 case CM: {// \resizebox*{h-length}{v-length}{text}
1580 sprintf(buf, "%g", txwid); // should find better
1587 sprintf(buf, "%g", txwid);
1594 sprintf(buf, "%g", txwid/100);
1596 resizeW += "\\textwidth";
1601 sprintf(buf, "%g", txwid/100);
1603 resizeW += "\\columnwidth";
1613 sprintf(buf, "%g", txhgh);
1620 sprintf(buf, "%g", txhgh);
1627 sprintf(buf, "%g", txhgh/100);
1629 resizeH += "\\textheight";
1633 // Doesn't occur; case exists to suppress compiler warnings.
1638 // \resizebox*{h-length}{v-length}{text}
1639 if (!resizeW.empty() || !resizeH.empty()) {
1640 recmd = "\\resizebox*{";
1641 if (!resizeW.empty())
1646 if (!resizeH.empty())
1655 sprintf(buf, "%g", tangle);
1656 // \rotatebox{angle}{text}
1657 rotate = "\\rotatebox{";
1665 if (!rotate.empty()) cmdbuf += '}';
1666 if (!recmd.empty()) cmdbuf += '}';
1667 if (psubfigure && !tsubcap.empty()) {
1668 cmdbuf = string("\\subfigure{") + tsubcap
1669 + string("}{") + cmdbuf + "}";
1674 void InsetFig::Recompute()
1676 bool changed = changedfname;
1677 int newx, newy, nraw_x, nraw_y;
1679 if (changed) GetPSSizes();
1681 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1682 float cos_a = cos (angle / DEG2PI);
1683 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1684 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1686 /* now recompute wid and hgh, and if that is changed, set changed */
1687 /* this depends on chosen size of the picture and its bbox */
1688 // This will be redone in 0.13 ... (hen)
1689 if (!fname.empty()) {
1690 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1698 newx = int(28.346 * xwid);
1701 newx = int(72 * xwid);
1703 case PER_PAGE: /* % of page */
1704 newx = int(5.95 * xwid);
1706 case PER_COL: /* % of col */
1707 newx = int(2.975 * xwid);
1711 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1715 //lyxerr << "This should not happen!" << endl;
1718 newy = int(28.346 * xhgh);
1721 newy = int(72 * xhgh);
1723 case PER_PAGE: /* % of page */
1724 newy = int(8.42 * xhgh);
1727 // Doesn't occur; case exists to suppress
1728 // compiler warnings.
1731 if (htype && !wtype && frame_hgh)
1732 newx = newy*frame_wid/frame_hgh;
1741 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1746 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1748 // cannot be zero, actually, set it to some minimum, so its clickable
1749 if (newx < 5) newx = 5;
1750 if (newy < 5) newy = 5;
1752 if (newx != wid || newy != hgh ||
1753 nraw_x != raw_wid || nraw_y != raw_hgh ||
1754 flags != pflags || subfigure != psubfigure)
1762 subfigure = psubfigure;
1765 figdata * pf = figure->data;
1768 if (!fname.empty() && (flags & 3)
1769 && !lyxrc->ps_command.empty()) {
1770 // do not display if there is "do not display"
1771 // chosen (Matthias 260696)
1772 figure->data = getfigdata(wid, hgh, fname,
1773 psx, psy, pswid, pshgh,
1775 angle, flags & (3|8));
1776 } else figure->data = 0;
1778 // free the old data
1779 if (pf) freefigdata(pf);
1782 changedfname = false;
1786 void InsetFig::GetPSSizes()
1788 /* get %%BoundingBox: from postscript file */
1790 /* defaults to associated size
1791 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1798 if (fname.empty()) return;
1800 ifstream ifs(fname.c_str());
1802 if (!ifs) return; // file not found !!!!
1804 /* defaults to A4 page */
1810 char lastchar = 0; ifs.get(lastchar);
1812 char c = 0; ifs.get(c);
1814 lyxerr.debug() << "End of (E)PS file reached and"
1815 " no BoundingBox!" << endl;
1818 if (c == '%' && lastchar == '%') {
1820 if (p.empty()) break;
1821 // we should not use this, with it we cannot
1822 // discover bounding box and end of file.
1823 //if (strcmp(p, "EndComments") == 0) break;
1824 lyxerr.debug() << "Token: `" << p << "'" << endl;
1825 if (p == "BoundingBox:") {
1826 float fpsx, fpsy, fpswid, fpshgh;
1827 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1830 pswid = int(fpswid);
1831 pshgh = int(fpshgh);
1833 if (lyxerr.debugging()) {
1834 lyxerr << "%%%%BoundingBox:"
1852 void InsetFig::CallbackFig(long arg)
1857 if (lyxerr.debugging()) {
1858 lyxerr << "Figure callback, arg " << arg << endl;
1864 case 12: /* width type */
1871 fl_deactivate_object(form->Width);
1876 fl_activate_object(form->Width);
1881 fl_activate_object(form->Width);
1886 fl_activate_object(form->Width);
1891 fl_activate_object(form->Width);
1894 lyxerr.debug() << "Unknown type!" << endl;
1901 case 22: /* height type */
1907 fl_deactivate_object(form->Height);
1912 fl_activate_object(form->Height);
1917 fl_activate_object(form->Height);
1922 fl_activate_object(form->Height);
1925 lyxerr.debug() << "Unknown type!" << endl;
1931 pflags = pflags & ~3; /* wysiwyg0 */
1934 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1937 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1940 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1943 pflags ^= 4; /* frame */
1946 pflags ^= 8; /* do translations */
1949 psubfigure = !psubfigure; /* This is a subfigure */
1952 regen = true; /* regenerate command */
1954 case 0: /* browse file */
1958 case 1: /* preview */
1959 p = fl_get_input(form->EpsFile);
1963 case 8: /* ok (apply and close) */
1964 if(!current_view->buffer()->isReadonly()) {
1967 xwid = atof(fl_get_input(form->Width));
1968 xhgh = atof(fl_get_input(form->Height));
1969 angle = atof(fl_get_input(form->Angle));
1970 p = fl_get_input(form->EpsFile);
1972 string buf1 = OnlyPath(owner->fileName());
1973 fname = MakeAbsPath(p, buf1);
1974 changedfname = true;
1976 if (!fname.empty()) {
1977 changedfname = true;
1981 subcaption = fl_get_input(form->Subcaption);
1985 /* now update inset */
1986 if (lyxerr.debugging()) {
1987 lyxerr << "Update: ["
1988 << wid << 'x' << hgh << ']' << endl;
1990 UpdateInset(current_view, this);
1992 fl_set_focus_object(form->Figure, form->OkBtn);
1993 fl_hide_form(form->Figure);
1994 #if FL_REVISION == 89
1995 #warning Reactivate this free_form calls
1997 fl_free_form(form->Figure);
1998 free(form); // Why free?
2004 // The user has already been informed about RO in ::Edit
2005 if(arg == 7) // if 'Apply'
2008 case 9: /* cancel = restore and close */
2009 fl_set_focus_object(form->Figure, form->OkBtn);
2010 fl_hide_form(form->Figure);
2011 #if FL_REVISION == 89
2012 #warning Reactivate this free_form calls
2013 #warning Jug, is this still a problem?
2015 fl_free_form(form->Figure);
2016 free(form); // Why free?
2022 if (regen) TempRegenerate();
2026 inline void DisableFigurePanel(FD_Figure * const form)
2028 fl_deactivate_object(form->EpsFile);
2029 fl_deactivate_object(form->Browse);
2030 fl_deactivate_object(form->Width);
2031 fl_deactivate_object(form->Height);
2032 fl_deactivate_object(form->Frame);
2033 fl_deactivate_object(form->Translations);
2034 fl_deactivate_object(form->Angle);
2035 fl_deactivate_object(form->HeightGrp);
2036 fl_deactivate_object(form->page2);
2037 fl_deactivate_object(form->Default2);
2038 fl_deactivate_object(form->cm2);
2039 fl_deactivate_object(form->in2);
2040 fl_deactivate_object(form->HeightLabel);
2041 fl_deactivate_object(form->WidthLabel);
2042 fl_deactivate_object(form->DisplayGrp);
2043 fl_deactivate_object(form->Wysiwyg3);
2044 fl_deactivate_object(form->Wysiwyg0);
2045 fl_deactivate_object(form->Wysiwyg2);
2046 fl_deactivate_object(form->Wysiwyg1);
2047 fl_deactivate_object(form->WidthGrp);
2048 fl_deactivate_object(form->Default1);
2049 fl_deactivate_object(form->cm1);
2050 fl_deactivate_object(form->in1);
2051 fl_deactivate_object(form->page1);
2052 fl_deactivate_object(form->column1);
2053 fl_deactivate_object(form->Subcaption);
2054 fl_deactivate_object(form->Subfigure);
2055 fl_deactivate_object (form->OkBtn);
2056 fl_deactivate_object (form->ApplyBtn);
2057 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
2058 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
2062 inline void EnableFigurePanel(FD_Figure * const form)
2064 fl_activate_object(form->EpsFile);
2065 fl_activate_object(form->Browse);
2066 fl_activate_object(form->Width);
2067 fl_activate_object(form->Height);
2068 fl_activate_object(form->Frame);
2069 fl_activate_object(form->Translations);
2070 fl_activate_object(form->Angle);
2071 fl_activate_object(form->HeightGrp);
2072 fl_activate_object(form->page2);
2073 fl_activate_object(form->Default2);
2074 fl_activate_object(form->cm2);
2075 fl_activate_object(form->in2);
2076 fl_activate_object(form->HeightLabel);
2077 fl_activate_object(form->WidthLabel);
2078 fl_activate_object(form->DisplayGrp);
2079 fl_activate_object(form->Wysiwyg3);
2080 fl_activate_object(form->Wysiwyg0);
2081 fl_activate_object(form->Wysiwyg2);
2082 fl_activate_object(form->Wysiwyg1);
2083 fl_activate_object(form->WidthGrp);
2084 fl_activate_object(form->Default1);
2085 fl_activate_object(form->cm1);
2086 fl_activate_object(form->in1);
2087 fl_activate_object(form->page1);
2088 fl_activate_object(form->column1);
2089 fl_activate_object(form->Subcaption);
2090 fl_activate_object(form->Subfigure);
2091 fl_activate_object (form->OkBtn);
2092 fl_activate_object (form->ApplyBtn);
2093 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2094 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2098 void InsetFig::RestoreForm()
2102 EnableFigurePanel(form);
2105 fl_set_button(form->Default1, (wtype == 0));
2106 fl_set_button(form->cm1, (wtype == 1));
2107 fl_set_button(form->in1, (wtype == 2));
2108 fl_set_button(form->page1, (wtype == 3));
2109 fl_set_button(form->column1, (wtype == 4));
2111 fl_deactivate_object(form->Width);
2113 fl_activate_object(form->Width);
2116 // enable and disable should be put here.
2118 fl_set_button(form->Default2, (htype == 0));
2119 fl_set_button(form->cm2, (htype == 1));
2120 fl_set_button(form->in2, (htype == 2));
2121 fl_set_button(form->page2, (htype == 3));
2122 // enable and disable should be put here.
2124 fl_deactivate_object(form->Height);
2126 fl_activate_object(form->Height);
2129 int pflags = flags & 3;
2130 fl_set_button(form->Wysiwyg0, (pflags == 0));
2131 fl_set_button(form->Wysiwyg1, (pflags == 1));
2132 fl_set_button(form->Wysiwyg2, (pflags == 2));
2133 fl_set_button(form->Wysiwyg3, (pflags == 3));
2134 fl_set_button(form->Frame, ((flags & 4) != 0));
2135 fl_set_button(form->Translations, ((flags & 8) != 0));
2136 fl_set_button(form->Subfigure, (subfigure != 0));
2138 psubfigure = subfigure;
2139 sprintf(buf, "%g", xwid);
2140 fl_set_input(form->Width, buf);
2141 sprintf(buf, "%g", xhgh);
2142 fl_set_input(form->Height, buf);
2143 sprintf(buf, "%g", angle);
2144 fl_set_input(form->Angle, buf);
2145 if (!fname.empty()){
2146 string buf1 = OnlyPath(owner->fileName());
2147 string fname2 = MakeRelPath(fname, buf1);
2148 fl_set_input(form->EpsFile, fname2.c_str());
2150 else fl_set_input(form->EpsFile, "");
2151 fl_set_input(form->Subcaption, subcaption.c_str());
2152 if(current_view->buffer()->isReadonly())
2153 DisableFigurePanel(form);
2159 void InsetFig::Preview(char const * p)
2164 lyxerr << "Cannot fork process!" << endl;
2169 return; // parent process
2172 string buf1 = OnlyPath(owner->fileName());
2173 string buf2 = MakeAbsPath(p, buf1);
2175 lyxerr << "Error during rendering "
2176 << execlp(lyxrc->view_pspic_command.c_str(),
2177 lyxrc->view_pspic_command.c_str(),
2184 void InsetFig::BrowseFile()
2186 static string current_figure_path;
2187 static int once = 0;
2190 if (lyxerr.debugging()) {
2191 lyxerr << "Filename: "
2192 << owner->fileName() << endl;
2194 string p = fl_get_input(form->EpsFile);
2196 string buf = MakeAbsPath(owner->fileName());
2197 string buf2 = OnlyPath(buf);
2199 buf = MakeAbsPath(p, buf2);
2200 buf = OnlyPath(buf);
2202 buf = OnlyPath(owner->fileName().c_str());
2205 // Does user clipart directory exist?
2206 string bufclip = AddName (user_lyxdir, "clipart");
2207 FileInfo fileInfo(bufclip);
2208 if (!(fileInfo.isOK() && fileInfo.isDir()))
2209 // No - bail out to system clipart directory
2210 bufclip = AddName (system_lyxdir, "clipart");
2213 fileDlg.SetButton(0, _("Clipart"), bufclip);
2214 fileDlg.SetButton(1, _("Document"), buf);
2220 p = fileDlg.Select(_("EPS Figure"),
2221 current_figure_path,
2224 p = fileDlg.Select(_("EPS Figure"), buf,
2229 if (p.empty()) return;
2231 buf = MakeRelPath(p, buf2);
2232 current_figure_path = OnlyPath(p);
2235 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2236 || contains(p, "%") || contains(p, " "))
2238 WriteAlert(_("Filename can't contain any "
2239 "of these characters:"),
2240 // xgettext:no-c-format
2241 _("space, '#', '~', '$' or '%'."));
2246 if (form) fl_set_input(form->EpsFile, buf.c_str());
2250 void GraphicsCB(FL_OBJECT * obj, long arg)
2252 /* obj->form contains the form */
2254 if (lyxerr.debugging()) {
2255 lyxerr << "GraphicsCB callback: " << arg << endl;
2258 /* find inset we were reacting to */
2259 for (int i = 0; i < figinsref; ++i)
2260 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2263 if (lyxerr.debugging()) {
2264 lyxerr << "Calling back figure " << i << endl;
2266 figures[i]->inset->CallbackFig(arg);
2272 void HideFiguresPopups()
2274 for (int i = 0; i < figinsref; ++i)
2275 if (figures[i]->inset->form
2276 && figures[i]->inset->form->Figure->visible) {
2277 if (lyxerr.debugging()) {
2278 lyxerr << "Hiding figure " << i << endl;
2280 // hide and free the form
2281 figures[i]->inset->CallbackFig(9);