+ default:
+ if (!bv->Dispatch(action, arg))
+ result = UNDISPATCHED;
+ break;
+ }
+
+ if (clear)
+ lt = 0;
+ if (updwhat > 0)
+ updateLocal(bv, updwhat, updflag);
+ /// If the action has deleted all text in the inset, we need to change the
+ // language to the language of the surronding text.
+ if (!was_empty && par->size() == 0 && !par->next()) {
+ LyXFont font(LyXFont::ALL_IGNORE);
+ font.setLanguage(bv->getParentLanguage(this));
+ setFont(bv, font, false);
+ }
+
+ if (result < FINISHED) {
+ showInsetCursor(bv);
+ } else
+ bv->unlockInset(this);
+ return result;
+}
+
+
+int InsetText::latex(Buffer const * buf, ostream & os, bool, bool) const
+{
+ TexRow texrow;
+ buf->latexParagraphs(os, par, 0, texrow);
+ return texrow.rows();
+}
+
+
+int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
+{
+ Paragraph * p = par;
+ unsigned int lines = 0;
+
+ while (p) {
+ string const tmp = buf->asciiParagraph(p, linelen, p->previous()==0);
+ lines += lyx::count(tmp.begin(), tmp.end(), '\n');
+ os << tmp;
+ p = p->next();
+ }
+ return lines;
+}
+
+
+int InsetText::docbook(Buffer const * buf, ostream & os) const
+{
+ Paragraph * p = par;
+ unsigned int lines = 0;
+
+ vector<string> environment_stack(10);
+ vector<string> environment_inner(10);
+
+ int const command_depth = 0;
+ string item_name;
+
+ Paragraph::depth_type depth = 0; // paragraph depth
+
+ while (p) {
+ string sgmlparam;
+ int desc_on = 0; // description mode
+
+ LyXLayout const & style =
+ textclasslist[buf->params.textclass][p->layout()];
+
+ // environment tag closing
+ for (; depth > p->params().depth(); --depth) {
+ if (environment_inner[depth] != "!-- --") {
+ item_name = "listitem";
+ buf->sgmlCloseTag(os, command_depth + depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os, depth+command_depth,
+ environment_inner[depth]);
+ }
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_stack[depth]);
+ environment_stack[depth].erase();
+ environment_inner[depth].erase();
+ }
+
+ if (depth == p->params().depth()
+ && environment_stack[depth] != style.latexname()
+ && !environment_stack[depth].empty()) {
+ if (environment_inner[depth] != "!-- --") {
+ item_name= "listitem";
+ buf->sgmlCloseTag(os, command_depth+depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os,
+ depth + command_depth,
+ environment_inner[depth]);
+ }
+
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_stack[depth]);
+
+ environment_stack[depth].erase();
+ environment_inner[depth].erase();
+ }
+
+ // Write opening SGML tags.
+ switch (style.latextype) {
+ case LATEX_PARAGRAPH:
+ buf->sgmlOpenTag(os, depth + command_depth,
+ style.latexname());
+ break;
+
+ case LATEX_COMMAND:
+ buf->sgmlError(p, 0,
+ _("Error : LatexType Command not allowed here.\n"));
+ return -1;
+ break;
+
+ case LATEX_ENVIRONMENT:
+ case LATEX_ITEM_ENVIRONMENT:
+ if (depth < p->params().depth()) {
+ depth = p->params().depth();
+ environment_stack[depth].erase();
+ }
+
+ if (environment_stack[depth] != style.latexname()) {
+ if (environment_stack.size() == depth + 1) {
+ environment_stack.push_back("!-- --");
+ environment_inner.push_back("!-- --");
+ }
+ environment_stack[depth] = style.latexname();
+ environment_inner[depth] = "!-- --";
+ buf->sgmlOpenTag(os, depth + command_depth,
+ environment_stack[depth]);
+ } else {
+ if (environment_inner[depth] != "!-- --") {
+ item_name= "listitem";
+ buf->sgmlCloseTag(os,
+ command_depth + depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os,
+ depth + command_depth,
+ environment_inner[depth]);
+ }
+ }
+
+ if (style.latextype == LATEX_ENVIRONMENT) {
+ if (!style.latexparam().empty()) {
+ if (style.latexparam() == "CDATA")
+ os << "<![CDATA[";
+ else
+ buf->sgmlOpenTag(os, depth + command_depth,
+ style.latexparam());
+ }
+ break;
+ }
+
+ desc_on = (style.labeltype == LABEL_MANUAL);
+
+ if (desc_on)
+ environment_inner[depth]= "varlistentry";
+ else
+ environment_inner[depth]= "listitem";
+
+ buf->sgmlOpenTag(os, depth + 1 + command_depth,
+ environment_inner[depth]);
+
+ if (desc_on) {
+ item_name= "term";
+ buf->sgmlOpenTag(os, depth + 1 + command_depth,
+ item_name);
+ } else {
+ item_name= "para";
+ buf->sgmlOpenTag(os, depth + 1 + command_depth,
+ item_name);
+ }
+ break;
+ default:
+ buf->sgmlOpenTag(os, depth + command_depth,
+ style.latexname());
+ break;
+ }
+
+ buf->simpleDocBookOnePar(os, p, desc_on,
+ depth + 1 + command_depth);
+ p = p->next();
+
+ string end_tag;
+ // write closing SGML tags
+ switch (style.latextype) {
+ case LATEX_ENVIRONMENT:
+ if (!style.latexparam().empty()) {
+ if (style.latexparam() == "CDATA")
+ os << "]]>";
+ else
+ buf->sgmlCloseTag(os, depth + command_depth,
+ style.latexparam());
+ }
+ break;
+ case LATEX_ITEM_ENVIRONMENT:
+ if (desc_on == 1) break;
+ end_tag= "para";
+ buf->sgmlCloseTag(os, depth + 1 + command_depth, end_tag);
+ break;
+ case LATEX_PARAGRAPH:
+ buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
+ break;
+ default:
+ buf->sgmlCloseTag(os, depth + command_depth, style.latexname());
+ break;
+ }
+ }
+
+ // Close open tags
+ for (int d = depth; d >= 0; --d) {
+ if (!environment_stack[depth].empty()) {
+ if (environment_inner[depth] != "!-- --") {
+ item_name = "listitem";
+ buf->sgmlCloseTag(os, command_depth + depth,
+ item_name);
+ if (environment_inner[depth] == "varlistentry")
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_inner[depth]);
+ }
+
+ buf->sgmlCloseTag(os, depth + command_depth,
+ environment_stack[depth]);
+ }
+ }
+
+ return lines;
+}
+
+
+void InsetText::validate(LaTeXFeatures & features) const
+{
+ Paragraph * p = par;
+ while (p) {
+ p->validate(features);
+ p = p->next();
+ }
+}
+
+
+int InsetText::beginningOfMainBody(Buffer const * buf, Paragraph * p) const
+{
+ if (textclasslist[buf->params.textclass][p->layout()].labeltype != LABEL_MANUAL)
+ return 0;
+ else
+ return p->beginningOfMainBody();
+}
+
+
+void InsetText::getCursorPos(BufferView * bv,
+ int & x, int & y) const
+{
+ if (the_locking_inset) {
+ the_locking_inset->getCursorPos(bv, x, y);
+ return;
+ }
+ x = cx(bv);
+ y = cy(bv);
+}
+
+
+unsigned int InsetText::insetInInsetY()
+{
+ if (!the_locking_inset)
+ return 0;
+
+ return (inset_y + the_locking_inset->insetInInsetY());
+}
+
+
+void InsetText::toggleInsetCursor(BufferView * bv)
+{
+ if (the_locking_inset) {
+ the_locking_inset->toggleInsetCursor(bv);
+ return;
+ }
+
+ LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
+
+ int const asc = lyxfont::maxAscent(font);
+ int const desc = lyxfont::maxDescent(font);
+
+ if (isCursorVisible())
+ bv->hideLockedInsetCursor();
+ else
+ bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
+ toggleCursorVisible();
+}
+
+
+void InsetText::showInsetCursor(BufferView * bv, bool show)
+{
+ if (the_locking_inset) {
+ the_locking_inset->showInsetCursor(bv, show);
+ return;
+ }
+ if (!isCursorVisible()) {
+ LyXFont const font =
+ getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
+
+ int const asc = lyxfont::maxAscent(font);
+ int const desc = lyxfont::maxDescent(font);
+
+ bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
+ if (show)
+ bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
+ setCursorVisible(true);
+ }
+}
+
+
+void InsetText::hideInsetCursor(BufferView * bv)
+{
+ if (isCursorVisible()) {
+ bv->hideLockedInsetCursor();
+ setCursorVisible(false);
+ }
+ if (the_locking_inset)
+ the_locking_inset->hideInsetCursor(bv);
+}
+
+
+void InsetText::fitInsetCursor(BufferView * bv) const
+{
+ if (the_locking_inset) {
+ the_locking_inset->fitInsetCursor(bv);
+ return;
+ }
+ LyXFont const font =
+ getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
+
+ int const asc = lyxfont::maxAscent(font);
+ int const desc = lyxfont::maxDescent(font);
+
+ bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
+}
+
+
+UpdatableInset::RESULT
+InsetText::moveRight(BufferView * bv, bool activate_inset, bool selecting)
+{
+ if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ return moveLeftIntern(bv, false, activate_inset, selecting);
+ else
+ return moveRightIntern(bv, false, activate_inset, selecting);
+}
+
+
+UpdatableInset::RESULT
+InsetText::moveLeft(BufferView * bv, bool activate_inset, bool selecting)
+{
+ if (getLyXText(bv)->cursor.par()->isRightToLeftPar(bv->buffer()->params))
+ return moveRightIntern(bv, true, activate_inset, selecting);
+ else
+ return moveLeftIntern(bv, true, activate_inset, selecting);
+}
+
+
+UpdatableInset::RESULT
+InsetText::moveRightIntern(BufferView * bv, bool behind,
+ bool activate_inset, bool selecting)
+{
+ if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
+ return FINISHED_RIGHT;
+ if (activate_inset && checkAndActivateInset(bv, behind))
+ return DISPATCHED;
+ getLyXText(bv)->cursorRight(bv);
+ if (!selecting)
+ getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
+ return DISPATCHED_NOUPDATE;
+}
+
+
+UpdatableInset::RESULT
+InsetText::moveLeftIntern(BufferView * bv, bool behind,
+ bool activate_inset, bool selecting)
+{
+ if (!cpar(bv)->previous() && (cpos(bv) <= 0))
+ return FINISHED;
+ getLyXText(bv)->cursorLeft(bv);
+ if (!selecting)
+ getLyXText(bv)->selection.cursor = getLyXText(bv)->cursor;
+ if (activate_inset && checkAndActivateInset(bv, behind))
+ return DISPATCHED;
+ return DISPATCHED_NOUPDATE;
+}