]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCaption.cpp
Polish the Toc and labels updating when loading a child document.
[lyx.git] / src / insets / InsetCaption.cpp
index e719e9cbc217106d6bbe8b6b5c2d1c50bacb55c3..831032b039b31a79bd351a5cf40eb7b0d6ba396a 100644 (file)
 #include "InsetFloat.h"
 #include "InsetWrap.h"
 
-#include "buffer.h"
-#include "bufferparams.h"
-#include "counters.h"
-#include "cursor.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+#include "Counters.h"
+#include "Cursor.h"
 #include "BufferView.h"
 #include "Floating.h"
 #include "FloatList.h"
-#include "funcrequest.h"
+#include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "gettext.h"
-#include "LColor.h"
-#include "metricsinfo.h"
+#include "Color.h"
+#include "MetricsInfo.h"
 #include "output_latex.h"
-#include "outputparams.h"
-#include "paragraph.h"
+#include "OutputParams.h"
+#include "Paragraph.h"
 #include "paragraph_funcs.h"
 #include "TocBackend.h"
 
@@ -51,12 +51,20 @@ namespace lyx {
 
 using support::bformat;
 
+InsetCaption::InsetCaption(InsetCaption const & ic)
+       : InsetText(ic), textclass_(ic.textclass_)
+{
+       setAutoBreakRows(true);
+       setDrawFrame(true);
+       setFrameColor(Color::captionframe);
+}
+
 InsetCaption::InsetCaption(BufferParams const & bp)
-       : InsetText(bp), textclass_(bp.getLyXTextClass())
+       : InsetText(bp), textclass_(bp.getTextClass())
 {
        setAutoBreakRows(true);
        setDrawFrame(true);
-       setFrameColor(LColor::captionframe);
+       setFrameColor(Color::captionframe);
 }
 
 
@@ -67,7 +75,7 @@ void InsetCaption::write(Buffer const & buf, ostream & os) const
 }
 
 
-void InsetCaption::read(Buffer const & buf, LyXLex & lex)
+void InsetCaption::read(Buffer const & buf, Lexer & lex)
 {
 #if 0
        // We will enably this check again when the compability
@@ -107,7 +115,7 @@ void InsetCaption::setCustomLabel(docstring const & label)
 }
 
 
-void InsetCaption::addToToc(TocList & toclist, Buffer const & buf) const
+void InsetCaption::addToToc(TocList & toclist, Buffer const & buf, ParConstIterator &) const
 {
        if (type_.empty())
                return;
@@ -126,7 +134,7 @@ bool InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const
        int const width_offset = TEXT_TO_INSET_OFFSET / 2;
        mi.base.textwidth -= width_offset;
 
-       computeFullLabel();
+       computeFullLabel(*mi.base.bv->buffer());
 
        labelwidth_ = theFontMetrics(mi.base.font).width(full_label_);
        // add some space to separate the label from the inset text
@@ -158,7 +166,7 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const
        // the text inset or the paragraph?
        // We should also draw the float number (Lgb)
 
-       // Answer: the text inset (in buffer_funcs.C: setCaption).
+       // Answer: the text inset (in buffer_funcs.cpp: setCaption).
 
        labelwidth_ = pi.pain.text(x, y, full_label_, pi.base.font);
        // add some space to separate the label from the inset text
@@ -174,21 +182,21 @@ void InsetCaption::drawSelection(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetCaption::edit(LCursor & cur, bool left)
+void InsetCaption::edit(Cursor & cur, bool left)
 {
        cur.push(*this);
        InsetText::edit(cur, left);
 }
 
 
-InsetBase * InsetCaption::editXY(LCursor & cur, int x, int y)
+Inset * InsetCaption::editXY(Cursor & cur, int x, int y)
 {
        cur.push(*this);
        return InsetText::editXY(cur, x, y);
 }
 
 
-bool InsetCaption::insetAllowed(InsetBase::Code code) const
+bool InsetCaption::insetAllowed(Inset::Code code) const
 {
        switch (code) {
        case FLOAT_CODE:
@@ -203,7 +211,7 @@ bool InsetCaption::insetAllowed(InsetBase::Code code) const
 }
 
 
-bool InsetCaption::getStatus(LCursor & cur, FuncRequest const & cmd,
+bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
        FuncStatus & status) const
 {
        switch (cmd.action) {
@@ -225,7 +233,7 @@ bool InsetCaption::getStatus(LCursor & cur, FuncRequest const & cmd,
 
 
 int InsetCaption::latex(Buffer const & buf, odocstream & os,
-                        OutputParams const & runparams_in) const
+                       OutputParams const & runparams_in) const
 {
        // This is a bit too simplistic to take advantage of
        // caption options we must add more later. (Lgb)
@@ -247,9 +255,9 @@ int InsetCaption::latex(Buffer const & buf, odocstream & os,
 
 
 int InsetCaption::plaintext(Buffer const & buf, odocstream & os,
-                            OutputParams const & runparams) const
+                           OutputParams const & runparams) const
 {
-       computeFullLabel();
+       computeFullLabel(buf);
 
        os << '[' << full_label_ << "\n";
        InsetText::plaintext(buf, os, runparams);
@@ -260,7 +268,7 @@ int InsetCaption::plaintext(Buffer const & buf, odocstream & os,
 
 
 int InsetCaption::docbook(Buffer const & buf, odocstream & os,
-                          OutputParams const & runparams) const
+                         OutputParams const & runparams) const
 {
        int ret;
        os << "<title>";
@@ -270,21 +278,35 @@ int InsetCaption::docbook(Buffer const & buf, odocstream & os,
 }
 
 
-void InsetCaption::computeFullLabel() const
+int InsetCaption::getArgument(Buffer const & buf, odocstream & os,
+                       OutputParams const & runparams) const
+{
+       return InsetText::latex(buf, os, runparams);
+}
+
+
+int InsetCaption::getOptArg(Buffer const & buf, odocstream & os,
+                       OutputParams const & runparams) const
+{
+       return latexOptArgInsets(buf, paragraphs()[0], os, runparams, 1);
+}
+
+
+void InsetCaption::computeFullLabel(Buffer const & buf) const
 {
        if (type_.empty())
-               full_label_ = _("Senseless!!! ");
+               full_label_ = buf.B_("Senseless!!! ");
        else {
                docstring const number = convert<docstring>(counter_);
-               docstring label = custom_label_.empty()? _(type_): custom_label_;
+               docstring label = custom_label_.empty()? buf.B_(type_): custom_label_;
                full_label_ = bformat(from_ascii("%1$s %2$s:"), label, number);
        }
 }
 
 
-auto_ptr<InsetBase> InsetCaption::doClone() const
+auto_ptr<Inset> InsetCaption::doClone() const
 {
-       return auto_ptr<InsetBase>(new InsetCaption(*this));
+       return auto_ptr<Inset>(new InsetCaption(*this));
 }