]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBibitem.cpp
Fix text frame drawing.
[lyx.git] / src / insets / InsetBibitem.cpp
index 8c9410b2b1fc725148940959acae7baf3b584d89..924b931d82825a9794cf2cc9d0a7cf591fc5fb8f 100644 (file)
 
 #include "InsetBibitem.h"
 
-#include "Biblio.h"
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "BufferView.h"
+#include "Counters.h"
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "Font.h"
 
 namespace lyx {
 
-using support::prefixIs;
-
-using std::max;
-using std::string;
-using std::auto_ptr;
-using std::ostream;
 
 int InsetBibitem::key_counter = 0;
+
+
 docstring const key_prefix = from_ascii("key-");
 
+
 InsetBibitem::InsetBibitem(InsetCommandParams const & p)
-       : InsetCommand(p, "bibitem"), counter(1)
+       : InsetCommand(p, "bibitem")
 {
        if (getParam("key").empty())
                setParam("key", key_prefix + convert<docstring>(++key_counter));
 }
 
 
-auto_ptr<Inset> InsetBibitem::doClone() const
+Inset * InsetBibitem::clone() const
 {
-       auto_ptr<InsetBibitem> b(new InsetBibitem(params()));
-       b->setCounter(counter);
-       return auto_ptr<Inset>(b);
+       InsetBibitem * b = new InsetBibitem(params());
+       b->autolabel_ = autolabel_;
+       return b;
 }
 
 
@@ -68,7 +66,7 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
                        break;
                }
                if (p["key"] != params()["key"])
-                       cur.bv().buffer()->changeRefsIfUnique(params()["key"],
+                       cur.bv().buffer().changeRefsIfUnique(params()["key"],
                                                       p["key"], Inset::CITE_CODE);
                setParams(p);
        }
@@ -80,19 +78,13 @@ void InsetBibitem::doDispatch(Cursor & cur, FuncRequest & cmd)
 }
 
 
-void InsetBibitem::setCounter(int c)
-{
-       counter = c;
-}
-
-
 void InsetBibitem::read(Buffer const & buf, Lexer & lex)
 {
        InsetCommand::read(buf, lex);
 
-       if (prefixIs(getParam("key"), key_prefix)) {
+       if (support::prefixIs(getParam("key"), key_prefix)) {
                int const key = convert<int>(getParam("key").substr(key_prefix.length()));
-               key_counter = max(key_counter, key);
+               key_counter = std::max(key_counter, key);
        }
 }
 
@@ -100,7 +92,7 @@ void InsetBibitem::read(Buffer const & buf, Lexer & lex)
 docstring const InsetBibitem::getBibLabel() const
 {
        docstring const & label = getParam("label");
-       return label.empty() ? convert<docstring>(counter) : label;
+       return label.empty() ? autolabel_ : label;
 }
 
 
@@ -114,7 +106,7 @@ int InsetBibitem::plaintext(Buffer const &, odocstream & os,
                            OutputParams const &) const
 {
        odocstringstream oss;
-       oss << '[' << getCounter() << "] ";
+       oss << '[' << getBibLabel() << "] ";
 
        docstring const str = oss.str();
        os << str;
@@ -187,16 +179,31 @@ docstring const bibitemWidest(Buffer const & buffer)
 
 
 void InsetBibitem::fillWithBibKeys(Buffer const & buf,
-       biblio::BibKeyList & keys, InsetIterator const & it) const
+       BiblioInfo & keys, InsetIterator const & it) const
 {
-       string const key = to_utf8(getParam("key"));
-       biblio::BibTeXInfo keyvalmap;
+       docstring const key = getParam("key");
+       BibTeXInfo keyvalmap;
        keyvalmap[from_ascii("label")] = getParam("label");
        DocIterator doc_it(it); 
        doc_it.forwardPos();
-       keyvalmap [from_ascii("ref")] = doc_it.paragraph().asString(buf, false);
+       keyvalmap[from_ascii("ref")] = doc_it.paragraph().asString(buf, false);
        keyvalmap.isBibTeX = false;
        keys[key] = keyvalmap;
 }
 
+
+/// Update the counters of this inset and of its contents
+void InsetBibitem::updateLabels(Buffer const &buf, ParIterator const &) 
+{
+       Counters & counters = buf.params().getTextClass().counters();
+       docstring const bibitem = from_ascii("bibitem");
+       if (counters.hasCounter(bibitem) && getParam("label").empty()) {
+               counters.step(bibitem);
+               autolabel_ = counters.theCounter(bibitem);
+       } else
+               autolabel_ = from_ascii("??");
+       refresh();
+}
+
+
 } // namespace lyx