]> git.lyx.org Git - features.git/commitdiff
Fixed selection in insets and some small fixes.
authorJürgen Vigna <jug@sad.it>
Fri, 7 Jul 2000 15:00:56 +0000 (15:00 +0000)
committerJürgen Vigna <jug@sad.it>
Fri, 7 Jul 2000 15:00:56 +0000 (15:00 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@869 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/insets/inset.C
src/insets/insettext.C
src/insets/lyxinset.h
src/lyxscreen.h
src/screen.C
src/text.C
src/text2.C

index cdbdbe25401a84816c108dab277f02f2b332151e..1e1465a6cd1e68fd69c7c4c9e2a292a3ceb7efcf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2000-07-07  Juergen Vigna  <jug@sad.it>
+
+       * src/screen.C (ToggleSelection): added y_offset and x_offset
+       parameters.
+
+       * src/insets/insettext.C (InsetMotionNotify): fixed selection with
+       mouse.
+
+       * src/text.C (GetVisibleRow): fixed selection drawing in insets.
+
+       * src/insets/insettext.C: fixed Layout-Display!
+
 2000-07-07  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * configure.in: add check for strings.h header.
index b63d267077812f9bbae83363e28d579250078a0f..37abd2a4dd6b13d102f10175572292dbf691b552 100644 (file)
@@ -69,6 +69,16 @@ char const * Inset::EditMessage() const
        return _("Opened inset");
 }
 
+
+LyXText * Inset::getLyXText(BufferView * bv) const
+{
+    if (owner())
+           return owner()->getLyXText(bv);
+    else
+           return bv->text;
+}
+
+
  /* some stuff for inset locking */
 
 void UpdatableInset::InsetButtonPress(BufferView *, int x, int y, int button)
index c595f6d72e20bb1e08736e6e7c63d369105d813c..56ef2d368d938922f6e79373ed512f0bc321e245 100644 (file)
@@ -264,6 +264,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        top_x = int(x);
        owner()->update(bv, f, true);
        bv->text->status = LyXText::CHANGED_IN_DRAW;
+//     return;
     }
 
     top_baseline = baseline;
@@ -275,12 +276,12 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        inset_x = cx(bv) - top_x + drawTextXOffset;
        inset_y = cy(bv) + drawTextYOffset;
     }
-    if (!cleared && (need_update == CURSOR)) {
+    if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) {
        x += width(bv, f);
        need_update = NONE;
        return;
     }
-    x += TEXT_TO_INSET_OFFSET; // place for border
+    x += 1; // place for border
     long int y = 0;
     Row * row = TEXT(bv)->GetRowNearY(y);
     y += baseline - row->ascent_of_text() + 1;
@@ -291,9 +292,14 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
            row = row->next();
        }
     } else if (need_update == SELECTION) {
-       bv->screen()->ToggleToggle(getLyXText(bv), y, x);
+       bv->screen()->ToggleToggle(TEXT(bv), y, x);
     } else {
        locked = false;
+       if (need_update == CURSOR) {
+           bv->screen()->ToggleSelection(TEXT(bv), y, x, true);
+           TEXT(bv)->ClearSelection();
+           TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
+       }
        bv->screen()->Update(TEXT(bv), y, x);
        locked = true;
     }
@@ -388,7 +394,8 @@ void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
        else if (!the_locking_inset || (what != CURSOR))
            need_update = what;
     }
-    if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
+    if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED) ||
+       TEXT(bv)->selection)
            bv->updateInset(this, mark_dirty);
     if (old_par != cpar(bv)) {
            bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
@@ -416,6 +423,7 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
     the_locking_inset = 0;
     inset_pos = inset_x = inset_y = 0;
     inset_par = 0;
+    old_par = 0;
     if (!checkAndActivateInset(bv, x, y, button))
        TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
                                           y+TEXT(bv)->first+insetAscent);
@@ -436,7 +444,12 @@ void InsetText::InsetUnlock(BufferView * bv)
     locked = false;
     TEXT(bv)->selection = 0;
     UpdateLocal(bv, CLEAR_FRAME, false);
-    bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->GetLayout()+1);
+    if (owner())
+           bv->owner()->getToolbar()->combox->
+                   select(owner()->getLyXText(bv)->cursor.par()->GetLayout()+1);
+    else
+           bv->owner()->getToolbar()->combox->select(bv->text->cursor.par()->
+                                                     GetLayout()+1);
 }
 
 
@@ -482,6 +495,7 @@ bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
         the_locking_inset = 0;
         if (lr)
             moveRight(bv, false);
+       old_par = 0; // force layout setting
        UpdateLocal(bv, CURSOR_PAR, false);
         return true;
     }
@@ -511,10 +525,6 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
 
 void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
 {
-    if (TEXT(bv)->selection) {
-       TEXT(bv)->selection = 0;
-       UpdateLocal(bv, FULL, false);
-    }
     no_selection = false;
 
     int tmp_x = x - drawTextXOffset;
@@ -557,9 +567,14 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
            return;
        }
     }
-    if (!inset)
+    if (!inset) {
        TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
                                           y+TEXT(bv)->first+insetAscent);
+       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
+       UpdateLocal(bv, CURSOR, false);
+       bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
+       old_par = cpar(bv);
+    }
 }
 
 
@@ -594,14 +609,14 @@ void InsetText::InsetMotionNotify(BufferView * bv, int x, int y, int state)
                                             y - inset_y,state);
         return;
     }
-#warning REDO this (Jug)
     if (!no_selection) {
-//     LyXCursor old = selection_end_cursor;
        HideInsetCursor(bv);
-//     setPos(bv->painter(), x, y);
-//     selection_end_cursor = cursor;
-//     if (old != selection_end_cursor)
-//         UpdateLocal(bv, false, false);
+       TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
+                                          y+TEXT(bv)->first+insetAscent);
+       TEXT(bv)->SetSelection();
+       if (TEXT(bv)->toggle_cursor.par()!=TEXT(bv)->toggle_end_cursor.par() ||
+           TEXT(bv)->toggle_cursor.pos()!=TEXT(bv)->toggle_end_cursor.pos())
+           UpdateLocal(bv, SELECTION, false);
        ShowInsetCursor(bv);
     }
     no_selection = false;
@@ -693,10 +708,8 @@ InsetText::LocalDispatch(BufferView * bv,
        UpdateLocal(bv, SELECTION, false);
        break;
     case LFUN_RIGHT:
-       bv->text->FinishUndo();
        result = moveRight(bv);
-       TEXT(bv)->selection = 0;
-       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
+       bv->text->FinishUndo();
        UpdateLocal(bv, CURSOR, false);
        break;
     case LFUN_LEFTSEL:
@@ -708,8 +721,6 @@ InsetText::LocalDispatch(BufferView * bv,
     case LFUN_LEFT:
        bv->text->FinishUndo();
        result= moveLeft(bv);
-       TEXT(bv)->selection = 0;
-       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        UpdateLocal(bv, CURSOR, false);
        break;
     case LFUN_DOWNSEL:
@@ -721,8 +732,6 @@ InsetText::LocalDispatch(BufferView * bv,
     case LFUN_DOWN:
        bv->text->FinishUndo();
        result = moveDown(bv);
-       TEXT(bv)->selection = 0;
-       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        UpdateLocal(bv, CURSOR, false);
        break;
     case LFUN_UPSEL:
@@ -734,21 +743,15 @@ InsetText::LocalDispatch(BufferView * bv,
     case LFUN_UP:
        bv->text->FinishUndo();
        result = moveUp(bv);
-       TEXT(bv)->selection = 0;
-       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        UpdateLocal(bv, CURSOR, false);
        break;
     case LFUN_HOME:
        bv->text->FinishUndo();
        TEXT(bv)->CursorHome(bv);
-       TEXT(bv)->selection = 0;
-       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        UpdateLocal(bv, CURSOR, false);
        break;
     case LFUN_END:
        TEXT(bv)->CursorEnd(bv);
-       TEXT(bv)->selection = 0;
-       TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        UpdateLocal(bv, CURSOR, false);
        break;
     case LFUN_BACKSPACE:
index 4d531757ab171d70e395776c799b2dd5dfc4e2ea..d5c219081686cd3f8b7a03689434186314bd2480 100644 (file)
@@ -210,6 +210,11 @@ public:
        int x() const { return top_x; }
        ///
        int y() const { return top_baseline; }
+       ///
+       /// because we could have fake text insets and have to call this
+       /// inside them without cast!!!
+       virtual LyXText * getLyXText(BufferView *) const;
+       virtual void deleteLyXText(BufferView *) {}
 
 protected:
        ///
@@ -336,11 +341,6 @@ public:
        virtual bool isCursorVisible() const { return cursor_visible; }
        ///
        virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const;
-       ///
-       /// because we could have fake text insets and have to call this
-       /// inside them without cast!!!
-       virtual LyXText * getLyXText(BufferView *) const { return 0; }
-       virtual void deleteLyXText(BufferView *) {}
 
 protected:
        ///
index ef50f28f97c70db2e63381fc1b13ded55657c67a..16de9b3dfc2a1808d25342a67519a00f88cea7ad 100644 (file)
@@ -69,7 +69,8 @@ public:
        /// returns 1 if first has changed, otherwise 0
        bool FitManualCursor(LyXText *, long, long, int, int);
        ///
-       void ToggleSelection(LyXText *, bool = true);
+       void ToggleSelection(LyXText *, int y_offset = 0, int x_offset = 0,
+                            bool = true);
        ///
        void ToggleToggle(LyXText *, int y_offset = 0, int x_offset = 0);
        
index 621e0b4cfe48b70b2592655ab0d512020e891bcc..f4ffa0c391256324cd93dcc4555766d4e56142eb 100644 (file)
@@ -425,7 +425,8 @@ void LyXScreen::Update(LyXText * text, int y_offset, int x_offset)
 }
 
 
-void LyXScreen::ToggleSelection(LyXText * text, bool kill_selection)
+void LyXScreen::ToggleSelection(LyXText * text,  int y_offset, int x_offset,
+                               bool kill_selection)
 {
        // only if there is a selection
        if (!text->selection) return;
@@ -440,7 +441,8 @@ void LyXScreen::ToggleSelection(LyXText * text, bool kill_selection)
 
        if (kill_selection)
                text->selection = 0;
-       DrawFromTo(text, top - text->first, bottom - text->first);
+       DrawFromTo(text, top - text->first, bottom - text->first,
+                  y_offset, x_offset);
        expose(0, top - text->first,
               owner.workWidth(),
               bottom - text->first - (top - text->first));
@@ -463,7 +465,7 @@ void LyXScreen::ToggleToggle(LyXText * text, int y_offset, int x_offset)
        
        bottom = min(max(ulong(bottom), text->first), text->first + owner.height());
        top = min(max(ulong(top), text->first), text->first + owner.height());
-       
+
        DrawFromTo(text, top - text->first, bottom - text->first, y_offset,
                   x_offset);
        expose(0, top - text->first, owner.workWidth(),
index 862579febac8443a53cc6becd296b11cd775a741..ae8594686eaeccd9891a919d1f16b6d5944da1ac 100644 (file)
@@ -3816,6 +3816,11 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        }
        
        if (selection) {
+               int w;
+               if (inset_owner)
+                       w = inset_owner->width(bview, font);
+               else
+                       w = ww;
                /* selection code */
                if (bidi_same_direction) {
                        if (sel_start_cursor.row() == row_ptr &&
@@ -3841,14 +3846,14 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                else
                                        pain.fillRectangle(x_offset + sel_start_cursor.x(),
                                                           y_offset,
-                                                          ww - sel_start_cursor.x(),
+                                                          w - sel_start_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                        } else if (sel_end_cursor.row() == row_ptr) {
                                if (is_rtl)
                                        pain.fillRectangle(x_offset + sel_end_cursor.x(),
                                                           y_offset,
-                                                          ww - sel_end_cursor.x(),
+                                                          w - sel_end_cursor.x(),
                                                           row_ptr->height(),
                                                           LColor::selection);
                                else
@@ -3858,7 +3863,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                                                           LColor::selection);
                        } else if (y > long(sel_start_cursor.y())
                                   && y < long(sel_end_cursor.y())) {
-                               pain.fillRectangle(x_offset, y_offset, ww,
+                               pain.fillRectangle(x_offset, y_offset, w,
                                                   row_ptr->height(),
                                                   LColor::selection);
                        }
@@ -3866,7 +3871,7 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
                            sel_end_cursor.row() != row_ptr &&
                            y > long(sel_start_cursor.y())
                            && y < long(sel_end_cursor.y())) {
-                       pain.fillRectangle(x_offset, y_offset, ww,
+                       pain.fillRectangle(x_offset, y_offset, w,
                                           row_ptr->height(),
                                           LColor::selection);
                } else if (sel_start_cursor.row() == row_ptr ||
index 5eabab4c0f102cdac9e362ffdfb5310a29908711..0503f5f2b3d1920cae2f958f4121346e2a1b52e3 100644 (file)
@@ -132,6 +132,7 @@ void LyXText::init(BufferView * bview)
                par = par->Next();
        }
        SetCursorIntern(bview, firstrow->par(), 0);
+       sel_cursor = cursor;
 #if 0
        // Dump all rowinformation:
        Row * tmprow = firstrow;