]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetGraphics.cpp
pimpl not needed here
[lyx.git] / src / insets / InsetGraphics.cpp
index 70cfe9767d719a3d35a8a24788fe9cca231b2310..7d1ea0bd4d81c8828234bd15136b314ed30b789c 100644 (file)
@@ -76,6 +76,7 @@ TODO
 #include "frontends/alert.h"
 
 #include "support/convert.h"
+#include "support/docstream.h"
 #include "support/filetools.h"
 #include "support/lyxlib.h" // sum
 #include "support/lstrings.h"
@@ -99,7 +100,6 @@ using support::DocFileName;
 using support::FileName;
 using support::float_equal;
 using support::getExtension;
-using support::isFileReadable;
 using support::isValidLaTeXFilename;
 using support::latex_path;
 using support::onlyFilename;
@@ -239,24 +239,32 @@ void InsetGraphics::registerEmbeddedFiles(Buffer const &,
 }
 
 
+void InsetGraphics::updateEmbeddedFile(Buffer const & buf,
+       EmbeddedFile const & file)
+{
+       BOOST_ASSERT(buf.embeddedFiles().enabled());
+       params_.filename = file;
+       LYXERR(Debug::FILES) << "Update InsetGraphic with File " 
+               << params_.filename.toFilesystemEncoding() 
+               << ", embedding status: "
+               << params_.filename.embedded() << std::endl;
+}
+
+
 void InsetGraphics::edit(Cursor & cur, bool)
 {
        InsetGraphicsMailer(*this).showDialog(&cur.bv());
 }
 
 
-bool InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        graphic_->metrics(mi, dim);
-       bool const changed = dim_ != dim;
-       dim_ = dim;
-       return changed;
 }
 
 
 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
-       setPosCache(pi, x, y);
        graphic_->draw(pi, x, y);
 }
 
@@ -291,7 +299,7 @@ void InsetGraphics::read(Buffer const & buf, Lexer & lex)
                if (it != buf.embeddedFiles().end())
                        // using available file, embedded or external, depending on file availability and
                        // embedding status.
-                       params_.filename = DocFileName(it->availableFile(&buf));
+                       params_.filename = *it;
        }
        graphic_->update(params().as_grfxParams());
 }
@@ -442,7 +450,8 @@ docstring const InsetGraphics::createDocBookAttributes() const
        // Calculate the options part of the command, we must do it to a string
        // stream since we copied the code from createLatexParams() ;-)
 
-       // FIXME: av: need to translate spec -> Docbook XSL spec (http://www.sagehill.net/docbookxsl/ImageSizing.html)
+       // FIXME: av: need to translate spec -> Docbook XSL spec
+       // (http://www.sagehill.net/docbookxsl/ImageSizing.html)
        // Right now it only works with my version of db2latex :-)
 
        odocstringstream options;
@@ -476,7 +485,7 @@ docstring const InsetGraphics::createDocBookAttributes() const
 
 namespace {
 
-enum CopyStatus {
+enum GraphicsCopyStatus {
        SUCCESS,
        FAILURE,
        IDENTICAL_PATHS,
@@ -484,7 +493,7 @@ enum CopyStatus {
 };
 
 
-std::pair<CopyStatus, FileName> const
+std::pair<GraphicsCopyStatus, FileName> const
 copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
 {
        unsigned long const checksum_in  = support::sum(file_in);
@@ -505,12 +514,12 @@ copyFileIfNeeded(FileName const & file_in, FileName const & file_out)
                        << std::endl;
        }
 
-       CopyStatus status = success ? SUCCESS : FAILURE;
+       GraphicsCopyStatus status = success ? SUCCESS : FAILURE;
        return std::make_pair(status, file_out);
 }
 
 
-std::pair<CopyStatus, FileName> const
+std::pair<GraphicsCopyStatus, FileName> const
 copyToDirIfNeeded(DocFileName const & file, string const & dir)
 {
        using support::rtrim;
@@ -598,34 +607,33 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
 
        // The master buffer. This is useful when there are multiple levels
        // of include files
-       Buffer const * m_buffer = buf.getMasterBuffer();
+       Buffer const * masterBuffer = buf.masterBuffer();
 
        // Return the output name if we are inside a comment or the file does
        // not exist.
        // We are not going to change the extension or using the name of the
        // temporary file, the code is already complicated enough.
-       if (runparams.inComment || !isFileReadable(params().filename))
-               return params().filename.outputFilename(m_buffer->filePath());
+       if (runparams.inComment || !params().filename.isFileReadable())
+               return params().filename.outputFilename(masterBuffer->filePath());
 
        // We place all temporary files in the master buffer's temp dir.
        // This is possible because we use mangled file names.
        // This is necessary for DVI export.
-       string const temp_path = m_buffer->temppath();
+       string const temp_path = masterBuffer->temppath();
 
-       CopyStatus status;
+       GraphicsCopyStatus status;
        boost::tie(status, temp_file) =
                        copyToDirIfNeeded(params().filename, temp_path);
 
        if (status == FAILURE)
                return orig_file;
 
-       // a relative filename should be relative to the master
-       // buffer.
+       // a relative filename should be relative to the master buffer.
        // "nice" means that the buffer is exported to LaTeX format but not
-       //        run through the LaTeX compiler.
-       string output_file = support::os::external_path(runparams.nice ?
-               params().filename.outputFilename(m_buffer->filePath()) :
-               onlyFilename(temp_file.absFilename()));
+       // run through the LaTeX compiler.
+       string output_file = runparams.nice ?
+               params().filename.outputFilename(masterBuffer->filePath()) :
+               onlyFilename(temp_file.absFilename());
 
        if (runparams.nice && !isValidLaTeXFilename(output_file)) {
                frontend::Alert::warning(_("Invalid filename"),
@@ -787,8 +795,8 @@ int InsetGraphics::latex(Buffer const & buf, odocstream & os,
        string const relative_file =
                params().filename.relFilename(buf.filePath());
 
-       bool const file_exists = !params().filename.empty() &&
-                                isFileReadable(params().filename);
+       bool const file_exists = !params().filename.empty()
+                       && params().filename.isFileReadable();
        string const message = file_exists ?
                string() : string("bb = 0 0 200 100, draft, type=eps");
        // if !message.empty() then there was no existing file
@@ -942,8 +950,8 @@ void InsetGraphics::validate(LaTeXFeatures & features) const
        features.require("graphicx");
 
        if (features.runparams().nice) {
-               Buffer const * m_buffer = features.buffer().getMasterBuffer();
-               string const rel_file = removeExtension(params().filename.relFilename(m_buffer->filePath()));
+               Buffer const * masterBuffer = features.buffer().masterBuffer();
+               string const rel_file = removeExtension(params().filename.relFilename(masterBuffer->filePath()));
                if (contains(rel_file, "."))
                        features.require("lyxdot");
        }