]> git.lyx.org Git - lyx.git/commitdiff
More textinset fixes! Now also undo works and I removed some unneeded
authorJürgen Vigna <jug@sad.it>
Thu, 20 Apr 2000 13:48:34 +0000 (13:48 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 20 Apr 2000 13:48:34 +0000 (13:48 +0000)
computation. Please test and tell me if there are more problems you see.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@683 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/BufferView_pimpl.C
src/CutAndPaste.C
src/insets/inset.C
src/insets/insettext.C

index 0dfc16f1495b702493a833c4a8f4b046a5c404de..641e243b0e0165f9be2e56b6c4fb390ea6b27d08 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2000-04-20  Juergen Vigna  <jug@sad.it>
+
+       * src/insets/insettext.C (cutSelection): 
+       (copySelection): Fixed with selection from right to left.
+       (draw): now the rows are not recalculated at every draw.
+       (computeTextRows): for now reset the inset-owner here (this is
+       important for an undo or copy where the inset-owner is not set
+       automatically!)
+
+       * src/BufferView_pimpl.C (workAreaMotionNotify): when passing the
+       motion to the_locking_inset screen->first was forgotten, this was
+       not important till we got multiline insets.
+
 2000-04-19  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * src/mathed/formulamacro.C (Latex): remove CHECK comment, since
index f5bae8bf449fcc50050fe19a19d0860f095d5d85..40564cfffdb3ac0f0263bb3c9d5edfad15975a31 100644 (file)
@@ -561,7 +561,7 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
                bv_->the_locking_inset->
                        InsetMotionNotify(bv_,
                                          x - cursor.x,
-                                         y - cursor.y,
+                                         y - cursor.y + screen->first,
                                          state);
                return;
        }
@@ -973,7 +973,9 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, unsigned int /* butto
                if (x > start_x && x < end_x
                    && y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
                    && y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
+#if 0
                        if (move_cursor && (tmpinset != bv_->the_locking_inset))
+#endif
                                bv_->text->SetCursor(cursor.par,cursor.pos,true);
                        x = x - start_x;
                        // The origin of an inset is on the baseline
@@ -1001,8 +1003,10 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y, unsigned int /* butto
                if (x > start_x && x < end_x
                    && y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
                    && y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
+#if 0
                        if (move_cursor && (tmpinset != bv_->the_locking_inset))
-                               bv_->text->SetCursor(cursor.par,cursor.pos,true);
+#endif
+                               bv_->text->SetCursor(cursor.par,cursor.pos-1,true);
                        x = x - start_x;
                        // The origin of an inset is on the baseline
                        y = y_tmp - (bv_->text->cursor.y); 
index 52ff00ad6a9468b09206f2f0f83fe17f5bbbaad9..d28498c7a0fe21268c55409aa6baf4996dd37f43 100644 (file)
@@ -30,6 +30,14 @@ using std::pair;
 // in and some method of choosing beween them (based on the first few chars
 // in the selection probably.) This would be a nice feature and quite
 // easy to implement. (Lgb)
+//
+// Sure but I just cleaned up this code for now with the same functionality
+// as before. I also want to add a XClipboard function so that we can copy
+// text from LyX to some other X-application in the form of ASCII or in the
+// form of LaTeX (or Docbook depending on the document-class!). Think how nice
+// it could be to select a math-inset do a "Copy to X-Clipboard as LaTeX" and
+// then do a middle mouse button click in the application you want and have
+// the whole formula there in LaTeX-Code. (Jug)
 
 static LyXParagraph * buf = 0;
 static LyXTextClassList::size_type textclass = 0;
@@ -41,16 +49,17 @@ static LyXTextClassList::size_type textclass = 0;
 static
 void DeleteBuffer()
 {
-       if (!buf) return;
+    if (!buf)
+       return;
        
-       LyXParagraph * tmppar;
+    LyXParagraph * tmppar;
        
-       while (buf) {
-               tmppar =  buf;
-               buf = buf->next;
-               delete tmppar;
-       }
-       buf = 0;
+    while (buf) {
+       tmppar =  buf;
+       buf = buf->next;
+       delete tmppar;
+    }
+    buf = 0;
 }
 
 
index 2bf343027453b510098879d6886e3b6c7a6bdf21..c07a0f384cb3fc9ebdb6d92aa8c88893e660df59 100644 (file)
@@ -142,11 +142,12 @@ void UpdatableInset::Edit(BufferView * bv, int, int, unsigned int)
 
 
 void UpdatableInset::draw(Painter &, LyXFont const &,
-                         int baseline, float & x) const
+                         int /* baseline */, float & x) const
 {
     if (scx) x += float(scx);
-    top_x = int(x);
-    top_baseline = baseline;
+// ATTENTION: this is not good doing here
+//    top_x = int(x);
+//    top_baseline = baseline;
 }
 
 
index d06b57abcbea289530585557b584c1693f25551a..246be22a54068fb24f39a8fbe6d7f7fac458c118 100644 (file)
@@ -208,10 +208,15 @@ void InsetText::draw(Painter & pain, LyXFont const & f,
     xpos = x;
     UpdatableInset::draw(pain, f, baseline, x);
     
-    top_x = int(x);
-    top_baseline = baseline;
-    computeTextRows(pain, x);
-    computeBaselines(baseline);
+    if (init_inset || (baseline != top_baseline) || (top_x != int(x))) {
+       top_baseline = baseline;
+       if (init_inset || (top_x != int(x))) {
+           top_x = int(x);
+           computeTextRows(pain, x);
+           init_inset = false;
+       }
+       computeBaselines(baseline);
+    }
     if (the_locking_inset && (cursor.pos == inset_pos)) {
        resetPos(pain);
        inset_x = cursor.x - top_x + drawTextXOffset;
@@ -1287,7 +1292,7 @@ void InsetText::computeTextRows(Painter & pain, float x) const
            }
            rows.back().asc = wordAscent;
            rows.back().desc = wordDescent;
-           row.pos = ++p; // +1;
+           row.pos = ++p;
            rows.push_back(row);
            SingleHeight(pain, par, p, oasc, odesc);
            insetWidth = max(insetWidth, owidth);
@@ -1297,39 +1302,42 @@ void InsetText::computeTextRows(Painter & pain, float x) const
            nwp = p;
            continue;
        }
-       Inset const * inset = 0;
+       Inset * inset = 0;
        if (((p + 1) < par->Last()) &&
            (par->GetChar(p + 1)==LyXParagraph::META_INSET))
            inset = par->GetInset(p + 1);
-       if (inset && inset->display()) {
-           if (!is_first_word_in_row && (width >= maxWidth)) {
-               // we have to split also the row above
+       if (inset) {
+           inset->setOwner(this);
+           if (inset->display()) {
+               if (!is_first_word_in_row && (width >= maxWidth)) {
+                   // we have to split also the row above
+                   rows.back().asc = oasc;
+                   rows.back().desc = odesc;
+                   row.pos = nwp;
+                   rows.push_back(row);
+                   oasc = wordAscent;
+                   odesc = wordDescent;
+                   insetWidth = max(insetWidth, owidth);
+                   width = lastWordWidth;
+                   lastWordWidth = 0;
+               } else {
+                   oasc = max(oasc, wordAscent);
+                   odesc = max(odesc, wordDescent);
+               }
                rows.back().asc = oasc;
                rows.back().desc = odesc;
-               row.pos = nwp;
+               row.pos = ++p;
                rows.push_back(row);
-               oasc = wordAscent;
-               odesc = wordDescent;
-               insetWidth = max(insetWidth, owidth);
-               width = lastWordWidth;
-               lastWordWidth = 0;
-           } else {
-                   oasc = max(oasc, wordAscent);
-                   odesc = max(odesc, wordDescent);
+               SingleHeight(pain, par, p, asc, desc);
+               rows.back().asc = asc;
+               rows.back().desc = desc;
+               row.pos = nwp = p + 1;
+               rows.push_back(row);
+               oasc = odesc = width = lastWordWidth = 0;
+               is_first_word_in_row = true;
+               wordAscent = wordDescent = 0;
+               continue;
            }
-           rows.back().asc = oasc;
-           rows.back().desc = odesc;
-           row.pos = ++p;
-           rows.push_back(row);
-           SingleHeight(pain, par, p, asc, desc);
-           rows.back().asc = asc;
-           rows.back().desc = desc;
-           row.pos = nwp = p + 1;
-           rows.push_back(row);
-           oasc = odesc = width = lastWordWidth = 0;
-           is_first_word_in_row = true;
-           wordAscent = wordDescent = 0;
-           continue;
        } else if (par->IsSeparator(p)) {
            if (width >= maxWidth) {
                if (is_first_word_in_row) {
@@ -1402,7 +1410,6 @@ void InsetText::computeBaselines(int baseline) const
 
 void InsetText::UpdateLocal(BufferView *bv, bool flag)
 {
-#if 1
     if (flag) {
        computeTextRows(bv->painter(), xpos);
        computeBaselines(top_baseline);
@@ -1410,10 +1417,6 @@ void InsetText::UpdateLocal(BufferView *bv, bool flag)
     bv->updateInset(this, flag);
     if (flag)
        resetPos(bv->painter());
-#else
-    init_inset = flag;
-    bv->updateInset(this, flag);
-#endif
 }
 
 bool InsetText::cutSelection()
@@ -1424,9 +1427,16 @@ bool InsetText::cutSelection()
     CutAndPaste cap;
 
     LyXParagraph *endpar = par;
+    int start, end;
+    if (selection_start > selection_end) {
+           start = selection_end;
+           end = selection_start;
+    } else {
+           start = selection_start;
+           end = selection_end;
+    }
 
-    return cap.cutSelection(par, &endpar, selection_start, selection_end,
-                           buffer->params.textclass);
+    return cap.cutSelection(par, &endpar, start, end,buffer->params.textclass);
 }
 
 bool InsetText::copySelection()
@@ -1436,8 +1446,15 @@ bool InsetText::copySelection()
 
     CutAndPaste cap;
 
-    return cap.copySelection(par, par, selection_start, selection_end,
-                            buffer->params.textclass);
+    int start, end;
+    if (selection_start > selection_end) {
+           start = selection_end;
+           end = selection_start;
+    } else {
+           start = selection_start;
+           end = selection_end;
+    }
+    return cap.copySelection(par, par, start, end, buffer->params.textclass);
 }
 
 bool InsetText::pasteSelection()