]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Routines for calculating numerical labels for BibTeX citations.
[lyx.git] / src / Paragraph.cpp
index f3ba6921cf628c5478f0337cb603ccd3dcb66a3b..233057e9163ad9058363f378066dbef466f92de7 100644 (file)
@@ -189,9 +189,8 @@ public:
        FontList fontlist_;
 
        ///
-       unsigned int id_;
-       ///
-       static unsigned int paragraph_id;
+       int id_;
+
        ///
        ParagraphParameters params_;
 
@@ -208,17 +207,14 @@ public:
        ///
        TextContainer text_;
        
-       typedef std::set<docstring> Words;
+       typedef set<docstring> Words;
        ///
-       Words words_;
+       map<Language, Words> words_;
        ///
        Layout const * layout_;
 };
 
 
-// Initialization of the counter for the paragraph id's,
-unsigned int Paragraph::Private::paragraph_id = 0;
-
 namespace {
 
 struct special_phrase {
@@ -240,20 +236,26 @@ size_t const phrases_nr = sizeof(special_phrases)/sizeof(special_phrase);
 
 
 Paragraph::Private::Private(Paragraph * owner, Layout const & layout)
-       : owner_(owner), inset_owner_(0), begin_of_body_(0), layout_(&layout)
+       : owner_(owner), inset_owner_(0), id_(-1), begin_of_body_(0), layout_(&layout)
 {
-       id_ = paragraph_id++;
        text_.reserve(100);
 }
 
 
+// Initialization of the counter for the paragraph id's,
+//
+// FIXME: There should be a more intelligent way to generate and use the
+// paragraph ids per buffer instead a global static counter for all InsetText
+// in the running program.
+static int paragraph_id = -1;
+
 Paragraph::Private::Private(Private const & p, Paragraph * owner)
        : owner_(owner), inset_owner_(p.inset_owner_), fontlist_(p.fontlist_), 
          params_(p.params_), changes_(p.changes_), insetlist_(p.insetlist_),
          begin_of_body_(p.begin_of_body_), text_(p.text_), words_(p.words_),
          layout_(p.layout_)
 {
-       id_ = paragraph_id++;
+       id_ = ++paragraph_id;
 }
 
 
@@ -265,7 +267,7 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner,
          begin_of_body_(p.begin_of_body_), words_(p.words_),
          layout_(p.layout_)
 {
-       id_ = paragraph_id++;
+       id_ = ++paragraph_id;
        if (beg >= pos_type(p.text_.size()))
                return;
        text_ = p.text_.substr(beg, end - beg);
@@ -2312,7 +2314,7 @@ pos_type Paragraph::firstWordLyXHTML(XHTMLStream & xs, OutputParams const & runp
                        char_type c = d->text_[i];
                        if (c == ' ')
                                break;
-                       xs << html::escapeChar(c);
+                       xs << c;
                }
        }
        return i;
@@ -2401,9 +2403,16 @@ docstring Paragraph::simpleLyXHTMLOnePar(Buffer const & buf,
 
        bool emph_flag = false;
        bool bold_flag = false;
-       std::string closing_tag;
+       string closing_tag;
 
        Layout const & style = *d->layout_;
+
+       if (!fortoc) {
+               // generate a magic label for this paragraph
+               string const attr = "id='" + magicLabel() + "'";
+               xs << CompTag("a", attr);
+       }
+
        FontInfo font_old =
                style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
 
@@ -2647,6 +2656,12 @@ int Paragraph::id() const
 }
 
 
+void Paragraph::setId(int id)
+{
+       d->id_ = id;
+}
+
+
 Layout const & Paragraph::layout() const
 {
        return *d->layout_;
@@ -3015,10 +3030,13 @@ bool Paragraph::isSeparator(pos_type pos) const
 
 void Paragraph::deregisterWords()
 {
+       map<Language, Private::Words>::const_iterator itl;
        Private::Words::const_iterator it;
-       WordList & wl = theWordList();
-       for (it = d->words_.begin(); it != d->words_.end(); ++it)
-               wl.remove(*it);
+       for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) {
+               WordList * wl = theWordList(itl->first);
+               for (it = (itl->second).begin(); it != (itl->second).end(); ++it)
+                       wl->remove(*it);
+       }
        d->words_.clear();
 }
 
@@ -3070,7 +3088,11 @@ void Paragraph::collectWords()
                locateWord(from, pos, WHOLE_WORD);
                if (pos - from >= 6) {
                        docstring word = asString(from, pos, AS_STR_NONE);
-                       d->words_.insert(word);
+                       FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
+                       if (cit == d->fontlist_.end())
+                               return;
+                       Language const * lang = cit->font().language();
+                       d->words_[*lang].insert(word);
                }
        }
 }
@@ -3078,10 +3100,13 @@ void Paragraph::collectWords()
 
 void Paragraph::registerWords()
 {
+       map<Language, Private::Words>::const_iterator itl;
        Private::Words::const_iterator it;
-       WordList & wl = theWordList();
-       for (it = d->words_.begin(); it != d->words_.end(); ++it)
-               wl.insert(*it);
+       for (itl = d->words_.begin(); itl != d->words_.end(); ++itl) {
+               WordList * wl = theWordList(itl->first);
+               for (it = (itl->second).begin(); it != (itl->second).end(); ++it)
+                       wl->insert(*it);
+       }
 }
 
 
@@ -3141,4 +3166,12 @@ bool Paragraph::isMisspelled(pos_type pos) const
 }
 
 
+string Paragraph::magicLabel() const
+{
+       stringstream ss;
+       ss << "magicparlabel-" << id();
+       return ss.str();
+}
+
+
 } // namespace lyx