]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetNote.cpp
Fix for bug 4135
[lyx.git] / src / insets / InsetNote.cpp
index f643ce8c37276f64b3b5fa4a0352f450fcc7dc1c..7e408255f7b38fe3ea16f7916d84351eda594823 100644 (file)
 
 #include "InsetNote.h"
 
+#include "Buffer.h"
+#include "BufferParams.h"
 #include "BufferView.h"
-#include "cursor.h"
+#include "BufferParams.h"
+#include "Counters.h"
+#include "Cursor.h"
 #include "debug.h"
-#include "dispatchresult.h"
-#include "exporter.h"
-#include "funcrequest.h"
+#include "DispatchResult.h"
+#include "Exporter.h"
+#include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
-#include "LColor.h"
-#include "lyxlex.h"
-#include "metricsinfo.h"
-#include "outputparams.h"
-#include "paragraph.h"
+#include "Lexer.h"
+#include "MetricsInfo.h"
+#include "OutputParams.h"
 
-#include "support/lyxalgo.h"
-#include "support/translator.h"
+#include "support/Translator.h"
 
+#include <algorithm>
 #include <sstream>
 
 
@@ -101,7 +103,7 @@ void InsetNoteParams::write(ostream & os) const
 }
 
 
-void InsetNoteParams::read(LyXLex & lex)
+void InsetNoteParams::read(Lexer & lex)
 {
        string label;
        lex >> label;
@@ -110,25 +112,19 @@ void InsetNoteParams::read(LyXLex & lex)
 }
 
 
-void InsetNote::init()
-{
-       setInsetName(from_ascii("Note"));
-       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();
 }
 
 
@@ -138,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));
 }
 
 
@@ -150,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);
@@ -157,10 +171,11 @@ void InsetNote::write(Buffer const & buf, ostream & os) const
 }
 
 
-void InsetNote::read(Buffer const & buf, LyXLex & lex)
+void InsetNote::read(Buffer const & buf, Lexer & lex)
 {
        params_.read(lex);
        InsetCollapsable::read(buf, lex);
+       setLayout(buf.params());
        setButtonLabel();
 }
 
@@ -169,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(LColor::note);
-               setBackgroundColor(LColor::notebg);
+               c = Color::notebg;
                break;
        case InsetNoteParams::Comment:
-               font.setColor(LColor::comment);
-               setBackgroundColor(LColor::commentbg);
+               c = Color::commentbg;
                break;
        case InsetNoteParams::Greyedout:
-               font.setColor(LColor::greyedout);
-               setBackgroundColor(LColor::greyedoutbg);
+               c = Color::greyedoutbg;
                break;
        case InsetNoteParams::Framed:
-               font.setColor(LColor::greyedout);
-               setBackgroundColor(LColor::greyedoutbg);
+               c = Color::greyedoutbg;
                break;
        case InsetNoteParams::Shaded:
-               font.setColor(LColor::greyedout);
-               setBackgroundColor(LColor::shadedbg);
+               c = Color::shadedbg;
                break;
        }
-       setLabelFont(font);
+       return c;
 }
 
 
@@ -207,12 +219,14 @@ bool InsetNote::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetNote::doDispatch(LCursor & cur, FuncRequest & cmd)
+void InsetNote::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY:
                InsetNoteMailer::string2params(to_utf8(cmd.argument()), params_);
+               // get a bp from cur:
+               setLayout(cur.buffer().params());
                setButtonLabel();
                break;
 
@@ -234,7 +248,7 @@ void InsetNote::doDispatch(LCursor & cur, FuncRequest & cmd)
 }
 
 
-bool InsetNote::getStatus(LCursor & cur, FuncRequest const & cmd,
+bool InsetNote::getStatus(Cursor & cur, FuncRequest const & cmd,
                FuncStatus & flag) const
 {
        switch (cmd.action) {
@@ -249,6 +263,14 @@ bool InsetNote::getStatus(LCursor & 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
@@ -292,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;
@@ -308,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]";
 
@@ -317,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;
@@ -337,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;
 }
 
 
@@ -391,7 +413,7 @@ void InsetNoteMailer::string2params(string const & in,
                return;
 
        istringstream data(in);
-       LyXLex lex(0,0);
+       Lexer lex(0,0);
        lex.setStream(data);
 
        string name;
@@ -400,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")