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.
1104 if (figure && figure->data && figure->data->bitmap &&
1105 !figure->data->reading && !figure->data->broken) {
1107 pain.pixmap(int(x + 1), baseline - hgh,
1108 wid, hgh, figure->data->bitmap);
1111 pain.rectangle(int(x), baseline - hgh - 1,
1117 pain.rectangle(x, baseline - hgh - 1, wid + 1, hgh + 1);
1119 if (figure && figure->data) {
1120 if (figure->data->broken) msg = _("[render error]");
1121 else if (figure->data->reading) msg = _("[rendering ... ]");
1123 if (fname.empty()) msg = _("[no file]");
1124 else if ((flags & 3) == 0) msg = _("[not displayed]");
1125 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1127 if (!msg) msg = _("[unknown error]");
1129 font.setFamily(LyXFont::SANS_FAMILY);
1130 font.setSize(LyXFont::SIZE_FOOTNOTE);
1131 string justname = OnlyFilename (fname);
1132 pain.text(int(x + 8), baseline - font.maxAscent() - 4,
1135 font.setSize(LyXFont::SIZE_TINY);
1136 pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
1138 x += width(pain, font); // ?
1141 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1143 if (bitmap_waiting) getbitmaps();
1145 // I wish that I didn't have to use this
1146 // but the figinset code is so complicated so
1147 // I don't want to fiddle with it now.
1148 unsigned long pm = scr.getForeground();
1150 if (figure && figure->data && figure->data->bitmap &&
1151 !figure->data->reading && !figure->data->broken) {
1153 XCopyArea(fl_display, figure->data->bitmap, pm, local_gc_copy,
1154 0, 0, wid, hgh, int(x+1), baseline-hgh);
1156 if (flags & 4) XDrawRectangle(fl_display, pm, local_gc_copy,
1157 int(x), baseline - hgh - 1,
1162 XDrawRectangle(fl_display, pm, local_gc_copy,
1164 baseline - hgh - 1, wid+1, hgh+1);
1165 if (figure && figure->data) {
1166 if (figure->data->broken) msg = _("[render error]");
1167 else if (figure->data->reading) msg = _("[rendering ... ]");
1169 if (fname.empty()) msg = _("[no file]");
1170 else if ((flags & 3) == 0) msg = _("[not displayed]");
1171 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1173 if (!msg) msg = _("[unknown error]");
1175 font.setFamily (LyXFont::SANS_FAMILY);
1176 font.setSize (LyXFont::SIZE_FOOTNOTE);
1177 string justname = OnlyFilename (fname);
1178 font.drawString(justname, pm,
1179 baseline - font.maxAscent() - 4,
1181 font.setSize (LyXFont::SIZE_TINY);
1182 font.drawText (msg, strlen(msg), pm,
1187 x += Width(font); // ?
1192 void InsetFig::Write(ostream & os)
1195 os << "Figure size " << wid << " " << hgh << "\n";
1196 if (!fname.empty()) {
1197 string buf1 = OnlyPath(owner->fileName());
1198 string fname2 = MakeRelPath(fname, buf1);
1199 os << "file " << fname2 << "\n";
1201 if (!subcaption.empty())
1202 os << "subcaption " << subcaption << "\n";
1203 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1204 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1205 if (angle != 0) os << "angle " << angle << "\n";
1206 os << "flags " << flags << "\n";
1207 if (subfigure) os << "subfigure\n";
1211 void InsetFig::Read(LyXLex & lex)
1214 bool finished = false;
1216 while (lex.IsOK() && !finished) {
1219 string const token = lex.GetString();
1220 lyxerr.debug() << "Token: " << token << endl;
1224 else if (token == "\\end_inset") {
1226 } else if (token == "file") {
1228 buf = lex.GetString();
1229 string buf1 = OnlyPath(owner->fileName());
1230 fname = MakeAbsPath(buf, buf1);
1231 changedfname = true;
1233 } else if (token == "extra") {
1235 // kept for backwards compability. Delete in 0.13.x
1236 } else if (token == "subcaption") {
1238 subcaption = lex.GetString();
1239 } else if (token == "label") {
1241 // kept for backwards compability. Delete in 0.13.x
1242 } else if (token == "angle") {
1244 angle = lex.GetFloat();
1245 } else if (token == "size") {
1247 wid = lex.GetInteger();
1249 hgh = lex.GetInteger();
1250 } else if (token == "flags") {
1252 flags = pflags = lex.GetInteger();
1253 } else if (token == "subfigure") {
1254 subfigure = psubfigure = true;
1255 } else if (token == "width") {
1258 typ = lex.GetInteger();
1260 xwid = lex.GetFloat();
1262 case DEF: wtype = DEF; break;
1263 case CM: wtype = CM; break;
1264 case IN: wtype = IN; break;
1265 case PER_PAGE: wtype = PER_PAGE; break;
1266 case PER_COL: wtype = PER_COL; break;
1268 lyxerr.debug() << "Unknown type!" << endl;
1272 } else if (token == "height") {
1275 typ = lex.GetInteger();
1277 xhgh = lex.GetFloat();
1279 case DEF: htype = DEF; break;
1280 case CM: htype = CM; break;
1281 case IN: htype = IN; break;
1282 case PER_PAGE: htype = PER_PAGE; break;
1284 lyxerr.debug() << "Unknown type!" << endl;
1295 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1298 if (!cmd.empty()) os << cmd << " ";
1303 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1311 int InsetFig::Linuxdoc(string &/*file*/)
1317 int InsetFig::DocBook(string & file)
1319 string figurename = fname;
1321 if(suffixIs(figurename, ".eps"))
1322 figurename.erase(fname.length() - 5);
1324 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1329 void InsetFig::Validate(LaTeXFeatures & features) const
1331 features.graphics = true;
1332 if (subfigure) features.subfigure = true;
1336 unsigned char InsetFig::Editable() const
1342 bool InsetFig::Deletable() const
1348 void InsetFig::Edit(int, int)
1350 lyxerr.debug() << "Editing InsetFig." << endl;
1353 // We should have RO-versions of the form instead.
1354 // The actual prevention of altering a readonly doc
1355 // is done in CallbackFig()
1356 if(current_view->buffer()->isReadonly())
1357 WarnReadonly(current_view->buffer()->fileName());
1360 form = create_form_Figure();
1361 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1362 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1363 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1364 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1367 if (form->Figure->visible) {
1368 fl_raise_form(form->Figure);
1370 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1371 FL_FULLBORDER, _("Figure"));
1376 Inset * InsetFig::Clone() const
1378 InsetFig * tmp = new InsetFig(100, 100, owner);
1380 if (lyxerr.debugging()) {
1381 lyxerr << "Clone Figure: buffer:["
1382 << current_view->buffer()
1383 << "], cbuffer:[xx]" << endl;
1388 tmp->raw_wid = raw_wid;
1389 tmp->raw_hgh = raw_hgh;
1394 tmp->pflags = pflags;
1395 tmp->subfigure = subfigure;
1396 tmp->psubfigure = psubfigure;
1404 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1405 // do not display if there is
1406 // "do not display" chosen (Matthias 260696)
1407 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1408 pswid, pshgh, raw_wid, raw_hgh,
1409 angle, flags & (3|8));
1410 } else tmp->figure->data = 0;
1411 tmp->subcaption = subcaption;
1412 tmp->changedfname = false;
1419 Inset::Code InsetFig::LyxCode() const
1421 return Inset::GRAPHICS_CODE;
1425 void InsetFig::Regenerate()
1428 string resizeW, resizeH;
1429 string rotate, recmd;
1431 if (fname.empty()) {
1432 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1433 cmd += _("empty figure path");
1438 string buf1 = OnlyPath(owner->fileName());
1439 string fname2 = MakeRelPath(fname, buf1);
1441 string gcmd = "\\includegraphics{" + fname2 + '}';
1446 case CM:{// \resizebox*{h-length}{v-length}{text}
1448 sprintf(buf, "%g", xwid); // should find better
1455 sprintf(buf, "%g", xwid);
1462 sprintf(buf, "%g", xwid/100);
1464 resizeW += "\\textwidth";
1469 sprintf(buf, "%g", xwid/100);
1471 resizeW += "\\columnwidth";
1481 sprintf(buf, "%g", xhgh);
1488 sprintf(buf, "%g", xhgh);
1495 sprintf(buf, "%g", xhgh/100);
1497 resizeH += "\\textheight";
1501 // Doesn't occur; case exists to suppress compiler warnings.
1506 if (!resizeW.empty() || !resizeH.empty()) {
1507 recmd = "\\resizebox*{";
1508 if (!resizeW.empty())
1513 if (!resizeH.empty())
1523 sprintf(buf, "%g", angle);
1524 // \rotatebox{angle}{text}
1525 rotate = "\\rotatebox{";
1533 if (!rotate.empty()) cmdbuf += '}';
1534 if (!recmd.empty()) cmdbuf += '}';
1536 if (!subcaption.empty())
1537 cmdbuf = "\\subfigure[" + subcaption +
1538 "]{" + cmdbuf + "}";
1540 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1547 void InsetFig::TempRegenerate()
1550 string resizeW, resizeH;
1551 string rotate, recmd;
1553 char const * tfname = fl_get_input(form->EpsFile);
1554 string tsubcap = fl_get_input(form->Subcaption);
1555 float tangle = atof(fl_get_input(form->Angle));
1556 float txwid = atof(fl_get_input(form->Width));
1557 float txhgh = atof(fl_get_input(form->Height));
1559 if (!tfname || !*tfname) {
1560 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1561 cmd += _("empty figure path");
1566 string buf1 = OnlyPath(owner->fileName());
1567 string fname2 = MakeRelPath(tfname, buf1);
1568 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1569 string gcmd = "\\includegraphics{" + fname2 + '}';
1574 case CM: {// \resizebox*{h-length}{v-length}{text}
1576 sprintf(buf, "%g", txwid); // should find better
1583 sprintf(buf, "%g", txwid);
1590 sprintf(buf, "%g", txwid/100);
1592 resizeW += "\\textwidth";
1597 sprintf(buf, "%g", txwid/100);
1599 resizeW += "\\columnwidth";
1609 sprintf(buf, "%g", txhgh);
1616 sprintf(buf, "%g", txhgh);
1623 sprintf(buf, "%g", txhgh/100);
1625 resizeH += "\\textheight";
1629 // Doesn't occur; case exists to suppress compiler warnings.
1634 // \resizebox*{h-length}{v-length}{text}
1635 if (!resizeW.empty() || !resizeH.empty()) {
1636 recmd = "\\resizebox*{";
1637 if (!resizeW.empty())
1642 if (!resizeH.empty())
1651 sprintf(buf, "%g", tangle);
1652 // \rotatebox{angle}{text}
1653 rotate = "\\rotatebox{";
1661 if (!rotate.empty()) cmdbuf += '}';
1662 if (!recmd.empty()) cmdbuf += '}';
1663 if (psubfigure && !tsubcap.empty()) {
1664 cmdbuf = string("\\subfigure{") + tsubcap
1665 + string("}{") + cmdbuf + "}";
1670 void InsetFig::Recompute()
1672 bool changed = changedfname;
1673 int newx, newy, nraw_x, nraw_y;
1675 if (changed) GetPSSizes();
1677 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1678 float cos_a = cos (angle / DEG2PI);
1679 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1680 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1682 /* now recompute wid and hgh, and if that is changed, set changed */
1683 /* this depends on chosen size of the picture and its bbox */
1684 // This will be redone in 0.13 ... (hen)
1685 if (!fname.empty()) {
1686 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1694 newx = int(28.346 * xwid);
1697 newx = int(72 * xwid);
1699 case PER_PAGE: /* % of page */
1700 newx = int(5.95 * xwid);
1702 case PER_COL: /* % of col */
1703 newx = int(2.975 * xwid);
1707 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1711 //lyxerr << "This should not happen!" << endl;
1714 newy = int(28.346 * xhgh);
1717 newy = int(72 * xhgh);
1719 case PER_PAGE: /* % of page */
1720 newy = int(8.42 * xhgh);
1723 // Doesn't occur; case exists to suppress
1724 // compiler warnings.
1727 if (htype && !wtype && frame_hgh)
1728 newx = newy*frame_wid/frame_hgh;
1737 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1742 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1744 // cannot be zero, actually, set it to some minimum, so its clickable
1745 if (newx < 5) newx = 5;
1746 if (newy < 5) newy = 5;
1748 if (newx != wid || newy != hgh ||
1749 nraw_x != raw_wid || nraw_y != raw_hgh ||
1750 flags != pflags || subfigure != psubfigure)
1758 subfigure = psubfigure;
1761 figdata * pf = figure->data;
1764 if (!fname.empty() && (flags & 3)
1765 && !lyxrc->ps_command.empty()) {
1766 // do not display if there is "do not display"
1767 // chosen (Matthias 260696)
1768 figure->data = getfigdata(wid, hgh, fname,
1769 psx, psy, pswid, pshgh,
1771 angle, flags & (3|8));
1772 } else figure->data = 0;
1774 // free the old data
1775 if (pf) freefigdata(pf);
1778 changedfname = false;
1782 void InsetFig::GetPSSizes()
1784 /* get %%BoundingBox: from postscript file */
1786 /* defaults to associated size
1787 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1794 if (fname.empty()) return;
1796 ifstream ifs(fname.c_str());
1798 if (!ifs) return; // file not found !!!!
1800 /* defaults to A4 page */
1806 char lastchar = 0; ifs.get(lastchar);
1808 char c = 0; ifs.get(c);
1810 lyxerr.debug() << "End of (E)PS file reached and"
1811 " no BoundingBox!" << endl;
1814 if (c == '%' && lastchar == '%') {
1816 if (p.empty()) break;
1817 // we should not use this, with it we cannot
1818 // discover bounding box and end of file.
1819 //if (strcmp(p, "EndComments") == 0) break;
1820 lyxerr.debug() << "Token: `" << p << "'" << endl;
1821 if (p == "BoundingBox:") {
1822 float fpsx, fpsy, fpswid, fpshgh;
1823 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1826 pswid = int(fpswid);
1827 pshgh = int(fpshgh);
1829 if (lyxerr.debugging()) {
1830 lyxerr << "%%%%BoundingBox:"
1848 void InsetFig::CallbackFig(long arg)
1853 if (lyxerr.debugging()) {
1854 lyxerr << "Figure callback, arg " << arg << endl;
1860 case 12: /* width type */
1867 fl_deactivate_object(form->Width);
1872 fl_activate_object(form->Width);
1877 fl_activate_object(form->Width);
1882 fl_activate_object(form->Width);
1887 fl_activate_object(form->Width);
1890 lyxerr.debug() << "Unknown type!" << endl;
1897 case 22: /* height type */
1903 fl_deactivate_object(form->Height);
1908 fl_activate_object(form->Height);
1913 fl_activate_object(form->Height);
1918 fl_activate_object(form->Height);
1921 lyxerr.debug() << "Unknown type!" << endl;
1927 pflags = pflags & ~3; /* wysiwyg0 */
1930 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1933 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1936 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1939 pflags ^= 4; /* frame */
1942 pflags ^= 8; /* do translations */
1945 psubfigure = !psubfigure; /* This is a subfigure */
1948 regen = true; /* regenerate command */
1950 case 0: /* browse file */
1954 case 1: /* preview */
1955 p = fl_get_input(form->EpsFile);
1959 case 8: /* ok (apply and close) */
1960 if(!current_view->buffer()->isReadonly()) {
1963 xwid = atof(fl_get_input(form->Width));
1964 xhgh = atof(fl_get_input(form->Height));
1965 angle = atof(fl_get_input(form->Angle));
1966 p = fl_get_input(form->EpsFile);
1968 string buf1 = OnlyPath(owner->fileName());
1969 fname = MakeAbsPath(p, buf1);
1970 changedfname = true;
1972 if (!fname.empty()) {
1973 changedfname = true;
1977 subcaption = fl_get_input(form->Subcaption);
1981 /* now update inset */
1982 if (lyxerr.debugging()) {
1983 lyxerr << "Update: ["
1984 << wid << 'x' << hgh << ']' << endl;
1986 UpdateInset(current_view, this);
1988 fl_set_focus_object(form->Figure, form->OkBtn);
1989 fl_hide_form(form->Figure);
1990 #if FL_REVISION == 89
1991 #warning Reactivate this free_form calls
1993 fl_free_form(form->Figure);
1994 free(form); // Why free?
2000 // The user has already been informed about RO in ::Edit
2001 if(arg == 7) // if 'Apply'
2004 case 9: /* cancel = restore and close */
2005 fl_set_focus_object(form->Figure, form->OkBtn);
2006 fl_hide_form(form->Figure);
2007 #if FL_REVISION == 89
2008 #warning Reactivate this free_form calls
2009 #warning Jug, is this still a problem?
2011 fl_free_form(form->Figure);
2012 free(form); // Why free?
2018 if (regen) TempRegenerate();
2022 inline void DisableFigurePanel(FD_Figure * const form)
2024 fl_deactivate_object(form->EpsFile);
2025 fl_deactivate_object(form->Browse);
2026 fl_deactivate_object(form->Width);
2027 fl_deactivate_object(form->Height);
2028 fl_deactivate_object(form->Frame);
2029 fl_deactivate_object(form->Translations);
2030 fl_deactivate_object(form->Angle);
2031 fl_deactivate_object(form->HeightGrp);
2032 fl_deactivate_object(form->page2);
2033 fl_deactivate_object(form->Default2);
2034 fl_deactivate_object(form->cm2);
2035 fl_deactivate_object(form->in2);
2036 fl_deactivate_object(form->HeightLabel);
2037 fl_deactivate_object(form->WidthLabel);
2038 fl_deactivate_object(form->DisplayGrp);
2039 fl_deactivate_object(form->Wysiwyg3);
2040 fl_deactivate_object(form->Wysiwyg0);
2041 fl_deactivate_object(form->Wysiwyg2);
2042 fl_deactivate_object(form->Wysiwyg1);
2043 fl_deactivate_object(form->WidthGrp);
2044 fl_deactivate_object(form->Default1);
2045 fl_deactivate_object(form->cm1);
2046 fl_deactivate_object(form->in1);
2047 fl_deactivate_object(form->page1);
2048 fl_deactivate_object(form->column1);
2049 fl_deactivate_object(form->Subcaption);
2050 fl_deactivate_object(form->Subfigure);
2051 fl_deactivate_object (form->OkBtn);
2052 fl_deactivate_object (form->ApplyBtn);
2053 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
2054 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
2058 inline void EnableFigurePanel(FD_Figure * const form)
2060 fl_activate_object(form->EpsFile);
2061 fl_activate_object(form->Browse);
2062 fl_activate_object(form->Width);
2063 fl_activate_object(form->Height);
2064 fl_activate_object(form->Frame);
2065 fl_activate_object(form->Translations);
2066 fl_activate_object(form->Angle);
2067 fl_activate_object(form->HeightGrp);
2068 fl_activate_object(form->page2);
2069 fl_activate_object(form->Default2);
2070 fl_activate_object(form->cm2);
2071 fl_activate_object(form->in2);
2072 fl_activate_object(form->HeightLabel);
2073 fl_activate_object(form->WidthLabel);
2074 fl_activate_object(form->DisplayGrp);
2075 fl_activate_object(form->Wysiwyg3);
2076 fl_activate_object(form->Wysiwyg0);
2077 fl_activate_object(form->Wysiwyg2);
2078 fl_activate_object(form->Wysiwyg1);
2079 fl_activate_object(form->WidthGrp);
2080 fl_activate_object(form->Default1);
2081 fl_activate_object(form->cm1);
2082 fl_activate_object(form->in1);
2083 fl_activate_object(form->page1);
2084 fl_activate_object(form->column1);
2085 fl_activate_object(form->Subcaption);
2086 fl_activate_object(form->Subfigure);
2087 fl_activate_object (form->OkBtn);
2088 fl_activate_object (form->ApplyBtn);
2089 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2090 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2094 void InsetFig::RestoreForm()
2098 EnableFigurePanel(form);
2101 fl_set_button(form->Default1, (wtype == 0));
2102 fl_set_button(form->cm1, (wtype == 1));
2103 fl_set_button(form->in1, (wtype == 2));
2104 fl_set_button(form->page1, (wtype == 3));
2105 fl_set_button(form->column1, (wtype == 4));
2107 fl_deactivate_object(form->Width);
2109 fl_activate_object(form->Width);
2112 // enable and disable should be put here.
2114 fl_set_button(form->Default2, (htype == 0));
2115 fl_set_button(form->cm2, (htype == 1));
2116 fl_set_button(form->in2, (htype == 2));
2117 fl_set_button(form->page2, (htype == 3));
2118 // enable and disable should be put here.
2120 fl_deactivate_object(form->Height);
2122 fl_activate_object(form->Height);
2125 int pflags = flags & 3;
2126 fl_set_button(form->Wysiwyg0, (pflags == 0));
2127 fl_set_button(form->Wysiwyg1, (pflags == 1));
2128 fl_set_button(form->Wysiwyg2, (pflags == 2));
2129 fl_set_button(form->Wysiwyg3, (pflags == 3));
2130 fl_set_button(form->Frame, ((flags & 4) != 0));
2131 fl_set_button(form->Translations, ((flags & 8) != 0));
2132 fl_set_button(form->Subfigure, (subfigure != 0));
2134 psubfigure = subfigure;
2135 sprintf(buf, "%g", xwid);
2136 fl_set_input(form->Width, buf);
2137 sprintf(buf, "%g", xhgh);
2138 fl_set_input(form->Height, buf);
2139 sprintf(buf, "%g", angle);
2140 fl_set_input(form->Angle, buf);
2141 if (!fname.empty()){
2142 string buf1 = OnlyPath(owner->fileName());
2143 string fname2 = MakeRelPath(fname, buf1);
2144 fl_set_input(form->EpsFile, fname2.c_str());
2146 else fl_set_input(form->EpsFile, "");
2147 fl_set_input(form->Subcaption, subcaption.c_str());
2148 if(current_view->buffer()->isReadonly())
2149 DisableFigurePanel(form);
2155 void InsetFig::Preview(char const * p)
2160 lyxerr << "Cannot fork process!" << endl;
2165 return; // parent process
2168 string buf1 = OnlyPath(owner->fileName());
2169 string buf2 = MakeAbsPath(p, buf1);
2171 lyxerr << "Error during rendering "
2172 << execlp(lyxrc->view_pspic_command.c_str(),
2173 lyxrc->view_pspic_command.c_str(),
2180 void InsetFig::BrowseFile()
2182 static string current_figure_path;
2183 static int once = 0;
2186 if (lyxerr.debugging()) {
2187 lyxerr << "Filename: "
2188 << owner->fileName() << endl;
2190 string p = fl_get_input(form->EpsFile);
2192 string buf = MakeAbsPath(owner->fileName());
2193 string buf2 = OnlyPath(buf);
2195 buf = MakeAbsPath(p, buf2);
2196 buf = OnlyPath(buf);
2198 buf = OnlyPath(owner->fileName().c_str());
2201 // Does user clipart directory exist?
2202 string bufclip = AddName (user_lyxdir, "clipart");
2203 FileInfo fileInfo(bufclip);
2204 if (!(fileInfo.isOK() && fileInfo.isDir()))
2205 // No - bail out to system clipart directory
2206 bufclip = AddName (system_lyxdir, "clipart");
2209 fileDlg.SetButton(0, _("Clipart"), bufclip);
2210 fileDlg.SetButton(1, _("Document"), buf);
2216 p = fileDlg.Select(_("EPS Figure"),
2217 current_figure_path,
2220 p = fileDlg.Select(_("EPS Figure"), buf,
2225 if (p.empty()) return;
2227 buf = MakeRelPath(p, buf2);
2228 current_figure_path = OnlyPath(p);
2231 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2232 || contains(p, "%") || contains(p, " "))
2234 WriteAlert(_("Filename can't contain any "
2235 "of these characters:"),
2236 // xgettext:no-c-format
2237 _("space, '#', '~', '$' or '%'."));
2242 if (form) fl_set_input(form->EpsFile, buf.c_str());
2246 void GraphicsCB(FL_OBJECT * obj, long arg)
2248 /* obj->form contains the form */
2250 if (lyxerr.debugging()) {
2251 lyxerr << "GraphicsCB callback: " << arg << endl;
2254 /* find inset we were reacting to */
2255 for (int i = 0; i < figinsref; ++i)
2256 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2259 if (lyxerr.debugging()) {
2260 lyxerr << "Calling back figure " << i << endl;
2262 figures[i]->inset->CallbackFig(arg);
2268 void HideFiguresPopups()
2270 for (int i = 0; i < figinsref; ++i)
2271 if (figures[i]->inset->form
2272 && figures[i]->inset->form->Figure->visible) {
2273 if (lyxerr.debugging()) {
2274 lyxerr << "Hiding figure " << i << endl;
2276 // hide and free the form
2277 figures[i]->inset->CallbackFig(9);