]> 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 d1a5103e604d1ce2e8706937b833903eebf5a660..490a8b0fc1c8f3480fa3b5a091836e891632ce87 100644 (file)
@@ -2,9 +2,6 @@
  *     figinset.C - part of LyX project
  */
 
-#ifdef MONO
-extern int     reverse_video;
-#endif
 extern long int background_pixels;
 
 /*  Rework of path-handling (Matthias 04.07.1996 )
@@ -60,9 +57,6 @@ using std::flush;
 #include "support/filetools.h"
 #include "LyXView.h" // just because of form_main
 #include "debug.h"
-#ifndef USE_PAINTER
-#include "lyxdraw.h"
-#endif
 #include "LaTeXFeatures.h"
 #include "lyxrc.h"
 #include "gettext.h"
@@ -75,9 +69,7 @@ extern BufferView * current_view;
 extern FL_OBJECT * figinset_canvas;
 
 extern char ** environ; // is this only redundtant on linux systems? Lgb.
-extern void UpdateInset(BufferView *, Inset * inset, bool mark_dirty = true);
-// better for asyncron updating:
-void PutInsetIntoInsetUpdateList(Inset * inset);
+
 extern void ProhibitInput();
 extern void AllowInput();
 
@@ -243,11 +235,10 @@ extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
                                // query current colormap
                                        XColor * cmap = new XColor[gs_allcolors];
                                        for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
-#if 1
-                                       XQueryColors(tmpdisp, fl_state[fl_get_vclass()].colormap, cmap, gs_allcolors);
-#else
-                                       XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
-#endif
+                                       XQueryColors(tmpdisp,
+                                                    fl_state[fl_get_vclass()]
+                                                    .colormap, cmap,
+                                                    gs_allcolors);
                                        XFlush(tmpdisp);
                                        wid1 = p->wid - 1;
                                // now we process all the image
@@ -312,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()) {
@@ -411,11 +403,6 @@ void InitFigures()
        fl_add_canvas_handler(figinset_canvas, ClientMessage,
                              GhostscriptMsg, current_view->owner()->getMainForm());
 
-#if 0
-       // now we have to init color_map
-       if (!color_map) color_map = DefaultColormap(fl_display,
-                                                   DefaultScreen(fl_display));
-#endif
        // allocate color cube on pseudo-color display
        // first get visual
        gs_color = false;
@@ -457,15 +444,6 @@ void DoneFigures()
 
        fl_remove_canvas_handler(figinset_canvas, ClientMessage,
                                 GhostscriptMsg);
-
-#if 0
-       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 ??????***/
-       }
-#endif
 }
 
 
@@ -480,7 +458,8 @@ int FindBmpIndex(figdata * tmpdata)
 }
 
 
-static void freefigdata(figdata * tmpdata)
+static
+void freefigdata(figdata * tmpdata)
 {
        tmpdata->ref--;
        if (tmpdata->ref) return;
@@ -506,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) {
@@ -647,31 +627,9 @@ static void runqueue()
                                break;
                        }
 
-#ifdef USE_PAINTER
-#ifdef MONO
-                       if (reverse_video) {
-                               sprintf(tbuf+1, " %ld %ld", WhitePixelOfScreen(
-                                       DefaultScreenOfDisplay(fl_display)),
-                                       fl_get_pixel(FL_BLACK));
-                       } else {
-#endif
-                               sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
-                                       DefaultScreenOfDisplay(fl_display)),
-                                       fl_get_pixel(FL_WHITE));
-#ifdef MONO
-                       }
-#endif
-#else
-                       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);
-                       }
-#endif
+                       sprintf(tbuf+1, " %ld %ld", BlackPixelOfScreen(
+                               DefaultScreenOfDisplay(fl_display)),
+                               fl_get_pixel(FL_WHITE));
 
                        XChangeProperty(tempdisp, 
                                        fl_get_canvas_id(figinset_canvas),
@@ -744,7 +702,8 @@ static void runqueue()
 }
 
 
-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_element p;
@@ -762,7 +721,8 @@ static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
 }
 
 
-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)
 {
@@ -833,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) {
@@ -849,7 +811,7 @@ static void makeupdatelist(figdata * p)
                                       << endl;
                        }
                        // add inset figures[i]->inset into to_update list
-                       PutInsetIntoInsetUpdateList(figures[i]->inset);
+                       current_view->pushIntoUpdateList(figures[i]->inset);
                }
 }
 
@@ -936,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)
@@ -945,7 +908,8 @@ static void getbitmaps()
 }
 
 
-static void RegisterFigure(InsetFig * fi)
+static
+void RegisterFigure(InsetFig * fi)
 {
        if (figinsref == 0) InitFigures();
        fi->form = 0;
@@ -956,7 +920,7 @@ static void RegisterFigure(InsetFig * fi)
                typedef Figref * Figref_p;
                Figref ** tmp = new Figref_p[figarrsize];
                memcpy(tmp, figures,
-                      sizeof(Figref*)*(figarrsize-figallocchunk));
+                      sizeof(Figref*) * (figarrsize-figallocchunk));
                delete[] figures;
                figures = tmp;
        }
@@ -984,7 +948,8 @@ int FindFigIndex(Figref * tmpfig)
 }
 
 
-static void UnregisterFigure(InsetFig * fi)
+static
+void UnregisterFigure(InsetFig * fi)
 {
        Figref * tmpfig = fi->figure;
 
@@ -1015,7 +980,8 @@ static void UnregisterFigure(InsetFig * fi)
 }
 
 
-static string NextToken(istream & is)
+static
+string NextToken(istream & is)
 {
        string token;
        char c;
@@ -1058,46 +1024,24 @@ InsetFig::~InsetFig()
 }
 
 
-#ifdef USE_PAINTER
 int InsetFig::ascent(Painter &, LyXFont const &) const
 {
        return hgh + 3;
 }
-#else
-int InsetFig::Ascent(LyXFont const &) const
-{
-       return hgh + 3;
-}
-#endif
 
 
-#ifdef USE_PAINTER
 int InsetFig::descent(Painter &, LyXFont const &) const
 {
        return 1;
 }
-#else
-int InsetFig::Descent(LyXFont const &) const
-{
-       return 1;
-}
-#endif
 
 
-#ifdef USE_PAINTER
 int InsetFig::width(Painter &, LyXFont const &) const
 {
        return wid + 2;
 }
-#else
-int InsetFig::Width(LyXFont const &) const
-{
-       return wid + 2;
-}
-#endif
 
 
-#ifdef USE_PAINTER
 void InsetFig::draw(Painter & pain, LyXFont const & f,
                    int baseline, float & x) const
 {
@@ -1145,59 +1089,9 @@ void InsetFig::draw(Painter & pain, LyXFont const & f,
        }
        x += width(pain, font);    // ?
 }
-#else
-void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
-{
-       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, local_gc_copy,
-                         0, 0, wid, hgh, int(x+1), baseline-hgh);
-               XFlush(fl_display);
-               if (flags & 4) XDrawRectangle(fl_display, pm, local_gc_copy,
-                                             int(x), baseline - hgh - 1,
-                                             wid+1, hgh+1);
-       } else {
-               char * msg = 0;
-               // draw frame
-               XDrawRectangle(fl_display, pm, local_gc_copy,
-                              int(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 ... ]");
-               } else 
-                       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);
-               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);
-
-       }
-       x += Width(font);    // ?
-}
-#endif
 
 
-void InsetFig::Write(ostream & os)
+void InsetFig::Write(ostream & os) const
 {
        Regenerate();
        os << "Figure size " << wid << " " << hgh << "\n";
@@ -1300,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 << " ";
@@ -1308,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 + ' ';
@@ -1316,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;
 
@@ -1333,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
 {
@@ -1353,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();
@@ -1361,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();
@@ -1430,7 +1345,7 @@ Inset::Code InsetFig::LyxCode() const
 }
 
 
-void InsetFig::Regenerate()
+void InsetFig::Regenerate() const
 {
        string cmdbuf;
        string resizeW, resizeH;
@@ -1991,7 +1906,7 @@ void InsetFig::CallbackFig(long arg)
                                lyxerr << "Update: ["
                                       << wid << 'x' << hgh << ']' << endl;
                        }
-                       UpdateInset(current_view, this);
+                       current_view->updateInset(this, true);
                        if (arg == 8) {
                                fl_set_focus_object(form->Figure, form->OkBtn);
                                fl_hide_form(form->Figure);
@@ -2027,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);
@@ -2063,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);