]> git.lyx.org Git - lyx.git/blobdiff - src/insets/figinset.C
Some more changes for updating text-insets.
[lyx.git] / src / insets / figinset.C
index 5729de4a681a3b4cd2ff1ff5c9191ff46858eac3..e546f7edbb4a77a819e83c7fef44dbe6f08a166e 100644 (file)
@@ -405,7 +405,7 @@ void InitFigures()
        if (lyxrc.use_gui) {
                fl_add_canvas_handler(figinset_canvas, ClientMessage,
                                      GhostscriptMsg,
-                                     current_view->owner()->getMainForm());
+                                     current_view->owner()->getForm());
 
                local_gc_copy = createGC();
 
@@ -775,7 +775,8 @@ figdata * getfigdata(int wid, int hgh, string const & fname,
 {
        /* first search for an exact match with fname and width/height */
 
-       if (fname.empty()) return 0;
+       if (fname.empty() || !IsFileReadable(fname)) 
+               return 0;
 
        for (bitmaps_type::iterator it = bitmaps.begin();
             it != bitmaps.end(); ++it) {
@@ -1033,10 +1034,11 @@ int InsetFig::width(Painter &, LyXFont const &) const
 }
 
 
-void InsetFig::draw(Painter & pain, LyXFont const & f,
-                   int baseline, float & x) const
+void InsetFig::draw(BufferView * bv, LyXFont const & f,
+                   int baseline, float & x, bool) const
 {
        LyXFont font(f);
+       Painter & pain = bv->painter();
        
        if (bitmap_waiting) getbitmaps();
        
@@ -1057,15 +1059,20 @@ void InsetFig::draw(Painter & pain, LyXFont const & f,
        } else {
                char * msg = 0;
                // draw frame
-               pain.rectangle(x, baseline - hgh - 1, wid + 1, hgh + 1);
+               pain.rectangle(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]");
+               } 
+               else if (fname.empty()) 
+                       msg = _("[no file]");
+               else if (!IsFileReadable(fname))
+                       msg = _("[bad file name]");
+               else if ((flags & 3) == 0) 
+                       msg = _("[not displayed]");
+               else if (lyxrc.ps_command.empty()) 
+                       msg = _("[no ghostscript]");
                
                if (!msg) msg = _("[unknown error]");
                
@@ -1082,7 +1089,7 @@ void InsetFig::draw(Painter & pain, LyXFont const & f,
 }
 
 
-void InsetFig::Write(ostream & os) const
+void InsetFig::Write(Buffer const *, ostream & os) const
 {
        Regenerate();
        os << "Figure size " << wid << " " << hgh << "\n";
@@ -1101,7 +1108,7 @@ void InsetFig::Write(ostream & os) const
 }
 
 
-void InsetFig::Read(LyXLex & lex)
+void InsetFig::Read(Buffer const *, LyXLex & lex)
 {
        string buf;
        bool finished = false;
@@ -1185,7 +1192,7 @@ void InsetFig::Read(LyXLex & lex)
 }
 
 
-int InsetFig::Latex(ostream & os,
+int InsetFig::Latex(Buffer const *, ostream & os,
                    bool /* fragile*/, bool /* fs*/) const
 {
        Regenerate();
@@ -1194,28 +1201,29 @@ int InsetFig::Latex(ostream & os,
 }
 
 
-int InsetFig::Ascii(ostream &) const
+int InsetFig::Ascii(Buffer const *, ostream &) const
 {
        return 0;
 }
 
 
-int InsetFig::Linuxdoc(ostream &) const
+int InsetFig::Linuxdoc(Buffer const *, ostream &) const
 {
        return 0;
 }
 
 
-int InsetFig::DocBook(ostream & os) const
+int InsetFig::DocBook(Buffer const *, ostream & os) const
 {
-       string figurename = fname;
+       string buf1 = OnlyPath(owner->fileName());
+       string figurename = MakeRelPath(fname, buf1);
 
        if(suffixIs(figurename, ".eps"))
                figurename.erase(fname.length() - 4);
 
        os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
        return 0;
-}
+} 
 
 
 void InsetFig::Validate(LaTeXFeatures & features) const
@@ -1299,7 +1307,8 @@ Inset * InsetFig::Clone() const
        tmp->pswid = pswid;
        tmp->pshgh = pshgh;
        tmp->fname = fname;
-       if (!fname.empty() && (flags & 3) && !lyxrc.ps_command.empty()
+       if (!fname.empty() && IsFileReadable(fname) 
+           && (flags & 3) && !lyxrc.ps_command.empty()
            && lyxrc.use_gui) { 
                // do not display if there is
                // "do not display" chosen (Matthias 260696)
@@ -1475,7 +1484,7 @@ void InsetFig::Recompute()
        /* now recompute wid and hgh, and if that is changed, set changed */
        /* this depends on chosen size of the picture and its bbox */
        // This will be redone in 0.13 ... (hen)
-       if (!fname.empty()) {
+       if (!fname.empty() && IsFileReadable(fname)) {
                // say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
 
                newx = frame_wid;
@@ -1554,7 +1563,7 @@ void InsetFig::Recompute()
                figdata * pf = figure->data;
 
                // get new data
-               if (!fname.empty() && (flags & 3)
+               if (!fname.empty() && IsFileReadable(fname) && (flags & 3)
                    && !lyxrc.ps_command.empty()) {
                        // do not display if there is "do not display"
                        // chosen (Matthias 260696)
@@ -1761,7 +1770,7 @@ void InsetFig::CallbackFig(long arg)
                        } else {
                                if (!fname.empty()) {
                                        changedfname = true;
-                                       fname.clear();
+                                       fname.erase();
                                }
                        }
                        subcaption = fl_get_input(form->Subcaption);
@@ -1912,11 +1921,11 @@ void InsetFig::RestoreForm()
                fl_activate_object(form->Height);
        }
 
-       int pflags = flags & 3;
-       fl_set_button(form->Wysiwyg0, (pflags == 0));
-       fl_set_button(form->Wysiwyg1, (pflags == 1));
-       fl_set_button(form->Wysiwyg2, (pflags == 2));
-       fl_set_button(form->Wysiwyg3, (pflags == 3));
+       int piflags = flags & 3;
+       fl_set_button(form->Wysiwyg0, (piflags == 0));
+       fl_set_button(form->Wysiwyg1, (piflags == 1));
+       fl_set_button(form->Wysiwyg2, (piflags == 2));
+       fl_set_button(form->Wysiwyg3, (piflags == 3));
        fl_set_button(form->Frame, ((flags & 4) != 0));
        fl_set_button(form->Translations, ((flags & 8) != 0));
        fl_set_button(form->Subfigure, (subfigure != 0));