]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetnote.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insetnote.C
index 17ce3425e452bb44f829ce91ae171079f6ddaddf..b840955032cdb0b16831769f57f38ed2e1158825 100644 (file)
@@ -34,6 +34,9 @@
 
 #include <sstream>
 
+
+namespace lyx {
+
 using std::string;
 using std::auto_ptr;
 using std::istringstream;
@@ -44,8 +47,10 @@ using std::ostringstream;
 namespace {
 
 typedef Translator<std::string, InsetNoteParams::Type> NoteTranslator;
+typedef Translator<docstring, InsetNoteParams::Type> NoteTranslatorLoc;
 
-NoteTranslator const init_notetranslator() {
+NoteTranslator const init_notetranslator()
+{
        NoteTranslator translator("Note", InsetNoteParams::Note);
        translator.addPair("Comment", InsetNoteParams::Comment);
        translator.addPair("Greyedout", InsetNoteParams::Greyedout);
@@ -55,8 +60,9 @@ NoteTranslator const init_notetranslator() {
 }
 
 
-NoteTranslator const init_notetranslator_loc() {
-       NoteTranslator translator(_("Note"), InsetNoteParams::Note);
+NoteTranslatorLoc const init_notetranslator_loc()
+{
+       NoteTranslatorLoc translator(_("Note"), InsetNoteParams::Note);
        translator.addPair(_("Comment"), InsetNoteParams::Comment);
        translator.addPair(_("Greyed out"), InsetNoteParams::Greyedout);
        translator.addPair(_("Framed"), InsetNoteParams::Framed);
@@ -65,14 +71,16 @@ NoteTranslator const init_notetranslator_loc() {
 }
 
 
-NoteTranslator const & notetranslator() {
+NoteTranslator const & notetranslator()
+{
        static NoteTranslator translator = init_notetranslator();
        return translator;
 }
 
 
-NoteTranslator const & notetranslator_loc() {
-       static NoteTranslator translator = init_notetranslator_loc();
+NoteTranslatorLoc const & notetranslator_loc()
+{
+       static NoteTranslatorLoc translator = init_notetranslator_loc();
        return translator;
 }
 
@@ -104,7 +112,7 @@ void InsetNoteParams::read(LyXLex & lex)
 
 void InsetNote::init()
 {
-       setInsetName("Note");
+       setInsetName(from_ascii("Note"));
        setButtonLabel();
 }
 
@@ -136,7 +144,7 @@ auto_ptr<InsetBase> InsetNote::doClone() const
 }
 
 
-string const InsetNote::editMessage() const
+docstring const InsetNote::editMessage() const
 {
        return _("Opened Note Inset");
 }
@@ -159,7 +167,7 @@ void InsetNote::read(Buffer const & buf, LyXLex & lex)
 
 void InsetNote::setButtonLabel()
 {
-       string const label = notetranslator_loc().find(params_.type);
+       docstring const label = notetranslator_loc().find(params_.type);
        setLabel(label);
 
        LyXFont font(LyXFont::ALL_SANE);
@@ -204,7 +212,7 @@ void InsetNote::doDispatch(LCursor & cur, FuncRequest & cmd)
        switch (cmd.action) {
 
        case LFUN_INSET_MODIFY:
-               InsetNoteMailer::string2params(cmd.argument, params_);
+               InsetNoteMailer::string2params(to_utf8(cmd.argument()), params_);
                setButtonLabel();
                break;
 
@@ -242,7 +250,7 @@ bool InsetNote::getStatus(LCursor & cur, FuncRequest const & cmd,
 }
 
 
-int InsetNote::latex(Buffer const & buf, ostream & os,
+int InsetNote::latex(Buffer const & buf, odocstream & os,
                     OutputParams const & runparams_in) const
 {
        if (params_.type == InsetNoteParams::Note)
@@ -262,10 +270,10 @@ int InsetNote::latex(Buffer const & buf, ostream & os,
        else if (params_.type == InsetNoteParams::Shaded)
                type = "shaded";
 
-       ostringstream ss;
-       ss << "%\n\\begin{" << type << "}\n";
+       odocstringstream ss;
+       ss << "%\n\\begin{" << from_ascii(type) << "}\n";
        InsetText::latex(buf, ss, runparams);
-       ss << "\n\\end{" << type << "}\n";
+       ss << "\n\\end{" << from_ascii(type) << "}\n";
        // the space after the comment in 'a[comment] b' will be eaten by the
        // comment environment since the space before b is ignored with the
        // following latex output:
@@ -280,41 +288,39 @@ int InsetNote::latex(Buffer const & buf, ostream & os,
        if (params_.type == InsetNoteParams::Comment)
                ss << "{}";
 
-       string const str = ss.str();
+       docstring const str = ss.str();
        os << str;
        // Return how many newlines we issued.
-       return int(lyx::count(str.begin(), str.end(),'\n'));
+       return int(lyx::count(str.begin(), str.end(), '\n'));
 }
 
 
-int InsetNote::docbook(Buffer const & buf, std::ostream & os,
+int InsetNote::docbook(Buffer const & buf, odocstream & os,
                       OutputParams const & runparams_in) const
 {
        if (params_.type == InsetNoteParams::Note)
                return 0;
 
        OutputParams runparams(runparams_in);
-       ostringstream ss;
        if (params_.type == InsetNoteParams::Comment) {
-               ss << "<remark>\n";
+               os << "<remark>\n";
                runparams.inComment = true;
                // Ignore files that are exported inside a comment
                runparams.exportdata.reset(new ExportData);
        }
 
-       InsetText::docbook(buf, ss, runparams);
+       int const n = InsetText::docbook(buf, os, runparams);
 
        if (params_.type == InsetNoteParams::Comment)
-               ss << "\n</remark>\n";
+               os << "\n</remark>\n";
 
-       string const str = ss.str();
-       os << str;
        // Return how many newlines we issued.
-       return int(lyx::count(str.begin(), str.end(),'\n'));
+       //return int(count(str.begin(), str.end(), '\n'));
+        return n + 1 + 2;
 }
 
 
-int InsetNote::plaintext(Buffer const & buf, std::ostream & os,
+int InsetNote::plaintext(Buffer const & buf, odocstream & os,
                         OutputParams const & runparams_in) const
 {
        if (params_.type == InsetNoteParams::Note)
@@ -326,15 +332,12 @@ int InsetNote::plaintext(Buffer const & buf, std::ostream & os,
                // Ignore files that are exported inside a comment
                runparams.exportdata.reset(new ExportData);
        }
-       ostringstream ss;
-       ss << "[";
-       InsetText::plaintext(buf, ss, runparams);
-       ss << "]";
+       os << "[";
+       int const nlines = InsetText::plaintext(buf, os, runparams);
+       os << "]";
 
-       string const str = ss.str();
-       os << str;
        // Return how many newlines we issued.
-       return int(lyx::count(str.begin(), str.end(),'\n'));
+       return nlines;
 }
 
 
@@ -349,7 +352,7 @@ void InsetNote::validate(LaTeXFeatures & features) const
        if (params_.type == InsetNoteParams::Shaded) {
                features.require("color");
                features.require("framed");
-       }               
+       }
        if (params_.type == InsetNoteParams::Framed)
                features.require("framed");
        InsetText::validate(features);
@@ -405,3 +408,6 @@ void InsetNoteMailer::string2params(string const & in,
 
        params.read(lex);
 }
+
+
+} // namespace lyx