]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphics.C
prevent crash when inserting minipage in table cell,
[lyx.git] / src / insets / insetgraphics.C
index 46f49c08eaaf5a7ece41b1d6d8769e84dab81f26..c2b4a355f7e43ec987f3d1cdb60b42c8b5e72877 100644 (file)
@@ -82,13 +82,13 @@ TODO
 
 #include <algorithm> // For the std::max
 
-extern string system_tempdir;
 // set by Exporters
 
 using namespace lyx::support;
 
 using std::ostream;
 using std::endl;
+using std::auto_ptr;
 
 
 namespace {
@@ -143,7 +143,7 @@ InsetGraphics::InsetGraphics()
 
 
 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
-       : Inset(ig),
+       : InsetOld(ig),
          boost::signals::trackable(),
          graphic_label(uniqueID()),
          graphic_(new GraphicRenderer(*ig.graphic_))
@@ -153,9 +153,9 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig)
 }
 
 
-InsetBase * InsetGraphics::clone() const
+auto_ptr<InsetBase> InsetGraphics::clone() const
 {
-       return new InsetGraphics(*this);
+       return auto_ptr<InsetBase>(new InsetGraphics(*this));
 }
 
 
@@ -177,9 +177,9 @@ dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
-               string const bufpath = cmd.view()->buffer()->filePath();
+               Buffer const & buffer = *cmd.view()->buffer();
                InsetGraphicsParams p;
-               InsetGraphicsMailer::string2params(cmd.argument, bufpath, p);
+               InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
                if (!p.filename.empty()) {
                        setParams(p);
                        cmd.view()->updateInset(this);
@@ -197,7 +197,7 @@ dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd)
                return DISPATCHED;
 
        default:
-               return Inset::localDispatch(cmd);
+               return InsetOld::localDispatch(cmd);
        }
 }
 
@@ -215,7 +215,7 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-Inset::EDITABLE InsetGraphics::editable() const
+InsetOld::EDITABLE InsetGraphics::editable() const
 {
        return IS_EDITABLE;
 }
@@ -468,7 +468,7 @@ int InsetGraphics::latex(Buffer const * buf, ostream & os,
                << "insetgraphics::latex: Filename = "
                << params().filename.absFilename() << endl;
 
-       string const relative_file = 
+       string const relative_file =
                params().filename.relFilename(buf->filePath());
 
        // A missing (e)ps-extension is no problem for LaTeX, so
@@ -550,9 +550,14 @@ int InsetGraphics::ascii(Buffer const *, ostream & os, int) const
 }
 
 
-int InsetGraphics::linuxdoc(Buffer const *, ostream &) const
+int InsetGraphics::linuxdoc(Buffer const * buf, ostream & os) const
 {
-       // No graphics in LinuxDoc output. Should check how/what to add.
+       string const file_name = buf->niceFile ?
+                               params().filename.relFilename(buf->filePath()):
+                               params().filename.absFilename();
+
+       os << "<eps file=\"" << file_name << "\">\n";
+       os << "<img src=\"" << file_name << "\">";
        return 0;
 }
 
@@ -610,12 +615,6 @@ InsetGraphicsParams const & InsetGraphics::params() const
 }
 
 
-BufferView * InsetGraphics::view() const
-{
-       return graphic_->view();
-}
-
-
 string const InsetGraphicsMailer::name_("graphics");
 
 InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
@@ -623,18 +622,15 @@ InsetGraphicsMailer::InsetGraphicsMailer(InsetGraphics & inset)
 {}
 
 
-string const InsetGraphicsMailer::inset2string() const
+string const InsetGraphicsMailer::inset2string(Buffer const & buffer) const
 {
-       BufferView * bv = inset_.view();
-       if (bv)
-               return params2string(inset_.params(), bv->buffer()->filePath());
-       return string();
+       return params2string(inset_.params(), buffer);
 }
 
 
 void InsetGraphicsMailer::string2params(string const & in,
-                                       string const & buffer_path,
-                                       InsetGraphicsParams & params)
+                                       Buffer const & buffer,
+                                       InsetGraphicsParams & params)
 {
        params = InsetGraphicsParams();
 
@@ -654,7 +650,7 @@ void InsetGraphicsMailer::string2params(string const & in,
 
        if (lex.isOK()) {
                InsetGraphics inset;
-               inset.readInsetGraphics(lex, buffer_path);
+               inset.readInsetGraphics(lex, buffer.filePath());
                params = inset.params();
        }
 }
@@ -662,11 +658,11 @@ void InsetGraphicsMailer::string2params(string const & in,
 
 string const
 InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
-                                  string const & buffer_path)
+                                  Buffer const & buffer)
 {
        ostringstream data;
        data << name_ << ' ';
-       params.Write(data, buffer_path);
+       params.Write(data, buffer.filePath());
        data << "\\end_inset\n";
        return STRCONV(data.str());
 }