]> git.lyx.org Git - features.git/commitdiff
Various fixes look at ChangeLog
authorJürgen Vigna <jug@sad.it>
Thu, 9 Mar 2000 16:04:28 +0000 (16:04 +0000)
committerJürgen Vigna <jug@sad.it>
Thu, 9 Mar 2000 16:04:28 +0000 (16:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@595 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/BufferView.C
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettext.C
src/support/lyxalgo.h

index e94c6eaad0d2018578c948a0e046938bd679c724..62d092d026b4ee8dfa611ec451d496899d63144d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2000-03-09  Juergen Vigna  <jug@sad.it>
+
+       * src/insets/insettext.C (setPos): fixed various cursor positioning
+       problems (via mouse and cursor-keys)
+       (LocalDispatch): added posibility to add a Ctrl-Enter inside a text
+       inset (still a small display problem but it works ;)
+
+       * src/insets/insetcollapsable.C (draw): added button_top_y and
+       button_bottom_y to have correct values for clicking on the inset.
+
+       * src/support/lyxalgo.h: commented out 'using std::less'
+
+2000-03-08  Juergen Vigna  <jug@sad.it>
+
+       * src/insets/insetcollapsable.C (InsetButtonRelease): Now a
+       Button-Release event closes as it is alos the Release-Event
+       which opens it.
+
+       * src/lyxfunc.C (Dispatch): forgot a break in the LFUN_INSET_ERT
+
 2000-03-07  Kayvan A. Sylvan  <kayvan@camel.internal.sylvan.com>
 
        * lib/layouts/literate-scrap.inc: Fixed initial comment. Now we
        (search_kw): use lower_bound instead of manually implemented
        binary search.
 
-2000-03-08  Juergen Vigna  <jug@sad.it>
-
-       * src/lyxfunc.C (Dispatch): forgot a break in the LFUN_INSET_ERT
-
 2000-03-08  Jean-Marc Lasgouttes  <Jean-Marc.Lasgouttes@inria.fr>
 
        * src/insets/insetcollapsable.h: fix Clone() declaration.
index 1fd4c3cd4ab0770e4804ac507a9ac7f16a6a0984..f65392994c8338a0810eae5ad09a149b986e54d0 100644 (file)
@@ -995,10 +995,10 @@ Inset * BufferView::checkInsetHit(int & x, int & y)
                }
        }
 
-       if (cursor.pos - 1 >= 0
-                  && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET
-                  && cursor.par->GetInset(cursor.pos - 1)
-                  && cursor.par->GetInset(cursor.pos - 1)->Editable()) {
+       if ((cursor.pos - 1 >= 0) &&
+           (cursor.par->GetChar(cursor.pos-1) == LyXParagraph::META_INSET) &&
+           (cursor.par->GetInset(cursor.pos - 1)) &&
+           (cursor.par->GetInset(cursor.pos - 1)->Editable())) {
                text->CursorLeft();
                Inset * tmpinset = cursor.par->GetInset(cursor.pos);
                LyXFont font = text->GetFont(cursor.par, cursor.pos);
index 1a218c4ba2cc2304f8480410b54f8c576b87863d..f64a6fc636e1d9e3dcacd70e7c0638ad9c74b800 100644 (file)
@@ -27,7 +27,8 @@ InsetCollapsable::InsetCollapsable(Buffer * bf): InsetText(bf)
     autocolapse = true;
     autoBreakRows = true;
     framecolor = LColor::footnoteframe;
-    widthOffset = 7;
+    widthOffset = 10;
+    button_x = button_top_y = button_bottom_y = top_x = -1;
 }
 
 
@@ -87,7 +88,7 @@ int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
     if (collapsed) 
        return width_collapsed(pain, font);
 
-    return getMaxWidth(pain);
+    return getMaxWidth(pain) - widthOffset + 2;
 }
 
 
@@ -111,7 +112,9 @@ void InsetCollapsable::draw(Painter & pain, LyXFont const & f,
     top_x = int(x);
     top_baseline = baseline;
     draw_collapsed(pain, f, baseline, x);
-    button_x = int(x - top_x);
+    button_x = int(x);
+    button_top_y = -ascent_collapsed(pain, f);
+    button_bottom_y = descent_collapsed(pain, f);
     
     maxWidth = getMaxWidth(pain) - button_x;
     x += 2;
@@ -171,12 +174,7 @@ void InsetCollapsable::UpdateLocal(BufferView *bv, bool flag)
 
 void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
 {
-    if ((x < button_x)  &&
-       (y < (labelfont.maxDescent()+labelfont.maxAscent()))) {
-       collapsed = true;
-       UpdateLocal(bv, false);
-        bv->unlockInset(this);
-    } else if (x >= button_x) {
+    if ((x >= button_x) && (y >= button_top_y)) {
        InsetText::InsetButtonPress(bv, x-top_x, y, button);
     }
 }
@@ -184,13 +182,19 @@ void InsetCollapsable::InsetButtonPress(BufferView *bv,int x,int y,int button)
 
 void InsetCollapsable::InsetButtonRelease(BufferView *bv, int x, int y, int button)
 {
-    if (x >= button_x)
+    if ((x < button_x)  && (y >= button_top_y) && (y <= button_bottom_y)) {
+       collapsed = true;
+       UpdateLocal(bv, false);
+        bv->unlockInset(this);
+    } else if ((x >= button_x) && (y >= button_top_y)) {
        InsetText::InsetButtonRelease(bv, x-top_x, y, button);
+    }
 }
 
 
 void InsetCollapsable::InsetMotionNotify(BufferView *bv, int x, int y, int button)
 {
-    if (x >= button_x)
+    if ((x >= button_x) && (y >= button_top_y)) {
        InsetText::InsetMotionNotify(bv, x-top_x, y, button);
+    }
 }
index ec92ccb98873a59c43081a4e574ae62514904e56..da93bc8266140672d148ef1f2d0668c74f25e25a 100644 (file)
@@ -95,7 +95,7 @@ private:
     ///
     mutable int
         top_baseline, top_x,
-       button_x;
+       button_x, button_top_y, button_bottom_y;
 };
 
 #endif
index f7703842b4ee722d45bf859eb9ef0a62a725ba11..1176130eff5816a9c3dbb584ee511fb420e35be0 100644 (file)
@@ -271,6 +271,35 @@ void InsetText::drawRowText(Painter & pain, int startpos, int endpos,
        LyXFont font = GetFont(par,p);
        if (IsFloatChar(ch)) {
            // skip for now
+       } else if (par->IsNewline(p)) {
+               // Draw end-of-line marker
+               int wid = font.width('n');
+               int asc = font.maxAscent();
+               int y = baseline;
+               int xp[3], yp[3];
+               
+               xp[0] = int(x + wid * 0.375);
+               yp[0] = int(y - 0.875 * asc * 0.75);
+               
+               xp[1] = int(x);
+               yp[1] = int(y - 0.500 * asc * 0.75);
+               
+               xp[2] = int(x + wid * 0.375);
+               yp[2] = int(y - 0.125 * asc * 0.75);
+               
+               pain.lines(xp, yp, 3, LColor::eolmarker);
+               
+               xp[0] = int(x);
+               yp[0] = int(y - 0.500 * asc * 0.75);
+               
+               xp[1] = int(x + wid);
+               yp[1] = int(y - 0.500 * asc * 0.75);
+               
+               xp[2] = int(x + wid);
+               yp[2] = int(y - asc * 0.75);
+                       
+               pain.lines(xp, yp, 3, LColor::eolmarker);
+               x += wid;
        } else if (ch == LyXParagraph::META_INSET) {
            Inset * tmpinset = par->GetInset(p);
            if (tmpinset) 
@@ -457,36 +486,36 @@ InsetText::LocalDispatch(BufferView * bv,
     }
     HideInsetCursor(bv);
     switch (action) {
-        // Normal chars
-      case -1:
-          par->InsertChar(actpos,arg[0]);
-         par->SetFont(actpos,real_current_font);
-         UpdateLocal(bv, true);
-          ++actpos;
-         selection_start = selection_end = actpos;
-          resetPos(bv);
-          break;
+       // Normal chars
+    case -1:
+       par->InsertChar(actpos,arg[0]);
+       par->SetFont(actpos,real_current_font);
+       UpdateLocal(bv, true);
+       ++actpos;
+       selection_start = selection_end = actpos;
+       resetPos(bv);
+       break;
         // --- Cursor Movements ---------------------------------------------
-      case LFUN_RIGHTSEL:
-          moveRight(bv, false);
-         selection_end = actpos;
-         UpdateLocal(bv, false);
-         break;
-      case LFUN_RIGHT:
-          result= DISPATCH_RESULT(moveRight(bv));
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          break;
-      case LFUN_LEFTSEL:
-          moveLeft(bv, false);
-         selection_end = actpos;
-         UpdateLocal(bv, false);
-         break;
-      case LFUN_LEFT:
+    case LFUN_RIGHTSEL:
+       moveRight(bv, false);
+       selection_end = actpos;
+       UpdateLocal(bv, false);
+       break;
+    case LFUN_RIGHT:
+       result= DISPATCH_RESULT(moveRight(bv));
+       if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       } else {
+           selection_start = selection_end = actpos;
+       }
+       break;
+    case LFUN_LEFTSEL:
+       moveLeft(bv, false);
+       selection_end = actpos;
+       UpdateLocal(bv, false);
+       break;
+    case LFUN_LEFT:
           result= DISPATCH_RESULT(moveLeft(bv));
          if (hasSelection()) {
              selection_start = selection_end = actpos;
@@ -495,85 +524,98 @@ InsetText::LocalDispatch(BufferView * bv,
              selection_start = selection_end = actpos;
          }
           break;
-      case LFUN_DOWNSEL:
-          moveDown(bv, false);
-         selection_end = actpos;
-         UpdateLocal(bv, false);
-         break;
-      case LFUN_DOWN:
-          result= DISPATCH_RESULT(moveDown(bv));
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          break;
-      case LFUN_UPSEL:
-          moveUp(bv, false);
-         selection_end = actpos;
-         UpdateLocal(bv, false);
-         break;
-      case LFUN_UP:
-          result= DISPATCH_RESULT(moveUp(bv));
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          break;
-      case LFUN_BACKSPACE:
-          if (!actpos || par->IsNewline(actpos-1)) {
-             if (hasSelection()) {
-                 selection_start = selection_end = actpos;
-                 UpdateLocal(bv, false);
-             }
-              break;
-         }
-          moveLeft(bv);
-      case LFUN_DELETE:
-          if (Delete()) { // we need update
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, true);
-          } else if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         }
-          break;
-      case LFUN_HOME:
-          for(; actpos > rows[actrow].pos; --actpos)
-              cx -= SingleWidth(bv->getPainter(), par, actpos);
-         cx -= SingleWidth(bv->getPainter(), par, actpos);
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          break;
-      case LFUN_END:
-          for(; actpos < rows[actrow + 1].pos; ++actpos)
-              cx += SingleWidth(bv->getPainter(), par, actpos);
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          break;
-      case LFUN_MATH_MODE:   // Open or create a math inset
-          InsertInset(bv, new InsetFormula);
-         if (hasSelection()) {
-             selection_start = selection_end = actpos;
-             UpdateLocal(bv, false);
-         } else {
-             selection_start = selection_end = actpos;
-         }
-          return DISPATCHED;
-      default:
-          result = UNDISPATCHED;
-          break;
+    case LFUN_DOWNSEL:
+       moveDown(bv, false);
+       selection_end = actpos;
+       UpdateLocal(bv, false);
+       break;
+    case LFUN_DOWN:
+       result= DISPATCH_RESULT(moveDown(bv));
+       if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       } else {
+           selection_start = selection_end = actpos;
+       }
+       break;
+    case LFUN_UPSEL:
+       moveUp(bv, false);
+       selection_end = actpos;
+       UpdateLocal(bv, false);
+       break;
+    case LFUN_UP:
+       result= DISPATCH_RESULT(moveUp(bv));
+       if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       } else {
+           selection_start = selection_end = actpos;
+       }
+       break;
+    case LFUN_BACKSPACE:
+       if (!actpos || par->IsNewline(actpos-1)) {
+           if (hasSelection()) {
+               selection_start = selection_end = actpos;
+               UpdateLocal(bv, false);
+           }
+           break;
+       }
+       moveLeft(bv);
+    case LFUN_DELETE:
+       if (Delete()) { // we need update
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, true);
+       } else if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       }
+       break;
+    case LFUN_HOME:
+       for(; actpos > rows[actrow].pos; --actpos)
+           cx -= SingleWidth(bv->getPainter(), par, actpos);
+       cx -= SingleWidth(bv->getPainter(), par, actpos);
+       if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       } else {
+           selection_start = selection_end = actpos;
+       }
+       break;
+    case LFUN_END:
+    {
+       int checkpos = (int)rows[actrow + 1].pos;
+       if ((actrow + 2) < (int)rows.size())
+           --checkpos;
+       for(; actpos < checkpos; ++actpos)
+           cx += SingleWidth(bv->getPainter(), par, actpos);
+       if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       } else {
+           selection_start = selection_end = actpos;
+       }
+    }
+    break;
+    case LFUN_MATH_MODE:   // Open or create a math inset
+       InsertInset(bv, new InsetFormula);
+       if (hasSelection()) {
+           selection_start = selection_end = actpos;
+           UpdateLocal(bv, false);
+       } else {
+           selection_start = selection_end = actpos;
+       }
+       return DISPATCHED;
+    case LFUN_BREAKLINE:
+       par->InsertChar(actpos,LyXParagraph::META_NEWLINE);
+       par->SetFont(actpos,real_current_font);
+       UpdateLocal(bv, true);
+       ++actpos;
+       selection_start = selection_end = actpos;
+       resetPos(bv);
+       break;
+    default:
+       result = UNDISPATCHED;
+       break;
     }
     if (result != FINISHED) {
        if (!the_locking_inset)
@@ -808,8 +850,8 @@ void InsetText::HideInsetCursor(BufferView * bv)
 
 void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
 {
-       int ox = x;
-       int oy = y;
+    int ox = x;
+    int oy = y;
        
     // search right X-pos x==0 -> top_x
     actpos = actrow = 0;
@@ -826,10 +868,16 @@ void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
     x += top_x;
 
     int swh;
-    int sw = swh = SingleWidth(bv->getPainter(), par,actpos);
+    int sw;
+    int checkpos;
+
+    sw = swh = SingleWidth(bv->getPainter(), par,actpos);
     if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
        swh /= 2;
-    while ((actpos < (rows[actrow + 1].pos - 1)) && ((cx + swh) < x)) {
+    checkpos = rows[actrow + 1].pos;
+    if ((actrow+2) < (int)rows.size())
+       --checkpos;
+    while ((actpos < checkpos) && ((cx + swh) < x)) {
        cx += sw;
        ++actpos;
        sw = swh = SingleWidth(bv->getPainter(), par,actpos);
@@ -914,7 +962,8 @@ void InsetText::resetPos(BufferView * bv)
 
     cy = top_baseline;
     actrow = 0;
-    for(int i = 0; rows[i].pos <= actpos; ++i) {
+    for(unsigned int i = 0; (i < (rows.size()-1)) && (rows[i].pos <= actpos);
+       ++i) {
        cy = rows[i].baseline;
        actrow = i;
     }
@@ -1083,7 +1132,7 @@ void InsetText::computeTextRows(Painter & pain, float x) const
 
     int cw, lastWordWidth = 0;
 
-    maxWidth = UpdatableInset::getMaxWidth(pain) - widthOffset;
+    maxWidth = getMaxWidth(pain) - widthOffset;
     for(p = 0; p < par->Last(); ++p) {
        cw = SingleWidth(pain, par, p);
        width += cw;
@@ -1091,6 +1140,17 @@ void InsetText::computeTextRows(Painter & pain, float x) const
        SingleHeight(pain, par, p, asc, desc);
        wordAscent = max(wordAscent, asc);
        wordDescent = max(wordDescent, desc);
+       if (par->IsNewline(p)) {
+           rows.back().asc = wordAscent;
+           rows.back().desc = wordDescent;
+           row.pos = p+1;
+           rows.push_back(row);
+           SingleHeight(pain, par, p, oasc, odesc);
+           width = lastWordWidth = 0;
+           is_first_word_in_row = true;
+           wordAscent = wordDescent = 0;
+           continue;
+       }
        Inset const * inset = 0;
        if (((p + 1) < par->Last()) &&
            (par->GetChar(p + 1)==LyXParagraph::META_INSET))
@@ -1123,7 +1183,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const
            oasc = odesc = width = lastWordWidth = 0;
            is_first_word_in_row = true;
            wordAscent = wordDescent = 0;
-//         x = 0.0;
            continue;
        } else if (par->IsSeparator(p)) {
            if (width >= maxWidth - x) {
@@ -1145,7 +1204,6 @@ void InsetText::computeTextRows(Painter & pain, float x) const
                }
                wordAscent = wordDescent = lastWordWidth = 0;
                nwp = p + 1;
-//             x = 0.0;
                continue;
            }
            owidth = width;
index 27cae60bb5ef76dae0816989969857f5f2d27aaa..8e243bd506c0c57cf6db838dac64b7759abd4bfe 100644 (file)
@@ -5,7 +5,7 @@
 
 #include <algorithm>
 
-using std::less;
+// using std::less;
 
 // Both these functions should ideally be placed into namespace lyx.
 // Also the using std::less should not be used.