+ frame_is_visible = false;
+}
+
+
+Paragraph * InsetText::getParFromID(int id) const
+{
+#if 0
+ Paragraph * result = par;
+ Paragraph * ires = 0;
+ while (result && result->id() != id) {
+ if ((ires = result->getParFromID(id)))
+ return ires;
+ result = result->next();
+ }
+ return result;
+#else
+ Paragraph * tmp = par;
+ while (tmp) {
+ if (tmp->id() == id) {
+ return tmp;
+ }
+ Paragraph * tmp2 = tmp->getParFromID(id);
+ if (tmp2 != 0) {
+ return tmp2;
+ }
+ tmp = tmp->next();
+ }
+ return 0;
+#endif
+}
+
+
+Paragraph * InsetText::firstParagraph() const
+{
+ Paragraph * result;
+ if (the_locking_inset)
+ if ((result = the_locking_inset->firstParagraph()))
+ return result;
+ return par;
+}
+
+
+Paragraph * InsetText::getFirstParagraph(int i) const
+{
+ return (i == 0) ? par : 0;
+}
+
+
+LyXCursor const & InsetText::cursor(BufferView * bv) const
+{
+ if (the_locking_inset)
+ return the_locking_inset->cursor(bv);
+ return getLyXText(bv)->cursor;
+}
+
+
+Paragraph * InsetText::paragraph() const
+{
+ return par;
+}
+
+
+void InsetText::paragraph(Paragraph * p)
+{
+ // GENERAL COMMENT: We don't have to free the old paragraphs as the
+ // caller of this function has to take care of it. This IS important
+ // as we could have to insert a paragraph before this one and just
+ // link the actual to a new ones next and set it with this function
+ // and are done!
+ par = p;
+ // set ourself as owner for all the paragraphs inserted!
+ Paragraph * np = par;
+ while (np) {
+ np->setInsetOwner(this);
+ np = np->next();
+ }
+ reinitLyXText();
+ // redraw myself when asked for
+ need_update = INIT;
+}
+
+
+Inset * InsetText::getInsetFromID(int id_arg) const
+{
+ if (id_arg == id())
+ return const_cast<InsetText *>(this);
+
+ Paragraph * lp = par;
+
+ while (lp) {
+ for (Paragraph::inset_iterator it = lp->inset_iterator_begin(),
+ en = lp->inset_iterator_end();
+ it != en; ++it)
+ {
+ if ((*it)->id() == id_arg)
+ return *it;
+ Inset * in = (*it)->getInsetFromID(id_arg);
+ if (in)
+ return in;
+ }
+ lp = lp->next();
+ }
+ return 0;
+}
+
+
+string const InsetText::selectNextWordToSpellcheck(BufferView * bv, float & value) const
+{
+ bool clear = false;
+ string str;
+
+ if (!lt) {
+ lt = getLyXText(bv);
+ clear = true;
+ }
+ if (the_locking_inset) {
+ str = the_locking_inset->selectNextWordToSpellcheck(bv, value);
+ if (!str.empty()) {
+ value += cy(bv);
+ if (clear)
+ lt = 0;
+ return str;
+ }
+ // we have to go on checking so move cusor to the next char
+ lt->cursor.pos(lt->cursor.pos() + 1);
+ }
+ str = lt->selectNextWordToSpellcheck(bv, value);
+ if (str.empty())
+ bv->unlockInset(const_cast<InsetText *>(this));
+ else
+ value = cy(bv);
+ if (clear)
+ lt = 0;
+ return str;
+}
+
+
+void InsetText::selectSelectedWord(BufferView * bv)
+{
+ if (the_locking_inset) {
+ the_locking_inset->selectSelectedWord(bv);
+ return;
+ }
+ getLyXText(bv)->selectSelectedWord(bv);
+ updateLocal(bv, SELECTION, false);
+}
+
+
+void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
+{
+ if (the_locking_inset) {
+ the_locking_inset->toggleSelection(bv, kill_selection);
+ }
+ bool clear = false;
+ if (!lt) {
+ lt = getLyXText(bv);
+ clear = true;
+ }
+
+ int x = top_x + TEXT_TO_INSET_OFFSET;
+
+ Row * row = lt->firstRow();
+ int y_offset = top_baseline - row->ascent_of_text();
+ int y = y_offset;
+ while ((row != 0) && ((y+row->height()) <= 0)) {
+ y += row->height();
+ row = row->next();
+ }
+ if (y_offset < 0)
+ y_offset = y;
+
+ if (need_update & SELECTION)
+ need_update = NONE;
+ bv->screen()->toggleSelection(lt, bv, kill_selection, y_offset, x);
+ if (clear)
+ lt = 0;
+}
+
+
+bool InsetText::searchForward(BufferView * bv, string const & str,
+ bool cs, bool mw)
+{
+ if (the_locking_inset) {
+ if (the_locking_inset->searchForward(bv, str, cs, mw))
+ return true;
+ bool clear = false;
+ if (!lt) {
+ lt = getLyXText(bv);
+ clear = true;
+ }
+ Paragraph * lpar = lt->cursor.par();
+ pos_type pos = lt->cursor.pos();
+ if (pos < lpar->size() - 1)
+ ++pos;
+ else {
+ pos = 0;
+ lpar = lpar->next();
+ }
+ if (!lpar) {
+ if (clear)
+ lt = 0;
+ // we have to unlock ourself in this function by default!
+ bv->unlockInset(const_cast<InsetText *>(this));
+ return false;
+ }
+ lt->setCursor(bv, lpar, pos);
+ if (clear)
+ lt = 0;
+ }
+ if (LyXFind(bv, str, true, true, cs , mw)) {
+ return true;
+ }
+ // we have to unlock ourself in this function by default!
+ bv->unlockInset(const_cast<InsetText *>(this));
+ return false;
+}
+
+bool InsetText::searchBackward(BufferView * bv, string const & str,
+ bool cs, bool mw)
+{
+ if (the_locking_inset)
+ if (the_locking_inset->searchBackward(bv, str, cs, mw))
+ return true;
+ if (LyXFind(bv, str, false, true, cs, mw)) {
+ return true;
+ }
+ // we have to unlock ourself in this function by default!
+ bv->unlockInset(const_cast<InsetText *>(this));
+ return false;
+}
+
+
+bool InsetText::checkInsertChar(LyXFont & font)
+{
+ if (owner())
+ return owner()->checkInsertChar(font);
+ return true;
+}
+
+
+void InsetText::collapseParagraphs(BufferParams const & bparams) const
+{
+ while(par->next()) {
+ if (!par->isSeparator(par->size()-1))
+ par->insertChar(par->size()-1, ' ');
+ par->pasteParagraph(bparams);
+ }
+ reinitLyXText();