]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNote.cpp
Fix for bug 4135
[lyx.git] / src / insets / InsetNote.cpp
index 83fb70a185566d45610aafcdf4df91def21a31b3..7e408255f7b38fe3ea16f7916d84351eda594823 100644 (file)
 
 #include "InsetNote.h"
 
+#include "Buffer.h"
+#include "BufferParams.h"
 #include "BufferView.h"
+#include "BufferParams.h"
+#include "Counters.h"
 #include "Cursor.h"
 #include "debug.h"
 #include "DispatchResult.h"
 #include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "Color.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
-#include "Paragraph.h"
 
-#include "support/lyxalgo.h"
 #include "support/Translator.h"
 
+#include <algorithm>
 #include <sstream>
 
 
@@ -110,24 +112,19 @@ void InsetNoteParams::read(Lexer & lex)
 }
 
 
-void InsetNote::init()
-{
-       setButtonLabel();
-}
-
-
 InsetNote::InsetNote(BufferParams const & bp, string const & label)
        : InsetCollapsable(bp)
 {
        params_.type = notetranslator().find(label);
-       init();
+       setLayout(bp);
+       setButtonLabel();
 }
 
 
 InsetNote::InsetNote(InsetNote const & in)
        : InsetCollapsable(in), params_(in.params_)
 {
-       init();
+       setButtonLabel();
 }
 
 
@@ -137,9 +134,9 @@ InsetNote::~InsetNote()
 }
 
 
-auto_ptr<InsetBase> InsetNote::doClone() const
+auto_ptr<Inset> InsetNote::doClone() const
 {
-       return auto_ptr<InsetBase>(new InsetNote(*this));
+       return auto_ptr<Inset>(new InsetNote(*this));
 }
 
 
@@ -149,6 +146,24 @@ docstring const InsetNote::editMessage() const
 }
 
 
+docstring InsetNote::name() const 
+{
+       return from_ascii(string("Note") + string(":") + string(notetranslator().find(params_.type)));
+}
+
+
+Inset::DisplayType InsetNote::display() const
+{
+       switch (params_.type) {
+       case InsetNoteParams::Framed:
+       case InsetNoteParams::Shaded:
+               return AlignLeft;
+       default:
+               return Inline;
+       }
+}
+
+
 void InsetNote::write(Buffer const & buf, ostream & os) const
 {
        params_.write(os);
@@ -160,6 +175,7 @@ void InsetNote::read(Buffer const & buf, Lexer & lex)
 {
        params_.read(lex);
        InsetCollapsable::read(buf, lex);
+       setLayout(buf.params());
        setButtonLabel();
 }
 
@@ -168,34 +184,31 @@ void InsetNote::setButtonLabel()
 {
        docstring const label = notetranslator_loc().find(params_.type);
        setLabel(label);
+       setLabelFont(layout_.labelfont);
+}
 
-       LyXFont font(LyXFont::ALL_SANE);
-       font.decSize();
-       font.decSize();
 
+Color_color InsetNote::backgroundColor() const
+{
+       Color_color c;
        switch (params_.type) {
        case InsetNoteParams::Note:
-               font.setColor(Color::note);
-               setBackgroundColor(Color::notebg);
+               c = Color::notebg;
                break;
        case InsetNoteParams::Comment:
-               font.setColor(Color::comment);
-               setBackgroundColor(Color::commentbg);
+               c = Color::commentbg;
                break;
        case InsetNoteParams::Greyedout:
-               font.setColor(Color::greyedout);
-               setBackgroundColor(Color::greyedoutbg);
+               c = Color::greyedoutbg;
                break;
        case InsetNoteParams::Framed:
-               font.setColor(Color::greyedout);
-               setBackgroundColor(Color::greyedoutbg);
+               c = Color::greyedoutbg;
                break;
        case InsetNoteParams::Shaded:
-               font.setColor(Color::greyedout);
-               setBackgroundColor(Color::shadedbg);
+               c = Color::shadedbg;
                break;
        }
-       setLabelFont(font);
+       return c;
 }
 
 
@@ -212,6 +225,8 @@ void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
 
        case LFUN_INSET_MODIFY:
                InsetNoteMailer::string2params(to_utf8(cmd.argument()), params_);
+               // get a bp from cur:
+               setLayout(cur.buffer().params());
                setButtonLabel();
                break;
 
@@ -248,6 +263,14 @@ bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
        }
 }
 
+void InsetNote::updateLabels(Buffer const & buf, ParIterator const & it)
+{
+       TextClass const & tclass = buf.params().getTextClass();
+       Counters savecnt = tclass.counters();
+       InsetCollapsable::updateLabels(buf, it);
+       tclass.counters() = savecnt;
+}
+
 
 int InsetNote::latex(Buffer const & buf, odocstream & os,
                     OutputParams const & runparams_in) const
@@ -291,12 +314,12 @@ int InsetNote::latex(Buffer const & buf, odocstream & os,
        os << str;
        runparams_in.encoding = runparams.encoding;
        // Return how many newlines we issued.
-       return int(lyx::count(str.begin(), str.end(), '\n'));
+       return int(std::count(str.begin(), str.end(), '\n'));
 }
 
 
 int InsetNote::plaintext(Buffer const & buf, odocstream & os,
-                         OutputParams const & runparams_in) const
+                        OutputParams const & runparams_in) const
 {
        if (params_.type == InsetNoteParams::Note)
                return 0;
@@ -307,7 +330,7 @@ int InsetNote::plaintext(Buffer const & buf, odocstream & os,
                // Ignore files that are exported inside a comment
                runparams.exportdata.reset(new ExportData);
        }
-       os << '[' << _("note") << ":\n";
+       os << '[' << buf.B_("note") << ":\n";
        InsetText::plaintext(buf, os, runparams);
        os << "\n]";
 
@@ -316,7 +339,7 @@ int InsetNote::plaintext(Buffer const & buf, odocstream & os,
 
 
 int InsetNote::docbook(Buffer const & buf, odocstream & os,
-                       OutputParams const & runparams_in) const
+                      OutputParams const & runparams_in) const
 {
        if (params_.type == InsetNoteParams::Note)
                return 0;
@@ -336,7 +359,7 @@ int InsetNote::docbook(Buffer const & buf, odocstream & os,
 
        // Return how many newlines we issued.
        //return int(count(str.begin(), str.end(), '\n'));
-        return n + 1 + 2;
+       return n + 1 + 2;
 }
 
 
@@ -399,7 +422,7 @@ void InsetNoteMailer::string2params(string const & in,
                return print_mailer_error("InsetNoteMailer", in, 1, name_);
 
        // This is part of the inset proper that is usually swallowed
-       // by LyXText::readInset
+       // by Text::readInset
        string id;
        lex >> id;
        if (!lex || id != "Note")