]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphics.C
Prevent an assert when opening the citation dialog if the bibtex
[lyx.git] / src / insets / insetgraphics.C
index 5b5a5cad3e09d8e1b364db2749bd3098cf620e47..4a025357c98d4cc4bec63d749f64de4341e6cff4 100644 (file)
@@ -4,7 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Baruch Even
- * \author Herbert Voss
+ * \author Herbert Voß
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -53,24 +53,27 @@ TODO
 #include <config.h>
 
 #include "insets/insetgraphics.h"
-#include "insets/renderers.h"
+#include "insets/render_graphic.h"
 
 #include "buffer.h"
 #include "BufferView.h"
 #include "converter.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "format.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "support/std_sstream.h"
+#include "lyx_main.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
+#include "metricsinfo.h"
+#include "outputparams.h"
 
 #include "frontends/Alert.h"
+#include "frontends/LyXView.h"
 
 #include "support/filetools.h"
-#include "support/LAssert.h"
 #include "support/lyxalgo.h" // lyx::count
 #include "support/lyxlib.h" // float_equal
 #include "support/os.h"
@@ -80,10 +83,28 @@ TODO
 #include <boost/bind.hpp>
 #include <boost/tuple/tuple.hpp>
 
+#include "support/std_sstream.h"
+
 namespace support = lyx::support;
-using namespace lyx::support;
+using lyx::support::AbsolutePath;
+using lyx::support::bformat;
+using lyx::support::ChangeExtension;
+using lyx::support::contains;
+using lyx::support::FileName;
+using lyx::support::float_equal;
+using lyx::support::GetExtension;
+using lyx::support::getExtFromContents;
+using lyx::support::IsFileReadable;
+using lyx::support::LibFileSearch;
+using lyx::support::rtrim;
+using lyx::support::Systemcall;
+using lyx::support::unzipFile;
+using lyx::support::unzippedFileName;
+
+namespace os = lyx::support::os;
 
 using std::endl;
+using std::string;
 using std::auto_ptr;
 using std::istringstream;
 using std::ostream;
@@ -112,10 +133,10 @@ string const uniqueID()
 }
 
 
-string findTargetFormat(string const & suffix, LatexRunParams const & runparams)
+string findTargetFormat(string const & suffix, OutputParams const & runparams)
 {
        // Are we using latex or pdflatex).
-       if (runparams.flavor == LatexRunParams::PDFLATEX) {
+       if (runparams.flavor == OutputParams::PDFLATEX) {
                lyxerr[Debug::GRAPHICS] << "findTargetFormat: PDF mode" << endl;
                if (contains(suffix, "ps") || suffix == "pdf")
                        return "pdf";
@@ -135,7 +156,7 @@ string findTargetFormat(string const & suffix, LatexRunParams const & runparams)
 
 InsetGraphics::InsetGraphics()
        : graphic_label(uniqueID()),
-         graphic_(new GraphicRenderer)
+         graphic_(new RenderGraphic)
 {
        graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
 }
@@ -145,7 +166,7 @@ InsetGraphics::InsetGraphics(InsetGraphics const & ig)
        : InsetOld(ig),
          boost::signals::trackable(),
          graphic_label(uniqueID()),
-         graphic_(new GraphicRenderer(*ig.graphic_))
+         graphic_(new RenderGraphic(*ig.graphic_))
 {
        graphic_->connect(boost::bind(&InsetGraphics::statusChanged, this));
        setParams(ig.params());
@@ -164,15 +185,14 @@ InsetGraphics::~InsetGraphics()
 }
 
 
-void InsetGraphics::statusChanged()
+void InsetGraphics::statusChanged() const
 {
-       BufferView * bv = graphic_->view();
-       if (bv)
-               bv->updateInset(this);
+       LyX::cref().updateInset(this);
 }
 
 
-dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd)
+DispatchResult
+InsetGraphics::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
@@ -181,26 +201,31 @@ dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd)
                InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
                if (!p.filename.empty()) {
                        setParams(p);
-                       cmd.view()->updateInset(this);
+                       cmd.view()->update();
                }
-               return DISPATCHED;
+               return DispatchResult(true, true);
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
                InsetGraphicsMailer(*this).updateDialog(cmd.view());
-               return DISPATCHED;
+               return DispatchResult(true, true);
 
-       case LFUN_INSET_EDIT:
        case LFUN_MOUSE_RELEASE:
                InsetGraphicsMailer(*this).showDialog(cmd.view());
-               return DISPATCHED;
+               return DispatchResult(true, true);
 
        default:
-               return InsetOld::localDispatch(cmd);
+               return DispatchResult(false);
        }
 }
 
 
+void InsetGraphics::edit(BufferView * bv, bool)
+{
+       InsetGraphicsMailer(*this).showDialog(bv);
+}
+
+
 void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        graphic_->metrics(mi, dim);
@@ -210,6 +235,8 @@ void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
+       xo_ = x;
+       yo_ = y;
        graphic_->draw(pi, x, y);
 }
 
@@ -319,7 +346,7 @@ string const InsetGraphics::createLatexOptions() const
        if (!params().special.empty())
            options << params().special << ",\n";
 
-       string opts = STRCONV(options.str());
+       string opts = options.str();
        // delete last ",\n"
        return opts.substr(0, opts.size() - 2);
 }
@@ -340,7 +367,7 @@ copyToDirIfNeeded(string const & file_in, string const & dir)
 {
        using support::rtrim;
 
-       support::Assert(AbsolutePath(file_in));
+       BOOST_ASSERT(AbsolutePath(file_in));
 
        string const only_path = support::OnlyPath(file_in);
        if (rtrim(support::OnlyPath(file_in) , "/") == rtrim(dir, "/"))
@@ -356,7 +383,7 @@ copyToDirIfNeeded(string const & file_in, string const & dir)
                mangled = FileName(file_in).mangledFilename();
 
        string const file_out = support::MakeAbsPath(mangled, dir);
-       
+
        unsigned long const checksum_in  = support::sum(file_in);
        unsigned long const checksum_out = support::sum(file_out);
 
@@ -391,7 +418,7 @@ string const stripExtensionIfPossible(string const & file, string const & to)
 
 
 string const InsetGraphics::prepareFile(Buffer const & buf,
-                                       LatexRunParams const & runparams) const
+                                       OutputParams const & runparams) const
 {
        string orig_file = params().filename.absFilename();
        string const rel_file = params().filename.relFilename(buf.filePath());
@@ -425,7 +452,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
        if (zipped) {
                CopyStatus status;
                boost::tie(status, temp_file) =
-                       copyToDirIfNeeded(orig_file, buf.tmppath);
+                       copyToDirIfNeeded(orig_file, buf.temppath());
 
                if (status == FAILURE)
                        return orig_file;
@@ -437,7 +464,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
                                << "\tunzipped to " << orig_file << endl;
                }
        }
-       
+
        string const from = getExtFromContents(orig_file);
        string const to   = findTargetFormat(from, runparams);
        lyxerr[Debug::GRAPHICS]
@@ -457,7 +484,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
        if (lyxrc.use_tempdir) {
                CopyStatus status;
                boost::tie(status, temp_file) =
-                       copyToDirIfNeeded(orig_file, buf.tmppath);
+                       copyToDirIfNeeded(orig_file, buf.temppath());
 
                if (status == FAILURE)
                        return orig_file;
@@ -514,7 +541,7 @@ string const InsetGraphics::prepareFile(Buffer const & buf,
 
 
 int InsetGraphics::latex(Buffer const & buf, ostream & os,
-                        LatexRunParams const & runparams) const
+                        OutputParams const & runparams) const
 {
        // If there is no file specified or not existing,
        // just output a message about it in the latex output.
@@ -591,7 +618,8 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os,
 }
 
 
-int InsetGraphics::ascii(Buffer const &, ostream & os, int) const
+int InsetGraphics::plaintext(Buffer const &, ostream & os,
+                        OutputParams const &) const
 {
        // No graphics in ascii output. Possible to use gifscii to convert
        // images to ascii approximation.
@@ -604,9 +632,10 @@ int InsetGraphics::ascii(Buffer const &, ostream & os, int) const
 }
 
 
-int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os) const
+int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os,
+                           OutputParams const &) const
 {
-       string const file_name = buf.niceFile ?
+       string const file_name = buf.niceFile() ?
                                params().filename.relFilename(buf.filePath()):
                                params().filename.absFilename();
 
@@ -620,7 +649,7 @@ int InsetGraphics::linuxdoc(Buffer const & buf, ostream & os) const
 // http://en.tldp.org/LDP/LDP-Author-Guide/inserting-pictures.html
 // See also the docbook guide at http://www.docbook.org/
 int InsetGraphics::docbook(Buffer const &, ostream & os,
-                          bool /*mixcont*/) const
+                          OutputParams const &) const
 {
        // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will
        // need to switch to MediaObject. However, for now this is sufficient and
@@ -691,7 +720,7 @@ void InsetGraphicsMailer::string2params(string const & in,
        if (in.empty())
                return;
 
-       istringstream data(STRCONV(in));
+       istringstream data(in);
        LyXLex lex(0,0);
        lex.setStream(data);
 
@@ -718,5 +747,5 @@ InsetGraphicsMailer::params2string(InsetGraphicsParams const & params,
        data << name_ << ' ';
        params.Write(data, buffer.filePath());
        data << "\\end_inset\n";
-       return STRCONV(data.str());
+       return data.str();
 }