]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetGraphics.cpp
Remove all BufferParam arguments in InsetXXX methods (since insets know about their...
[lyx.git] / src / insets / InsetGraphics.cpp
index dce13c03fb3a2864f98276854699b5aa9e2a4b35..9decdaaa80cc0b0ee08a5ee6bb54bb22d922b202 100644 (file)
@@ -4,7 +4,7 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Baruch Even
- * \author Herbert Voß
+ * \author Herbert Voß
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -59,6 +59,7 @@ TODO
 #include "Format.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetIterator.h"
 #include "LaTeXFeatures.h"
 #include "Length.h"
 #include "Lexer.h"
@@ -82,7 +83,6 @@ TODO
 #include "support/os.h"
 #include "support/Systemcall.h"
 
-#include <boost/bind.hpp>
 #include <boost/tuple/tuple.hpp>
 
 #include <algorithm>
@@ -101,8 +101,9 @@ namespace {
 /// Note that \p format may be unknown (i. e. an empty string)
 string findTargetFormat(string const & format, OutputParams const & runparams)
 {
-       // Are we using latex or pdflatex?
-       if (runparams.flavor == OutputParams::PDFLATEX) {
+       // Are we using latex or XeTeX/pdflatex?
+       if (runparams.flavor == OutputParams::PDFLATEX
+           || runparams.flavor == OutputParams::XETEX) {
                LYXERR(Debug::GRAPHICS, "findTargetFormat: PDF mode");
                Format const * const f = formats.getFormat(format);
                // Convert vector graphics to pdf
@@ -163,8 +164,7 @@ InsetGraphics::InsetGraphics(Buffer & buf)
 
 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
        : Inset(ig),
-         boost::signals::trackable(),
-               graphic_label(sgml::uniqueID(from_ascii("graph"))),
+         graphic_label(sgml::uniqueID(from_ascii("graph"))),
          graphic_(new RenderGraphic(*ig.graphic_, this))
 {
        setParams(ig.params());
@@ -180,6 +180,7 @@ Inset * InsetGraphics::clone() const
 InsetGraphics::~InsetGraphics()
 {
        hideDialogs("graphics", this);
+       delete graphic_;
 }
 
 
@@ -197,22 +198,22 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_INSET_MODIFY: {
                InsetGraphicsParams p;
                string2params(to_utf8(cmd.argument()), buffer(), p);
-               if (!p.filename.empty())
-                       setParams(p);
-               else
+               if (p.filename.empty()) {
                        cur.noUpdate();
+                       break;
+               }
+
+               setParams(p);
+               // if the inset is part of a graphics group, all the
+               // other members should be updated too.
+               if (!params_.groupId.empty())
+                       graphics::unifyGraphicsGroups(buffer(), 
+                                                     to_utf8(cmd.argument()));
                break;
        }
 
        case LFUN_INSET_DIALOG_UPDATE:
-               cur.bv().updateDialog("graphics", params2string(params(),
-                                     cur.bv().buffer()));
-               break;
-
-       case LFUN_MOUSE_RELEASE:
-               if (!cur.selection() && cmd.button() == mouse_button::button1)
-                       cur.bv().showDialog("graphics", params2string(params(),
-                                           cur.bv().buffer()), this);
+               cur.bv().updateDialog("graphics", params2string(params(), buffer()));
                break;
 
        default:
@@ -229,7 +230,7 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_INSET_EDIT:
        case LFUN_INSET_MODIFY:
        case LFUN_INSET_DIALOG_UPDATE:
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        default:
@@ -238,13 +239,15 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 }
 
 
-void InsetGraphics::edit(Cursor & cur, bool, EntryDirection)
+bool InsetGraphics::showInsetDialog(BufferView * bv) const
 {
-       cur.bv().showDialog("graphics", params2string(params(),
-               cur.bv().buffer()), this);
+       bv->showDialog("graphics", params2string(params(), bv->buffer()),
+               const_cast<InsetGraphics *>(this));
+       return true;
 }
 
 
+
 void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        graphic_->metrics(mi, dim);
@@ -257,12 +260,6 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 }
 
 
-Inset::EDITABLE InsetGraphics::editable() const
-{
-       return IS_EDITABLE;
-}
-
-
 void InsetGraphics::write(ostream & os) const
 {
        os << "Graphics\n";
@@ -661,7 +658,7 @@ string InsetGraphics::prepareFile(OutputParams const & runparams) const
        LYXERR(Debug::GRAPHICS, "\tthe orig file is: " << orig_file);
 
        if (from == to) {
-               if (!runparams.nice && getExtension(temp_file.absFilename()) != ext) {
+               if (!runparams.nice && !FileName(temp_file).hasExtension(ext)) {
                        // The LaTeX compiler will not be able to determine
                        // the file format from the extension, so we must
                        // change it.
@@ -906,11 +903,12 @@ void InsetGraphics::editGraphics(InsetGraphicsParams const & p,
 }
 
 
-void InsetGraphics::addToToc(ParConstIterator const & cpit) const
+void InsetGraphics::addToToc(DocIterator const & cpit)
 {
        TocBackend & backend = buffer().tocBackend();
 
-       docstring const str = params_.filename.displayName();
+       //FIXME UNICODE
+       docstring const str = from_utf8(params_.filename.onlyFileName());
        backend.toc("graphics").push_back(TocItem(cpit, 0, str));
 }
 
@@ -947,5 +945,97 @@ string InsetGraphics::params2string(InsetGraphicsParams const & params,
        return data.str();
 }
 
+namespace graphics {
+
+void getGraphicsGroups(Buffer const & b, set<string> & ids)
+{
+       Inset & inset = b.inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it)
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       InsetGraphicsParams inspar = ins.getParams();
+                       if (!inspar.groupId.empty())
+                               ids.insert(inspar.groupId);
+               }
+}
+
+
+int countGroupMembers(Buffer const & b, string const & groupId)
+{
+       int n = 0;
+       if (groupId.empty())
+               return n;
+       Inset & inset = b.inset();
+       InsetIterator it = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it)
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       if (ins.getParams().groupId == groupId)
+                               ++n;
+               }
+       return n;
+}
+
+
+string getGroupParams(Buffer const & b, string const & groupId)
+{
+       if (groupId.empty())
+               return string();
+       Inset & inset = b.inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it)
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       InsetGraphicsParams inspar = ins.getParams();
+                       if (inspar.groupId == groupId) {
+                               InsetGraphicsParams tmp = inspar;
+                               tmp.filename.erase();
+                               return InsetGraphics::params2string(tmp, b);
+                       }
+               }
+       return string();
+}
+
+
+void unifyGraphicsGroups(Buffer & b, string const & argument)
+{
+       InsetGraphicsParams params;
+       InsetGraphics::string2params(argument, b, params);
+
+       b.undo().beginUndoGroup();
+       Inset & inset = b.inset();
+       InsetIterator it  = inset_iterator_begin(inset);
+       InsetIterator const end = inset_iterator_end(inset);
+       for (; it != end; ++it) {
+               if (it->lyxCode() == GRAPHICS_CODE) {
+                       InsetGraphics & ins = static_cast<InsetGraphics &>(*it);
+                       InsetGraphicsParams inspar = ins.getParams();
+                       if (params.groupId == inspar.groupId) {
+                               b.undo().recordUndo(it);
+                               params.filename = inspar.filename;
+                               ins.setParams(params);
+                       }
+               }
+       }
+       b.undo().endUndoGroup();
+}
+
+
+InsetGraphics * getCurrentGraphicsInset(Cursor const & cur)
+{
+       Inset * instmp = &cur.inset();
+       if (instmp->lyxCode() != GRAPHICS_CODE)
+               instmp = cur.nextInset();
+       if (!instmp || instmp->lyxCode() != GRAPHICS_CODE)
+               return 0;
+
+       return static_cast<InsetGraphics *>(instmp);
+}
+
+} // namespace graphics
 
 } // namespace lyx