]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetinclude.C
Enable convertDefault.sh to run even if its executable bit is not set.
[lyx.git] / src / insets / insetinclude.C
index 44922eb2d07ff385b0d5b5ee1ef1c44edabc05f2..7e1af317bb7dacbda3fa09b1a6df5150e1f5c601 100644 (file)
@@ -5,7 +5,7 @@
  *
  * \author Lars Gullik Bjønnes
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
@@ -49,6 +49,8 @@ using std::ostream;
 using std::endl;
 using std::vector;
 using std::pair;
+using std::auto_ptr;
+
 
 extern BufferList bufferlist;
 
@@ -111,7 +113,7 @@ InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
 
 
 InsetInclude::InsetInclude(InsetInclude const & other)
-       : Inset(other),
+       : InsetOld(other),
          params_(other.params_),
          include_label(other.include_label),
          preview_(new PreviewImpl(*this)),
@@ -151,7 +153,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
                return DISPATCHED;
 
        default:
-               return Inset::localDispatch(cmd);
+               return InsetOld::localDispatch(cmd);
        }
 }
 
@@ -206,24 +208,36 @@ void InsetInclude::set(Params const & p)
 }
 
 
-InsetBase * InsetInclude::clone() const
+auto_ptr<InsetBase> InsetInclude::clone() const
 {
        //Params p(params_);
        //p.masterFilename_ = buffer.fileName();
 #warning FIXME: broken cross-doc copy/paste - must fix
 
-       return new InsetInclude(params_);
+       return auto_ptr<InsetBase>(new InsetInclude(params_));
 }
 
 
-void InsetInclude::write(Buffer const *, ostream & os) const
+void InsetInclude::write(Buffer const &, ostream & os) const
+{
+       write(os);
+}
+
+
+void InsetInclude::write(ostream & os) const
 {
        os << "Include " << params_.cparams.getCommand() << '\n'
           << "preview " << tostr(params_.cparams.preview()) << '\n';
 }
 
 
-void InsetInclude::read(Buffer const *, LyXLex & lex)
+void InsetInclude::read(Buffer const &, LyXLex & lex)
+{
+       read(lex);
+}
+
+
+void InsetInclude::read(LyXLex & lex)
 {
        params_.cparams.read(lex);
 
@@ -240,13 +254,7 @@ void InsetInclude::read(Buffer const *, LyXLex & lex)
 }
 
 
-bool InsetInclude::display() const
-{
-       return !(params_.flag == INPUT);
-}
-
-
-string const InsetInclude::getScreenLabel(Buffer const *) const
+string const InsetInclude::getScreenLabel(Buffer const &) const
 {
        string temp;
 
@@ -301,7 +309,7 @@ bool InsetInclude::loadIfNeeded() const
 }
 
 
-int InsetInclude::latex(Buffer const * buffer, ostream & os,
+int InsetInclude::latex(Buffer const & buffer, ostream & os,
                        LatexRunParams const & runparams) const
 {
        string incfile(params_.cparams.getContents());
@@ -314,13 +322,13 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
                Buffer * tmp = bufferlist.getBuffer(getFileName());
 
                // FIXME: this should be a GUI warning
-               if (tmp->params.textclass != buffer->params.textclass) {
+               if (tmp->params.textclass != buffer.params.textclass) {
                        lyxerr << "WARNING: Included file `"
                               << MakeDisplayPath(getFileName())
                               << "' has textclass `"
                               << tmp->params.getLyXTextClass().name()
                               << "' while parent file has textclass `"
-                              << buffer->params.getLyXTextClass().name()
+                              << buffer.params.getLyXTextClass().name()
                               << "'." << endl;
                        //return 0;
                }
@@ -328,22 +336,22 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
                // write it to a file (so far the complete file)
                string writefile = ChangeExtension(getFileName(), ".tex");
 
-               if (!buffer->tmppath.empty() && !runparams.nice) {
+               if (!buffer.tmppath.empty() && !runparams.nice) {
                        incfile = subst(incfile, '/','@');
 #ifdef __EMX__
                        incfile = subst(incfile, ':', '$');
 #endif
-                       writefile = AddName(buffer->tmppath, incfile);
+                       writefile = AddName(buffer.tmppath, incfile);
                } else
                        writefile = getFileName();
                writefile = ChangeExtension(writefile, ".tex");
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-               tmp->markDepClean(buffer->tmppath);
+               tmp->markDepClean(buffer.tmppath);
 
                tmp->makeLaTeXFile(writefile, OnlyPath(getMasterFilename()),
-                                  runparams, true);
+                                  runparams, false);
        }
 
        if (isVerbatim()) {
@@ -369,7 +377,7 @@ int InsetInclude::latex(Buffer const * buffer, ostream & os,
 }
 
 
-int InsetInclude::ascii(Buffer const *, ostream & os, int) const
+int InsetInclude::ascii(Buffer const &, ostream & os, int) const
 {
        if (isVerbatim())
                os << GetFileContents(getFileName());
@@ -377,7 +385,7 @@ int InsetInclude::ascii(Buffer const *, ostream & os, int) const
 }
 
 
-int InsetInclude::linuxdoc(Buffer const * buffer, ostream & os) const
+int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os) const
 {
        string incfile(params_.cparams.getContents());
 
@@ -390,9 +398,9 @@ int InsetInclude::linuxdoc(Buffer const * buffer, ostream & os) const
 
                // write it to a file (so far the complete file)
                string writefile = ChangeExtension(getFileName(), ".sgml");
-               if (!buffer->tmppath.empty() && !buffer->niceFile) {
+               if (!buffer.tmppath.empty() && !buffer.niceFile) {
                        incfile = subst(incfile, '/','@');
-                       writefile = AddName(buffer->tmppath, incfile);
+                       writefile = AddName(buffer.tmppath, incfile);
                } else
                        writefile = getFileName();
 
@@ -402,7 +410,7 @@ int InsetInclude::linuxdoc(Buffer const * buffer, ostream & os) const
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-               tmp->makeLinuxDocFile(writefile, buffer->niceFile, true);
+               tmp->makeLinuxDocFile(writefile, buffer.niceFile, true);
        }
 
        if (isVerbatim()) {
@@ -416,7 +424,7 @@ int InsetInclude::linuxdoc(Buffer const * buffer, ostream & os) const
 }
 
 
-int InsetInclude::docbook(Buffer const * buffer, ostream & os,
+int InsetInclude::docbook(Buffer const & buffer, ostream & os,
                          bool /*mixcont*/) const
 {
        string incfile(params_.cparams.getContents());
@@ -430,9 +438,9 @@ int InsetInclude::docbook(Buffer const * buffer, ostream & os,
 
                // write it to a file (so far the complete file)
                string writefile = ChangeExtension(getFileName(), ".sgml");
-               if (!buffer->tmppath.empty() && !buffer->niceFile) {
+               if (!buffer.tmppath.empty() && !buffer.niceFile) {
                        incfile = subst(incfile, '/','@');
-                       writefile = AddName(buffer->tmppath, incfile);
+                       writefile = AddName(buffer.tmppath, incfile);
                } else
                        writefile = getFileName();
                if (IsLyXFilename(getFileName()))
@@ -441,7 +449,7 @@ int InsetInclude::docbook(Buffer const * buffer, ostream & os,
                lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
                lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
 
-               tmp->makeDocBookFile(writefile, buffer->niceFile, true);
+               tmp->makeDocBookFile(writefile, buffer.niceFile, true);
        }
 
        if (isVerbatim()) {
@@ -461,11 +469,11 @@ void InsetInclude::validate(LaTeXFeatures & features) const
        string incfile(params_.cparams.getContents());
        string writefile;
 
-       Buffer const * const b = bufferlist.getBuffer(getMasterFilename());
+       Buffer const & b = *bufferlist.getBuffer(getMasterFilename());
 
-       if (b && !b->tmppath.empty() && !b->niceFile && !isVerbatim()) {
+       if (!b.tmppath.empty() && !b.niceFile && !isVerbatim()) {
                incfile = subst(incfile, '/','@');
-               writefile = AddName(b->tmppath, incfile);
+               writefile = AddName(b.tmppath, incfile);
        } else
                writefile = getFileName();
 
@@ -484,8 +492,7 @@ void InsetInclude::validate(LaTeXFeatures & features) const
                // a file got loaded
                Buffer * const tmp = bufferlist.getBuffer(getFileName());
                if (tmp) {
-                       if (b)
-                               tmp->niceFile = b->niceFile;
+                       tmp->niceFile = b.niceFile;
                        tmp->validate(features);
                }
        }
@@ -523,11 +530,16 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
        } else {
                if (!set_label_) {
                        set_label_ = true;
-                       button_.update(getScreenLabel(mi.base.bv->buffer()),
+                       button_.update(getScreenLabel(*mi.base.bv->buffer()),
                                       editable() != NOT_EDITABLE);
                }
                button_.metrics(mi, dim);
        }
+       if (params_.flag == INPUT)
+               center_indent_ = 0;
+       else
+               center_indent_ = (mi.base.textwidth - dim.wid) / 2;
+       dim.wid = mi.base.textwidth;
        dim_ = dim;
 }
 
@@ -536,14 +548,14 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
 {
        cache(pi.base.bv);
        if (!preview_->previewReady()) {
-               button_.draw(pi, x, y);
+               button_.draw(pi, x + center_indent_, y);
                return;
        }
 
        if (!preview_->monitoring())
                preview_->startMonitoring();
 
-       pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(),
+       pi.pain.image(x + center_indent_, y - dim_.asc, dim_.wid, dim_.height(),
                            *(preview_->pimage()->image()));
 }
 
@@ -580,7 +592,7 @@ string const InsetInclude::PreviewImpl::latexString() const
        ostringstream os;
        LatexRunParams runparams;
        runparams.flavor = LatexRunParams::LATEX;
-       parent().latex(view()->buffer(), os, runparams);
+       parent().latex(*view()->buffer(), os, runparams);
 
        return STRCONV(os.str());
 }
@@ -647,7 +659,7 @@ void InsetIncludeMailer::string2params(string const & in,
 
        if (lex.isOK()) {
                InsetInclude inset(params);
-               inset.read(0, lex);
+               inset.read(lex);
                params = inset.params();
        }
 }
@@ -660,7 +672,7 @@ InsetIncludeMailer::params2string(InsetInclude::Params const & params)
        inset.set(params);
        ostringstream data;
        data << name_ << ' ';
-       inset.write(0, data);
+       inset.write(data);
        data << "\\end_inset\n";
        return STRCONV(data.str());
 }