]> git.lyx.org Git - features.git/blobdiff - src/insets/figinset.C
apply the ostream changes to mathed, some other small related things
[features.git] / src / insets / figinset.C
index 41f482b30123c621080b0066dc1ef1d5a728a73a..490a8b0fc1c8f3480fa3b5a091836e891632ce87 100644 (file)
@@ -2,7 +2,6 @@
  *     figinset.C - part of LyX project
  */
 
-extern int     reverse_video;
 extern long int background_pixels;
 
 /*  Rework of path-handling (Matthias 04.07.1996 )
@@ -40,8 +39,15 @@ extern long int background_pixels;
 #include <cctype>
 #include <cmath>
 #include <fstream>
+#include <queue>
+#include <list>
+#include <algorithm>
 using std::ofstream;
 using std::ifstream;
+using std::queue;
+using std::list;
+using std::find;
+using std::flush;
 
 #include "figinset.h"
 #include "lyx.h"
@@ -51,30 +57,19 @@ using std::ifstream;
 #include "support/filetools.h"
 #include "LyXView.h" // just because of form_main
 #include "debug.h"
-#include "lyxdraw.h"
 #include "LaTeXFeatures.h"
 #include "lyxrc.h"
 #include "gettext.h"
 #include "lyx_gui_misc.h" // CancelCloseBoxCB
 #include "support/FileInfo.h"
+#include "support/lyxlib.h"
+#include "Painter.h"
 
 extern BufferView * current_view;
-#if 0
-static volatile bool alarmed;
-#endif
 extern FL_OBJECT * figinset_canvas;
-#if 0
-//inline
-extern "C" void waitalarm(int)
-{
-       alarmed = true;
-}
-#endif
 
 extern char ** environ; // is this only redundtant on linux systems? Lgb.
-extern void UpdateInset(Inset * inset, bool mark_dirty = true);
-// better for asyncron updating:
-void PutInsetIntoInsetUpdateList(Inset * inset);
+
 extern void ProhibitInput();
 extern void AllowInput();
 
@@ -86,23 +81,19 @@ static int figarrsize = 0;  /* current max number of figures */
 static int bmpinsref = 0;      /* number of bitmaps */
 static int bmparrsize = 0;     /* current max number of bitmaps */
 
-struct queue {
-       float rx, ry;           /* resolution x and y */
-       int ofsx, ofsy;         /* x and y translation */
-       figdata * data;         /* we are doing it for this data */
-       queue * next;           /* next item in queue */
-};
-
-struct pidwait {
-       int pid;                /* pid to wait for */
-       pidwait * next; /* next */
+struct queue_element {
+       float rx, ry;          // resolution x and y
+       int ofsx, ofsy;        // x and y translation
+       figdata * data;        // we are doing it for this data
 };
 
 static int const MAXGS = 3;                    /* maximum 3 gs's at a time */
 
 static Figref ** figures;      /* all the figures */
 static figdata ** bitmaps;     /* all the bitmaps */
-static queue * gsqueue = 0;    /* queue for ghostscripting */
+
+static queue<queue_element> gsqueue; // queue for ghostscripting
+
 static int gsrunning = 0;      /* currently so many gs's are running */
 static bool bitmap_waiting = false; /* bitmaps are waiting finished */
 static char bittable[256];     /* bit reversion table */
@@ -116,26 +107,44 @@ static int gs_spc;                        // shades per color
 static bool gs_gray;                   // is grayscale?
 static int gs_allcolors;               // number of all colors
 
-static pidwait * pw = 0;               // pid wait list
+static list<int> pidwaitlist; // pid wait list
 
+//extern Colormap color_map;
+
+
+
+static
+GC createGC()
+{
+       XGCValues val;
+       val.foreground = BlackPixel(fl_display, 
+                                   DefaultScreen(fl_display));
+       
+       val.function=GXcopy;
+       val.graphics_exposures = false;
+       val.line_style = LineSolid;
+       val.line_width = 0;
+       return XCreateGC(fl_display, RootWindow(fl_display, 0), 
+                        GCForeground | GCFunction | GCGraphicsExposures
+                        | GCLineWidth | GCLineStyle , &val);
+}
+
+static
+GC local_gc_copy;
 
-extern Colormap color_map;
 
 void addpidwait(int pid)
 {
        // adds pid to pid wait list
-       register pidwait * p = new pidwait;
-
-       p->pid = pid;
-       p->next = pw;
-       pw = p;
+       pidwaitlist.push_back(pid);
 
        if (lyxerr.debugging()) {
-               lyxerr << "Pids to wait for: " << p->pid << endl;
-               while (p->next) {
-                       p = p->next;
-                       lyxerr << p->pid << endl;
+               lyxerr << "Pids to wait for: \n";
+               for (list<int>::const_iterator cit = pidwaitlist.begin();
+                    cit != pidwaitlist.end(); ++cit) {
+                       lyxerr << (*cit) << '\n';
                }
+               lyxerr << flush;
        }
 }
 
@@ -168,11 +177,15 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                //XColor * cmap;
                                XWindowAttributes wa;
                                register XImage * im;
-                               int i, y, wid1, spc1 = gs_spc-1,
-                                       spc2 = gs_spc * gs_spc, wid = p->wid,
-                                       forkstat;
+                               int i;
+                               int y;
+                               int wid1;
+                               int spc1 = gs_spc-1;
+                               int spc2 = gs_spc * gs_spc;
+                               int wid = p->wid;
+                               int forkstat;
                                Display * tmpdisp;
-                               GC gc = getGC(gc_copy);
+                               GC gc = local_gc_copy;
 
                                XGetWindowAttributes(fl_display,
                                                     fl_get_canvas_id(
@@ -194,15 +207,15 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                                << "Cannot fork, using slow "
                                                "method for pixmap translation." << endl;
                                        tmpdisp = fl_display;
-                               } else if (forkstat > 0) {
+                               } else if (forkstat > 0) { // parent
                                        // register child
                                        if (lyxerr.debugging()) {
                                                lyxerr << "Spawned child "
                                                       << forkstat << endl;
                                        }
                                        addpidwait(forkstat);
-                                       break; // in parent process
-                               } else {
+                                       break;
+                               } else {  // child
                                        tmpdisp = XOpenDisplay(XDisplayName(0));
                                        XFlush(tmpdisp);
                                }
@@ -220,10 +233,12 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                }
                                {
                                // query current colormap
-                               //cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
                                        XColor * cmap = new XColor[gs_allcolors];
                                        for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
-                                       XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
+                                       XQueryColors(tmpdisp,
+                                                    fl_state[fl_get_vclass()]
+                                                    .colormap, cmap,
+                                                    gs_allcolors);
                                        XFlush(tmpdisp);
                                        wid1 = p->wid - 1;
                                // now we process all the image
@@ -260,7 +275,7 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                        lyxerr << "Killing gs " 
                                               << p->gspid << endl;
                                }
-                               kill(p->gspid, SIGHUP);
+                               lyx::kill(p->gspid, SIGHUP);
 
                                sprintf(tmp, "%s/~lyxgs%d.ps",
                                        system_tempdir.c_str(), 
@@ -275,7 +290,7 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                        lyxerr << "Killing gs " 
                                               << p->gspid << endl;
                                }
-                               kill(p->gspid, SIGHUP);
+                               lyx::kill(p->gspid, SIGHUP);
 
                                sprintf(tmp, "%s/~lyxgs%d.ps", 
                                        system_tempdir.c_str(),
@@ -288,7 +303,8 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
 }
 
 
-static void AllocColors(int num)
+static
+void AllocColors(int num)
 // allocate color cube numxnumxnum, if possible
 {
        if (lyxerr.debugging()) {
@@ -308,8 +324,10 @@ static void AllocColors(int num)
                xcol.green = 65535 * ((i / num) % num) / (num - 1);
                xcol.blue = 65535 * (i % num) / (num - 1);
                xcol.flags = DoRed | DoGreen | DoBlue;
-               if (!XAllocColor(fl_display, color_map, &xcol)) {
-                       if (i) XFreeColors(fl_display, color_map,
+               if (!XAllocColor(fl_display,
+                                fl_state[fl_get_vclass()].colormap, &xcol)) {
+                       if (i) XFreeColors(fl_display,
+                                          fl_state[fl_get_vclass()].colormap,
                                           gs_pixels, i, 0);
                        if(lyxerr.debugging()) {
                                lyxerr << "Cannot allocate color cube "
@@ -346,8 +364,10 @@ void AllocGrays(int num)
        for (int i = 0; i < num; ++i) {
                xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
                xcol.flags = DoRed | DoGreen | DoBlue;
-               if (!XAllocColor(fl_display, color_map, &xcol)) {
-                       if (i) XFreeColors(fl_display, color_map,
+               if (!XAllocColor(fl_display,
+                                fl_state[fl_get_vclass()].colormap, &xcol)) {
+                       if (i) XFreeColors(fl_display,
+                                          fl_state[fl_get_vclass()].colormap,
                                           gs_pixels, i, 0);
                        if (lyxerr.debugging()) {
                                lyxerr << "Cannot allocate grayscale " 
@@ -367,10 +387,10 @@ void AllocGrays(int num)
 void InitFigures()
 {
        bmparrsize = figarrsize = figallocchunk;
-       figures = static_cast<Figref**>
-               (malloc(sizeof(Figref*) * figallocchunk));
-       bitmaps = static_cast<figdata**>
-               (malloc(sizeof(figdata*) * figallocchunk));
+       typedef Figref * Figref_p;
+       figures = new Figref_p[figallocchunk];
+       typedef figdata * figdata_p;
+       bitmaps = new figdata_p[figallocchunk];
 
        unsigned int k;
        for (unsigned int i = 0; i < 256; ++i) {
@@ -383,12 +403,10 @@ void InitFigures()
        fl_add_canvas_handler(figinset_canvas, ClientMessage,
                              GhostscriptMsg, current_view->owner()->getMainForm());
 
-       // now we have to init color_map
-       if (!color_map) color_map = DefaultColormap(fl_display,
-                                                   DefaultScreen(fl_display));
        // allocate color cube on pseudo-color display
        // first get visual
        gs_color = false;
+       local_gc_copy = createGC();
 
        Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
        if (lyxerr.debugging()) {
@@ -417,8 +435,8 @@ void InitFigures()
 
 void DoneFigures()
 {
-       free(figures);
-       free(bitmaps);
+       delete[] figures;
+       delete[] bitmaps;
        figarrsize = 0;
        bmparrsize = 0;
 
@@ -426,13 +444,6 @@ void DoneFigures()
 
        fl_remove_canvas_handler(figinset_canvas, ClientMessage,
                                 GhostscriptMsg);
-
-       if (gs_color) {
-               lyxerr.debug() << "Freeing up the colors..." << endl;
-               XFreeColors(fl_display, color_map, gs_pixels,
-                           gs_num_pixels, 0);
-               /******????????????????? what's planes in this case ??????***/
-       }
 }
 
 
@@ -447,20 +458,8 @@ int FindBmpIndex(figdata * tmpdata)
 }
 
 
-static void chpixmap(Pixmap, int, int)
-{
-#if 0
-       Display * tempdisp = XOpenDisplay(XDisplayName(0));
-
-       // here read the pixmap and change all colors to those we
-       // have allocated
-
-       XCloseDisplay(tempdisp);
-#endif
-}
-
-
-static void freefigdata(figdata * tmpdata)
+static
+void freefigdata(figdata * tmpdata)
 {
        tmpdata->ref--;
        if (tmpdata->ref) return;
@@ -468,11 +467,9 @@ static void freefigdata(figdata * tmpdata)
        if (tmpdata->gspid > 0) {
                int pid = tmpdata->gspid;
                char buf[128];
-               // change Pixmap according to our allocated colormap
-               chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
                // kill ghostscript and unlink it's files
                tmpdata->gspid = -1;
-               kill(pid, SIGKILL);
+               lyx::kill(pid, SIGKILL);
                sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
                unlink(buf);
        }
@@ -488,7 +485,8 @@ static void freefigdata(figdata * tmpdata)
 }
 
 
-static void runqueue()
+static
+void runqueue()
 {
        // run queued requests for ghostscript, if any
        if (!gsrunning && gs_color && !gs_xcolor) {
@@ -503,7 +501,7 @@ static void runqueue()
                Atom * prop;
                int nprop, i;
 
-               if (!gsqueue) {
+               if (gsqueue.empty()) {
                        if (!gsrunning && gs_xcolor) {
                                // de-allocate rest of colors
                                // *****
@@ -511,10 +509,9 @@ static void runqueue()
                        }
                        return;
                }
-               queue * p = gsqueue;
-
+               queue_element * p = &gsqueue.front();
                if (!p->data) {
-                       delete p;
+                       gsqueue.pop();
                        continue;
                }
 
@@ -606,17 +603,8 @@ static void runqueue()
                                               << "] GHOSTVIEW property"
                                                " found. Waiting." << endl;
                                }
-#if 0
-#ifdef WITH_WARNINGS
-#warning What is this doing? (wouldn't a sleep(1); work too?')
-#endif
-                               alarm(1);
-                               alarmed = false;
-                               signal(SIGALRM, waitalarm);
-                               while (!alarmed) pause();
-#else
+
                                sleep(1);
-#endif
                        }
 
                        XChangeProperty(tempdisp, 
@@ -639,15 +627,9 @@ static void runqueue()
                                break;
                        }
 
-                       if (reverse_video) {
-                               sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
-                                       DefaultScreenOfDisplay(fl_display)),
-                                       background_pixels);
-                       } else {
-                               sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
-                                       DefaultScreenOfDisplay(fl_display)),
-                                       background_pixels);
-                       }
+                       sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
+                               DefaultScreenOfDisplay(fl_display)),
+                               fl_get_pixel(FL_WHITE));
 
                        XChangeProperty(tempdisp, 
                                        fl_get_canvas_id(figinset_canvas),
@@ -666,8 +648,8 @@ static void runqueue()
 
                        // set up environment
                        while (environ[ne]) ++ne;
-                       env = static_cast<char **>
-                               (malloc(sizeof(char*) * (ne + 2)));
+                       typedef char * char_p;
+                       env = new char_p[ne + 2];
                        env[0] = tbuf2;
                        memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
                        environ = env;
@@ -712,40 +694,35 @@ static void runqueue()
                if (lyxerr.debugging()) {
                        lyxerr << "GS ["  << pid << "] started" << endl;
                }
-               gsqueue = gsqueue->next;
-               gsrunning++;
+
                p->data->gspid = pid;
-               delete p;
+               ++gsrunning;
+               gsqueue.pop();
        }
 }
 
 
-static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
+static
+void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
 {
        // recompute the stuff and put in the queue
-       queue * p = new queue;
-       p->ofsx = psx;
-       p->ofsy = psy;
-       p->rx = (float(data->raw_wid) * 72.0) / pswid;
-       p->ry = (float(data->raw_hgh) * 72.0) / pshgh;
+       queue_element p;
+       p.ofsx = psx;
+       p.ofsy = psy;
+       p.rx = (float(data->raw_wid) * 72.0) / pswid;
+       p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
 
-       p->data = data;
-       p->next = 0;
+       p.data = data;
 
-       // now put into queue
-       queue * p2 = gsqueue;
-       if (!gsqueue) gsqueue = p;
-       else {
-               while (p2->next) p2 = p2->next;
-               p2->next = p;
-       }
+       gsqueue.push(p);
 
        // if possible, run the queue
        runqueue();
 }
 
 
-static figdata * getfigdata(int wid, int hgh, string const & fname, 
+static
+figdata * getfigdata(int wid, int hgh, string const & fname, 
                            int psx, int psy, int pswid, int pshgh, 
                            int raw_wid, int raw_hgh, float angle, char flags)
 {
@@ -768,11 +745,11 @@ static figdata * getfigdata(int wid, int hgh, string const & fname,
        if (bmpinsref > bmparrsize) {
                // allocate more space
                bmparrsize += figallocchunk;
-               figdata ** tmp = static_cast<figdata**>
-                       (malloc(sizeof(figdata*) * bmparrsize));
+               typedef figdata * figdata_p;
+               figdata ** tmp = new figdata_p[bmparrsize];
                memcpy(tmp, bitmaps,
                       sizeof(figdata*) * (bmparrsize - figallocchunk));
-               free(bitmaps);
+               delete[] bitmaps;
                bitmaps = tmp;
        }
        figdata * p = new figdata;
@@ -816,13 +793,15 @@ static figdata * getfigdata(int wid, int hgh, string const & fname,
 }
 
 
-static void getbitmap(figdata * p)
+static
+void getbitmap(figdata * p)
 {
        p->gspid = -1;
 }
 
 
-static void makeupdatelist(figdata * p)
+static
+void makeupdatelist(figdata * p)
 {
        for (int i = 0; i < figinsref; ++i)
                if (figures[i]->data == p) {
@@ -831,9 +810,8 @@ static void makeupdatelist(figdata * p)
                                       << figures[i]->inset
                                       << endl;
                        }
-                       //UpdateInset(figures[i]->inset);
                        // add inset figures[i]->inset into to_update list
-                       PutInsetIntoInsetUpdateList(figures[i]->inset);
+                       current_view->pushIntoUpdateList(figures[i]->inset);
                }
 }
 
@@ -874,30 +852,22 @@ void sigchldchecker(pid_t pid, int * status)
                                p->broken = true;
                        }
                        makeupdatelist(bitmaps[i]);
-                       gsrunning--;
+                       --gsrunning;
                        runqueue();
                        pid_handled = true;
                }
        }
        if (!pid_handled) {
                lyxerr.debug() << "Checking pid in pidwait" << endl;
-               pidwait * p = pw, * prev = 0;
-               while (p) {
-                       if (pid == p->pid) {
-                               lyxerr.debug() << "Found pid in pidwait" << endl;
-                               lyxerr.debug() << "Caught child pid of recompute routine " << pid << endl;
-                               if (prev)
-                                       prev->next = p->next;
-                               else
-                                       pw = p->next;
-                               delete p;
-                               break;
-                       }
-                       prev = p;
-                       p = p->next;
+               list<int>::iterator it = find(pidwaitlist.begin(),
+                                             pidwaitlist.end(), pid);
+               if (it != pidwaitlist.end()) {
+                       lyxerr.debug() << "Found pid in pidwait\n"
+                                      << "Caught child pid of recompute "
+                               "routine" << pid << endl;
+                       pidwaitlist.erase(it);
                }
        }
-
        if (pid == -1) {
                lyxerr.debug() << "waitpid error" << endl;
                switch (errno) {
@@ -928,7 +898,8 @@ void sigchldchecker(pid_t pid, int * status)
 }
 
 
-static void getbitmaps()
+static
+void getbitmaps()
 {
        bitmap_waiting = false;
        for (int i = 0; i < bmpinsref; ++i)
@@ -937,7 +908,8 @@ static void getbitmaps()
 }
 
 
-static void RegisterFigure(InsetFig *fi)
+static
+void RegisterFigure(InsetFig * fi)
 {
        if (figinsref == 0) InitFigures();
        fi->form = 0;
@@ -945,11 +917,11 @@ static void RegisterFigure(InsetFig *fi)
        if (figinsref > figarrsize) {
                // allocate more space
                figarrsize += figallocchunk;
-               Figref ** tmp = static_cast<Figref**>
-                       (malloc(sizeof(Figref*)*figarrsize));
+               typedef Figref * Figref_p;
+               Figref ** tmp = new Figref_p[figarrsize];
                memcpy(tmp, figures,
-                      sizeof(Figref*)*(figarrsize-figallocchunk));
-               free(figures);
+                      sizeof(Figref*) * (figarrsize-figallocchunk));
+               delete[] figures;
                figures = tmp;
        }
        Figref * tmpfig = new Figref;
@@ -976,7 +948,8 @@ int FindFigIndex(Figref * tmpfig)
 }
 
 
-static void UnregisterFigure(InsetFig * fi)
+static
+void UnregisterFigure(InsetFig * fi)
 {
        Figref * tmpfig = fi->figure;
 
@@ -991,7 +964,7 @@ static void UnregisterFigure(InsetFig * fi)
 #warning Reactivate this free_form calls
 #else
                fl_free_form(tmpfig->inset->form->Figure);
-               free(tmpfig->inset->form);
+               free(tmpfig->inset->form); // Why free?
                tmpfig->inset->form = 0;
 #endif
        }
@@ -1007,7 +980,8 @@ static void UnregisterFigure(InsetFig * fi)
 }
 
 
-static string NextToken(istream & is)
+static
+string NextToken(istream & is)
 {
        string token;
        char c;
@@ -1050,48 +1024,50 @@ InsetFig::~InsetFig()
 }
 
 
-int InsetFig::Ascent(LyXFont const &) const
+int InsetFig::ascent(Painter &, LyXFont const &) const
 {
        return hgh + 3;
 }
 
 
-int InsetFig::Descent(LyXFont const &) const
+int InsetFig::descent(Painter &, LyXFont const &) const
 {
        return 1;
 }
 
 
-int InsetFig::Width(LyXFont const &) const
+int InsetFig::width(Painter &, LyXFont const &) const
 {
        return wid + 2;
 }
 
 
-void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
+void InsetFig::draw(Painter & pain, LyXFont const & f,
+                   int baseline, float & x) const
 {
+       LyXFont font(f);
+       
        if (bitmap_waiting) getbitmaps();
-
+       
        // I wish that I didn't have to use this
        // but the figinset code is so complicated so
        // I don't want to fiddle with it now.
-       unsigned long pm = scr.getForeground();
-       
+
        if (figure && figure->data && figure->data->bitmap &&
            !figure->data->reading && !figure->data->broken) {
                // draw the bitmap
-               XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
-                         0, 0, wid, hgh, int(x+1), baseline-hgh);
-               XFlush(fl_display);
-               if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
-                                             int(x), baseline - hgh - 1,
-                                             wid+1, hgh+1);
+               pain.pixmap(int(x + 1), baseline - hgh,
+                           wid, hgh, figure->data->bitmap);
+
+               if (flags & 4)
+                       pain.rectangle(int(x), baseline - hgh - 1,
+                                      wid + 1, hgh + 1);
+               
        } else {
                char * msg = 0;
                // draw frame
-               XDrawRectangle(fl_display, pm, getGC(gc_copy),
-                              int(x),
-                              baseline - hgh - 1, wid+1, hgh+1);
+               pain.rectangle(x, baseline - hgh - 1, wid + 1, hgh + 1);
+
                if (figure && figure->data) {
                        if (figure->data->broken)  msg = _("[render error]");
                        else if (figure->data->reading) msg = _("[rendering ... ]");
@@ -1099,26 +1075,23 @@ void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
                        if (fname.empty()) msg = _("[no file]");
                        else if ((flags & 3) == 0) msg = _("[not displayed]");
                        else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
-
+               
                if (!msg) msg = _("[unknown error]");
                
-               font.setFamily (LyXFont::SANS_FAMILY);
-               font.setSize (LyXFont::SIZE_FOOTNOTE);
+               font.setFamily(LyXFont::SANS_FAMILY);
+               font.setSize(LyXFont::SIZE_FOOTNOTE);
                string justname = OnlyFilename (fname);
-               font.drawString(justname, pm,
-                               baseline - font.maxAscent() - 4,
-                               int(x) + 8);
-               font.setSize (LyXFont::SIZE_TINY);
-               font.drawText (msg, strlen(msg), pm,
-                              baseline - 4,
-                              int(x) + 8);
-
+               pain.text(int(x + 8), baseline - font.maxAscent() - 4,
+                         justname, font);
+               
+               font.setSize(LyXFont::SIZE_TINY);
+               pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
        }
-       x += Width(font);    // ?
+       x += width(pain, font);    // ?
 }
 
 
-void InsetFig::Write(ostream & os)
+void InsetFig::Write(ostream & os) const
 {
        Regenerate();
        os << "Figure size " << wid << " " << hgh << "\n";
@@ -1221,7 +1194,7 @@ void InsetFig::Read(LyXLex & lex)
 }
 
 
-int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
+int InsetFig::Latex(ostream & os, signed char /* fragile*/ ) const
 {
        Regenerate();
        if (!cmd.empty()) os << cmd << " ";
@@ -1229,7 +1202,8 @@ int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
 }
 
 
-int InsetFig::Latex(string & file, signed char /* fragile*/ )
+#ifndef USE_OSTREAM_ONLY
+int InsetFig::Latex(string & file, signed char /* fragile*/ ) const
 {
        Regenerate();
        file += cmd + ' ';
@@ -1237,13 +1211,13 @@ int InsetFig::Latex(string & file, signed char /* fragile*/ )
 }
 
 
-int InsetFig::Linuxdoc(string &/*file*/)
+int InsetFig::Linuxdoc(string &/*file*/) const
 {
        return 0;
 }
 
 
-int InsetFig::DocBook(string & file)
+int InsetFig::DocBook(string & file) const
 {
        string figurename = fname;
 
@@ -1254,6 +1228,26 @@ int InsetFig::DocBook(string & file)
        return 0;
 }
 
+#else
+
+int InsetFig::Linuxdoc(ostream &) const
+{
+       return 0;
+}
+
+
+int InsetFig::DocBook(ostream & os) const
+{
+       string figurename = fname;
+
+       if(suffixIs(figurename, ".eps"))
+               figurename.erase(fname.length() - 5);
+
+       os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
+       return 0;
+}
+#endif
+
 
 void InsetFig::Validate(LaTeXFeatures & features) const
 {
@@ -1274,7 +1268,7 @@ bool InsetFig::Deletable() const
 }
 
 
-void InsetFig::Edit(int, int)
+void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
 {
        lyxerr.debug() << "Editing InsetFig." << endl;
        Regenerate();
@@ -1282,8 +1276,8 @@ void InsetFig::Edit(int, int)
        // We should have RO-versions of the form instead.
        // The actual prevention of altering a readonly doc
        // is done in CallbackFig()
-       if(current_view->buffer()->isReadonly()) 
-               WarnReadonly(current_view->buffer()->fileName());
+       if(bv->buffer()->isReadonly()) 
+               WarnReadonly(bv->buffer()->fileName());
 
        if (!form) {
                form = create_form_Figure();
@@ -1351,7 +1345,7 @@ Inset::Code InsetFig::LyxCode() const
 }
 
 
-void InsetFig::Regenerate()
+void InsetFig::Regenerate() const
 {
        string cmdbuf;
        string resizeW, resizeH;
@@ -1361,7 +1355,6 @@ void InsetFig::Regenerate()
                cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
                cmd += _("empty figure path");
                cmd += '}';
-               //if (form) fl_set_object_label(form->cmd, "");
                return;
        }
 
@@ -1471,8 +1464,6 @@ void InsetFig::Regenerate()
        }
        
        cmd = cmdbuf;
-
-       //if (form) fl_set_object_label(form->cmd, cmd.c_str());
 }
 
 
@@ -1489,8 +1480,6 @@ void InsetFig::TempRegenerate()
        float txhgh = atof(fl_get_input(form->Height));
 
        if (!tfname || !*tfname) {
-               //fl_set_object_label(form->cmd, "");
-               //fl_redraw_object(form->cmd);
                cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
                cmd += _("empty figure path");
                cmd += '}';
@@ -1917,7 +1906,7 @@ void InsetFig::CallbackFig(long arg)
                                lyxerr << "Update: ["
                                       << wid << 'x' << hgh << ']' << endl;
                        }
-                       UpdateInset(this);
+                       current_view->updateInset(this, true);
                        if (arg == 8) {
                                fl_set_focus_object(form->Figure, form->OkBtn);
                                fl_hide_form(form->Figure);
@@ -1925,7 +1914,7 @@ void InsetFig::CallbackFig(long arg)
 #warning Reactivate this free_form calls
 #else
                                fl_free_form(form->Figure);
-                               free(form);
+                               free(form); // Why free?
                                form = 0;
 #endif
                        }
@@ -1943,7 +1932,7 @@ void InsetFig::CallbackFig(long arg)
 #warning Jug, is this still a problem?
 #else
                fl_free_form(form->Figure);
-               free(form);
+               free(form); // Why free?
                form = 0;
 #endif
                break;
@@ -1953,7 +1942,8 @@ void InsetFig::CallbackFig(long arg)
 }
 
 
-inline void DisableFigurePanel(FD_Figure * const form)
+inline
+void DisableFigurePanel(FD_Figure * const form)
 {
         fl_deactivate_object(form->EpsFile);
        fl_deactivate_object(form->Browse);
@@ -1989,7 +1979,8 @@ inline void DisableFigurePanel(FD_Figure * const form)
 }
 
 
-inline void EnableFigurePanel(FD_Figure * const form)
+inline
+void EnableFigurePanel(FD_Figure * const form)
 {
         fl_activate_object(form->EpsFile);
        fl_activate_object(form->Browse);