]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetgraphics.C
* insettabular.[Ch]: remove remains of the 'update' mechanism,
[lyx.git] / src / insets / insetgraphics.C
index db63aaba09893bb1e210c225fb518519efe21c6c..bb4a0cdfd0e749ca75136b3f5a35ffd1296e098b 100644 (file)
@@ -53,21 +53,26 @@ 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 "cursor.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "format.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "latexrunparams.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/lyxalgo.h" // lyx::count
@@ -75,12 +80,11 @@ TODO
 #include "support/os.h"
 #include "support/systemcall.h"
 #include "support/tostr.h"
+#include "support/std_sstream.h"
 
 #include <boost/bind.hpp>
 #include <boost/tuple/tuple.hpp>
 
-#include "support/std_sstream.h"
-
 namespace support = lyx::support;
 using lyx::support::AbsolutePath;
 using lyx::support::bformat;
@@ -129,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";
@@ -152,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));
 }
@@ -162,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());
@@ -183,41 +187,45 @@ InsetGraphics::~InsetGraphics()
 
 void InsetGraphics::statusChanged() const
 {
-       BufferView * bv = graphic_->view();
-       if (bv)
-               bv->updateInset(this);
+       LyX::cref().updateInset(this);
 }
 
 
-dispatch_result InsetGraphics::localDispatch(FuncRequest const & cmd)
+void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
-               Buffer const & buffer = *cmd.view()->buffer();
+               Buffer const & buffer = *cur.bv().buffer();
                InsetGraphicsParams p;
                InsetGraphicsMailer::string2params(cmd.argument, buffer, p);
                if (!p.filename.empty()) {
                        setParams(p);
-                       cmd.view()->updateInset(this);
+                       cur.bv().update();
                }
-               return DISPATCHED;
+               break;
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               InsetGraphicsMailer(*this).updateDialog(cmd.view());
-               return DISPATCHED;
+               InsetGraphicsMailer(*this).updateDialog(&cur.bv());
+               break;
 
-       case LFUN_INSET_EDIT:
        case LFUN_MOUSE_RELEASE:
-               InsetGraphicsMailer(*this).showDialog(cmd.view());
-               return DISPATCHED;
+               InsetGraphicsMailer(*this).showDialog(&cur.bv());
+               break;
 
        default:
-               return InsetOld::localDispatch(cmd);
+               InsetOld::priv_dispatch(cur, cmd);
+               break;
        }
 }
 
 
+void InsetGraphics::edit(LCursor & cur, bool)
+{
+       InsetGraphicsMailer(*this).showDialog(&cur.bv());
+}
+
+
 void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        graphic_->metrics(mi, dim);
@@ -227,6 +235,7 @@ void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
+       setPosCache(pi, x, y);
        graphic_->draw(pi, x, y);
 }
 
@@ -408,7 +417,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());
@@ -531,7 +540,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.
@@ -608,7 +617,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.
@@ -621,9 +631,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 & runparams) const
 {
-       string const file_name = buf.niceFile() ?
+       string const file_name = runparams.nice ?
                                params().filename.relFilename(buf.filePath()):
                                params().filename.absFilename();
 
@@ -637,7 +648,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
@@ -704,7 +715,6 @@ void InsetGraphicsMailer::string2params(string const & in,
                                        InsetGraphicsParams & params)
 {
        params = InsetGraphicsParams();
-
        if (in.empty())
                return;
 
@@ -712,18 +722,14 @@ void InsetGraphicsMailer::string2params(string const & in,
        LyXLex lex(0,0);
        lex.setStream(data);
 
-       if (lex.isOK()) {
-               lex.next();
-               string const token = lex.getString();
-               if (token != name_)
-                       return;
-       }
+       string name;
+       lex >> name;
+       if (!lex || name != name_)
+               return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
 
-       if (lex.isOK()) {
-               InsetGraphics inset;
-               inset.readInsetGraphics(lex, buffer.filePath());
-               params = inset.params();
-       }
+       InsetGraphics inset;
+       inset.readInsetGraphics(lex, buffer.filePath());
+       params = inset.params();
 }