]> git.lyx.org Git - features.git/commitdiff
Small changes and fixes for Insets (still work in progress)
authorJürgen Vigna <jug@sad.it>
Fri, 25 Feb 2000 16:05:26 +0000 (16:05 +0000)
committerJürgen Vigna <jug@sad.it>
Fri, 25 Feb 2000 16:05:26 +0000 (16:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@573 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/inset.C
src/insets/insettext.C
src/insets/insettext.h
src/insets/lyxinset.h
src/lyx_cb.C
src/text.C

index 12a904a78f78d3d1a57ce558c780d8c8aa9c8c74..5fe53f1e54882a2d8bd67011d808abccac82a7e4 100644 (file)
@@ -127,7 +127,7 @@ void UpdatableInset::draw(Painter &, LyXFont const &,
 }
 
 
-void UpdatableInset::SetFont(LyXFont const &, bool )
+void UpdatableInset::SetFont(BufferView *, LyXFont const &, bool )
 {
 }
 
index b6764c2ea273b1cf0cee8aee3acf992e0117697a..11981d55f39f2cd4d94efee5694ee3df2542a2e8 100644 (file)
@@ -377,24 +377,36 @@ void InsetText::Read(LyXLex & lex)
 }
 
 
-int InsetText::ascent(Painter &, LyXFont const & font) const
+int InsetText::ascent(Painter &pain, LyXFont const & font) const
 {
+    if (init_inset) {
+       computeTextRows(pain);
+       init_inset = false;
+    }
     if (maxAscent)
        return maxAscent;
     return font.maxAscent();
 }
 
 
-int InsetText::descent(Painter &, LyXFont const & font) const
+int InsetText::descent(Painter &pain, LyXFont const & font) const
 {
+    if (init_inset) {
+       computeTextRows(pain);
+       init_inset = false;
+    }
     if (maxDescent)
        return maxDescent;
     return font.maxDescent();
 }
 
 
-int InsetText::width(Painter &, LyXFont const &) const
+int InsetText::width(Painter &pain, LyXFont const &) const
 {
+    if (init_inset) {
+       computeTextRows(pain);
+       init_inset = false;
+    }
     return insetWidth;
 }
 
@@ -416,6 +428,10 @@ int InsetText::getMaxWidth(UpdatableInset * inset) const
 void InsetText::draw(Painter & pain, LyXFont const & f,
                     int baseline, float & x) const
 {
+//    if (init_inset) {
+       computeTextRows(pain);
+//     init_inset = false;
+//    }
     UpdatableInset::draw(pain, f, baseline, x);
     
     bool do_reset_pos = (x != top_x) || (baseline != top_baseline);
@@ -685,7 +701,7 @@ UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
       case -1:
           par->InsertChar(actpos,arg[0]);
          par->SetFont(actpos,real_current_font);
-         computeTextRows(bv);
+         computeTextRows(bv->getPainter());
          bv->updateInset(this, true);
           ++actpos;
          selection_start = selection_end = actpos;
@@ -760,7 +776,7 @@ UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
       case LFUN_DELETE:
           if (Delete()) { // we need update
              selection_start = selection_end = actpos;
-             computeTextRows(bv);
+             computeTextRows(bv->getPainter());
              bv->updateInset(this, true);
           } else if (hasSelection()) {
              selection_start = selection_end = actpos;
@@ -769,8 +785,8 @@ UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
           break;
       case LFUN_HOME:
           for(; actpos > rows[actrow].pos; --actpos)
-              cx -= SingleWidth(bv, par, actpos);
-         cx -= SingleWidth(bv, par, actpos);
+              cx -= SingleWidth(bv->getPainter(), par, actpos);
+         cx -= SingleWidth(bv->getPainter(), par, actpos);
          if (hasSelection()) {
              selection_start = selection_end = actpos;
              bv->updateInset(this, false);
@@ -780,7 +796,7 @@ UpdatableInset::RESULT InsetText::LocalDispatch(BufferView * bv,
           break;
       case LFUN_END:
           for(; actpos < rows[actrow + 1].pos; ++actpos)
-              cx += SingleWidth(bv, par, actpos);
+              cx += SingleWidth(bv->getPainter(), par, actpos);
          if (hasSelection()) {
              selection_start = selection_end = actpos;
              bv->updateInset(this, false);
@@ -836,18 +852,17 @@ void InsetText::Validate(LaTeXFeatures & features) const
 
 
 // Returns the width of a character at a certain spot
-int InsetText::SingleWidth(BufferView * bv, LyXParagraph * par, int pos)
+int InsetText::SingleWidth(Painter & pain, LyXParagraph * par, int pos) const
 {
     LyXFont font = GetFont(par, pos);
     char c = par->GetChar(pos);
 
-    // The most common case is handled first (Asger)
     if (IsPrintable(c)) {
         return font.width(c);
     } else if (c == LyXParagraph::META_INSET) {
         Inset const * tmpinset=par->GetInset(pos);
         if (tmpinset)
-            return tmpinset->width(bv->getPainter(), font);
+            return tmpinset->width(pain, font);
         else
             return 0;
     } else if (IsSeparatorChar(c))
@@ -859,19 +874,18 @@ int InsetText::SingleWidth(BufferView * bv, LyXParagraph * par, int pos)
 
 
 // Returns the width of a character at a certain spot
-void InsetText::SingleHeight(BufferView * bv, LyXParagraph * par,int pos,
-                            int & asc, int & desc)
+void InsetText::SingleHeight(Painter & pain, LyXParagraph * par,int pos,
+                            int & asc, int & desc) const
 {
     LyXFont font = GetFont(par, pos);
     char c = par->GetChar(pos);
 
     asc = desc = 0;
-    // The most common case is handled first (Asger)
     if (c == LyXParagraph::META_INSET) {
         Inset const * tmpinset=par->GetInset(pos);
         if (tmpinset) {
-           asc = tmpinset->ascent(bv->getPainter(),font);
-           desc = tmpinset->descent(bv->getPainter(),font);
+           asc = tmpinset->ascent(pain, font);
+           desc = tmpinset->descent(pain, font);
         }
     } else {
         asc = font.maxAscent();
@@ -1042,13 +1056,13 @@ void InsetText::setPos(BufferView * bv, int x, int y, bool activate_inset)
     x += top_x;
 
     int swh;
-    int sw = swh = SingleWidth(bv, par,actpos);
+    int 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)) {
        cx += sw;
        ++actpos;
-       sw = swh = SingleWidth(bv, par,actpos);
+       sw = swh = SingleWidth(bv->getPainter(), par,actpos);
        if (par->GetChar(actpos)!=LyXParagraph::META_INSET)
            swh /= 2;
     }
@@ -1138,7 +1152,7 @@ void InsetText::resetPos(BufferView * bv)
     setPos(bv, 0, cy, false);
     cx = top_x;
     while(actpos < old_pos) {
-       cx += SingleWidth(bv, par,actpos);
+       cx += SingleWidth(bv->getPainter(), par,actpos);
        ++actpos;
     }
 }
@@ -1166,7 +1180,7 @@ bool InsetText::InsertInset(BufferView * bv, Inset * inset)
 {
     par->InsertChar(actpos, LyXParagraph::META_INSET);
     par->InsertInset(actpos, inset);
-    computeTextRows(bv);
+    computeTextRows(bv->getPainter());
     bv->updateInset(this, true);
     the_locking_inset = static_cast<UpdatableInset*>(inset);
     inset_x = cx - top_x;
@@ -1220,7 +1234,7 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
        SetCharFont(s_start, newfont);
        ++s_start;
     }
-    computeTextRows(bv);
+    computeTextRows(bv->getPainter());
     bv->updateInset(this, true);
 }
 
@@ -1256,7 +1270,7 @@ void InsetText::SetCharFont(int pos, LyXFont const & f)
 }
 
 
-void InsetText::computeTextRows(BufferView * bv)
+void InsetText::computeTextRows(Painter & pain) const
 {
     int p,
        nwp = 0,
@@ -1280,8 +1294,8 @@ void InsetText::computeTextRows(BufferView * bv)
     rows.push_back(row);
     if (maxWidth < 0) {
        for(p=0; p < par->Last(); ++p) {
-           insetWidth += SingleWidth(bv, par, p);
-           SingleHeight(bv, par, p, asc, desc);
+           insetWidth += SingleWidth(pain, par, p);
+           SingleHeight(pain, par, p, asc, desc);
            if (asc > maxAscent)
                maxAscent = asc;
            if (desc > maxDescent)
@@ -1300,10 +1314,10 @@ void InsetText::computeTextRows(BufferView * bv)
        lastWordWidth=0;
 
     for(p = 0; p < par->Last(); ++p) {
-       cw = SingleWidth(bv, par, p);
+       cw = SingleWidth(pain, par, p);
        width += cw;
        lastWordWidth += cw;
-       SingleHeight(bv, par, p, asc, desc);
+       SingleHeight(pain, par, p, asc, desc);
        if (asc > wordAscent)
            wordAscent = asc;
        if (desc > wordDescent)
@@ -1335,7 +1349,7 @@ void InsetText::computeTextRows(BufferView * bv)
            rows[rows.size() - 1].desc = odesc;
            row.pos = ++p;
            rows.push_back(row);
-           SingleHeight(bv, par, p, asc, desc);
+           SingleHeight(pain, par, p, asc, desc);
            rows[rows.size() - 1].asc = asc;
            rows[rows.size() - 1].desc = desc;
            row.pos = nwp = p + 1;
@@ -1412,6 +1426,7 @@ void InsetText::computeTextRows(BufferView * bv)
     for (unsigned int i=1; i<rows.size()-1; ++i) {
        maxDescent += rows[i].asc + rows[i].desc + interline_space;
     }
+#if 0
     if (the_locking_inset) {
        computeBaselines(top_baseline);
        actpos = inset_pos;
@@ -1419,6 +1434,7 @@ void InsetText::computeTextRows(BufferView * bv)
        inset_x = cx-top_x;
        inset_y = cy;
     }
+#endif
 }
 
 
@@ -1430,13 +1446,3 @@ void InsetText::computeBaselines(int baseline) const
            rows[i].asc + interline_space;
     }
 }
-
-
-void InsetText::init(BufferView * bv)
-{
-//    if (init_inset)
-    {
-       computeTextRows(bv);
-       init_inset = false;
-    }
-}
index fdc0aba99d2c4ae38ebb1d0f56c5b6dd44a5a28f..88de0c5d10e8fea5acd5069757b06ffdbbd1cb6d 100644 (file)
@@ -103,8 +103,6 @@ public:
     UpdatableInset * GetLockingInset();
     ///
     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
-    ///
-    void init(BufferView *);
 
     LyXParagraph * par;
 
@@ -114,28 +112,28 @@ protected:
     ///
     void resetPos(BufferView *);
     ///
-    void drawSelection(Painter & pain, int pos, int baseline, float x);
+    void drawSelection(Painter &, int pos, int baseline, float x);
     ///
-    void SingleHeight(BufferView *, LyXParagraph * par,int pos,
-                     int & asc, int & desc);
+    void SingleHeight(Painter &, LyXParagraph * par,int pos,
+                     int & asc, int & desc) const;
     ///
-    int SingleWidth(BufferView * bv, LyXParagraph * par, int pos);
+    int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
     ///
     LyXFont GetFont(LyXParagraph * par, int pos) const;
     ///
     Buffer * buffer;
     ///
     LyXFont current_font;
-       ///
-        LyXFont real_current_font;
-       ///
-       int maxWidth;
-       ///
-        int maxAscent;
-       ///
-       int maxDescent;
-       ///
-       int insetWidth;
+    ///
+    LyXFont real_current_font;
+    ///
+    int maxWidth;
+    ///
+    mutable int maxAscent;
+    ///
+    mutable int maxDescent;
+    ///
+    mutable int insetWidth;
 
 private:
     ///
@@ -145,7 +143,7 @@ private:
     void drawRowText(Painter &, int startpos, int endpos, int baseline,
                      float x) const;
     ///
-    void computeTextRows(BufferView *);
+    void computeTextRows(Painter &) const;
     ///
     void computeBaselines(int) const;
     ///
@@ -195,7 +193,7 @@ private:
     ///
     bool no_selection;
     ///
-    bool init_inset;
+    mutable bool init_inset;
     ///
     UpdatableInset * the_locking_inset;
     ///
index 2a007b8d027d78bb62093224dd37c699db920410..5d09aecb8db76eb43b1d717c1d90491feb33f0c6 100644 (file)
@@ -226,9 +226,9 @@ public:
        virtual void draw(Painter &, LyXFont const &,
                          int baseline, float & x) const;
        ///
-       virtual void SetFont(LyXFont const &, bool toggleall = false);
+       virtual void SetFont(BufferView *, LyXFont const &, bool toggleall=false);
        ///
-       virtual bool InsertInset(Inset *) { return false; }
+       virtual bool InsertInset(BufferView *, Inset *) { return false; }
        ///
        virtual UpdatableInset * GetLockingInset() { return this; }
        ///
index 2477c0d0d59a80e0b435cd2d8d5f2eb40e725b50..d1250cc40c7292e7a44bdf593722fb8d0762ab9c 100644 (file)
@@ -2135,7 +2135,7 @@ void ToggleAndShow(BufferView * bv, LyXFont const & font)
                bv->hideCursor();
                bv->update(-2);
                if (bv->the_locking_inset)
-                       bv->the_locking_inset->SetFont(font, toggleall);
+                       bv->the_locking_inset->SetFont(bv, font, toggleall);
                else
                        bv->text->ToggleFree(font, toggleall);
                bv->update(1);
index 717b05c68156b5d7c2440cd0e7326d2d6459a44d..bf1ea534d731506debb20c9066441e37b4a8b376 100644 (file)
@@ -371,7 +371,6 @@ void LyXText::draw(Row const * row,
        } else if (c == LyXParagraph::META_INSET) {
                Inset * tmpinset = row->par->GetInset(pos);
                if (tmpinset) {
-                       tmpinset->init(owner_);
                        tmpinset->draw(owner_->painter(), font,
                                       offset + row->baseline, x);
                }