]> git.lyx.org Git - lyx.git/blobdiff - src/insets/figinset.C
removed a warning from screen and added CFLAGS in lyx.spec.in.
[lyx.git] / src / insets / figinset.C
index 1e884f179822eabdf9b868d87597a43887631e2d..4fb1b106e0bdc3fea23fe85f1daae753b405f17a 100644 (file)
@@ -32,13 +32,13 @@ extern long int background_pixels;
 #include <config.h>
 
 #include <unistd.h>
-#include <signal.h>
+#include <csignal>
 #include <sys/wait.h>
 
 #include FORMS_H_LOCATION
-#include <stdlib.h>
-#include <ctype.h>
-#include <math.h>
+#include <cstdlib>
+#include <cctype>
+#include <cmath>
 
 #include "form1.h"
 #include "figinset.h"
@@ -46,28 +46,22 @@ extern long int background_pixels;
 #include "lyx_main.h"
 #include "buffer.h"
 #include "filedlg.h"
-#include "filetools.h"
+#include "support/filetools.h"
 #include "LyXView.h" // just because of form_main
-#include "error.h"
+#include "debug.h"
 #include "lyxdraw.h"
 #include "LaTeXFeatures.h"
 #include "lyxrc.h"
 #include "gettext.h"
 #include "lyx_gui_misc.h" // CancelCloseBoxCB
-#include "FileInfo.h"
-
-//     $Id: figinset.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $  
-
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: figinset.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
-#endif /* lint */
+#include "support/FileInfo.h"
 
 extern BufferView *current_view;
 static volatile bool alarmed;
 
 extern FL_OBJECT *figinset_canvas;
-inline
-void waitalarm(int)
+//inline
+extern "C" void waitalarm(int)
 {
        alarmed = true;
 }
@@ -103,7 +97,7 @@ struct pidwait {
 
 static Figref **figures;       /* all the figures */
 static figdata **bitmaps;      /* all the bitmaps */
-static queue *gsqueue = NULL;  /* queue for ghostscripting */
+static queue *gsqueue = 0;     /* 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 */
@@ -117,7 +111,7 @@ static int gs_spc;                  // shades per color
 static bool gs_gray;                   // is grayscale?
 static int gs_allcolors;               // number of all colors
 
-static pidwait *pw = NULL;             // pid wait list
+static pidwait *pw = 0;                // pid wait list
 
 
 extern FD_form_main *fd_form_main;
@@ -133,16 +127,16 @@ void addpidwait(int pid)
        pw = p;
 
        if (lyxerr.debugging()) {
-               lyxerr.print(LString("Pids to wait for: ") + int(p->pid));
+               lyxerr << "Pids to wait for: " << p->pid << endl;
                while (p->next) {
                        p = p->next;
-                       lyxerr.print(LString() + int(p->pid));
+                       lyxerr << p->pid << endl;
                }
        }
 }
 
 
-int GhostscriptMsg(FL_OBJECT *, Window, int, int,
+extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                   XEvent *ev, void *)
 {
        int i;
@@ -151,9 +145,8 @@ int GhostscriptMsg(FL_OBJECT *, Window, int, int,
        XClientMessageEvent *e = (XClientMessageEvent*) ev;
 
        if(lyxerr.debugging()) {
-               fprintf(stderr,
-                       "ClientMessage, win:[xx] gs:[%ld] pm:[%ld]\n",
-                       e->data.l[0], e->data.l[1]);
+               lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
+                      << "] pm:[" << e->data.l[1] << "]" << endl;
        }
 
        // just kill gs, that way it will work for sure
@@ -180,39 +173,42 @@ int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                        figinset_canvas), &wa);
                                XFlush(fl_display);
                                if (lyxerr.debugging()) {
-                                       fprintf(stderr,
-                                               "Starting image translation %ld %d %dx%d %d %d\n",
-                                              p->bitmap, p->flags, p->wid, p->hgh, wa.depth,
-                                              XYPixmap);
+                                       lyxerr 
+                                               << "Starting image translation "
+                                               << p->bitmap << " "
+                                               << p->flags << " "
+                                               << p->wid << "x" << p->hgh
+                                               << " " << wa.depth
+                                               << " " << XYPixmap << endl;
+
                                }
                                // now fork rendering process
                                forkstat = fork();
                                if (forkstat == -1) {
-                                       lyxerr.debug("Cannot fork, using slow "
-                                                     "method for pixmap translation.");
+                                       lyxerr.debug() << "Cannot fork, using slow "
+                                               "method for pixmap translation." << endl;
                                        tmpdisp = fl_display;
                                } else if (forkstat > 0) {
                                        // register child
                                        if (lyxerr.debugging()) {
-                                               lyxerr.print(
-                                                       LString("Spawned child ")
-                                                       + int(forkstat));
+                                               lyxerr << "Spawned child "
+                                                      << forkstat << endl;
                                        }
                                        addpidwait(forkstat);
                                        break; // in parent process
                                } else {
-                                       tmpdisp = XOpenDisplay(XDisplayName(NULL));
+                                       tmpdisp = XOpenDisplay(XDisplayName(0));
                                        XFlush(tmpdisp);
                                }
                                im = XGetImage(tmpdisp, p->bitmap, 0, 0,
                                               p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
                                XFlush(tmpdisp);
                                if (lyxerr.debugging()) {
-                                       lyxerr.print("Got the image");
+                                       lyxerr << "Got the image" << endl;
                                }
                                if (!im) {
                                        if (lyxerr.debugging()) {
-                                               lyxerr.print("Error getting the image");
+                                               lyxerr << "Error getting the image" << endl;
                                        }
                                        goto noim;
                                }
@@ -237,18 +233,18 @@ int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                        }
                                }
                                if (lyxerr.debugging()) {
-                                       lyxerr.print("Putting image back");
+                                       lyxerr << "Putting image back" << endl;
                                }
                                XPutImage(tmpdisp, p->bitmap, gc, im, 0, 0,
                                          0, 0, p->wid, p->hgh);
                                XDestroyImage(im);
                                if (lyxerr.debugging()) {
-                                       lyxerr.print("Done translation");
+                                       lyxerr << "Done translation" << endl;
                                }
                          noim:
                                if (lyxerr.debugging()) {
-                                       lyxerr.print(LString("Killing gs ") 
-                                                    + int(p->gspid));
+                                       lyxerr << "Killing gs " 
+                                              << p->gspid << endl;
                                }
                                kill(p->gspid, SIGHUP);
 
@@ -262,8 +258,8 @@ int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                }
                        } else {
                                if (lyxerr.debugging()) {
-                                       lyxerr.print(LString("Killing gs ") 
-                                                    +int(p->gspid));
+                                       lyxerr << "Killing gs " 
+                                              << p->gspid << endl;
                                }
                                kill(p->gspid, SIGHUP);
 
@@ -285,11 +281,12 @@ static void AllocColors(int num)
        int i;
 
        if (lyxerr.debugging()) {
-               printf("Allocating color cube %dx%dx%d\n", num, num, num);
+               lyxerr << "Allocating color cube " << num
+                      << 'x' << num << 'x' << num << endl;
        }
 
        if (num <= 1) {
-               lyxerr.print("Error allocating color colormap.");
+               lyxerr << "Error allocating color colormap." << endl;
                gs_color = false;
                return;
        }
@@ -303,8 +300,8 @@ static void AllocColors(int num)
                        if (i) XFreeColors(fl_display, color_map,
                                           gs_pixels, i, 0);
                        if(lyxerr.debugging()) {
-                               lyxerr.print(LString("Cannot allocate color cube " )
-                                            + int(num));
+                               lyxerr << "Cannot allocate color cube "
+                                      << num << endl;;
                        }
                        AllocColors(num-1);
                        return;
@@ -325,12 +322,12 @@ static void AllocGrays(int num)
        int i;
 
        if (lyxerr.debugging()) {
-               lyxerr.print(LString("Allocating grayscale ramp ") 
-                            + int(num));
+               lyxerr << "Allocating grayscale ramp "
+                      << num << endl;
        }
 
        if (num < 4) {
-               lyxerr.print("Error allocating grayscale colormap.");
+               lyxerr << "Error allocating grayscale colormap." << endl;
                gs_color = false;
                return;
        }
@@ -342,8 +339,8 @@ static void AllocGrays(int num)
                        if (i) XFreeColors(fl_display, color_map,
                                           gs_pixels, i, 0);
                        if (lyxerr.debugging()) {
-                               lyxerr.print(LString("Cannot allocate grayscale ") 
-                                            + int(num));
+                               lyxerr << "Cannot allocate grayscale " 
+                                      << num << endl;
                        }
                        AllocGrays(num/2);
                        return;
@@ -414,13 +411,13 @@ void DoneFigures()
        figarrsize = 0;
        bmparrsize = 0;
 
-       lyxerr.debug("Unregistering figures...");
+       lyxerr.debug() << "Unregistering figures..." << endl;
 
        fl_remove_canvas_handler(figinset_canvas, ClientMessage,
                                 GhostscriptMsg);
 
        if (gs_color) {
-               lyxerr.debug("Freeing up the colors...");
+               lyxerr.debug() << "Freeing up the colors..." << endl;
                XFreeColors(fl_display, color_map, gs_pixels,
                            gs_num_pixels, 0);
                /******????????????????? what's planes in this case ??????***/
@@ -441,7 +438,7 @@ int FindBmpIndex(figdata *tmpdata)
 
 static void chpixmap(Pixmap, int, int)
 {
-       Display* tempdisp = XOpenDisplay(XDisplayName(NULL));
+       Display* tempdisp = XOpenDisplay(XDisplayName(0));
 
        // here read the pixmap and change all colors to those we
        // have allocated
@@ -516,7 +513,7 @@ static void runqueue()
                
                if (pid == -1) {
                        if (lyxerr.debugging()) {
-                               lyxerr.print("GS start error! Cannot fork.");
+                               lyxerr << "GS start error! Cannot fork." << endl;
                        }
                        p->data->broken = true;
                        p->data->reading = false;
@@ -525,7 +522,7 @@ static void runqueue()
                if (pid == 0) { // child
                        char **env, rbuf[80], gbuf[40];
                        int ne = 0;
-                       Display* tempdisp = XOpenDisplay(XDisplayName(NULL));
+                       Display* tempdisp = XOpenDisplay(XDisplayName(0));
 
                        // create translation file
                        sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
@@ -561,9 +558,8 @@ static void runqueue()
 //#warning BUG seems that the only bug here might be the hardcoded dpi.. Bummer!
                        
                        if (lyxerr.debugging()) {
-                               lyxerr.print(LString("Will set GHOSTVIEW"
-                                                    " property to [") +
-                                            tbuf + "]");
+                               lyxerr << "Will set GHOSTVIEW property to ["
+                                      << tbuf << "]" << endl;
                        }
                        // wait until property is deleted if executing multiple
                        // ghostscripts
@@ -571,7 +567,7 @@ static void runqueue()
                                // grab server to prevent other child interfering
                                // with setting GHOSTVIEW property
                                if (lyxerr.debugging()) {
-                                       lyxerr.print("Grabbing the server");
+                                       lyxerr << "Grabbing the server" << endl;
                                }
                                XGrabServer(tempdisp);
                                prop = XListProperties(tempdisp, fl_get_canvas_id(
@@ -595,11 +591,11 @@ static void runqueue()
                                // ok, property found, we must wait until ghostscript
                                // deletes it
                                if (lyxerr.debugging()) {
-                                       lyxerr.print("Releasing the server");
-                                       lyxerr.print(LString('[') +
-                                                     int(getpid()) +
-                                                     "] GHOSTVIEW property"
-                                                     " found. Waiting.");
+                                       lyxerr << "Releasing the server" << endl;
+                                       lyxerr << "["
+                                              << getpid()
+                                              << "] GHOSTVIEW property"
+                                               " found. Waiting." << endl;
                                }
 #ifdef WITH_WARNINGS
 #warning What is this doing? (wouldn't a sleep(1); work too?')
@@ -650,7 +646,7 @@ static void runqueue()
                        XUngrabServer(tempdisp);
                        XFlush(tempdisp);
                        if (lyxerr.debugging()) {
-                               lyxerr.print("Releasing the server");
+                               lyxerr << "Releasing the server" << endl;
                        }
                        XCloseDisplay(tempdisp);
 
@@ -685,20 +681,20 @@ static void runqueue()
                                         "-dSAFER", 
                                         rbuf, gbuf, tbuf, 
                                         p->data->fname.c_str(), 
-                                        "showpage.ps", "quit.ps", "-", NULL);
+                                        "showpage.ps", "quit.ps", "-", 0);
                        // if we are still there, an error occurred.
-                       lyxerr.print(LString("Error executing ghostscript. ")
-                                    +"Code: "+err);
-                       lyxerr.debug("Cmd: " 
-                                    + lyxrc->ps_command
-                                    +" -sDEVICE=x11 "
-                                    + tbuf + LString(' ')
-                                    + p->data->fname);
+                       lyxerr << "Error executing ghostscript. "
+                              << "Code: " << err << endl;
+                       lyxerr.debug() << "Cmd: " 
+                                      << lyxrc->ps_command
+                                      << " -sDEVICE=x11 "
+                                      << tbuf << ' '
+                                      << p->data->fname << endl;
                        _exit(0);       // no gs?
                }
                // normal process (parent)
                if (lyxerr.debugging()) {
-                       lyxerr.print(LString("GS [") + int(pid) + "] started");
+                       lyxerr << "GS ["  << pid << "] started" << endl;
                }
                gsqueue = gsqueue->next;
                gsrunning++;
@@ -719,7 +715,7 @@ static void addwait(int psx, int psy, int pswid, int pshgh, figdata *data)
        p->ry = ((float)data->raw_hgh*72)/pshgh;
 
        p->data = data;
-       p->next = NULL;
+       p->next = 0;
 
        // now put into queue
        p2 = gsqueue;
@@ -734,7 +730,7 @@ static void addwait(int psx, int psy, int pswid, int pshgh, figdata *data)
 }
 
 
-static figdata *getfigdata(int wid, int hgh, LString 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)
 {
@@ -743,7 +739,7 @@ static figdata *getfigdata(int wid, int hgh, LString const & fname,
        figdata *p;
        XWindowAttributes wa;
 
-       if (fname.empty()) return NULL;
+       if (fname.empty()) return 0;
 
        while (i < bmpinsref) {
                if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
@@ -754,7 +750,7 @@ static figdata *getfigdata(int wid, int hgh, LString const & fname,
                }
                ++i;
        }
-       /* not found -> create new record or return NULL if no record */
+       /* not found -> create new record or return 0 if no record */
        ++bmpinsref;
        if (bmpinsref > bmparrsize) {
                // allocate more space
@@ -777,9 +773,11 @@ static figdata *getfigdata(int wid, int hgh, LString const & fname,
                figinset_canvas), &wa);
 
        if (lyxerr.debugging()) {
-               printf("Create pixmap disp:%d scr:%d w:%d h:%d depth:%d\n",
-                      PTR_AS_INT(fl_display), DefaultScreen(fl_display), 
-                      wid, hgh, wa.depth);
+               lyxerr << "Create pixmap disp:" << fl_display
+                      << " scr:" << DefaultScreen(fl_display)
+                      << " w:" << wid
+                      << " h:" << hgh
+                      << " depth:" << wa.depth << endl;
        }
        
        p->ref = 1;
@@ -814,8 +812,8 @@ static void makeupdatelist(figdata *p)
 
        for (i = 0; i < figinsref; ++i) if (figures[i]->data == p) {
                if (lyxerr.debugging()) {
-                       printf("Updating inset %d\n", 
-                              PTR_AS_INT(figures[i]->inset));
+                       lyxerr << "Updating inset " << figures[i]->inset
+                              << endl;
                }
                //UpdateInset(figures[i]->inset);
                // add inset figures[i]->inset into to_update list
@@ -831,22 +829,25 @@ void sigchldchecker(pid_t pid, int *status)
 
        bool pid_handled = false;
        
-       lyxerr.debug(LString("Got pid = ") + long (pid));
+       lyxerr.debug() << "Got pid = " << pid << endl;
        pid_handled = false;
        for (i = bmpinsref - 1; i >= 0; --i) {
                if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
-                       lyxerr.debug("Found pid in bitmaps");
+                       lyxerr.debug() << "Found pid in bitmaps" << endl;
                        // now read the file and remove it from disk
                        p = bitmaps[i];
                        p->reading = false;
                        if (bitmaps[i]->gsdone) *status = 0;
                        if (*status == 0) {
-                               lyxerr.debug(LString("GS [") + int(pid) +
-                                            "] exit OK.");
+                               lyxerr.debug() << "GS [" << pid
+                                              << "] exit OK." << endl;
                        } else {
-                               fprintf(stderr, "GS [%ld] error %d E:%d %d S:%d %d\n", long(pid),
-                                       *status, WIFEXITED(*status), WEXITSTATUS(*status),
-                                       WIFSIGNALED(*status), WTERMSIG(*status));
+                               lyxerr << "GS [" << pid  << "] error "
+                                      << *status << " E:"
+                                      << WIFEXITED(*status)
+                                      << " " << WEXITSTATUS(*status)
+                                      << " S:" << WIFSIGNALED(*status)
+                                      << " " << WTERMSIG(*status) << endl;
                        }
                        if (*status == 0) {
                                bitmap_waiting = true;
@@ -868,12 +869,12 @@ void sigchldchecker(pid_t pid, int *status)
                }
        }
        if (!pid_handled) {
-               lyxerr.debug("Checking pid in pidwait");
-               pidwait *p = pw, *prev = NULL;
+               lyxerr.debug() << "Checking pid in pidwait" << endl;
+               pidwait *p = pw, *prev = 0;
                while (p) {
                        if (pid == p->pid) {
-                               lyxerr.debug("Found pid in pidwait");
-                               lyxerr.debug(LString("Caught child pid of recompute routine ") + int(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
@@ -887,32 +888,31 @@ void sigchldchecker(pid_t pid, int *status)
        }
 
        if (pid == -1) {
-               lyxerr.debug("waitpid error");
+               lyxerr.debug() << "waitpid error" << endl;
                switch (errno) {
                case ECHILD:
-                       lyxerr.print(
-                               "The process or process group specified by pid "
-                               "does  not exist or is not a child of the cal-"
-                               "ling process or can never be  in  the  states "
-                               "specified by options.");
+                       lyxerr << "The process or process group specified by "
+                               "pid does  not exist or is not a child of "
+                               "the calling process or can never be in the "
+                               "states specified by options." << endl;
                        break;
                case EINTR:
-                       lyxerr.print(
-                               "waitpid() was interrupted due to the  receipt "
-                               "of a signal sent by the calling process.");
+                       lyxerr << "waitpid() was interrupted due to the "
+                               "receipt of a signal sent by the calling "
+                               "process." << endl;
                        break;
                case EINVAL:
-                       lyxerr.print(
-                               "An invalid value was specified for options.");
+                       lyxerr << "An invalid value was specified for "
+                               "options." << endl;
                        break;
                default:
-                       lyxerr.print("Unknown error from waitpid");
+                       lyxerr << "Unknown error from waitpid" << endl;
                        break;
                }
        } else if (pid == 0) {
-               lyxerr.print("waitpid nohang");
+               lyxerr << "waitpid nohang" << endl;;
        } else {
-               lyxerr.debug("normal exit from childhandler");
+               lyxerr.debug() << "normal exit from childhandler" << endl;
        }
 }
 
@@ -932,7 +932,7 @@ static void RegisterFigure(InsetFig *fi)
        Figref *tmpfig;
 
        if (figinsref == 0) InitFigures();
-       fi->form = NULL;
+       fi->form = 0;
        ++figinsref;
        if (figinsref > figarrsize) {
                // allocate more space
@@ -943,14 +943,14 @@ static void RegisterFigure(InsetFig *fi)
                figures = tmp;
        }
        tmpfig = new Figref;
-       tmpfig->data = NULL;
+       tmpfig->data = 0;
        tmpfig->inset = fi;
        figures[figinsref-1] = tmpfig;
        fi->figure = tmpfig;
 
        if (lyxerr.debugging()) {
-               lyxerr.print(LString("Register Figure: buffer:[") +
-                            long(current_view->currentBuffer()) + "]");
+               lyxerr << "Register Figure: buffer:["
+                      << current_view->currentBuffer() << "]" << endl;
        }
 }
 
@@ -973,11 +973,18 @@ static void UnregisterFigure(InsetFig *fi)
 
        if (tmpfig->data) freefigdata(tmpfig->data);
        if (tmpfig->inset->form) {
-               if (tmpfig->inset->form->Figure->visible)
+               if (tmpfig->inset->form->Figure->visible) {
+                       fl_set_focus_object(tmpfig->inset->form->Figure,
+                                           tmpfig->inset->form->OkBtn);
                        fl_hide_form(tmpfig->inset->form->Figure);
+               }
+#if FL_REVISION == 89
+#warning Reactivate this free_form calls
+#else
                fl_free_form(tmpfig->inset->form->Figure);
                free(tmpfig->inset->form);
-               tmpfig->inset->form = NULL;
+               tmpfig->inset->form = 0;
+#endif
        }
        i = FindFigIndex(tmpfig);
        --figinsref;
@@ -993,7 +1000,7 @@ static void UnregisterFigure(InsetFig *fi)
 
 static char* NextToken(FILE *myfile)
 {
-       char* token = NULL;
+       char* token = 0;
        char c;
        int i = 0;
    
@@ -1031,7 +1038,7 @@ InsetFig::InsetFig(int tmpx, int tmpy, Buffer *o)
 InsetFig::~InsetFig()
 {
        if (lyxerr.debugging()) {
-               lyxerr.print("Figure destructor called");
+               lyxerr << "Figure destructor called" << endl;
        }
        UnregisterFigure(this);
 }
@@ -1091,7 +1098,7 @@ void InsetFig::Draw(LyXFont font, LyXScreen &scr, int baseline, float &x)
                
                font.setFamily (LyXFont::SANS_FAMILY);
                font.setSize (LyXFont::SIZE_FOOTNOTE);
-               LString justname = OnlyFilename (fname);
+               string justname = OnlyFilename (fname);
                font.drawString(justname,pm,
                               baseline - font.maxAscent() - 4,
                               (int) x + 8);
@@ -1110,8 +1117,8 @@ void InsetFig::Write(FILE *file)
        Regenerate();
        fprintf(file, "Figure size %d %d\n", wid, hgh);
        if (!fname.empty()) {
-         LString buf1 = OnlyPath(owner->getFileName());
-         LString fname2 = MakeRelPath(fname, buf1);
+         string buf1 = OnlyPath(owner->getFileName());
+         string fname2 = MakeRelPath(fname, buf1);
          fprintf(file, "file %s\n", fname2.c_str());
        }
        if (!subcaption.empty())
@@ -1126,14 +1133,14 @@ void InsetFig::Write(FILE *file)
 
 void InsetFig::Read(LyXLex &lex)
 {
-       LString buf;
+       string buf;
        bool finished = false;
        
        while (lex.IsOK() && !finished) {
                lex.next();
 
-               LString const token = lex.GetString();
-               lyxerr.debug("Token: " + token);
+               string const token = lex.GetString();
+               lyxerr.debug() << "Token: " << token << endl;
                
                if (token.empty())
                        continue;
@@ -1142,7 +1149,7 @@ void InsetFig::Read(LyXLex &lex)
                } else if (token == "file") {
                        if (lex.next()) {
                                buf = lex.GetString();
-                               LString buf1 = OnlyPath(owner->getFileName());
+                               string buf1 = OnlyPath(owner->getFileName());
                                fname = MakeAbsPath(buf, buf1);
                                changedfname = true;
                        }
@@ -1181,7 +1188,7 @@ void InsetFig::Read(LyXLex &lex)
                        case PER_PAGE: wtype = PER_PAGE; break;
                        case PER_COL: wtype = PER_COL; break;
                        default:
-                               lyxerr.debug("Unknown type!");
+                               lyxerr.debug() << "Unknown type!" << endl;
                                break;
                        }
                        twtype = wtype;
@@ -1197,7 +1204,7 @@ void InsetFig::Read(LyXLex &lex)
                        case IN: htype = IN; break;
                        case PER_PAGE: htype = PER_PAGE; break;
                        default:
-                               lyxerr.debug("Unknown type!");
+                               lyxerr.debug() << "Unknown type!" << endl;
                                break;
                        }
                        thtype = htype;
@@ -1216,7 +1223,7 @@ int InsetFig::Latex(FILE *file, signed char /* fragile*/ )
 }
 
 
-int InsetFig::Latex(LString &file, signed char /* fragile*/ )
+int InsetFig::Latex(string &file, signed char /* fragile*/ )
 {
        Regenerate();
        file += cmd + ' ';
@@ -1224,18 +1231,18 @@ int InsetFig::Latex(LString &file, signed char /* fragile*/ )
 }
 
 
-int InsetFig::Linuxdoc(LString &/*file*/)
+int InsetFig::Linuxdoc(string &/*file*/)
 {
        return 0;
 }
 
 
-int InsetFig::DocBook(LString &file)
+int InsetFig::DocBook(string &file)
 {
-       LString figurename=fname;
+       string figurename=fname;
 
-       if(figurename.suffixIs(".eps"))
-               figurename=figurename.substring(0,fname.length()-5);
+       if(suffixIs(figurename, ".eps"))
+               figurename.erase(fname.length() - 5);
 
        file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
        return 0;
@@ -1263,7 +1270,7 @@ bool InsetFig::Deletable() const
 
 void InsetFig::Edit(int, int)
 {
-       lyxerr.debug("Editing InsetFig.");
+       lyxerr.debug() << "Editing InsetFig." << endl;
        Regenerate();
 
        // We should have RO-versions of the form instead.
@@ -1274,7 +1281,7 @@ void InsetFig::Edit(int, int)
 
        if (!form) {
                form = create_form_Figure();
-               fl_set_form_atclose(form->Figure, CancelCloseBoxCB, NULL);
+               fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
                fl_set_object_return(form->Angle,FL_RETURN_ALWAYS);
                fl_set_object_return(form->Width,FL_RETURN_ALWAYS);
                fl_set_object_return(form->Height,FL_RETURN_ALWAYS);
@@ -1294,8 +1301,9 @@ Inset *InsetFig::Clone()
        InsetFig *tmp = new InsetFig(100, 100, owner);
 
        if (lyxerr.debugging()) {
-               fprintf(stderr, "Clone Figure: buffer:[%d], cbuffer:[xx]\n",
-                      PTR_AS_INT(current_view->currentBuffer()));
+               lyxerr << "Clone Figure: buffer:["
+                      << current_view->currentBuffer()
+                      << "], cbuffer:[xx]" << endl;
        }
 
        tmp->wid = wid;
@@ -1321,7 +1329,7 @@ Inset *InsetFig::Clone()
                tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
                                               pswid, pshgh, raw_wid, raw_hgh,
                                               angle, flags & (3|8));
-       } else tmp->figure->data = NULL;
+       } else tmp->figure->data = 0;
        tmp->subcaption = subcaption;
        tmp->changedfname = false;
        tmp->owner = owner;
@@ -1338,10 +1346,10 @@ Inset::Code InsetFig::LyxCode() const
 
 void InsetFig::Regenerate()
 {
-       LString cmdbuf;
-       LString gcmd;
-       LString resizeW, resizeH;
-       LString rotate, recmd;
+       string cmdbuf;
+       string gcmd;
+       string resizeW, resizeH;
+       string rotate, recmd;
 
        if (fname.empty()) {
                cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
@@ -1351,8 +1359,8 @@ void InsetFig::Regenerate()
                return;
        }
 
-       LString buf1 = OnlyPath(owner->getFileName());
-       LString fname2 = MakeRelPath(fname, buf1);
+       string buf1 = OnlyPath(owner->getFileName());
+       string fname2 = MakeRelPath(fname, buf1);
 
        gcmd = "\\includegraphics{" + fname2 + '}';
        
@@ -1464,11 +1472,11 @@ void InsetFig::Regenerate()
 
 void InsetFig::TempRegenerate()
 {
-       LString gcmd;
-       LString cmdbuf;
-       LString resizeW, resizeH;
-       LString rotate, recmd;
-       LString tsubcap;
+       string gcmd;
+       string cmdbuf;
+       string resizeW, resizeH;
+       string rotate, recmd;
+       string tsubcap;
        
        char const *tfname; // *textra;
        float tangle, txwid, txhgh;
@@ -1488,8 +1496,8 @@ void InsetFig::TempRegenerate()
                return;
        }
 
-       LString buf1 = OnlyPath(owner->getFileName());
-       LString fname2 = MakeRelPath(tfname, buf1);
+       string buf1 = OnlyPath(owner->getFileName());
+       string fname2 = MakeRelPath(tfname, buf1);
        // \includegraphics*[<llx,lly>][<urx,ury>]{file}
        gcmd = "\\includegraphics{" + fname2 + '}';
        
@@ -1586,8 +1594,8 @@ void InsetFig::TempRegenerate()
        if (!rotate.empty()) cmdbuf += '}';
        if (!recmd.empty()) cmdbuf += '}';
        if (psubfigure && !tsubcap.empty()) {
-               cmdbuf = LString("\\subfigure{") + tsubcap
-                 + LString("}{") + cmdbuf + "}";
+               cmdbuf = string("\\subfigure{") + tsubcap
+                 + string("}{") + cmdbuf + "}";
        }
 
        
@@ -1638,19 +1646,19 @@ void InsetFig::Recompute()
                
                switch (htype) {
                case DEF:
-                       //fprintf(stderr, "This should not happen!\n");
+                       //lyxerr << "This should not happen!" << endl;
                        break;
-               case CM:        /* cm */
+               case CM:        /* cm */
                        newy = (int) (28.346*xhgh);
                        break;
                case IN: /* in */
                        newy = (int) (72*xhgh);
                        break;
-               case PER_PAGE:  /* % of page */
+               case PER_PAGE:  /* % of page */
                        newy = (int) (8.42*xhgh);
                        break;
-               case PER_COL: 
-                        // Doesn't occur; case exists to suppress
+               case PER_COL: 
+                       // Doesn't occur; case exists to suppress
                        // compiler warnings.  
                         break;
                }
@@ -1697,7 +1705,7 @@ void InsetFig::Recompute()
                                                  psx, psy, pswid, pshgh,
                                                  raw_wid, raw_hgh,
                                                  angle, flags & (3|8));
-               } else figure->data = NULL;
+               } else figure->data = 0;
 
                // free the old data
                if (pf) freefigdata(pf);
@@ -1711,7 +1719,7 @@ void InsetFig::GetPSSizes()
 {
        /* get %%BoundingBox: from postscript file */
        int lastchar, c;
-       char *p = NULL;
+       char *p = 0;
        
        /* defaults to associated size
         * ..just in case the PS-file is not readable (Henner,24-Aug-97) 
@@ -1737,8 +1745,8 @@ void InsetFig::GetPSSizes()
        for (;;) {
                c = fgetc(f);
                if (c == EOF) {
-                       lyxerr.debug("End of (E)PS file reached and"
-                                     " no BoundingBox!");
+                       lyxerr.debug() << "End of (E)PS file reached and"
+                               " no BoundingBox!" << endl;
                        break;
                }
                if (c == '%' && lastchar == '%') {
@@ -1756,15 +1764,17 @@ void InsetFig::GetPSSizes()
                                } 
 
                                if (lyxerr.debugging()) {
-                                       fprintf(stderr, "%%%%BoundingBox:"
-                                               " %d %d %d %d\n",
-                                               psx, psy, pswid, pshgh);
+                                       lyxerr << "%%%%BoundingBox:"
+                                              << psx << ' '
+                                              << psy << ' '
+                                              << pswid << ' '
+                                              << pshgh << endl;
                                        break;
                                }
                        }
                        c = 0;
                        delete[] p;
-                       p = NULL;
+                       p = 0;
                }
                lastchar = c;
        }
@@ -1817,7 +1827,7 @@ void InsetFig::CallbackFig(long arg)
                        fl_activate_object(form->Width);
                        break;
                default:
-                       lyxerr.debug("Unknown type!");
+                       lyxerr.debug() << "Unknown type!" << endl;
                        break;
                }
                regen = true;
@@ -1848,7 +1858,7 @@ void InsetFig::CallbackFig(long arg)
                        fl_activate_object(form->Height);
                        break;
                default:
-                       lyxerr.debug("Unknown type!");
+                       lyxerr.debug() << "Unknown type!" << endl;
                        break;
                }
                regen = true;
@@ -1896,13 +1906,13 @@ void InsetFig::CallbackFig(long arg)
                        angle = atof(fl_get_input(form->Angle));
                        p = fl_get_input(form->EpsFile);
                        if (p && *p) {
-                               LString buf1 = OnlyPath(owner->getFileName());
+                               string buf1 = OnlyPath(owner->getFileName());
                                fname = MakeAbsPath(p, buf1);
                                changedfname = true;
                        } else {
                                if (!fname.empty()) {
                                        changedfname = true;
-                                       fname.clean();
+                                       fname.clear();
                                }
                        }
                        subcaption = fl_get_input(form->Subcaption);
@@ -1911,14 +1921,20 @@ void InsetFig::CallbackFig(long arg)
                        Recompute();
                        /* now update inset */
                        if (lyxerr.debugging()) {
-                               fprintf(stderr, "Update: [%dx%d]\n", wid, hgh);
+                               lyxerr << "Update: ["
+                                      << wid << 'x' << hgh << ']' << endl;
                        }
                        UpdateInset(this);
                        if (arg == 8) {
+                               fl_set_focus_object(form->Figure, form->OkBtn);
                                fl_hide_form(form->Figure);
+#if FL_REVISION == 89
+#warning Reactivate this free_form calls
+#else
                                fl_free_form(form->Figure);
                                free(form);
-                               form = NULL;
+                               form = 0;
+#endif
                        }
                        break;
                } //if not readonly
@@ -1927,10 +1943,15 @@ void InsetFig::CallbackFig(long arg)
                        break;
                // fall through
        case 9:                         /* cancel = restore and close */
+               fl_set_focus_object(form->Figure, form->OkBtn);
                fl_hide_form(form->Figure);
+#if FL_REVISION == 89
+#warning Reactivate this free_form calls
+#else
                fl_free_form(form->Figure);
                free(form);
-               form = NULL;
+               form = 0;
+#endif
                break;
        }
 
@@ -2056,8 +2077,8 @@ void InsetFig::RestoreForm()
        sprintf(buf, "%g", angle);
        fl_set_input(form->Angle, buf);
        if (!fname.empty()){
-               LString buf1 = OnlyPath(owner->getFileName());
-               LString fname2 = MakeRelPath(fname, buf1);
+               string buf1 = OnlyPath(owner->getFileName());
+               string fname2 = MakeRelPath(fname, buf1);
                fl_set_input(form->EpsFile, fname2.c_str());
        }
        else fl_set_input(form->EpsFile, "");
@@ -2076,7 +2097,7 @@ void InsetFig::Preview(char const *p)
        pid = fork();
 
        if (pid == -1) {
-               lyxerr.print("Cannot fork process!");
+               lyxerr << "Cannot fork process!" << endl;
                return;         // error
        }
        if (pid > 0) {
@@ -2084,29 +2105,30 @@ void InsetFig::Preview(char const *p)
                return;         // parent process
        }
 
-       LString buf1 = OnlyPath(owner->getFileName());
-       LString buf2 = MakeAbsPath(p, buf1);
+       string buf1 = OnlyPath(owner->getFileName());
+       string buf2 = MakeAbsPath(p, buf1);
        
-       lyxerr.print(LString("Error during rendering ") +
-                     int(execlp(lyxrc->view_pspic_command.c_str(),
-                                lyxrc->view_pspic_command.c_str(),
-                                buf2.c_str(), 
-                                NULL)));
+       lyxerr << "Error during rendering "
+              << execlp(lyxrc->view_pspic_command.c_str(),
+                        lyxrc->view_pspic_command.c_str(),
+                        buf2.c_str(), 0)
+              << endl;
        _exit(0);
 }
 
 
 void InsetFig::BrowseFile()
 {
-       LString buf, buf2, bufclip;
-       static LString current_figure_path;
+       string buf, buf2, bufclip;
+       static string current_figure_path;
        static int once = 0;
        LyXFileDlg fileDlg;
 
        if (lyxerr.debugging()) {
-               fprintf(stderr, "Filename: %s\n", owner->getFileName().c_str());
+               lyxerr << "Filename: "
+                      << owner->getFileName() << endl;
        }
-       LString p = fl_get_input(form->EpsFile);
+       string p = fl_get_input(form->EpsFile);
 
        buf = MakeAbsPath(owner->getFileName());
        buf2 = OnlyPath(buf);
@@ -2133,10 +2155,10 @@ void InsetFig::BrowseFile()
                ProhibitInput();
                if (once) {
                        p =fileDlg.Select(_("EPS Figure"), current_figure_path,
-                                          "*ps", LString());
+                                          "*ps", string());
                } else {
                        p = fileDlg.Select(_("EPS Figure"), buf,
-                                          "*ps", LString());
+                                          "*ps", string());
                }
                AllowInput();
 
@@ -2146,8 +2168,8 @@ void InsetFig::BrowseFile()
                current_figure_path = OnlyPath(p);
                once = 1;
                
-               if (p.contains("#") || p.contains("~") || p.contains("$")
-                   || p.contains("%") || p.contains(" ")) 
+               if (contains(p, "#") || contains(p, "~") || contains(p, "$")
+                   || contains(p, "%") || contains(p, " ")) 
                {
                        WriteAlert(_("Filename can't contain any of these characters:"), // xgettext:no-c-format
                                   _("space, '#', '~', '$' or '%'.")); 
@@ -2164,7 +2186,7 @@ void GraphicsCB(FL_OBJECT *obj, long arg)
        /* obj->form contains the form */
 
        if (lyxerr.debugging()) {
-               lyxerr.print(LString("GraphicsCB callback: ") + long(arg));
+               lyxerr << "GraphicsCB callback: " << arg << endl;
        }
 
        /* find inset we were reacting to */
@@ -2173,8 +2195,7 @@ void GraphicsCB(FL_OBJECT *obj, long arg)
                    == obj->form) {
            
                        if (lyxerr.debugging()) {
-                               lyxerr.print(LString("Calling back figure ")
-                                            +int(i));
+                               lyxerr << "Calling back figure " << i << endl;
                        }
                        figures[i]->inset->CallbackFig(arg);
                        return;
@@ -2188,8 +2209,7 @@ void HideFiguresPopups()
                if (figures[i]->inset->form 
                    && figures[i]->inset->form->Figure->visible) {
                        if (lyxerr.debugging()) {
-                               lyxerr.print(LString("Hiding figure ")
-                                            +int(i));
+                               lyxerr << "Hiding figure " << i << endl;
                        }
                        // hide and free the form
                        figures[i]->inset->CallbackFig(9);