]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Minimal fix needed to give Qt a label dialog again.
[lyx.git] / src / text3.C
index eb907ad5fa170a8d29db2d6d1afa4d2517e12aa5..d7d588311745e93c0af9c17716cae87facd5355f 100644 (file)
@@ -31,7 +31,6 @@
 #include "frontends/Dialogs.h"
 #include "insets/insetspecialchar.h"
 #include "insets/insettext.h"
-#include "insets/insetbib.h"
 #include "insets/insetquotes.h"
 #include "insets/insetcommand.h"
 #include "undo_funcs.h"
@@ -47,7 +46,7 @@ extern string current_layout;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 // the selection possible is needed, that only motion events are
-// used, where the bottom press event was on the drawing area too 
+// used, where the bottom press event was on the drawing area too
 bool selection_possible = false;
 
 
@@ -59,12 +58,12 @@ namespace {
 
                if (selecting || lt->selection.mark()) {
                        lt->setSelection(bv);
-                       if (lt->bv_owner)
+                       if (lt->isTopLevel())
                                bv->toggleToggle();
                        else
                                bv->updateInset(lt->inset_owner, false);
                }
-               if (lt->bv_owner) {
+               if (lt->isTopLevel()) {
                        //if (fitcur)
                        //      bv->update(lt, BufferView::SELECT|BufferView::FITCUR);
                        //else
@@ -104,7 +103,7 @@ namespace {
 
                Inset /*const*/ * inset = par.getInset(pos);
 
-               if (!isEditableInset(inset)) 
+               if (!isEditableInset(inset))
                        return 0;
 
                // get inset dimensions
@@ -124,8 +123,9 @@ namespace {
                );
 
                if (!b.contained(x, y)) {
-                       lyxerr[Debug::GUI] << "Missed inset at x,y " << x << "," << y
-                               << " box " << b << endl;
+                       lyxerr[Debug::GUI] << "Missed inset at x,y "
+                                          << x << ',' << y
+                                          << " box " << b << endl;
                        return 0;
                }
 
@@ -257,12 +257,15 @@ void LyXText::cursorPrevious(BufferView * bv)
 
        int new_y;
        if (cursorrow == bv->text->cursor.row()) {
-               // we have a row which is higher than the workarea so we leave the
-               // cursor on the start of the row and move only the draw up as soon
-               // as we move the cursor or do something while inside the row (it may
-               // span several workarea-heights) we'll move to the top again, but this
-               // is better than just jump down and only display part of the row.
+               // we have a row which is taller than the workarea. The
+               // simplest solution is to move to the previous row instead.
+               cursorUp(bv, true);
+               return;
+               // This is what we used to do, so we wouldn't skip right past
+               // tall rows, but it's not working right now.
+#if 0
                new_y = bv->text->first_y - bv->workHeight();
+#endif
        } else {
                if (inset_owner) {
                        new_y = bv->text->cursor.iy()
@@ -318,12 +321,15 @@ void LyXText::cursorNext(BufferView * bv)
 
        int new_y;
        if (cursorrow == bv->text->cursor.row()) {
-               // we have a row which is higher than the workarea so we leave the
-               // cursor on the start of the row and move only the draw down as soon
-               // as we move the cursor or do something while inside the row (it may
-               // span several workarea-heights) we'll move to the top again, but this
-               // is better than just jump down and only display part of the row.
+               // we have a row which is taller than the workarea. The
+               // simplest solution is to move to the next row instead.
+               cursorDown(bv, true);
+               return;
+               // This is what we used to do, so we wouldn't skip right past
+               // tall rows, but it's not working right now.
+#if 0
                new_y = bv->text->first_y + bv->workHeight();
+#endif
        } else {
                if (inset_owner) {
                        new_y = bv->text->cursor.iy()
@@ -355,6 +361,7 @@ void LyXText::update(BufferView * bv, bool changed)
                bv->update(this, c);
 }
 
+namespace {
 
 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 {
@@ -368,10 +375,35 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 }
 
 
+void doInsertInset(LyXText * lt, FuncRequest const & cmd,
+                  bool edit, bool pastesel)
+{
+       Inset * inset = createInset(cmd);
+       BufferView * bv = cmd.view();
+
+       if (inset) {
+               bool gotsel = false;
+               if (lt->selection.set()) {
+                       lt->cutSelection(bv, true, false);
+                       gotsel = true;
+               }
+               if (bv->insertInset(inset)) {
+                       if (edit)
+                               inset->edit(bv);
+                       if (gotsel && pastesel)
+                               bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
+               }
+               else
+                       delete inset;
+       }
+}
+
+}
+
 Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 {
        lyxerr[Debug::ACTION] << "LyXFunc::dispatch: action[" << cmd.action
-                             <<"] arg[" << cmd.argument << "]" << endl;
+                             <<"] arg[" << cmd.argument << ']' << endl;
 
        BufferView * bv = cmd.view();
 
@@ -561,8 +593,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_WORDSEL: {
                update(bv, false);
-               LyXCursor cur1; 
-               LyXCursor cur2; 
+               LyXCursor cur1;
+               LyXCursor cur2;
                getWord(cur1, cur2, WHOLE_WORD);
                setCursor(bv, cur1.par(), cur1.pos());
                bv->beforeChange(this);
@@ -575,7 +607,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bool is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(bv);
+               update(bv, false);
                if (is_rtl)
                        cursorLeft(bv, false);
                if (cursor.pos() < cursor.par()->size()
@@ -598,7 +630,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bool const is_rtl = cursor.par()->isRightToLeftPar(bv->buffer()->params);
                if (!selection.mark())
                        bv->beforeChange(this);
-               update(bv);
+               update(bv, false);
                LyXCursor const cur = cursor;
                if (!is_rtl)
                        cursorLeft(bv, false);
@@ -963,7 +995,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_UPCASE_WORD:
                update(bv, false);
-               changeCase(bv, LyXText::text_uppercase);
+               changeCase(*bv, LyXText::text_uppercase);
                if (inset_owner)
                        bv->updateInset(inset_owner, true);
                update(bv);
@@ -971,7 +1003,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_LOWCASE_WORD:
                update(bv, false);
-               changeCase(bv, LyXText::text_lowercase);
+               changeCase(*bv, LyXText::text_lowercase);
                if (inset_owner)
                        bv->updateInset(inset_owner, true);
                update(bv);
@@ -979,7 +1011,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_CAPITALIZE_WORD:
                update(bv, false);
-               changeCase(bv, LyXText::text_capitalization);
+               changeCase(*bv, LyXText::text_capitalization);
                if (inset_owner)
                        bv->updateInset(inset_owner, true);
                update(bv);
@@ -1022,7 +1054,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_BEGINNINGBUFSEL:
                if (inset_owner)
-                       return Inset::UNDISPATCHED;
+                       return UNDISPATCHED;
                update(bv, false);
                cursorTop(bv);
                finishChange(bv, true);
@@ -1030,7 +1062,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_ENDBUFSEL:
                if (inset_owner)
-                       return Inset::UNDISPATCHED;
+                       return UNDISPATCHED;
                update(bv, false);
                cursorBottom(bv);
                finishChange(bv, true);
@@ -1048,7 +1080,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!is)
                        lyxerr << "SETXY: Could not parse coordinates in '"
                               << cmd.argument << std::endl;
-               else 
+               else
                        setCursorFromCoordinates(bv, x, y);
                break;
        }
@@ -1208,10 +1240,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_MOUSE_TRIPLE:
                if (!bv->buffer())
                        break;
-               if (bv_owner && bv->theLockingInset())
+               if (isTopLevel() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (bv_owner) {
+                       if (isTopLevel()) {
                                bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                        }
@@ -1219,7 +1251,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        selection.cursor = cursor;
                        cursorEnd(bv);
                        setSelection(bv);
-                       if (bv_owner)
+                       if (isTopLevel())
                                bv->screen().toggleSelection(this, bv, false);
                        update(bv, false);
                        bv->haveSelection(selection.set());
@@ -1229,10 +1261,10 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_MOUSE_DOUBLE:
                if (!bv->buffer())
                        break;
-               if (bv_owner && bv->theLockingInset())
+               if (isTopLevel() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (bv_owner) {
+                       if (isTopLevel()) {
                                bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                                selectWord(bv, LyXText::WHOLE_WORD_STRICT);
@@ -1290,7 +1322,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                // in some other local environment, but I would like to leave this here
                // for the moment until I can remove this (Jug 20020418)
                if (y_before < bv->text->cursor.y())
-                       lyxerr << y_before << ":" << bv->text->cursor.y() << endl;
+                       lyxerr << y_before << ':'
+                              << bv->text->cursor.y() << endl;
        #endif
                // This is to allow jumping over large insets
                if (cursorrow == bv->text->cursor.row()) {
@@ -1421,7 +1454,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                // do nothing if we used the mouse wheel
                if (!bv->buffer())
                        break;
-       
+
                if (cmd.button() == mouse_button::button4
                 || cmd.button() == mouse_button::button5)
                        break;
@@ -1504,7 +1537,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        } else {
                                FuncRequest cmd1(bv, LFUN_MOUSE_RELEASE, x, y, cmd.button());
                                inset_hit->localDispatch(cmd1);
-                               // IMO this is a grosshack! Inset's should be changed so that
+                               // IMO this is a gross hack! Insets should be changed so that
                                // they call the actions they have to do with the insetButtonRel.
                                // function and not in the edit(). This should be changed
                                // (Jug 20020329)
@@ -1516,17 +1549,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               // Maybe we want to edit a bibitem ale970302
-               if (bv->text->cursor.par()->bibkey) {
-                       bool const is_rtl =
-                               bv->text->cursor.par()->isRightToLeftPar(bv->buffer()->params);
-                       int const width =
-                               bibitemMaxWidth(bv, bv->buffer()->params.getLyXTextClass().defaultfont());
-                       if ((is_rtl && x > bv->text->workWidth(bv)-20-width) ||
-                                       (!is_rtl && x < 20 + width)) {
-                               bv->text->cursor.par()->bibkey->edit(bv, 0, 0, mouse_button::none);
-                       }
-               }
                break;
        }
 
@@ -1570,13 +1592,15 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_HTMLURL: {
                InsetCommandParams p("htmlurl");
-               bv->owner()->getDialogs().createUrl(p.getAsString());
+               string const data = InsetCommandMailer::params2string("url", p);
+               bv->owner()->getDialogs().show("url", data, 0);
                break;
        }
 
        case LFUN_URL: {
                InsetCommandParams p("url");
-               bv->owner()->getDialogs().createUrl(p.getAsString());
+               string const data = InsetCommandMailer::params2string("url", p);
+               bv->owner()->getDialogs().show("url", data, 0);
                break;
        }
 
@@ -1584,12 +1608,11 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 #if 0
        case LFUN_INSET_LIST:
        case LFUN_INSET_THEOREM:
+       case LFUN_INSET_CAPTION:
 #endif
        case LFUN_INSERT_NOTE:
-       case LFUN_INSERT_URL:
-       case LFUN_INSET_CAPTION:
+       case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT:
-       case LFUN_INSET_EXTERNAL:
        case LFUN_INSET_FLOAT:
        case LFUN_INSET_FOOTNOTE:
        case LFUN_INSET_MARGINAL:
@@ -1598,33 +1621,28 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_INSET_WIDE_FLOAT:
        case LFUN_INSET_WRAP:
        case LFUN_TABULAR_INSERT:
+               // Open the inset, and move the current selection
+               // inside it.
+               doInsertInset(this, cmd, true, true);
+               break;
+
+       case LFUN_INSERT_URL:
+       case LFUN_INSET_EXTERNAL:
        case LFUN_INDEX_INSERT:
-       case LFUN_INDEX_PRINT: 
+               // Just open the inset
+               doInsertInset(this, cmd, true, false);
+               break;
+
+       case LFUN_INDEX_PRINT:
        case LFUN_PARENTINSERT:
        case LFUN_TOC_INSERT:
-       {
-               Inset * inset = createInset(cmd);
-               if (inset) {
-                       bool gotsel = false;
-                       if (selection.set()) {
-                               cutSelection(bv, true, false);
-                               gotsel = true;
-                       }
-                       if (bv->insertInset(inset)) {
-                               inset->edit(bv);
-                               if (gotsel)
-                                       bv->owner()->dispatch(FuncRequest(LFUN_PASTESELECTION));
-                       }
-                       else
-                               delete inset;
-               }
+               // do nothing fancy
+               doInsertInset(this, cmd, false, false);
                break;
-       }
-
 
        default:
-               return Inset::UNDISPATCHED;
+               return UNDISPATCHED;
        }
 
-       return Inset::DISPATCHED;
+       return DISPATCHED;
 }