]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
Alfredo's double-dialog fix
[lyx.git] / src / insets / insettext.C
index 8bb0a7d6226a67418cac999e17b38f2d25995ace..e24e992051a4137bbda81690911caa01a45287d2 100644 (file)
@@ -1,11 +1,11 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file insettext.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Jürgen Vigna
  *
- *           Copyright 1998-2001 The LyX Team.
- *
- * ======================================================
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
@@ -38,6 +38,7 @@
 #include "undo_funcs.h"
 #include "WordLangTuple.h"
 #include "paragraph_funcs.h"
+#include "sgml.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -239,8 +240,9 @@ void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
 {
        ParagraphList::iterator it = paragraphs.begin();
        ParagraphList::iterator end = paragraphs.end();
+       Paragraph::depth_type dth = 0;
        for (; it != end; ++it) {
-               it->write(buf, os, buf->params, 0);
+               it->write(buf, os, buf->params, dth);
        }
 }
 
@@ -1003,7 +1005,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
 
        int tmp_x = cmd.x - drawTextXOffset;
        int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
-       Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
+       Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
 
        hideInsetCursor(bv);
        if (the_locking_inset) {
@@ -1112,7 +1114,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
 
        int tmp_x = cmd.x - drawTextXOffset;
        int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
-       Inset * inset = bv->checkInsetHit(getLyXText(bv), tmp_x, tmp_y);
+       Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
        bool ret = false;
        if (inset) {
                if (isHighlyEditableInset(inset))
@@ -1122,7 +1124,9 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
                        inset_y = ciy(bv) + drawTextYOffset;
                        cmd1.x = cmd.x - inset_x;
                        cmd1.y = cmd.x - inset_y;
-                       ret = inset->localDispatch(cmd1);
+// note that we should do ret = inset->localDispatch(cmd1) 
+// and fix this instead (Alfredo);
+                       ret = true;
                        inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
                }
                updateLocal(bv, CURSOR_PAR, false);
@@ -1176,6 +1180,19 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
 Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
 {
        BufferView * bv = ev.view();
+       switch (ev.action) {
+               case LFUN_MOUSE_PRESS:
+                       lfunMousePress(ev);
+                       return DISPATCHED;
+               case LFUN_MOUSE_MOTION:
+                       lfunMouseMotion(ev);
+                       return DISPATCHED;
+               case LFUN_MOUSE_RELEASE:
+                       return lfunMouseRelease(ev) ? DISPATCHED : UNDISPATCHED;
+               default:
+                       break;
+       }
+
        bool was_empty = (paragraphs.begin()->empty() && !paragraphs.begin()->next());
        no_selection = false;
        RESULT result = UpdatableInset::localDispatch(ev);
@@ -1240,17 +1257,6 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
        int updflag = false;
        switch (ev.action) {
 
-       case LFUN_MOUSE_PRESS:
-               lfunMousePress(ev);
-               return DISPATCHED;
-       case LFUN_MOUSE_MOTION:
-               lfunMouseMotion(ev);
-               return DISPATCHED;
-       case LFUN_MOUSE_RELEASE:
-               return lfunMouseRelease(ev) ? DISPATCHED : UNDISPATCHED;
        // Normal chars
        case LFUN_SELFINSERT:
                if (bv->buffer()->isReadonly()) {
@@ -1263,9 +1269,11 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                         * typed in now. Depends on lyxrc settings
                         * "auto_region_delete", which defaults to
                         * true (on). */
-
+#if 0
+                       // This should not be needed here and is also WRONG!
                        setUndo(bv, Undo::INSERT,
                                lt->cursor.par(), lt->cursor.par()->next());
+#endif
                        bv->switchKeyMap();
                        if (lyxrc.auto_region_delete) {
                                if (lt->selection.set()) {
@@ -1337,9 +1345,25 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                lt->cursorEnd(bv);
                updwhat = CURSOR;
                break;
+       case LFUN_PRIOR:
+               if (!crow(bv)->previous())
+                       result = FINISHED_UP;
+               else {
+                       lt->cursorPrevious(bv);
+                       result = DISPATCHED_NOUPDATE;
+               }
+               updwhat = CURSOR;
+               break;
+       case LFUN_NEXT:
+               if (!crow(bv)->next())
+                       result = FINISHED_DOWN;
+               else {
+                       lt->cursorNext(bv);
+                       result = DISPATCHED_NOUPDATE;
+               }
+               updwhat = CURSOR;
+               break;
        case LFUN_BACKSPACE: {
-               setUndo(bv, Undo::DELETE,
-                       lt->cursor.par(), lt->cursor.par()->next());
                if (lt->selection.set())
                        lt->cutSelection(bv, true, false);
                else
@@ -1350,8 +1374,6 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
        break;
 
        case LFUN_DELETE: {
-               setUndo(bv, Undo::DELETE,
-                       lt->cursor.par(), lt->cursor.par()->next());
                if (lt->selection.set()) {
                        lt->cutSelection(bv, true, false);
                } else {
@@ -1363,8 +1385,6 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
        break;
 
        case LFUN_CUT: {
-               setUndo(bv, Undo::DELETE,
-                       lt->cursor.par(), lt->cursor.par()->next());
                lt->cutSelection(bv);
                updwhat = CURSOR_PAR;
                updflag = true;
@@ -1404,8 +1424,11 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                                break;
                        }
                }
+#if 0
+               // This should not be needed here and is also WRONG!
                setUndo(bv, Undo::INSERT,
                        lt->cursor.par(), lt->cursor.par()->next());
+#endif
                lt->pasteSelection(bv);
                // bug 393
                lt->clearSelection();
@@ -1438,8 +1461,11 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                        result = DISPATCHED;
                        break;
                }
+#if 0
+               // This should not be needed here and is also WRONG!
                setUndo(bv, Undo::INSERT,
                        lt->cursor.par(), lt->cursor.par()->next());
+#endif
                lt->insertChar(bv, Paragraph::META_NEWLINE);
                updwhat = CURSOR | CURSOR_PAR;
                updflag = true;
@@ -1608,11 +1634,11 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                for (; depth > p->params().depth(); --depth) {
                        if (environment_inner[depth] != "!-- --") {
                                item_name = "listitem";
-                               lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name);
+                               lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
                                if (environment_inner[depth] == "varlistentry")
-                                       lines += buf->sgmlCloseTag(os, depth+command_depth, mixcont, environment_inner[depth]);
+                                       lines += sgml::closeTag(os, depth+command_depth, mixcont, environment_inner[depth]);
                        }
-                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+                       lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
                        environment_stack[depth].erase();
                        environment_inner[depth].erase();
                }
@@ -1622,12 +1648,12 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                   && !environment_stack[depth].empty()) {
                        if (environment_inner[depth] != "!-- --") {
                                item_name= "listitem";
-                               lines += buf->sgmlCloseTag(os, command_depth+depth, mixcont, item_name);
+                               lines += sgml::closeTag(os, command_depth+depth, mixcont, item_name);
                                if (environment_inner[depth] == "varlistentry")
-                                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]);
+                                       lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
                        }
 
-                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+                       lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
 
                        environment_stack[depth].erase();
                        environment_inner[depth].erase();
@@ -1636,7 +1662,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                // Write opening SGML tags.
                switch (style->latextype) {
                case LATEX_PARAGRAPH:
-                       lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style->latexname());
+                       lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
                        break;
 
                case LATEX_COMMAND:
@@ -1658,13 +1684,13 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                                }
                                environment_stack[depth] = style->latexname();
                                environment_inner[depth] = "!-- --";
-                               lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+                               lines += sgml::openTag(os, depth + command_depth, mixcont, environment_stack[depth]);
                        } else {
                                if (environment_inner[depth] != "!-- --") {
                                        item_name= "listitem";
-                                       lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name);
+                                       lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
                                        if (environment_inner[depth] == "varlistentry")
-                                               lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]);
+                                               lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
                                }
                        }
 
@@ -1673,22 +1699,22 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                                        if (style->latexparam() == "CDATA")
                                                os << "<![CDATA[";
                                        else
-                                         lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style->latexparam());
+                                         lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexparam());
                                }
                                break;
                        }
 
                        desc_on = (style->labeltype == LABEL_MANUAL);
 
-                       environment_inner[depth] = desc_on?"varlistentry":"listitem";
-                       lines += buf->sgmlOpenTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
+                       environment_inner[depth] = desc_on ? "varlistentry" : "listitem";
+                       lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]);
 
-                       item_name = desc_on?"term":"para";
-                       lines += buf->sgmlOpenTag(os, depth + 1 + command_depth, mixcont, item_name);
+                       item_name = desc_on ? "term" : "para";
+                       lines += sgml::openTag(os, depth + 1 + command_depth, mixcont, item_name);
 
                        break;
                default:
-                       lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style->latexname());
+                       lines += sgml::openTag(os, depth + command_depth, mixcont, style->latexname());
                        break;
                }
 
@@ -1703,19 +1729,19 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                                if (style->latexparam() == "CDATA")
                                        os << "]]>";
                                else
-                                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style->latexparam());
+                                       lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexparam());
                        }
                        break;
                case LATEX_ITEM_ENVIRONMENT:
                        if (desc_on == 1) break;
                        end_tag= "para";
-                       lines += buf->sgmlCloseTag(os, depth + 1 + command_depth, mixcont, end_tag);
+                       lines += sgml::closeTag(os, depth + 1 + command_depth, mixcont, end_tag);
                        break;
                case LATEX_PARAGRAPH:
-                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style->latexname());
+                       lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
                        break;
                default:
-                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style->latexname());
+                       lines += sgml::closeTag(os, depth + command_depth, mixcont, style->latexname());
                        break;
                }
        }
@@ -1725,12 +1751,12 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                if (!environment_stack[depth].empty()) {
                        if (environment_inner[depth] != "!-- --") {
                                item_name = "listitem";
-                               lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name);
+                               lines += sgml::closeTag(os, command_depth + depth, mixcont, item_name);
                               if (environment_inner[depth] == "varlistentry")
-                                      lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]);
+                                      lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_inner[depth]);
                        }
 
-                       lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]);
+                       lines += sgml::closeTag(os, depth + command_depth, mixcont, environment_stack[depth]);
                }
        }
 
@@ -1893,8 +1919,7 @@ InsetText::moveLeftIntern(BufferView * bv, bool front,
 }
 
 
-Inset::RESULT
-InsetText::moveUp(BufferView * bv)
+Inset::RESULT InsetText::moveUp(BufferView * bv)
 {
        if (!crow(bv)->previous())
                return FINISHED_UP;
@@ -1903,8 +1928,7 @@ InsetText::moveUp(BufferView * bv)
 }
 
 
-Inset::RESULT
-InsetText::moveDown(BufferView * bv)
+Inset::RESULT InsetText::moveDown(BufferView * bv)
 {
        if (!crow(bv)->next())
                return FINISHED_DOWN;
@@ -2049,7 +2073,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
        x -= drawTextXOffset;
        int dummyx = x;
        int dummyy = y + insetAscent;
-       Inset * inset = bv->checkInsetHit(getLyXText(bv), dummyx, dummyy);
+       Inset * inset = getLyXText(bv)->checkInsetHit(bv, dummyx, dummyy);
        // we only do the edit() call if the inset was hit by the mouse
        // or if it is a highly editable inset. So we should call this
        // function from our own edit with button < 0.
@@ -2742,7 +2766,7 @@ void InsetText::collapseParagraphs(BufferView * bv) const
                                        llt->selection.end.pos() + paragraphs.begin()->size());
                        }
                }
-               pasteParagraph(bparams, &*paragraphs.begin());
+               mergeParagraph(bparams, &*paragraphs.begin());
        }
        reinitLyXText();
 }
@@ -2784,7 +2808,7 @@ void InsetText::appendParagraphs(BufferParams const & bparams,
        // paste it!
        lastbuffer->next(buf);
        buf->previous(lastbuffer);
-       pasteParagraph(bparams, lastbuffer);
+       mergeParagraph(bparams, lastbuffer);
 
        reinitLyXText();
 }