2 * figinset.C - part of LyX project
6 extern int reverse_video;
8 extern long int background_pixels;
10 /* Rework of path-handling (Matthias 04.07.1996 )
11 * ------------------------------------------------
12 * figinsets keep an absolute path to the eps-file.
13 * For the user alway a relative path appears
14 * (in lyx-file, latex-file and edit-popup).
15 * To calculate this relative path the path to the
16 * document where the figinset is in is needed.
17 * This is done by a reference to the buffer, called
18 * figinset::cbuffer. To be up to date the cbuffer
19 * is sometimes set to the current buffer
20 * bufferlist.current(), when it can be assumed that
21 * this operation happens in the current buffer.
22 * This is true for InsetFig::Edit(...),
23 * InsetFig::InsetFig(...), InsetFig::Read(...),
24 * InsetFig::Write and InsetFig::Latex(...).
25 * Therefore the bufferlist has to make sure that
26 * during these operations bufferlist.current()
27 * returns the buffer where the figinsets are in.
28 * This made few changes in buffer.C necessary.
30 * The above is not totally valid anymore. (Lgb)
40 #include FORMS_H_LOCATION
60 #include "support/filetools.h"
61 #include "LyXView.h" // just because of form_main
66 #include "LaTeXFeatures.h"
69 #include "lyx_gui_misc.h" // CancelCloseBoxCB
70 #include "support/FileInfo.h"
71 #include "support/lyxlib.h"
74 extern BufferView * current_view;
75 extern FL_OBJECT * figinset_canvas;
77 extern char ** environ; // is this only redundtant on linux systems? Lgb.
78 extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
79 // better for asyncron updating:
80 void PutInsetIntoInsetUpdateList(Inset * inset);
81 extern void ProhibitInput();
82 extern void AllowInput();
84 static float const DEG2PI = 57.295779513;
85 static int const figallocchunk = 32;
87 static int figinsref = 0; /* number of figures */
88 static int figarrsize = 0; /* current max number of figures */
89 static int bmpinsref = 0; /* number of bitmaps */
90 static int bmparrsize = 0; /* current max number of bitmaps */
92 struct queue_element {
93 float rx, ry; // resolution x and y
94 int ofsx, ofsy; // x and y translation
95 figdata * data; // we are doing it for this data
98 static int const MAXGS = 3; /* maximum 3 gs's at a time */
100 static Figref ** figures; /* all the figures */
101 static figdata ** bitmaps; /* all the bitmaps */
103 static queue<queue_element> gsqueue; // queue for ghostscripting
105 static int gsrunning = 0; /* currently so many gs's are running */
106 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
107 static char bittable[256]; /* bit reversion table */
109 static bool gs_color; // do we allocate colors for gs?
110 static bool color_visual; // is the visual color?
111 static bool gs_xcolor = false; // allocated extended colors
112 static unsigned long gs_pixels[128]; // allocated pixels
113 static int gs_num_pixels; // number of pixels allocated
114 static int gs_spc; // shades per color
115 static bool gs_gray; // is grayscale?
116 static int gs_allcolors; // number of all colors
118 static list<int> pidwaitlist; // pid wait list
120 //extern Colormap color_map;
128 val.foreground = BlackPixel(fl_display,
129 DefaultScreen(fl_display));
132 val.graphics_exposures = false;
133 val.line_style = LineSolid;
135 return XCreateGC(fl_display, RootWindow(fl_display, 0),
136 GCForeground | GCFunction | GCGraphicsExposures
137 | GCLineWidth | GCLineStyle , &val);
144 void addpidwait(int pid)
146 // adds pid to pid wait list
147 pidwaitlist.push_back(pid);
149 if (lyxerr.debugging()) {
150 lyxerr << "Pids to wait for: \n";
151 for (list<int>::const_iterator cit = pidwaitlist.begin();
152 cit != pidwaitlist.end(); ++cit) {
153 lyxerr << (*cit) << '\n';
160 extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
165 XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
167 if(lyxerr.debugging()) {
168 lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
169 << "] pm:[" << e->data.l[1] << "]" << endl;
172 // just kill gs, that way it will work for sure
173 // This loop looks like S**T so it probably is...
174 for (int i = 0; i < bmpinsref; ++i)
175 if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
177 figdata * p = bitmaps[i];
180 // first update p->bitmap, if necessary
181 if (p->bitmap != None
182 && p->flags > (1|8) && gs_color && p->wid) {
183 // query current colormap and re-render
184 // the pixmap with proper colors
186 XWindowAttributes wa;
187 register XImage * im;
192 int spc2 = gs_spc * gs_spc;
196 GC gc = local_gc_copy;
198 XGetWindowAttributes(fl_display,
203 if (lyxerr.debugging()) {
204 lyxerr << "Starting image translation "
207 << p->wid << "x" << p->hgh
209 << " " << XYPixmap << endl;
211 // now fork rendering process
213 if (forkstat == -1) {
215 << "Cannot fork, using slow "
216 "method for pixmap translation." << endl;
217 tmpdisp = fl_display;
218 } else if (forkstat > 0) { // parent
220 if (lyxerr.debugging()) {
221 lyxerr << "Spawned child "
224 addpidwait(forkstat);
227 tmpdisp = XOpenDisplay(XDisplayName(0));
230 im = XGetImage(tmpdisp, p->bitmap, 0, 0,
231 p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
233 if (lyxerr.debugging()) {
234 lyxerr << "Got the image" << endl;
237 if (lyxerr.debugging()) {
238 lyxerr << "Error getting the image" << endl;
243 // query current colormap
244 XColor * cmap = new XColor[gs_allcolors];
245 for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
247 XQueryColors(tmpdisp, fl_state[fl_get_vclass()].colormap, cmap, gs_allcolors);
249 XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
253 // now we process all the image
254 for (y = 0; y < p->hgh; ++y) {
255 for (int x = 0; x < wid; ++x) {
260 gs_pixels[((pc->red+6553)*
261 spc1/65535)*spc2+((pc->green+6553)*
262 spc1/65535)*gs_spc+((pc->blue+6553)*
267 // This must be correct.
269 if (lyxerr.debugging()) {
270 lyxerr << "Putting image back"
273 XPutImage(tmpdisp, p->bitmap,
275 0, 0, p->wid, p->hgh);
277 if (lyxerr.debugging()) {
278 lyxerr << "Done translation"
283 if (lyxerr.debugging()) {
284 lyxerr << "Killing gs "
287 lyx::kill(p->gspid, SIGHUP);
289 sprintf(tmp, "%s/~lyxgs%d.ps",
290 system_tempdir.c_str(),
294 XCloseDisplay(tmpdisp);
298 if (lyxerr.debugging()) {
299 lyxerr << "Killing gs "
302 lyx::kill(p->gspid, SIGHUP);
304 sprintf(tmp, "%s/~lyxgs%d.ps",
305 system_tempdir.c_str(),
315 static void AllocColors(int num)
316 // allocate color cube numxnumxnum, if possible
318 if (lyxerr.debugging()) {
319 lyxerr << "Allocating color cube " << num
320 << 'x' << num << 'x' << num << endl;
324 lyxerr << "Error allocating color colormap." << endl;
328 if (num > 5) num = 5;
330 for (int i = 0; i < num * num * num; ++i) {
331 xcol.red = 65535 * (i / (num * num)) / (num - 1);
332 xcol.green = 65535 * ((i / num) % num) / (num - 1);
333 xcol.blue = 65535 * (i % num) / (num - 1);
334 xcol.flags = DoRed | DoGreen | DoBlue;
335 if (!XAllocColor(fl_display,
336 fl_state[fl_get_vclass()].colormap, &xcol)) {
337 if (i) XFreeColors(fl_display,
338 fl_state[fl_get_vclass()].colormap,
340 if(lyxerr.debugging()) {
341 lyxerr << "Cannot allocate color cube "
344 AllocColors(num - 1);
347 gs_pixels[i] = xcol.pixel;
352 gs_num_pixels = num * num * num;
356 // allocate grayscale ramp
358 void AllocGrays(int num)
360 if (lyxerr.debugging()) {
361 lyxerr << "Allocating grayscale colormap "
366 lyxerr << "Error allocating grayscale colormap." << endl;
370 if (num > 128) num = 128;
372 for (int i = 0; i < num; ++i) {
373 xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
374 xcol.flags = DoRed | DoGreen | DoBlue;
375 if (!XAllocColor(fl_display,
376 fl_state[fl_get_vclass()].colormap, &xcol)) {
377 if (i) XFreeColors(fl_display,
378 fl_state[fl_get_vclass()].colormap,
380 if (lyxerr.debugging()) {
381 lyxerr << "Cannot allocate grayscale "
387 gs_pixels[i] = xcol.pixel;
397 bmparrsize = figarrsize = figallocchunk;
398 typedef Figref * Figref_p;
399 figures = new Figref_p[figallocchunk];
400 typedef figdata * figdata_p;
401 bitmaps = new figdata_p[figallocchunk];
404 for (unsigned int i = 0; i < 256; ++i) {
406 for (unsigned int j = 0; j < 8; ++j)
407 if (i & (1 << (7-j))) k |= 1 << j;
408 bittable[i] = char(~k);
411 fl_add_canvas_handler(figinset_canvas, ClientMessage,
412 GhostscriptMsg, current_view->owner()->getMainForm());
415 // now we have to init color_map
416 if (!color_map) color_map = DefaultColormap(fl_display,
417 DefaultScreen(fl_display));
419 // allocate color cube on pseudo-color display
422 local_gc_copy = createGC();
424 Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
425 if (lyxerr.debugging()) {
426 printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
427 vi->visualid, vi->c_class,
428 vi->bits_per_rgb, vi->map_entries);
430 color_visual = ( (vi->c_class == StaticColor) ||
431 (vi->c_class == PseudoColor) ||
432 (vi->c_class == TrueColor) ||
433 (vi->c_class == DirectColor) );
434 if ((vi->c_class & 1) == 0) return;
435 // now allocate colors
436 if (vi->c_class == GrayScale) {
437 // allocate grayscale
438 AllocGrays(vi->map_entries/2);
440 // allocate normal color
442 while (i * i * i * 2 > vi->map_entries) --i;
445 gs_allcolors = vi->map_entries;
456 lyxerr.debug() << "Unregistering figures..." << endl;
458 fl_remove_canvas_handler(figinset_canvas, ClientMessage,
463 lyxerr.debug() << "Freeing up the colors..." << endl;
464 XFreeColors(fl_display, color_map, gs_pixels,
466 /******????????????????? what's planes in this case ??????***/
472 int FindBmpIndex(figdata * tmpdata)
475 while (i < bmpinsref) {
476 if (bitmaps[i] == tmpdata) return i;
483 static void freefigdata(figdata * tmpdata)
486 if (tmpdata->ref) return;
488 if (tmpdata->gspid > 0) {
489 int pid = tmpdata->gspid;
491 // kill ghostscript and unlink it's files
493 lyx::kill(pid, SIGKILL);
494 sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
498 if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
500 int i = FindBmpIndex(tmpdata);
502 while (i < bmpinsref) {
503 bitmaps[i] = bitmaps[i + 1];
509 static void runqueue()
511 // run queued requests for ghostscript, if any
512 if (!gsrunning && gs_color && !gs_xcolor) {
513 // here alloc all colors, so that gs will use only
514 // those we allocated for it
519 while (gsrunning < MAXGS) {
520 char tbuf[384], tbuf2[80];
524 if (gsqueue.empty()) {
525 if (!gsrunning && gs_xcolor) {
526 // de-allocate rest of colors
532 queue_element * p = &gsqueue.front();
541 if (lyxerr.debugging()) {
542 lyxerr << "GS start error! Cannot fork."
545 p->data->broken = true;
546 p->data->reading = false;
549 if (pid == 0) { // child
550 char ** env, rbuf[80], gbuf[40];
552 Display * tempdisp = XOpenDisplay(XDisplayName(0));
554 // create translation file
555 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
559 ofs << "gsave clippath pathbbox grestore\n"
561 << "/ury exch def /urx exch def /lly exch def "
563 << p->data->wid / 2.0 << " "
564 << p->data->hgh / 2.0 << " translate\n"
565 << p->data->angle << " rotate\n"
566 << -(p->data->raw_wid / 2.0) << " "
567 << -(p->data->raw_hgh / 2.0) << " translate\n"
568 << p->rx / 72.0 << " " << p->ry / 72.0
570 << -p->ofsx << " " << -p->ofsy << " translate\n"
572 ofs.close(); // Don't remove this.
574 // gs process - set ghostview environment first
575 sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
576 figinset_canvas), p->data->bitmap);
578 // now set up ghostview property on a window
579 sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
580 p->data->wid, p->data->hgh);
581 // #warning BUG seems that the only bug here
582 // might be the hardcoded dpi.. Bummer!
584 if (lyxerr.debugging()) {
585 lyxerr << "Will set GHOSTVIEW property to ["
586 << tbuf << "]" << endl;
588 // wait until property is deleted if executing multiple
591 // grab server to prevent other child
592 // interfering with setting GHOSTVIEW property
593 if (lyxerr.debugging()) {
594 lyxerr << "Grabbing the server"
597 XGrabServer(tempdisp);
598 prop = XListProperties(tempdisp,
600 figinset_canvas), &nprop);
604 for (i = 0; i < nprop; ++i) {
605 char * p = XGetAtomName(tempdisp,
607 if (strcmp(p, "GHOSTVIEW") == 0) {
613 XFree(reinterpret_cast<char *>(prop)); // jc:
615 // release the server
616 XUngrabServer(tempdisp);
618 // ok, property found, we must wait until
619 // ghostscript deletes it
620 if (lyxerr.debugging()) {
621 lyxerr << "Releasing the server\n["
623 << "] GHOSTVIEW property"
624 " found. Waiting." << endl;
630 XChangeProperty(tempdisp,
631 fl_get_canvas_id(figinset_canvas),
632 XInternAtom(tempdisp, "GHOSTVIEW", false),
633 XInternAtom(tempdisp, "STRING", false),
635 reinterpret_cast<unsigned char*>(tbuf),
638 switch (p->data->flags & 3) {
639 case 0: tbuf[0] = 'H'; break; // Hidden
640 case 1: tbuf[0] = 'M'; break; // Mono
641 case 2: tbuf[0] = 'G'; break; // Gray
644 tbuf[0] = 'C'; // Color
646 tbuf[0] = 'G'; // Gray
653 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
654 DefaultScreenOfDisplay(fl_display)),
655 fl_get_pixel(FL_BLACK));
658 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
659 DefaultScreenOfDisplay(fl_display)),
660 fl_get_pixel(FL_WHITE));
666 sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
667 DefaultScreenOfDisplay(fl_display)),
670 sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
671 DefaultScreenOfDisplay(fl_display)),
676 XChangeProperty(tempdisp,
677 fl_get_canvas_id(figinset_canvas),
678 XInternAtom(tempdisp,
679 "GHOSTVIEW_COLORS", false),
680 XInternAtom(tempdisp, "STRING", false),
682 reinterpret_cast<unsigned char*>(tbuf),
684 XUngrabServer(tempdisp);
686 if (lyxerr.debugging()) {
687 lyxerr << "Releasing the server" << endl;
689 XCloseDisplay(tempdisp);
691 // set up environment
692 while (environ[ne]) ++ne;
693 typedef char * char_p;
694 env = new char_p[ne + 2];
696 memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
699 // now make gs command
701 // close(1); do NOT close. If GS writes out
702 // errors it would hang. (Matthias 290596)
703 sprintf(rbuf, "-r%gx%g", p->rx, p->ry);
704 sprintf(gbuf, "-g%dx%d", p->data->wid, p->data->hgh);
705 // now chdir into dir with .eps file, to be on the safe
707 chdir(OnlyPath(p->data->fname).c_str());
708 // make temp file name
709 sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
711 if (lyxerr.debugging()) {
712 lyxerr << "starting gs " << tbuf << " "
714 << ", pid: " << getpid() << endl;
717 int err = execlp(lyxrc->ps_command.c_str(),
718 lyxrc->ps_command.c_str(),
720 "-dNOPAUSE", "-dQUIET",
723 p->data->fname.c_str(),
724 "showpage.ps", "quit.ps", "-", 0);
725 // if we are still there, an error occurred.
726 lyxerr << "Error executing ghostscript. "
727 << "Code: " << err << endl;
728 lyxerr.debug() << "Cmd: "
732 << p->data->fname << endl;
735 // normal process (parent)
736 if (lyxerr.debugging()) {
737 lyxerr << "GS [" << pid << "] started" << endl;
740 p->data->gspid = pid;
747 static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
749 // recompute the stuff and put in the queue
753 p.rx = (float(data->raw_wid) * 72.0) / pswid;
754 p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
760 // if possible, run the queue
765 static figdata * getfigdata(int wid, int hgh, string const & fname,
766 int psx, int psy, int pswid, int pshgh,
767 int raw_wid, int raw_hgh, float angle, char flags)
769 /* first search for an exact match with fname and width/height */
771 if (fname.empty()) return 0;
774 while (i < bmpinsref) {
775 if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
776 bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
777 bitmaps[i]->angle == angle) {
783 /* not found -> create new record or return 0 if no record */
785 if (bmpinsref > bmparrsize) {
786 // allocate more space
787 bmparrsize += figallocchunk;
788 typedef figdata * figdata_p;
789 figdata ** tmp = new figdata_p[bmparrsize];
791 sizeof(figdata*) * (bmparrsize - figallocchunk));
795 figdata * p = new figdata;
796 bitmaps[bmpinsref-1] = p;
799 p->raw_wid = raw_wid;
800 p->raw_hgh = raw_hgh;
804 XWindowAttributes wa;
805 XGetWindowAttributes(fl_display, fl_get_canvas_id(
806 figinset_canvas), &wa);
808 if (lyxerr.debugging()) {
809 lyxerr << "Create pixmap disp:" << fl_display
810 << " scr:" << DefaultScreen(fl_display)
813 << " depth:" << wa.depth << endl;
821 p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
822 figinset_canvas), wid, hgh, wa.depth);
824 // initialize reading of .eps file with correct sizes and stuff
825 addwait(psx, psy, pswid, pshgh, p);
836 static void getbitmap(figdata * p)
842 static void makeupdatelist(figdata * p)
844 for (int i = 0; i < figinsref; ++i)
845 if (figures[i]->data == p) {
846 if (lyxerr.debugging()) {
847 lyxerr << "Updating inset "
851 // add inset figures[i]->inset into to_update list
852 PutInsetIntoInsetUpdateList(figures[i]->inset);
857 void sigchldchecker(pid_t pid, int * status)
859 lyxerr.debug() << "Got pid = " << pid << endl;
860 bool pid_handled = false;
861 for (int i = bmpinsref - 1; i >= 0; --i) {
862 if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
863 lyxerr.debug() << "Found pid in bitmaps" << endl;
864 // now read the file and remove it from disk
865 figdata * p = bitmaps[i];
867 if (bitmaps[i]->gsdone) *status = 0;
869 lyxerr.debug() << "GS [" << pid
870 << "] exit OK." << endl;
872 lyxerr << "GS [" << pid << "] error "
874 << WIFEXITED(*status)
875 << " " << WEXITSTATUS(*status)
876 << " S:" << WIFSIGNALED(*status)
877 << " " << WTERMSIG(*status) << endl;
880 bitmap_waiting = true;
883 // remove temporary files
885 sprintf(tmp, "%s/~lyxgs%d.ps",
886 system_tempdir.c_str(),
892 makeupdatelist(bitmaps[i]);
899 lyxerr.debug() << "Checking pid in pidwait" << endl;
900 list<int>::iterator it = find(pidwaitlist.begin(),
901 pidwaitlist.end(), pid);
902 if (it != pidwaitlist.end()) {
903 lyxerr.debug() << "Found pid in pidwait\n"
904 << "Caught child pid of recompute "
905 "routine" << pid << endl;
906 pidwaitlist.erase(it);
910 lyxerr.debug() << "waitpid error" << endl;
913 lyxerr << "The process or process group specified by "
914 "pid does not exist or is not a child of "
915 "the calling process or can never be in the "
916 "states specified by options." << endl;
919 lyxerr << "waitpid() was interrupted due to the "
920 "receipt of a signal sent by the calling "
924 lyxerr << "An invalid value was specified for "
928 lyxerr << "Unknown error from waitpid" << endl;
931 } else if (pid == 0) {
932 lyxerr << "waitpid nohang" << endl;;
934 lyxerr.debug() << "normal exit from childhandler" << endl;
939 static void getbitmaps()
941 bitmap_waiting = false;
942 for (int i = 0; i < bmpinsref; ++i)
943 if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
944 getbitmap(bitmaps[i]);
948 static void RegisterFigure(InsetFig * fi)
950 if (figinsref == 0) InitFigures();
953 if (figinsref > figarrsize) {
954 // allocate more space
955 figarrsize += figallocchunk;
956 typedef Figref * Figref_p;
957 Figref ** tmp = new Figref_p[figarrsize];
959 sizeof(Figref*)*(figarrsize-figallocchunk));
963 Figref * tmpfig = new Figref;
966 figures[figinsref-1] = tmpfig;
969 if (lyxerr.debugging()) {
970 lyxerr << "Register Figure: buffer:["
971 << current_view->buffer() << "]" << endl;
976 int FindFigIndex(Figref * tmpfig)
979 while (i < figinsref) {
980 if (figures[i] == tmpfig) return i;
987 static void UnregisterFigure(InsetFig * fi)
989 Figref * tmpfig = fi->figure;
991 if (tmpfig->data) freefigdata(tmpfig->data);
992 if (tmpfig->inset->form) {
993 if (tmpfig->inset->form->Figure->visible) {
994 fl_set_focus_object(tmpfig->inset->form->Figure,
995 tmpfig->inset->form->OkBtn);
996 fl_hide_form(tmpfig->inset->form->Figure);
998 #if FL_REVISION == 89
999 #warning Reactivate this free_form calls
1001 fl_free_form(tmpfig->inset->form->Figure);
1002 free(tmpfig->inset->form); // Why free?
1003 tmpfig->inset->form = 0;
1006 int i = FindFigIndex(tmpfig);
1008 while (i < figinsref) {
1009 figures[i] = figures[i+1];
1014 if (figinsref == 0) DoneFigures();
1018 static string NextToken(istream & is)
1026 } while (!is.eof() && !isspace(c));
1027 token.erase(token.length() - 1); // remove the isspace
1033 InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
1043 psubfigure = subfigure = false;
1044 xwid = xhgh = angle = 0;
1046 raw_wid = raw_hgh = 0;
1047 changedfname = false;
1048 RegisterFigure(this);
1052 InsetFig::~InsetFig()
1054 if (lyxerr.debugging()) {
1055 lyxerr << "Figure destructor called" << endl;
1057 UnregisterFigure(this);
1062 int InsetFig::ascent(Painter &, LyXFont const &) const
1067 int InsetFig::Ascent(LyXFont const &) const
1075 int InsetFig::descent(Painter &, LyXFont const &) const
1080 int InsetFig::Descent(LyXFont const &) const
1088 int InsetFig::width(Painter &, LyXFont const &) const
1093 int InsetFig::Width(LyXFont const &) const
1101 void InsetFig::draw(Painter & pain, LyXFont const & f,
1102 int baseline, float & x) const
1106 if (bitmap_waiting) getbitmaps();
1108 // I wish that I didn't have to use this
1109 // but the figinset code is so complicated so
1110 // I don't want to fiddle with it now.
1112 if (figure && figure->data && figure->data->bitmap &&
1113 !figure->data->reading && !figure->data->broken) {
1115 pain.pixmap(int(x + 1), baseline - hgh,
1116 wid, hgh, figure->data->bitmap);
1119 pain.rectangle(int(x), baseline - hgh - 1,
1125 pain.rectangle(x, baseline - hgh - 1, wid + 1, hgh + 1);
1127 if (figure && figure->data) {
1128 if (figure->data->broken) msg = _("[render error]");
1129 else if (figure->data->reading) msg = _("[rendering ... ]");
1131 if (fname.empty()) msg = _("[no file]");
1132 else if ((flags & 3) == 0) msg = _("[not displayed]");
1133 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1135 if (!msg) msg = _("[unknown error]");
1137 font.setFamily(LyXFont::SANS_FAMILY);
1138 font.setSize(LyXFont::SIZE_FOOTNOTE);
1139 string justname = OnlyFilename (fname);
1140 pain.text(int(x + 8), baseline - font.maxAscent() - 4,
1143 font.setSize(LyXFont::SIZE_TINY);
1144 pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
1146 x += width(pain, font); // ?
1149 void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
1151 if (bitmap_waiting) getbitmaps();
1153 // I wish that I didn't have to use this
1154 // but the figinset code is so complicated so
1155 // I don't want to fiddle with it now.
1156 unsigned long pm = scr.getForeground();
1158 if (figure && figure->data && figure->data->bitmap &&
1159 !figure->data->reading && !figure->data->broken) {
1161 XCopyArea(fl_display, figure->data->bitmap, pm, local_gc_copy,
1162 0, 0, wid, hgh, int(x+1), baseline-hgh);
1164 if (flags & 4) XDrawRectangle(fl_display, pm, local_gc_copy,
1165 int(x), baseline - hgh - 1,
1170 XDrawRectangle(fl_display, pm, local_gc_copy,
1172 baseline - hgh - 1, wid+1, hgh+1);
1173 if (figure && figure->data) {
1174 if (figure->data->broken) msg = _("[render error]");
1175 else if (figure->data->reading) msg = _("[rendering ... ]");
1177 if (fname.empty()) msg = _("[no file]");
1178 else if ((flags & 3) == 0) msg = _("[not displayed]");
1179 else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
1181 if (!msg) msg = _("[unknown error]");
1183 font.setFamily (LyXFont::SANS_FAMILY);
1184 font.setSize (LyXFont::SIZE_FOOTNOTE);
1185 string justname = OnlyFilename (fname);
1186 font.drawString(justname, pm,
1187 baseline - font.maxAscent() - 4,
1189 font.setSize (LyXFont::SIZE_TINY);
1190 font.drawText (msg, strlen(msg), pm,
1195 x += Width(font); // ?
1200 void InsetFig::Write(ostream & os)
1203 os << "Figure size " << wid << " " << hgh << "\n";
1204 if (!fname.empty()) {
1205 string buf1 = OnlyPath(owner->fileName());
1206 string fname2 = MakeRelPath(fname, buf1);
1207 os << "file " << fname2 << "\n";
1209 if (!subcaption.empty())
1210 os << "subcaption " << subcaption << "\n";
1211 if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
1212 if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
1213 if (angle != 0) os << "angle " << angle << "\n";
1214 os << "flags " << flags << "\n";
1215 if (subfigure) os << "subfigure\n";
1219 void InsetFig::Read(LyXLex & lex)
1222 bool finished = false;
1224 while (lex.IsOK() && !finished) {
1227 string const token = lex.GetString();
1228 lyxerr.debug() << "Token: " << token << endl;
1232 else if (token == "\\end_inset") {
1234 } else if (token == "file") {
1236 buf = lex.GetString();
1237 string buf1 = OnlyPath(owner->fileName());
1238 fname = MakeAbsPath(buf, buf1);
1239 changedfname = true;
1241 } else if (token == "extra") {
1243 // kept for backwards compability. Delete in 0.13.x
1244 } else if (token == "subcaption") {
1246 subcaption = lex.GetString();
1247 } else if (token == "label") {
1249 // kept for backwards compability. Delete in 0.13.x
1250 } else if (token == "angle") {
1252 angle = lex.GetFloat();
1253 } else if (token == "size") {
1255 wid = lex.GetInteger();
1257 hgh = lex.GetInteger();
1258 } else if (token == "flags") {
1260 flags = pflags = lex.GetInteger();
1261 } else if (token == "subfigure") {
1262 subfigure = psubfigure = true;
1263 } else if (token == "width") {
1266 typ = lex.GetInteger();
1268 xwid = lex.GetFloat();
1270 case DEF: wtype = DEF; break;
1271 case CM: wtype = CM; break;
1272 case IN: wtype = IN; break;
1273 case PER_PAGE: wtype = PER_PAGE; break;
1274 case PER_COL: wtype = PER_COL; break;
1276 lyxerr.debug() << "Unknown type!" << endl;
1280 } else if (token == "height") {
1283 typ = lex.GetInteger();
1285 xhgh = lex.GetFloat();
1287 case DEF: htype = DEF; break;
1288 case CM: htype = CM; break;
1289 case IN: htype = IN; break;
1290 case PER_PAGE: htype = PER_PAGE; break;
1292 lyxerr.debug() << "Unknown type!" << endl;
1303 int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
1306 if (!cmd.empty()) os << cmd << " ";
1311 int InsetFig::Latex(string & file, signed char /* fragile*/ )
1319 int InsetFig::Linuxdoc(string &/*file*/)
1325 int InsetFig::DocBook(string & file)
1327 string figurename = fname;
1329 if(suffixIs(figurename, ".eps"))
1330 figurename.erase(fname.length() - 5);
1332 file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
1337 void InsetFig::Validate(LaTeXFeatures & features) const
1339 features.graphics = true;
1340 if (subfigure) features.subfigure = true;
1344 unsigned char InsetFig::Editable() const
1350 bool InsetFig::Deletable() const
1356 void InsetFig::Edit(int, int)
1358 lyxerr.debug() << "Editing InsetFig." << endl;
1361 // We should have RO-versions of the form instead.
1362 // The actual prevention of altering a readonly doc
1363 // is done in CallbackFig()
1364 if(current_view->buffer()->isReadonly())
1365 WarnReadonly(current_view->buffer()->fileName());
1368 form = create_form_Figure();
1369 fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
1370 fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
1371 fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
1372 fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
1375 if (form->Figure->visible) {
1376 fl_raise_form(form->Figure);
1378 fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
1379 FL_FULLBORDER, _("Figure"));
1384 Inset * InsetFig::Clone() const
1386 InsetFig * tmp = new InsetFig(100, 100, owner);
1388 if (lyxerr.debugging()) {
1389 lyxerr << "Clone Figure: buffer:["
1390 << current_view->buffer()
1391 << "], cbuffer:[xx]" << endl;
1396 tmp->raw_wid = raw_wid;
1397 tmp->raw_hgh = raw_hgh;
1402 tmp->pflags = pflags;
1403 tmp->subfigure = subfigure;
1404 tmp->psubfigure = psubfigure;
1412 if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
1413 // do not display if there is
1414 // "do not display" chosen (Matthias 260696)
1415 tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
1416 pswid, pshgh, raw_wid, raw_hgh,
1417 angle, flags & (3|8));
1418 } else tmp->figure->data = 0;
1419 tmp->subcaption = subcaption;
1420 tmp->changedfname = false;
1427 Inset::Code InsetFig::LyxCode() const
1429 return Inset::GRAPHICS_CODE;
1433 void InsetFig::Regenerate()
1436 string resizeW, resizeH;
1437 string rotate, recmd;
1439 if (fname.empty()) {
1440 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1441 cmd += _("empty figure path");
1446 string buf1 = OnlyPath(owner->fileName());
1447 string fname2 = MakeRelPath(fname, buf1);
1449 string gcmd = "\\includegraphics{" + fname2 + '}';
1454 case CM:{// \resizebox*{h-length}{v-length}{text}
1456 sprintf(buf, "%g", xwid); // should find better
1463 sprintf(buf, "%g", xwid);
1470 sprintf(buf, "%g", xwid/100);
1472 resizeW += "\\textwidth";
1477 sprintf(buf, "%g", xwid/100);
1479 resizeW += "\\columnwidth";
1489 sprintf(buf, "%g", xhgh);
1496 sprintf(buf, "%g", xhgh);
1503 sprintf(buf, "%g", xhgh/100);
1505 resizeH += "\\textheight";
1509 // Doesn't occur; case exists to suppress compiler warnings.
1514 if (!resizeW.empty() || !resizeH.empty()) {
1515 recmd = "\\resizebox*{";
1516 if (!resizeW.empty())
1521 if (!resizeH.empty())
1531 sprintf(buf, "%g", angle);
1532 // \rotatebox{angle}{text}
1533 rotate = "\\rotatebox{";
1541 if (!rotate.empty()) cmdbuf += '}';
1542 if (!recmd.empty()) cmdbuf += '}';
1544 if (!subcaption.empty())
1545 cmdbuf = "\\subfigure[" + subcaption +
1546 "]{" + cmdbuf + "}";
1548 cmdbuf = "\\subfigure{" + cmdbuf + "}";
1555 void InsetFig::TempRegenerate()
1558 string resizeW, resizeH;
1559 string rotate, recmd;
1561 char const * tfname = fl_get_input(form->EpsFile);
1562 string tsubcap = fl_get_input(form->Subcaption);
1563 float tangle = atof(fl_get_input(form->Angle));
1564 float txwid = atof(fl_get_input(form->Width));
1565 float txhgh = atof(fl_get_input(form->Height));
1567 if (!tfname || !*tfname) {
1568 cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
1569 cmd += _("empty figure path");
1574 string buf1 = OnlyPath(owner->fileName());
1575 string fname2 = MakeRelPath(tfname, buf1);
1576 // \includegraphics*[<llx,lly>][<urx,ury>]{file}
1577 string gcmd = "\\includegraphics{" + fname2 + '}';
1582 case CM: {// \resizebox*{h-length}{v-length}{text}
1584 sprintf(buf, "%g", txwid); // should find better
1591 sprintf(buf, "%g", txwid);
1598 sprintf(buf, "%g", txwid/100);
1600 resizeW += "\\textwidth";
1605 sprintf(buf, "%g", txwid/100);
1607 resizeW += "\\columnwidth";
1617 sprintf(buf, "%g", txhgh);
1624 sprintf(buf, "%g", txhgh);
1631 sprintf(buf, "%g", txhgh/100);
1633 resizeH += "\\textheight";
1637 // Doesn't occur; case exists to suppress compiler warnings.
1642 // \resizebox*{h-length}{v-length}{text}
1643 if (!resizeW.empty() || !resizeH.empty()) {
1644 recmd = "\\resizebox*{";
1645 if (!resizeW.empty())
1650 if (!resizeH.empty())
1659 sprintf(buf, "%g", tangle);
1660 // \rotatebox{angle}{text}
1661 rotate = "\\rotatebox{";
1669 if (!rotate.empty()) cmdbuf += '}';
1670 if (!recmd.empty()) cmdbuf += '}';
1671 if (psubfigure && !tsubcap.empty()) {
1672 cmdbuf = string("\\subfigure{") + tsubcap
1673 + string("}{") + cmdbuf + "}";
1678 void InsetFig::Recompute()
1680 bool changed = changedfname;
1681 int newx, newy, nraw_x, nraw_y;
1683 if (changed) GetPSSizes();
1685 float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
1686 float cos_a = cos (angle / DEG2PI);
1687 int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
1688 int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
1690 /* now recompute wid and hgh, and if that is changed, set changed */
1691 /* this depends on chosen size of the picture and its bbox */
1692 // This will be redone in 0.13 ... (hen)
1693 if (!fname.empty()) {
1694 // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
1702 newx = int(28.346 * xwid);
1705 newx = int(72 * xwid);
1707 case PER_PAGE: /* % of page */
1708 newx = int(5.95 * xwid);
1710 case PER_COL: /* % of col */
1711 newx = int(2.975 * xwid);
1715 if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
1719 //lyxerr << "This should not happen!" << endl;
1722 newy = int(28.346 * xhgh);
1725 newy = int(72 * xhgh);
1727 case PER_PAGE: /* % of page */
1728 newy = int(8.42 * xhgh);
1731 // Doesn't occur; case exists to suppress
1732 // compiler warnings.
1735 if (htype && !wtype && frame_hgh)
1736 newx = newy*frame_wid/frame_hgh;
1745 nraw_x = int((1.0 * pswid * newx)/frame_wid);
1750 nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
1752 // cannot be zero, actually, set it to some minimum, so its clickable
1753 if (newx < 5) newx = 5;
1754 if (newy < 5) newy = 5;
1756 if (newx != wid || newy != hgh ||
1757 nraw_x != raw_wid || nraw_y != raw_hgh ||
1758 flags != pflags || subfigure != psubfigure)
1766 subfigure = psubfigure;
1769 figdata * pf = figure->data;
1772 if (!fname.empty() && (flags & 3)
1773 && !lyxrc->ps_command.empty()) {
1774 // do not display if there is "do not display"
1775 // chosen (Matthias 260696)
1776 figure->data = getfigdata(wid, hgh, fname,
1777 psx, psy, pswid, pshgh,
1779 angle, flags & (3|8));
1780 } else figure->data = 0;
1782 // free the old data
1783 if (pf) freefigdata(pf);
1786 changedfname = false;
1790 void InsetFig::GetPSSizes()
1792 /* get %%BoundingBox: from postscript file */
1794 /* defaults to associated size
1795 * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
1802 if (fname.empty()) return;
1804 ifstream ifs(fname.c_str());
1806 if (!ifs) return; // file not found !!!!
1808 /* defaults to A4 page */
1814 char lastchar = 0; ifs.get(lastchar);
1816 char c = 0; ifs.get(c);
1818 lyxerr.debug() << "End of (E)PS file reached and"
1819 " no BoundingBox!" << endl;
1822 if (c == '%' && lastchar == '%') {
1824 if (p.empty()) break;
1825 // we should not use this, with it we cannot
1826 // discover bounding box and end of file.
1827 //if (strcmp(p, "EndComments") == 0) break;
1828 lyxerr.debug() << "Token: `" << p << "'" << endl;
1829 if (p == "BoundingBox:") {
1830 float fpsx, fpsy, fpswid, fpshgh;
1831 if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
1834 pswid = int(fpswid);
1835 pshgh = int(fpshgh);
1837 if (lyxerr.debugging()) {
1838 lyxerr << "%%%%BoundingBox:"
1856 void InsetFig::CallbackFig(long arg)
1861 if (lyxerr.debugging()) {
1862 lyxerr << "Figure callback, arg " << arg << endl;
1868 case 12: /* width type */
1875 fl_deactivate_object(form->Width);
1880 fl_activate_object(form->Width);
1885 fl_activate_object(form->Width);
1890 fl_activate_object(form->Width);
1895 fl_activate_object(form->Width);
1898 lyxerr.debug() << "Unknown type!" << endl;
1905 case 22: /* height type */
1911 fl_deactivate_object(form->Height);
1916 fl_activate_object(form->Height);
1921 fl_activate_object(form->Height);
1926 fl_activate_object(form->Height);
1929 lyxerr.debug() << "Unknown type!" << endl;
1935 pflags = pflags & ~3; /* wysiwyg0 */
1938 pflags = (pflags & ~3) | 1; /* wysiwyg1 */
1941 pflags = (pflags & ~3) | 2; /* wysiwyg2 */
1944 pflags = (pflags & ~3) | 3; /* wysiwyg3 */
1947 pflags ^= 4; /* frame */
1950 pflags ^= 8; /* do translations */
1953 psubfigure = !psubfigure; /* This is a subfigure */
1956 regen = true; /* regenerate command */
1958 case 0: /* browse file */
1962 case 1: /* preview */
1963 p = fl_get_input(form->EpsFile);
1967 case 8: /* ok (apply and close) */
1968 if(!current_view->buffer()->isReadonly()) {
1971 xwid = atof(fl_get_input(form->Width));
1972 xhgh = atof(fl_get_input(form->Height));
1973 angle = atof(fl_get_input(form->Angle));
1974 p = fl_get_input(form->EpsFile);
1976 string buf1 = OnlyPath(owner->fileName());
1977 fname = MakeAbsPath(p, buf1);
1978 changedfname = true;
1980 if (!fname.empty()) {
1981 changedfname = true;
1985 subcaption = fl_get_input(form->Subcaption);
1989 /* now update inset */
1990 if (lyxerr.debugging()) {
1991 lyxerr << "Update: ["
1992 << wid << 'x' << hgh << ']' << endl;
1994 UpdateInset(current_view, this);
1996 fl_set_focus_object(form->Figure, form->OkBtn);
1997 fl_hide_form(form->Figure);
1998 #if FL_REVISION == 89
1999 #warning Reactivate this free_form calls
2001 fl_free_form(form->Figure);
2002 free(form); // Why free?
2008 // The user has already been informed about RO in ::Edit
2009 if(arg == 7) // if 'Apply'
2012 case 9: /* cancel = restore and close */
2013 fl_set_focus_object(form->Figure, form->OkBtn);
2014 fl_hide_form(form->Figure);
2015 #if FL_REVISION == 89
2016 #warning Reactivate this free_form calls
2017 #warning Jug, is this still a problem?
2019 fl_free_form(form->Figure);
2020 free(form); // Why free?
2026 if (regen) TempRegenerate();
2030 inline void DisableFigurePanel(FD_Figure * const form)
2032 fl_deactivate_object(form->EpsFile);
2033 fl_deactivate_object(form->Browse);
2034 fl_deactivate_object(form->Width);
2035 fl_deactivate_object(form->Height);
2036 fl_deactivate_object(form->Frame);
2037 fl_deactivate_object(form->Translations);
2038 fl_deactivate_object(form->Angle);
2039 fl_deactivate_object(form->HeightGrp);
2040 fl_deactivate_object(form->page2);
2041 fl_deactivate_object(form->Default2);
2042 fl_deactivate_object(form->cm2);
2043 fl_deactivate_object(form->in2);
2044 fl_deactivate_object(form->HeightLabel);
2045 fl_deactivate_object(form->WidthLabel);
2046 fl_deactivate_object(form->DisplayGrp);
2047 fl_deactivate_object(form->Wysiwyg3);
2048 fl_deactivate_object(form->Wysiwyg0);
2049 fl_deactivate_object(form->Wysiwyg2);
2050 fl_deactivate_object(form->Wysiwyg1);
2051 fl_deactivate_object(form->WidthGrp);
2052 fl_deactivate_object(form->Default1);
2053 fl_deactivate_object(form->cm1);
2054 fl_deactivate_object(form->in1);
2055 fl_deactivate_object(form->page1);
2056 fl_deactivate_object(form->column1);
2057 fl_deactivate_object(form->Subcaption);
2058 fl_deactivate_object(form->Subfigure);
2059 fl_deactivate_object (form->OkBtn);
2060 fl_deactivate_object (form->ApplyBtn);
2061 fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
2062 fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
2066 inline void EnableFigurePanel(FD_Figure * const form)
2068 fl_activate_object(form->EpsFile);
2069 fl_activate_object(form->Browse);
2070 fl_activate_object(form->Width);
2071 fl_activate_object(form->Height);
2072 fl_activate_object(form->Frame);
2073 fl_activate_object(form->Translations);
2074 fl_activate_object(form->Angle);
2075 fl_activate_object(form->HeightGrp);
2076 fl_activate_object(form->page2);
2077 fl_activate_object(form->Default2);
2078 fl_activate_object(form->cm2);
2079 fl_activate_object(form->in2);
2080 fl_activate_object(form->HeightLabel);
2081 fl_activate_object(form->WidthLabel);
2082 fl_activate_object(form->DisplayGrp);
2083 fl_activate_object(form->Wysiwyg3);
2084 fl_activate_object(form->Wysiwyg0);
2085 fl_activate_object(form->Wysiwyg2);
2086 fl_activate_object(form->Wysiwyg1);
2087 fl_activate_object(form->WidthGrp);
2088 fl_activate_object(form->Default1);
2089 fl_activate_object(form->cm1);
2090 fl_activate_object(form->in1);
2091 fl_activate_object(form->page1);
2092 fl_activate_object(form->column1);
2093 fl_activate_object(form->Subcaption);
2094 fl_activate_object(form->Subfigure);
2095 fl_activate_object (form->OkBtn);
2096 fl_activate_object (form->ApplyBtn);
2097 fl_set_object_lcol (form->OkBtn, FL_BLACK);
2098 fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
2102 void InsetFig::RestoreForm()
2106 EnableFigurePanel(form);
2109 fl_set_button(form->Default1, (wtype == 0));
2110 fl_set_button(form->cm1, (wtype == 1));
2111 fl_set_button(form->in1, (wtype == 2));
2112 fl_set_button(form->page1, (wtype == 3));
2113 fl_set_button(form->column1, (wtype == 4));
2115 fl_deactivate_object(form->Width);
2117 fl_activate_object(form->Width);
2120 // enable and disable should be put here.
2122 fl_set_button(form->Default2, (htype == 0));
2123 fl_set_button(form->cm2, (htype == 1));
2124 fl_set_button(form->in2, (htype == 2));
2125 fl_set_button(form->page2, (htype == 3));
2126 // enable and disable should be put here.
2128 fl_deactivate_object(form->Height);
2130 fl_activate_object(form->Height);
2133 int pflags = flags & 3;
2134 fl_set_button(form->Wysiwyg0, (pflags == 0));
2135 fl_set_button(form->Wysiwyg1, (pflags == 1));
2136 fl_set_button(form->Wysiwyg2, (pflags == 2));
2137 fl_set_button(form->Wysiwyg3, (pflags == 3));
2138 fl_set_button(form->Frame, ((flags & 4) != 0));
2139 fl_set_button(form->Translations, ((flags & 8) != 0));
2140 fl_set_button(form->Subfigure, (subfigure != 0));
2142 psubfigure = subfigure;
2143 sprintf(buf, "%g", xwid);
2144 fl_set_input(form->Width, buf);
2145 sprintf(buf, "%g", xhgh);
2146 fl_set_input(form->Height, buf);
2147 sprintf(buf, "%g", angle);
2148 fl_set_input(form->Angle, buf);
2149 if (!fname.empty()){
2150 string buf1 = OnlyPath(owner->fileName());
2151 string fname2 = MakeRelPath(fname, buf1);
2152 fl_set_input(form->EpsFile, fname2.c_str());
2154 else fl_set_input(form->EpsFile, "");
2155 fl_set_input(form->Subcaption, subcaption.c_str());
2156 if(current_view->buffer()->isReadonly())
2157 DisableFigurePanel(form);
2163 void InsetFig::Preview(char const * p)
2168 lyxerr << "Cannot fork process!" << endl;
2173 return; // parent process
2176 string buf1 = OnlyPath(owner->fileName());
2177 string buf2 = MakeAbsPath(p, buf1);
2179 lyxerr << "Error during rendering "
2180 << execlp(lyxrc->view_pspic_command.c_str(),
2181 lyxrc->view_pspic_command.c_str(),
2188 void InsetFig::BrowseFile()
2190 static string current_figure_path;
2191 static int once = 0;
2194 if (lyxerr.debugging()) {
2195 lyxerr << "Filename: "
2196 << owner->fileName() << endl;
2198 string p = fl_get_input(form->EpsFile);
2200 string buf = MakeAbsPath(owner->fileName());
2201 string buf2 = OnlyPath(buf);
2203 buf = MakeAbsPath(p, buf2);
2204 buf = OnlyPath(buf);
2206 buf = OnlyPath(owner->fileName().c_str());
2209 // Does user clipart directory exist?
2210 string bufclip = AddName (user_lyxdir, "clipart");
2211 FileInfo fileInfo(bufclip);
2212 if (!(fileInfo.isOK() && fileInfo.isDir()))
2213 // No - bail out to system clipart directory
2214 bufclip = AddName (system_lyxdir, "clipart");
2217 fileDlg.SetButton(0, _("Clipart"), bufclip);
2218 fileDlg.SetButton(1, _("Document"), buf);
2224 p = fileDlg.Select(_("EPS Figure"),
2225 current_figure_path,
2228 p = fileDlg.Select(_("EPS Figure"), buf,
2233 if (p.empty()) return;
2235 buf = MakeRelPath(p, buf2);
2236 current_figure_path = OnlyPath(p);
2239 if (contains(p, "#") || contains(p, "~") || contains(p, "$")
2240 || contains(p, "%") || contains(p, " "))
2242 WriteAlert(_("Filename can't contain any "
2243 "of these characters:"),
2244 // xgettext:no-c-format
2245 _("space, '#', '~', '$' or '%'."));
2250 if (form) fl_set_input(form->EpsFile, buf.c_str());
2254 void GraphicsCB(FL_OBJECT * obj, long arg)
2256 /* obj->form contains the form */
2258 if (lyxerr.debugging()) {
2259 lyxerr << "GraphicsCB callback: " << arg << endl;
2262 /* find inset we were reacting to */
2263 for (int i = 0; i < figinsref; ++i)
2264 if (figures[i]->inset->form && figures[i]->inset->form->Figure
2267 if (lyxerr.debugging()) {
2268 lyxerr << "Calling back figure " << i << endl;
2270 figures[i]->inset->CallbackFig(arg);
2276 void HideFiguresPopups()
2278 for (int i = 0; i < figinsref; ++i)
2279 if (figures[i]->inset->form
2280 && figures[i]->inset->form->Figure->visible) {
2281 if (lyxerr.debugging()) {
2282 lyxerr << "Hiding figure " << i << endl;
2284 // hide and free the form
2285 figures[i]->inset->CallbackFig(9);