]> git.lyx.org Git - features.git/commitdiff
Lots of changes for update of TextInsets, still some problems!
authorJürgen Vigna <jug@sad.it>
Tue, 4 Jul 2000 11:30:07 +0000 (11:30 +0000)
committerJürgen Vigna <jug@sad.it>
Tue, 4 Jul 2000 11:30:07 +0000 (11:30 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@854 a592a061-630c-0410-9148-cb99ea01b6c8

26 files changed:
ChangeLog
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetert.C
src/insets/insetfloat.C
src/insets/insetfloat.h
src/insets/insetfoot.C
src/insets/insetfoot.h
src/insets/insetlist.C
src/insets/insetlist.h
src/insets/insetmarginal.C
src/insets/insetmarginal.h
src/insets/insetminipage.C
src/insets/insetminipage.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/lyxinset.h
src/lyxtext.h
src/mathed/formula.C
src/paragraph.C
src/tabular.C
src/text.C

index b62ff1d580c6266e0105bc104aa417d5fe76cec5..011c794361b75ff3e028ae7182b8271e9d4f7a32 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2000-07-04  Juergen Vigna  <jug@sad.it>
+
+       * src/text.C (NextBreakPoint): added support for needFullRow()
+
+       * src/insets/lyxinset.h: added needFullRow()
+
+       * src/insets/insetcollapsable.C: redone now this uses a text-inset
+       and isn't one.
+
+       * src/insets/insettext.C: lots of changes for update!
+
 2000-07-03 Angus Leeming <a.leeming@ic.ac.uk>
 
        * src/LaTeXFeatures.h: add a missing std:: qualifier.
        * src/lyx_main.C (easyParse): accept linuxdoc and docbook as
        formats to export with command line argument -x.
 
+2000-06-29  Juergen Vigna  <jug@sad.it>
+
+       * src/mathed/formula.C (LocalDispatch): changed only-cursor-movements
+       to return DISPATCHED_NOUPDATE so that a it does not redraw the inset!
+
+       * src/text.C (GetVisibleRow): added 'bool cleared' parameter as the
+       region could already been cleared by an inset!
+
 2000-06-28  Lars Gullik Bjønnes  <larsbj@lyx.org>
 
        * src/BufferView_pimpl.h: remove member variables lyx_focus and
index 1d8592f3c3e5ecb2584caa3048092939f073cddd..e244fb46b3605ecf6fb2eab451fe532f30a01f8d 100644 (file)
@@ -117,6 +117,13 @@ void BufferView::updateScrollbar()
 }
 
 
+Inset * BufferView::checkInsetHit(LyXText * text, int & x, int & y,
+                                 unsigned int button)
+{
+       return pimpl_->checkInsetHit(text, x, y, button);
+}
+
+
 void BufferView::redoCurrentBuffer()
 {
        pimpl_->redoCurrentBuffer();
index 2795f8c0cde91a25bdc02bb2f2635670bb720c22..b5783957aa64ad6e5858f0bff1ff68bb3663f3f2 100644 (file)
@@ -66,6 +66,8 @@ public:
        ///
        void updateScrollbar();
        ///
+       Inset * checkInsetHit(LyXText *, int & x, int & y, unsigned int button);
+       /// 
        void redoCurrentBuffer();
        ///
        int resizeCurrentBuffer();
index a9cc18b0999169dbb900c87230862d5356f5a2ed..df4a1244ad3ba16655c3159c67fa618fd2033cd9 100644 (file)
@@ -529,7 +529,7 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
 
        if (buffer_ == 0 || !screen_) return;
 
-       Inset * inset_hit = checkInsetHit(xpos, ypos, button);
+       Inset * inset_hit = checkInsetHit(bv_->text, xpos, ypos, button);
 
        // ok ok, this is a hack.
        if (button == 4 || button == 5) {
@@ -725,7 +725,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
        // If we hit an inset, we have the inset coordinates in these
        // and inset_hit points to the inset.  If we do not hit an
        // inset, inset_hit is 0, and inset_x == x, inset_y == y.
-       Inset * inset_hit = checkInsetHit(x, y, button);
+       Inset * inset_hit = checkInsetHit(bv_->text, x, y, button);
 
        if (bv_->the_locking_inset) {
                // We are in inset locking mode.
@@ -877,19 +877,19 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
  * If hit, the coordinates are changed relative to the inset. 
  * Otherwise coordinates are not changed, and false is returned.
  */
-Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
+Inset * BufferView::Pimpl::checkInsetHit(LyXText * text, int & x, int & y,
                                         unsigned int /* button */)
 {
        if (!screen_)
                return 0;
   
-       unsigned int y_tmp = y + bv_->text->first;
+       unsigned int y_tmp = y + text->first;
   
        LyXCursor cursor;
-       bv_->text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
+       text->SetCursorFromCoordinates(bv_, cursor, x, y_tmp);
 #if 0 // Are you planning to use this Jürgen? (Lgb)
-       bool move_cursor = ((cursor.par != bv_->text->cursor.par) ||
-                           (cursor.pos != bv_->text->cursor.pos()));
+       bool move_cursor = ((cursor.par != text->cursor.par) ||
+                           (cursor.pos != text->cursor.pos()));
 #endif
        if (cursor.pos() < cursor.par()->Last()
            && cursor.par()->GetChar(cursor.pos()) == LyXParagraph::META_INSET
@@ -898,7 +898,7 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
 
                // Check whether the inset really was hit
                Inset * tmpinset = cursor.par()->GetInset(cursor.pos());
-               LyXFont font = bv_->text->GetFont(bv_->buffer(),
+               LyXFont font = text->GetFont(bv_->buffer(),
                                                  cursor.par(), cursor.pos());
                bool is_rtl = font.isVisibleRightToLeft();
                int start_x, end_x;
@@ -917,10 +917,10 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
 #if 0
                        if (move_cursor && (tmpinset != bv_->the_locking_inset))
 #endif
-                               bv_->text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
+                               text->SetCursor(bv_, cursor.par(),cursor.pos(),true);
                        x = x - start_x;
                        // The origin of an inset is on the baseline
-                       y = y_tmp - (bv_->text->cursor.y()); 
+                       y = y_tmp - (text->cursor.y()); 
                        return tmpinset;
                }
        }
@@ -930,7 +930,7 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
            (cursor.par()->GetInset(cursor.pos() - 1)) &&
            (cursor.par()->GetInset(cursor.pos() - 1)->Editable())) {
                Inset * tmpinset = cursor.par()->GetInset(cursor.pos()-1);
-               LyXFont font = bv_->text->GetFont(bv_->buffer(), cursor.par(),
+               LyXFont font = text->GetFont(bv_->buffer(), cursor.par(),
                                                  cursor.pos()-1);
                bool is_rtl = font.isVisibleRightToLeft();
                int start_x, end_x;
@@ -948,10 +948,10 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
 #if 0
                        if (move_cursor && (tmpinset != bv_->the_locking_inset))
 #endif
-                               bv_->text->SetCursor(bv_, cursor.par(),cursor.pos()-1,true);
+                               text->SetCursor(bv_, 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()); 
+                       y = y_tmp - (text->cursor.y()); 
                        return tmpinset;
                }
        }
index 7f9aae0b96dbb979280bd70f1fe023b556d51a7f..6ee7a9c4bfeab40e214bbd879820f8c4efe1abf4 100644 (file)
@@ -50,7 +50,7 @@ struct BufferView::Pimpl : public SigC::Object {
        ///
        void scrollCB(double value);
        ///
-       Inset * checkInsetHit(int & x, int & y, unsigned int button);
+       Inset * checkInsetHit(LyXText *, int & x, int & y, unsigned int button);
        /// 
        int scrollUp(long time);
        ///
index 1889b8a1694c4417886d2f85e36f4dbf4021818e..0daae7037f1b2ba64c3c08b8050bcc2e47139406 100644 (file)
 #include "lyxfont.h"
 #include "BufferView.h"
 #include "Painter.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 #include "support/lstrings.h"
 
+class LyXText;
+
 using std::ostream;
 
 InsetCollapsable::InsetCollapsable()
-       : InsetText()
+       : UpdatableInset()
 {
+    inset = new InsetText;
+    inset->setOwner(this);
     collapsed = true;
     label = "Label";
     autocollapse = true;
-    autoBreakRows = true;
-    framecolor = LColor::footnoteframe;
-    widthOffset = 2 * TEXT_TO_INSET_OFFSET + 2; // 1+1 (frame)
+    inset->SetAutoBreakRows(true);
+    inset->SetDrawFrame(0, InsetText::ALWAYS);
+    inset->SetFrameColor(0, LColor::footnoteframe);
     button_length = button_top_y = button_bottom_y = 0;
     setInsetName("Collapsable");
+    widthCollapsed = oldWidth = 0;
+    need_update = FULL;
 }
 
 
 Inset * InsetCollapsable::Clone() const
 {
     InsetCollapsable * result = new InsetCollapsable();
-    result->init(this);
+    result->inset->init(inset);
+    result->inset->setOwner(result);
 
     result->collapsed = collapsed;
     return result;
@@ -50,11 +58,12 @@ Inset * InsetCollapsable::Clone() const
 
 void InsetCollapsable::Write(Buffer const * buf, ostream & os) const
 {
-    os << "collapsed " << tostr(!display()) << "\n";
-    WriteParagraphData(buf, os);
+    os << "collapsed " << tostr(collapsed) << "\n";
+    inset->WriteParagraphData(buf, os);
 }
 
 
+
 void InsetCollapsable::Read(Buffer const * buf, LyXLex & lex)
 {
     if (lex.IsOK()) {
@@ -65,7 +74,7 @@ void InsetCollapsable::Read(Buffer const * buf, LyXLex & lex)
            collapsed = lex.GetBool();
        }
     }
-    InsetText::Read(buf, lex);
+    inset->Read(buf, lex);
 }
 
 
@@ -101,7 +110,7 @@ int InsetCollapsable::ascent(Painter & pain, LyXFont const & font) const
     if (collapsed) 
        return ascent_collapsed(pain, font);
     else 
-       return InsetText::ascent(pain, font) + TEXT_TO_TOP_OFFSET;
+       return inset->ascent(pain, font) + TEXT_TO_TOP_OFFSET;
 }
 
 
@@ -110,28 +119,26 @@ int InsetCollapsable::descent(Painter & pain, LyXFont const & font) const
     if (collapsed) 
        return descent_collapsed(pain, font);
     else 
-       return InsetText::descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
+       return inset->descent(pain, font) + TEXT_TO_BOTTOM_OFFSET;
 }
 
 
 int InsetCollapsable::width(Painter & pain, LyXFont const & font) const
 {
     if (collapsed) 
-       return width_collapsed(pain, font);
+       return widthCollapsed;
 
-    return InsetText::width(pain, font) + width_collapsed(pain,font) +
-           widthOffset;
+    return inset->width(pain, font) + widthCollapsed;
 }
 
 
-void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const & font,
+void InsetCollapsable::draw_collapsed(Painter & pain, LyXFont const &,
                                      int baseline, float & x) const
 {
     int width = 0;
     pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET,
-                   baseline-ascent(pain, font)+ascent_collapsed(pain, font),
-                   label.c_str(), labelfont, true, width);
-    x += width + (2 * TEXT_TO_INSET_OFFSET);
+                   baseline, label.c_str(), labelfont, true, width);
+    x += width + TEXT_TO_INSET_OFFSET;
 }
 
 
@@ -140,56 +147,56 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f,
 {
     Painter & pain = bv->painter();
 
-    button_length = width_collapsed(pain, labelfont) + 2;
+    button_length = widthCollapsed;
     button_top_y = -ascent_collapsed(pain, f);
     button_bottom_y = descent_collapsed(pain, f);
     if (collapsed) {
        draw_collapsed(pain, f, baseline, x);
+       x += TEXT_TO_INSET_OFFSET;
        return;
     }
 
-    if (!cleared && ((need_update==FULL) || (topx!=int(x)) ||
-                    (topbaseline!=baseline))) {
-       int w =  width(pain, f);
+    if (!cleared && ((need_update == FULL) ||
+                    (top_x!=int(x)) || (top_baseline!=baseline))) {
+       int w =  owner()? width(pain, f) : pain.paperWidth();
        int h = ascent(pain,f) + descent(pain, f);
-       int tx = display()? 0:topx;
+       int tx = (display() && !owner())? 0:int(x);
        int ty = baseline - ascent(pain,f);
        
        if (ty < 0)
            ty = 0;
        if ((ty + h) > pain.paperHeight())
            h = pain.paperHeight();
-       if ((topx + w) > pain.paperWidth())
+       if ((top_x + w) > pain.paperWidth())
            w = pain.paperWidth();
        pain.fillRectangle(tx, ty-1, w, h+2);
        cleared = true;
     }
 
     // not needed if collapsed
-    topx = int(x);
-    topbaseline = baseline;
-
-    int w =  InsetText::width(pain, f) + (2 * TEXT_TO_INSET_OFFSET);
-    int h = ascent(pain,f) + descent(pain, f);
+    top_x = int(x);
+    top_baseline = baseline;
 
     draw_collapsed(pain, f, baseline, x);
-    x -= TEXT_TO_INSET_OFFSET;
-
-    int save_x = static_cast<int>(x);
-    x += TEXT_TO_INSET_OFFSET;
-    InsetText::draw(bv, f, baseline, x, cleared);
-    pain.rectangle(save_x, baseline - ascent(pain, f), w, h, framecolor);
+    inset->draw(bv, f, baseline, x, cleared);
+    need_update = NONE;
 }
 
 
 void InsetCollapsable::Edit(BufferView * bv, int x, int y, unsigned int button)
 {
+    UpdatableInset::Edit(bv, x, y, button);
+
     if (collapsed && autocollapse) {
        collapsed = false;
-       UpdateLocal(bv, FULL, false);
-       InsetText::Edit(bv, 0, 0, button);
+       if (!bv->lockInset(this))
+           return;
+       bv->updateInset(this, false);
+       inset->Edit(bv, 0, 0, button);
     } else if (!collapsed) {
-       InsetText::Edit(bv, x, y, button);
+       if (!bv->lockInset(this))
+           return;
+       inset->Edit(bv, x-widthCollapsed, y, button);
     }
 }
 
@@ -207,15 +214,15 @@ void InsetCollapsable::InsetUnlock(BufferView * bv)
     if (autocollapse) {
        collapsed = true;
     }
-    InsetText::InsetUnlock(bv);
-    UpdateLocal(bv, FULL, false);
+    inset->InsetUnlock(bv);
+    bv->updateInset(this, false);
 }
 
 
 void InsetCollapsable::InsetButtonPress(BufferView * bv,int x,int y,int button)
 {
     if (!collapsed && (x >= button_length)) {
-       InsetText::InsetButtonPress(bv, x, y, button);
+       inset->InsetButtonPress(bv, x-widthCollapsed, y, button);
     }
 }
 
@@ -227,15 +234,15 @@ void InsetCollapsable::InsetButtonRelease(BufferView * bv,
        (y >= button_top_y) &&  (y < button_bottom_y)) {
        if (collapsed) {
            collapsed = false;
-           InsetText::InsetButtonRelease(bv, 0, 0, button);
-           UpdateLocal(bv, FULL, false);
+           inset->InsetButtonRelease(bv, 0, 0, button);
+           bv->updateInset(this, false);
        } else {
            collapsed = true;
-           UpdateLocal(bv, FULL, false);
            bv->unlockInset(this);
+           bv->updateInset(this, false);
        }
     } else if (!collapsed && (x >= button_length) && (y >= button_top_y)) {
-       InsetText::InsetButtonRelease(bv, x, y, button);
+       inset->InsetButtonRelease(bv, x-widthCollapsed, y, button);
     }
 }
 
@@ -244,37 +251,166 @@ void InsetCollapsable::InsetMotionNotify(BufferView * bv,
                                         int x, int y, int state)
 {
     if (x >= button_length) {
-       InsetText::InsetMotionNotify(bv, x, y, state);
+       inset->InsetMotionNotify(bv, x-widthCollapsed, y, state);
     }
 }
 
 
+void InsetCollapsable::InsetKeyPress(XKeyEvent * xke)
+{
+    inset->InsetKeyPress(xke);
+}
+
+
+int InsetCollapsable::Latex(Buffer const * buf, ostream & os, bool fragile, bool free_spc) const
+{
+    return inset->Latex(buf, os, fragile, free_spc);
+}
+
+
 int InsetCollapsable::getMaxWidth(Painter & pain,
                                  UpdatableInset const * inset) const
 {
-    if ((this == inset) && !owner())
-       return pain.paperWidth();
-    if (this == inset)
-        return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain,inset);
+    int w;
     if (owner())
-        return static_cast<UpdatableInset*>(owner())->getMaxWidth(pain,inset)-
-               width_collapsed(pain, labelfont) - widthOffset;
+        w = static_cast<UpdatableInset*>(owner())->getMaxWidth(pain,inset);
+    else
+       w = pain.paperWidth();
 
-    return pain.paperWidth()-width_collapsed(pain, labelfont) - widthOffset;
+    if (w < 0)
+       return w;
+
+    return w; // - top_x - widthCollapsed;
 }
 
 
 int InsetCollapsable::getMaxTextWidth(Painter & pain,
                                      UpdatableInset const * inset) const
 {
-    return getMaxWidth(pain, inset) -
-       width_collapsed(pain, labelfont) - widthOffset;
+    return getMaxWidth(pain, inset) - widthCollapsed;
 }
 
 
 void InsetCollapsable::update(BufferView * bv,
                              LyXFont const & font, bool dodraw)
 {
-    drawTextXOffset = width_collapsed(bv->painter(), font);
-    InsetText::update(bv, font, dodraw);
+    if (!widthCollapsed) {
+       widthCollapsed = width_collapsed(bv->painter(), font);
+       inset->deleteLyXText(bv);
+       need_update = FULL;
+       if (owner()) {
+               owner()->update(bv, font, dodraw);
+               return;
+       }
+    }
+    if (oldWidth != width(bv->painter(), font)) {
+       oldWidth = width(bv->painter(), font);
+       inset->deleteLyXText(bv);
+       need_update = FULL;
+       if (owner()) {
+               owner()->update(bv, font, dodraw);
+               return;
+       }
+    }
+    inset->update(bv, font, dodraw);
+}
+
+UpdatableInset::RESULT
+InsetCollapsable::LocalDispatch(BufferView * bv, int action, string const & arg)
+{
+    UpdatableInset::RESULT result = inset->LocalDispatch(bv, action, arg);
+    if (result == FINISHED)
+        bv->unlockInset(this);
+    return result;
+}
+
+bool InsetCollapsable::LockInsetInInset(BufferView * bv, UpdatableInset * in)
+{
+    if (inset == in)
+       return true;
+    return inset->LockInsetInInset(bv, in);
+}
+
+
+bool InsetCollapsable::UnlockInsetInInset(BufferView * bv, UpdatableInset * in,
+                                         bool lr)
+{
+    if (inset == in) {
+       bv->unlockInset(this);
+       return true;
+    }
+    return inset->UnlockInsetInInset(bv, in, lr);
+}
+
+
+bool InsetCollapsable::UpdateInsetInInset(BufferView * bv, Inset *in)
+{
+    if (in == inset)
+       return true;
+    return inset->UpdateInsetInInset(bv, in);
+}
+
+
+int InsetCollapsable::InsetInInsetY()
+{
+    return inset->InsetInInsetY();
+}
+
+
+void InsetCollapsable::Validate(LaTeXFeatures & features) const
+{
+    inset->Validate(features);
 }
+
+
+void InsetCollapsable::GetCursorPos(BufferView * bv, int & x, int & y) const
+{
+    inset->GetCursorPos(bv, x , y);
+}
+
+
+void InsetCollapsable::ToggleInsetCursor(BufferView * bv)
+{
+    inset->ToggleInsetCursor(bv);
+}
+
+
+UpdatableInset * InsetCollapsable::GetLockingInset()
+{
+    UpdatableInset *in = inset->GetLockingInset();
+    if (inset == in)
+       return this;
+    return in;
+}
+
+
+UpdatableInset * InsetCollapsable::GetFirstLockingInsetOfType(Inset::Code c)
+{
+    if (c == LyxCode())
+       return this;
+    return inset->GetFirstLockingInsetOfType(c);
+}
+
+
+void InsetCollapsable::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
+{
+    inset->SetFont(bv, font, toggleall);
+}
+
+bool InsetCollapsable::doClearArea() const
+{
+    return inset->doClearArea();
+}
+
+
+LyXText * InsetCollapsable::getLyXText(BufferView * bv) const
+{
+    return inset->getLyXText(bv);
+}
+
+
+void InsetCollapsable::deleteLyXText(BufferView * bv)
+{
+    inset->deleteLyXText(bv);
+}
+
index 42ec6507fbcec9472d03846e2e365df1ce5eb85b..687c11317aa1eacda9a9589d9e6ec59e7b66b4ff 100644 (file)
 #pragma interface
 #endif
 
-#include "insettext.h"
+#include "lyxinset.h"
 #include "lyxfont.h"
 #include "LColor.h"
 
 
 class Painter;
+class InsetText;
+class LyXText;
 
 /** A colapsable text inset
   
 */
-class InsetCollapsable : public InsetText {
+class InsetCollapsable : public UpdatableInset {
 public:
+    ///
+    enum UpdateCodes {
+       NONE = 0,
+       FULL
+    };
     ///
     static int const TEXT_TO_TOP_OFFSET = 2;
     ///
@@ -59,9 +66,21 @@ public:
     ///
     EDITABLE Editable() const;
     ///
+    bool IsTextInset() const { return true; }
+    ///
+    bool doClearArea() const;
+    ///
     void InsetUnlock(BufferView *);
     ///
-    bool display() const { return (!collapsed); }
+    bool needFullRow() const { return !collapsed; }
+    ///
+    bool LockInsetInInset(BufferView *, UpdatableInset *);
+    ///
+    bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
+    ///
+    bool UpdateInsetInInset(BufferView *, Inset *);
+    ///
+    int InsetInInsetY();
     ///
     void InsetButtonRelease(BufferView *, int, int, int);
     ///
@@ -69,6 +88,30 @@ public:
     ///
     void InsetMotionNotify(BufferView *, int, int, int);
     ///
+    void InsetKeyPress(XKeyEvent *);
+    ///
+    UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
+    ///
+    int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
+    ///
+    int Ascii(Buffer const *, std::ostream &) const { return 0; }
+    ///
+    int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
+    ///
+    int DocBook(Buffer const *, std::ostream &) const { return 0; }
+    ///
+    void Validate(LaTeXFeatures & features) const;
+    ///
+    void GetCursorPos(BufferView *, int & x, int & y) const;
+    ///
+    void ToggleInsetCursor(BufferView *);
+    ///
+    UpdatableInset * GetLockingInset();
+    ///
+    UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
+    ///
+    void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
+    ///
     void setLabel(string const & l) { label = l; }
     ///
     void setLabelFont(LyXFont & f) { labelfont = f; }
@@ -76,6 +119,9 @@ public:
     void setAutoCollapse(bool f) { autocollapse = f; }
     ///
     int getMaxWidth(Painter & pain, UpdatableInset const *) const;
+    ///
+    LyXText * getLyXText(BufferView *) const;
+    void deleteLyXText(BufferView *);
 
 protected:
     ///
@@ -95,24 +141,27 @@ protected:
     LColor::color framecolor;
     ///
     LyXFont labelfont;
+    ///
+    InsetText * inset;
+    // Instead of making these ints protected we could have a
+    // protected method "clickInButton" (Lgb)
+    ///
+    mutable int
+       button_length, button_top_y, button_bottom_y;
 
 private:
     ///
     string label;
     ///
     bool autocollapse;
-protected:
-       // Instead of making these ints protected we could have a
-       // protected method "clickInButton" (Lgb)
     ///
-    mutable int
-       button_length, button_top_y, button_bottom_y;
-private:
+    int widthCollapsed;
     ///
-    int widthOffset;
+    int oldWidth;
     ///
     mutable int topx;
     mutable int topbaseline;
+    mutable UpdateCodes need_update;
 };
 
 #endif
index 67af3e3d132e86578991aed04771299b73a557aa..32bb4476f16637391b1bdadfb1962c79ed8d7b7c 100644 (file)
@@ -18,6 +18,7 @@
 #include "lyxfont.h"
 #include "Painter.h"
 #include "buffer.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 #include "lyx_gui_misc.h"
 
@@ -46,8 +47,8 @@ void InsetERT::Write(Buffer const * buf, ostream & os) const
 
 Inset * InsetERT::Clone() const
 {
-    InsetERT * result = new InsetERT();
-    result->init(this);
+    InsetERT * result = new InsetERT;
+    result->inset->init(inset);
 
     result->collapsed = collapsed;
     return result;
index 8d8c8c6a2f795671be1ed086c10f040d1691e110..cc893bc70d5fe5381d8803c415bea9a6e6b10e47 100644 (file)
@@ -19,6 +19,7 @@
 #include "BufferView.h"
 #include "Painter.h"
 #include "lyxtext.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 #include "FloatList.h"
 #include "LaTeXFeatures.h"
@@ -130,7 +131,7 @@ void InsetFloat::Validate(LaTeXFeatures & features) const
 Inset * InsetFloat::Clone() const
 {
     InsetFloat * result = new InsetFloat;
-    result->init(this);
+    result->inset->init(inset);
 
     result->collapsed = collapsed;
     return result;
@@ -152,32 +153,32 @@ int InsetFloat::Latex(Buffer const * buf,
                os << "[" << floatPlacement << "]";
        os << "%\n";
     
-    int i = InsetText::Latex(buf, os, fragile, fp);
+    int i = inset->Latex(buf, os, fragile, fp);
     os << "\\end{" << floatType << "}%\n";
     
     return i + 2;
 }
 
 
-bool InsetFloat::InsertInset(BufferView * bv, Inset * inset)
+bool InsetFloat::InsertInset(BufferView * bv, Inset * in)
 {
-    if (!InsertInsetAllowed(inset))
+    if (!InsertInsetAllowed(in))
        return false;
 
-    return InsetText::InsertInset(bv, inset);
+    return inset->InsertInset(bv, in);
 }
 
 
-bool InsetFloat::InsertInsetAllowed(Inset * inset) const
+bool InsetFloat::InsertInsetAllowed(Inset * in) const
 {
-    if ((inset->LyxCode() == Inset::FOOT_CODE) ||
-       (inset->LyxCode() == Inset::MARGIN_CODE)) {
+    if ((in->LyxCode() == Inset::FOOT_CODE) ||
+       (in->LyxCode() == Inset::MARGIN_CODE)) {
        return false;
     }
     return true;
 }
 
-
+#if 0
 LyXFont InsetFloat::GetDrawFont(BufferView * bv,
                                LyXParagraph * p, int pos) const
 {
@@ -185,7 +186,7 @@ LyXFont InsetFloat::GetDrawFont(BufferView * bv,
     fn.decSize().decSize();
     return fn;
 }
-
+#endif
 
 void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
 {
index b76d4e0241a0905443ce2120885a92a1f79b5df7..997c99f73a695fdd40bea3649e4b0fcd4d6fe402 100644 (file)
@@ -49,7 +49,7 @@ public:
        ///
        bool InsertInsetAllowed(Inset * inset) const;
        ///
-       LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
+//     LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
        ///
        void InsetButtonRelease(BufferView * bv, int x, int y, int button);
 private:
index 818db8b97ad19cda82f78262f251092c1d46d4be..e9f56e6785f7f11ac8ae169ba563f94a47188312 100644 (file)
@@ -20,6 +20,7 @@
 #include "BufferView.h"
 #include "Painter.h"
 #include "lyxtext.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 
 using std::ostream;
@@ -48,7 +49,7 @@ void InsetFoot::Write(Buffer const * buf, ostream & os) const
 Inset * InsetFoot::Clone() const
 {
     InsetFoot * result = new InsetFoot;
-    result->init(this);
+    result->inset->init(inset);
 
     result->collapsed = collapsed;
     return result;
@@ -66,32 +67,32 @@ int InsetFoot::Latex(Buffer const * buf,
 {
     os << "\\footnote{%\n";
     
-    int i = InsetText::Latex(buf, os, fragile, fp);
+    int i = inset->Latex(buf, os, fragile, fp);
     os << "}%\n";
     
     return i + 2;
 }
 
 
-bool InsetFoot::InsertInset(BufferView * bv, Inset * inset)
+bool InsetFoot::InsertInset(BufferView * bv, Inset * in)
 {
-    if (!InsertInsetAllowed(inset))
+    if (!InsertInsetAllowed(in))
        return false;
 
-    return InsetText::InsertInset(bv, inset);
+    return inset->InsertInset(bv, in);
 }
 
 
-bool InsetFoot::InsertInsetAllowed(Inset * inset) const
+bool InsetFoot::InsertInsetAllowed(Inset * in) const
 {
-    if ((inset->LyxCode() == Inset::FOOT_CODE) ||
-       (inset->LyxCode() == Inset::MARGIN_CODE)) {
+    if ((in->LyxCode() == Inset::FOOT_CODE) ||
+       (in->LyxCode() == Inset::MARGIN_CODE)) {
        return false;
     }
     return true;
 }
 
-
+#if 0
 LyXFont InsetFoot::GetDrawFont(BufferView * bv,
                               LyXParagraph * p, int pos) const
 {
@@ -99,3 +100,4 @@ LyXFont InsetFoot::GetDrawFont(BufferView * bv,
     fn.decSize().decSize();
     return fn;
 }
+#endif
index 0f417281d1561761b227b0773c3772100c98efdc..115ce8ff205aaeac413635c749d966a52728a0bd 100644 (file)
@@ -47,7 +47,7 @@ public:
        ///
        bool InsertInsetAllowed(Inset * inset) const;
        ///
-       LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
+//     LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
 };
 
 #endif
index 640b3cb5f1fa6dd1dc30d297ae108b9bcf241d9c..2b67d1946819cdcbb525410b67ac2e48687dee8a 100644 (file)
@@ -19,6 +19,7 @@
 #include "BufferView.h"
 #include "Painter.h"
 #include "lyxtext.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 
 using std::ostream;
@@ -59,7 +60,7 @@ void InsetList::Write(Buffer const * buf, ostream & os) const
 Inset * InsetList::Clone() const
 {
        InsetList * result = new InsetList;
-       result->init(this);
+       result->inset->init(inset);
        
        result->collapsed = collapsed;
        return result;
@@ -77,35 +78,36 @@ int InsetList::Latex(Buffer const * buf,
 {
        os << "\\footnote{%\n";
        
-       int i = InsetText::Latex(buf, os, fragile, fp);
+       int i = inset->Latex(buf, os, fragile, fp);
        os << "}%\n";
        
        return i + 2;
 }
 
 
-bool InsetList::InsertInset(BufferView * bv, Inset * inset)
+bool InsetList::InsertInset(BufferView * bv, Inset * in)
 {
-       if (!InsertInsetAllowed(inset))
+       if (!InsertInsetAllowed(in))
                return false;
        
-       return InsetText::InsertInset(bv, inset);
+       return inset->InsertInset(bv, in);
 }
 
 
-bool InsetList::InsertInsetAllowed(Inset * inset) const
+bool InsetList::InsertInsetAllowed(Inset * in) const
 {
-       if ((inset->LyxCode() == Inset::FOOT_CODE) ||
-           (inset->LyxCode() == Inset::MARGIN_CODE)) {
+       if ((in->LyxCode() == Inset::FOOT_CODE) ||
+           (in->LyxCode() == Inset::MARGIN_CODE)) {
                return false;
        }
        return true;
 }
 
-
+#if 0
 LyXFont InsetList::GetDrawFont(BufferView * bv,LyXParagraph * p, int pos) const
 {
        LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
        fn.decSize().decSize();
        return fn;
 }
+#endif
index a8e1a27c0f129374db548c725988ba1c4a2eb37e..342a7f8b28ba57bc4ee162440cfe9853df42cc79 100644 (file)
@@ -45,7 +45,7 @@ public:
        ///
        bool InsertInsetAllowed(Inset * inset) const;
        ///
-       LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
+//     LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
 };
 
 #endif
index 546a36c124f93900c37453fa0e4ff792e14974ea..ce0fe40f81304dd810aed6dfb0c5a45a1b9ea914 100644 (file)
@@ -20,6 +20,7 @@
 #include "BufferView.h"
 #include "Painter.h"
 #include "lyxtext.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 
 using std::ostream;
@@ -49,7 +50,7 @@ void InsetMarginal::Write(Buffer const * buf, ostream & os) const
 Inset * InsetMarginal::Clone() const
 {
     InsetMarginal * result = new InsetMarginal;
-    result->init(this);
+    result->inset->init(inset);
     
     result->collapsed = collapsed;
     return result;
@@ -67,32 +68,32 @@ int InsetMarginal::Latex(Buffer const * buf,
 {
     os << "\\marginpar{%\n";
     
-    int i = InsetText::Latex(buf, os, fragile, fp);
+    int i = inset->Latex(buf, os, fragile, fp);
     os << "}%\n";
     
     return i + 2;
 }
 
 
-bool InsetMarginal::InsertInset(BufferView * bv, Inset * inset)
+bool InsetMarginal::InsertInset(BufferView * bv, Inset * in)
 {
-    if (!InsertInsetAllowed(inset))
+    if (!InsertInsetAllowed(in))
        return false;
 
-    return InsetText::InsertInset(bv, inset);
+    return inset->InsertInset(bv, in);
 }
 
 
-bool InsetMarginal::InsertInsetAllowed(Inset * inset) const
+bool InsetMarginal::InsertInsetAllowed(Inset * in) const
 {
-    if ((inset->LyxCode() == Inset::FOOT_CODE) ||
-       (inset->LyxCode() == Inset::MARGIN_CODE)) {
+    if ((in->LyxCode() == Inset::FOOT_CODE) ||
+       (in->LyxCode() == Inset::MARGIN_CODE)) {
        return false;
     }
     return true;
 }
 
-
+#if 0
 LyXFont InsetMarginal::GetDrawFont(BufferView * bv,
                                   LyXParagraph * p, int pos) const
 {
@@ -100,3 +101,4 @@ LyXFont InsetMarginal::GetDrawFont(BufferView * bv,
     fn.decSize().decSize();
     return fn;
 }
+#endif
index f8d650b97069a6bd880f8d2e2aedcb504b64430d..6a47bfeb7b51237c175773c87261bbf9b5e90479 100644 (file)
@@ -45,7 +45,7 @@ public:
        ///
        bool InsertInsetAllowed(Inset * inset) const;
        ///
-       LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
+//     LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
 };
 
 #endif
index 606648bcb9da111cae6bcbc6e4943c72529a7387..2e90212764fd7942dbf026732cfb452cfbae2031 100644 (file)
@@ -19,6 +19,7 @@
 #include "BufferView.h"
 #include "Painter.h"
 #include "lyxtext.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 
 using std::ostream;
@@ -77,7 +78,7 @@ void InsetMinipage::Write(Buffer const * buf, ostream & os) const
 Inset * InsetMinipage::Clone() const
 {
        InsetMinipage * result = new InsetMinipage;
-       result->init(this);
+       result->inset->init(inset);
        
        result->collapsed = collapsed;
        return result;
@@ -95,32 +96,32 @@ int InsetMinipage::Latex(Buffer const * buf,
 {
        os << "\\begin{minipage}{\\columnwidth}%\n";
        
-       int i = InsetText::Latex(buf, os, fragile, fp);
+       int i = inset->Latex(buf, os, fragile, fp);
        os << "\\end{minipage}%\n";
        
        return i + 2;
 }
 
 
-bool InsetMinipage::InsertInset(BufferView * bv, Inset * inset)
+bool InsetMinipage::InsertInset(BufferView * bv, Inset * in)
 {
-       if (!InsertInsetAllowed(inset))
+       if (!InsertInsetAllowed(in))
                return false;
        
-       return InsetText::InsertInset(bv, inset);
+       return inset->InsertInset(bv, in);
 }
 
 
-bool InsetMinipage::InsertInsetAllowed(Inset * inset) const
+bool InsetMinipage::InsertInsetAllowed(Inset * in) const
 {
-       if ((inset->LyxCode() == Inset::FLOAT_CODE) ||
-           (inset->LyxCode() == Inset::MARGIN_CODE)) {
+       if ((in->LyxCode() == Inset::FLOAT_CODE) ||
+           (in->LyxCode() == Inset::MARGIN_CODE)) {
                return false;
        }
        return true;
 }
 
-
+#if 0
 LyXFont InsetMinipage::GetDrawFont(BufferView * bv,
                                   LyXParagraph * p, int pos) const
 {
@@ -128,3 +129,4 @@ LyXFont InsetMinipage::GetDrawFont(BufferView * bv,
        fn.decSize().decSize();
        return fn;
 }
+#endif
index 2c4cc024686eb60b38d827d1b33f6675c08ca408..daba5e9486b28a151f2ada33dbebe51250009249 100644 (file)
@@ -45,7 +45,7 @@ public:
        ///
        bool InsertInsetAllowed(Inset * inset) const;
        ///
-       LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
+//     LyXFont GetDrawFont(BufferView *, LyXParagraph * par, int pos) const;
 };
 
 #endif
index 735df9e4c1fb03131a7a23bdc525c43fc7acc99a..10347afe2e30591f994f7a9f295d418fce579ff8 100644 (file)
@@ -56,10 +56,6 @@ using std::max;
 
 extern unsigned char getCurrentTextClass(Buffer *);
 
-// Jürgen, we don't like macros, even small ones like this. (Lgb)
-//#define TEXT(a) getLyXText(a)
-// I created a inline function in insettext.h instead. (Lgb)
-
 InsetText::InsetText()
 {
     par = new LyXParagraph();
@@ -93,12 +89,13 @@ void InsetText::init(InsetText const * ins)
     no_selection = false;
     need_update = INIT;
     drawTextXOffset = drawTextYOffset = 0;
-    autoBreakRows = drawLockedFrame = false;
+    autoBreakRows = false;
+    drawFrame = NEVER;
     xpos = 0.0;
     if (ins) {
        SetParagraphData(ins->par);
        autoBreakRows = ins->autoBreakRows;
-       drawLockedFrame = ins->drawLockedFrame;
+       drawFrame = ins->drawFrame;
     }
     par->SetInsetOwner(this);
     frame_color = LColor::insetframe;
@@ -210,7 +207,21 @@ int InsetText::width(Painter &, LyXFont const &) const
 
 int InsetText::textWidth(Painter & pain) const
 {
-    return getMaxTextWidth(pain, this) - drawTextXOffset;
+    int w = getMaxWidth(pain, this);
+    if (w < 0) {
+//     printf("WW1: %d\n",w);
+       return w;
+    }
+#if 0
+    if (owner()) {
+       w = w - top_x + owner()->x();
+       printf("WW2: %d\n",w);
+       return w; // - top_x + owner()->x();
+    }
+#endif
+    w -= (2 * TEXT_TO_INSET_OFFSET);
+//    printf("WW2: %d\n",w);
+    return w; // - top_x - (2 * TEXT_TO_INSET_OFFSET);
 }
 
 
@@ -248,7 +259,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
     last_width = width(pain, f);
     last_height = ascent(pain, f) + descent(pain, f);
 
-    if (the_locking_inset && (cpos(bv) == inset_pos)) {
+    if (the_locking_inset && (cpar(bv) == inset_par) && (cpos(bv) == inset_pos)) {
        inset_x = cx(bv) - top_x + drawTextXOffset;
        inset_y = cy(bv) + drawTextYOffset;
     }
@@ -263,7 +274,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
     y += baseline - row->ascent_of_text() + 1;
     if (cleared || !locked || (need_update == FULL)) {
        while (row != 0) {
-           TEXT(bv)->GetVisibleRow(bv, y, x, row, y);
+           TEXT(bv)->GetVisibleRow(bv, y, x, row, y, cleared);
            y += row->height();
            row = row->next();
        }
@@ -276,12 +287,12 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
     }
     TEXT(bv)->refresh_y = 0;
     TEXT(bv)->status = LyXText::UNCHANGED;
-    if (drawLockedFrame && locked) {
-           pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
-                          ascent(pain,f) + descent(pain, f), frame_color);
+    if ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)) {
+           pain.rectangle(top_x, baseline - insetAscent, insetWidth,
+                          insetAscent + insetDescent, frame_color);
     } else {
-           pain.rectangle(top_x, baseline - ascent(pain, f), width(pain, f),
-                          ascent(pain,f) + descent(pain, f),
+           pain.rectangle(top_x, baseline - insetAscent, insetWidth,
+                          insetAscent + insetDescent,
                           LColor::background);
     }
     x += width(pain, f) - TEXT_TO_INSET_OFFSET;
@@ -297,19 +308,66 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool dodraw)
        deleteLyXText(bv);
        need_update = FULL;
     }
+    int oldw = insetWidth;
+#if 1
+    insetWidth = max(textWidth(bv->painter()),
+                    static_cast<int>(TEXT(bv)->width) + drawTextXOffset) +
+       (2 * TEXT_TO_INSET_OFFSET);
+#else
+    insetWidth = textWidth(bv->painter());
+    if (insetWidth < 0)
+           insetWidth = static_cast<int>(TEXT(bv)->width);
+#endif
+    if (oldw != insetWidth) {
+           printf("TW(%p): %d-%d-%d-%d\n",this,insetWidth, oldw,
+                  textWidth(bv->painter()),static_cast<int>(TEXT(bv)->width));
+       deleteLyXText(bv);
+#if 0
+       if (owner()) {
+               owner()->update(bv, font, dodraw);
+               return;
+       }
+#else
+#if 1
+       update(bv, font, dodraw);
+#else
+       UpdateLocal(bv, INIT, false);
+#endif
+#endif
+       return;
+    }
     if (dodraw && (need_update != CURSOR))
            need_update = FULL;
 
     TEXT(bv)->FullRebreak(bv);
 
+    if ((need_update==CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
+       the_locking_inset)
+    {
+       TEXT(bv)->UpdateInset(bv, the_locking_inset);
+    }
+
     long int y_temp = 0;
     Row * row = TEXT(bv)->GetRowNearY(y_temp);
     insetAscent = row->ascent_of_text() + TEXT_TO_INSET_OFFSET;
     insetDescent = TEXT(bv)->height - row->ascent_of_text() +
        TEXT_TO_INSET_OFFSET;
-    insetWidth = max(textWidth(bv->painter()),
-                    static_cast<int>(TEXT(bv)->width)) +
-       (2 * TEXT_TO_INSET_OFFSET);
+}
+
+
+void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
+{
+    TEXT(bv)->FullRebreak(bv);
+    if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
+       need_update = FULL;
+    else if (!the_locking_inset || (what != CURSOR))
+       need_update = what;
+    if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
+           bv->updateInset(this, mark_dirty);
+    if (old_par != cpar(bv)) {
+           bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
+           old_par = cpar(bv);
+    }
 }
 
 
@@ -331,10 +389,9 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
     locked = true;
     the_locking_inset = 0;
     inset_pos = inset_x = inset_y = 0;
-    TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
-                                      y+TEXT(bv)->first-drawTextYOffset+
-                                      insetAscent);
-    checkAndActivateInset(bv, x, y, button);
+    inset_par = 0;
+    if (!checkAndActivateInset(bv, x, y, button))
+       TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset, y);
     TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
     bv->text->FinishUndo();
     UpdateLocal(bv, FULL, false);
@@ -364,15 +421,15 @@ bool InsetText::LockInsetInInset(BufferView * bv, UpdatableInset * inset)
     if (inset == cpar(bv)->GetInset(cpos(bv))) {
        lyxerr[Debug::INSETS] << "OK" << endl;
        the_locking_inset = inset;
-//     resetPos(bv->painter());
        inset_x = cx(bv) - top_x + drawTextXOffset;
        inset_y = cy(bv) + drawTextYOffset;
        inset_pos = cpos(bv);
+       inset_par = cpar(bv);
+       TEXT(bv)->UpdateInset(bv, the_locking_inset);
        return true;
     } else if (the_locking_inset && (the_locking_inset == inset)) {
-       if (cpos(bv) == inset_pos) {
+       if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
            lyxerr[Debug::INSETS] << "OK" << endl;
-//         resetPos(bv->painter());
            inset_x = cx(bv) - top_x + drawTextXOffset;
            inset_y = cy(bv) + drawTextYOffset;
        } else {
@@ -398,7 +455,7 @@ bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
         the_locking_inset = 0;
         if (lr)
             moveRight(bv, false);
-       UpdateLocal(bv, FULL, false);
+       UpdateLocal(bv, CURSOR_PAR, false);
         return true;
     }
     return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
@@ -409,11 +466,15 @@ bool InsetText::UpdateInsetInInset(BufferView * bv, Inset * inset)
 {
     if (!the_locking_inset)
         return false;
-    if (the_locking_inset != inset)
+    if (the_locking_inset != inset) {
+       TEXT(bv)->UpdateInset(bv, the_locking_inset);
+       need_update = CURSOR_PAR;
         return the_locking_inset->UpdateInsetInInset(bv, inset);
+    }
 //    UpdateLocal(bv, FULL, false);
-    TEXT(bv)->UpdateInset(bv, inset);
-    if (cpos(bv) == inset_pos) {
+    if (TEXT(bv)->UpdateInset(bv, inset))
+       UpdateLocal(bv, CURSOR_PAR, false);
+    if (cpar(bv) == inset_par && cpos(bv) == inset_pos) {
        inset_x = cx(bv) - top_x + drawTextXOffset;
        inset_y = cy(bv) + drawTextYOffset;
     }
@@ -428,13 +489,13 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
        UpdateLocal(bv, FULL, false);
     }
     no_selection = false;
-    TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
-                                      y+TEXT(bv)->first-drawTextYOffset+
-                                      insetAscent);
+
+    int tmp_x = x - drawTextXOffset;
+//    int tmp_y = y + TEXT(bv)->first + insetAscent;
+    int tmp_y = y + insetAscent;
+    Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
+
     if (the_locking_inset) {
-       UpdatableInset * inset = 0;
-       if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET)
-           inset = static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
        if (the_locking_inset == inset) {
            the_locking_inset->InsetButtonPress(bv,x-inset_x,y-inset_y,button);
            return;
@@ -445,7 +506,8 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
            inset_y = cy(bv) + drawTextYOffset;
            inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
            inset->Edit(bv, x - inset_x, y - inset_y, button);
-           UpdateLocal(bv, FULL, false);
+           if (the_locking_inset)
+               UpdateLocal(bv, CURSOR_PAR, false);
            return;
        }
        // otherwise only unlock the_locking_inset
@@ -453,19 +515,22 @@ void InsetText::InsetButtonPress(BufferView * bv, int x, int y, int button)
        the_locking_inset = 0;
     }
     if (bv->the_locking_inset) {
-       if ((cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) &&
-           cpar(bv)->GetInset(cpos(bv)) &&
-           (cpar(bv)->GetInset(cpos(bv))->Editable() == Inset::HIGHLY_EDITABLE)) {
-           UpdatableInset * inset =
-               static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
+       if (inset && inset->Editable() == Inset::HIGHLY_EDITABLE) {
+           UpdatableInset * uinset = static_cast<UpdatableInset*>(inset);
            inset_x = cx(bv) - top_x + drawTextXOffset;
            inset_y = cy(bv) + drawTextYOffset;
-           inset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
-           inset->Edit(bv, x - inset_x, y - inset_y, 0);
-           UpdateLocal(bv, FULL, false);
+           inset_pos = cpos(bv);
+           inset_par = cpar(bv);
+           uinset->InsetButtonPress(bv, x - inset_x, y - inset_y, button);
+           uinset->Edit(bv, x - inset_x, y - inset_y, 0);
+           if (the_locking_inset)
+               UpdateLocal(bv, CURSOR_PAR, false);
+           return;
        }
     }
-//    selection_start_cursor = selection_end_cursor = cursor;
+    if (!inset)
+       TEXT(bv)->SetCursorFromCoordinates(bv, x-drawTextXOffset,
+                                          y+TEXT(bv)->first+insetAscent);
 }
 
 
@@ -903,11 +968,9 @@ InsetText::moveRight(BufferView * bv, bool activate_inset)
 {
     if (!cpar(bv)->next && (cpos(bv) >= cpar(bv)->Last()))
        return FINISHED;
-    if (activate_inset && checkAndActivateInset(bv)) {
+    if (activate_inset && checkAndActivateInset(bv, false))
        return DISPATCHED;
-    }
     TEXT(bv)->CursorRight(bv);
-//    real_current_font = current_font = GetFont(bv->buffer(), cpar(bv), cpos(bv));
     return DISPATCHED_NOUPDATE;
 }
 
@@ -918,9 +981,8 @@ InsetText::moveLeft(BufferView * bv, bool activate_inset)
     if (!cpar(bv)->previous && (cpos(bv) <= 0))
        return FINISHED;
     TEXT(bv)->CursorLeft(bv);
-    if (activate_inset)
-       if (checkAndActivateInset(bv, -1, -1))
-           return DISPATCHED;
+    if (activate_inset && checkAndActivateInset(bv, true))
+       return DISPATCHED;
     return DISPATCHED_NOUPDATE;
 }
 
@@ -989,32 +1051,43 @@ void InsetText::SetFont(BufferView * bv, LyXFont const & font, bool toggleall)
 }
 
 
-void InsetText::UpdateLocal(BufferView * bv, UpdateCodes what, bool mark_dirty)
+bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
 {
-    if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
-       need_update = FULL;
-    else
-       need_update = what;
-    if ((need_update != CURSOR) || (TEXT(bv)->status != LyXText::UNCHANGED))
-           bv->updateInset(this, mark_dirty);
-    if (old_par != cpar(bv)) {
-           bv->owner()->getToolbar()->combox->select(cpar(bv)->GetLayout()+1);
-           old_par = cpar(bv);
+    if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
+       int x, y;
+       Inset * inset =
+           static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
+       LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
+       if (behind) {
+           x = inset->width(bv->painter(), font);
+           y = inset->descent(bv->painter(), font);
+       } else {
+           x = y = 0;
+       }
+       inset_x = cx(bv) - top_x + drawTextXOffset;
+       inset_y = cy(bv) + drawTextYOffset;
+       inset->Edit(bv, x-inset_x, y-inset_y, 0);
+       if (!the_locking_inset)
+           return false;
+       UpdateLocal(bv, CURSOR_PAR, false);
+       return true;
     }
+    return false;
 }
 
 
 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
                                      int button)
 {
-    if (cpar(bv)->GetChar(cpos(bv)) == LyXParagraph::META_INSET) {
-       UpdatableInset * inset =
-           static_cast<UpdatableInset*>(cpar(bv)->GetInset(cpos(bv)));
-       LyXFont font = TEXT(bv)->GetFont(bv->buffer(), cpar(bv), cpos(bv));
+    int tmp_x = x - drawTextXOffset;
+    int tmp_y = y + insetAscent;
+    Inset * inset = bv->checkInsetHit(TEXT(bv), tmp_x, tmp_y, button);
+
+    if (inset) {
        if (x < 0)
-           x = inset->width(bv->painter(), font);
+           x = insetWidth;
        if (y < 0)
-           y = inset->descent(bv->painter(), font);
+           y = insetDescent;
        inset_x = cx(bv) - top_x + drawTextXOffset;
        inset_y = cy(bv) + drawTextYOffset;
        inset->Edit(bv, x - inset_x, y - inset_y, button);
@@ -1070,25 +1143,31 @@ void InsetText::SetAutoBreakRows(bool flag)
 }
 
 
-void InsetText::SetDrawLockedFrame(bool flag)
+void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how)
 {
-    if (flag != drawLockedFrame)
-       drawLockedFrame = flag;
+    if (how != drawFrame) {
+       drawFrame = how;
+       if (bv)
+           UpdateLocal(bv, FRAME, false);
+    }
 }
 
 
-void InsetText::SetFrameColor(LColor::color col)
+void InsetText::SetFrameColor(BufferView * bv, LColor::color col)
 {
-    if (frame_color != col)
+    if (frame_color != col) {
        frame_color = col;
+       if (bv)
+           UpdateLocal(bv, FRAME, false);
+    }
 }
 
-
+#if 0
 LyXFont InsetText::GetDrawFont(BufferView * bv, LyXParagraph * p, int pos) const
 {
     return TEXT(bv)->GetFont(bv->buffer(), p, pos);
 }
-
+#endif
 
 int InsetText::cx(BufferView * bv) const
 {
@@ -1129,6 +1208,9 @@ LyXText * InsetText::getLyXText(BufferView * bv) const
     LyXText * lt = new LyXText(const_cast<InsetText *>(this));
     lt->init(bv);
     cache[bv] = lt;
+    if (the_locking_inset) {
+       lt->SetCursor(bv, inset_par, inset_pos);
+    }
     return lt;
 }
 
@@ -1136,4 +1218,9 @@ LyXText * InsetText::getLyXText(BufferView * bv) const
 void InsetText::deleteLyXText(BufferView * bv)
 {
     cache.erase(bv);
+    /// then remove all LyXText in text-insets
+    LyXParagraph * p = par;
+    for(;p;p = p->next) {
+           p->deleteInsetsLyXText(bv);
+    }
 }
index b6738d95db03eaa233cc52d5a70fd6662e0f3323..f6382fe61ab107ea7c980f4b0008ea377d4fae56 100644 (file)
@@ -37,8 +37,6 @@ class LyXScreen;
  */
 class InsetText : public UpdatableInset {
 public:
-    ///
-    enum { TEXT_TO_INSET_OFFSET = 2 };
     ///
     enum UpdateCodes {
        NONE = 0,
@@ -46,7 +44,14 @@ public:
        FULL,
        CURSOR_PAR,
        CURSOR,
-       SELECTION
+       SELECTION,
+       FRAME
+    };
+    ///
+    enum DrawFrame {
+       NEVER = 0,
+       LOCKED,
+       ALWAYS
     };
     ///
     explicit
@@ -132,15 +137,17 @@ public:
     ///
     void init(InsetText const * ins = 0);
     ///
+    void WriteParagraphData(Buffer const *, std::ostream &) const;
+    ///
     void SetParagraphData(LyXParagraph *);
     ///
     void SetAutoBreakRows(bool);
     ///
-    void SetDrawLockedFrame(bool);
+    void SetDrawFrame(BufferView *, DrawFrame);
     ///
-    void SetFrameColor(LColor::color);
+    void SetFrameColor(BufferView *, LColor::color);
     ///
-    LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
+//    LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
     ///
     LyXText * getLyXText(BufferView *) const;
     void deleteLyXText(BufferView *);
@@ -151,15 +158,13 @@ protected:
     ///
     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
     ///
-    void WriteParagraphData(Buffer const *, std::ostream &) const;
-    ///
     virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
 
     mutable int drawTextXOffset;
     mutable int drawTextYOffset;
     ///
     bool autoBreakRows;
-    bool drawLockedFrame;
+    DrawFrame drawFrame;
     ///
     LColor::color frame_color;
     ///
@@ -189,6 +194,7 @@ private:
     ///
     string getText(int);
     ///
+    bool checkAndActivateInset(BufferView * bv, bool behind);
     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
                               int button = 0);
     ///
@@ -214,6 +220,8 @@ private:
     mutable int last_height;
     mutable int top_y;
     ///
+    LyXParagraph * inset_par;
+    ///
     int inset_pos;
     ///
     mutable int inset_x;
index cd73abe283c3039ca338fb3a5a8ffbb1e650371b..482037f17ebda121a3194d6552219d7988937014 100644 (file)
@@ -26,6 +26,7 @@
 class BufferView;
 class Buffer;
 class Painter;
+class LyXText;
 
 struct LaTeXFeatures;
 
@@ -102,6 +103,9 @@ public:
                EXTERNAL_CODE
        };
 
+       ///
+       enum { TEXT_TO_INSET_OFFSET = 2 };
+
        enum EDITABLE {
            NOT_EDITABLE = 0,
            IS_EDITABLE,
@@ -181,9 +185,13 @@ public:
        virtual bool DirectWrite() const;
 
        /// Returns true if the inset should be centered alone
-       virtual bool display() const { return false; }  
+       virtual bool display() const { return false; }
        /// Changes the display state of the inset
-       virtual void display(bool) {}  
+       virtual void display(bool) {}
+       ///
+       /// returns true if this inset needs a row on it's own
+       ///
+       virtual bool needFullRow() const { return false; }
        ///
        virtual bool InsertInsetAllowed(Inset *) const { return false; }
        ///
@@ -326,6 +334,11 @@ 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 87ef88642f8336d3273cf105d20c9fc7d2ec5313..48832114470bdb6f509a54057150b8e39aea47a3 100644 (file)
@@ -332,7 +332,7 @@ public:
          solution but faster.
         */
        void GetVisibleRow(BufferView *, int y_offset, int x_offset,
-                          Row * row_ptr, long y);
+                          Row * row_ptr, long y, bool cleared=false);
 
        /* footnotes: */
        ///
index c27f4c293ded9e6a3a944b0099264304dd0a5ae1..20d63d56eba247fc4ff294ee620a8fd7cdb63d1b 100644 (file)
@@ -735,28 +735,38 @@ InsetFormula::LocalDispatch(BufferView * bv,
     case LFUN_RIGHT:
       {
         result = DISPATCH_RESULT(mathcursor->Right(sel));
+        if (!sel && (result == DISPATCHED))
+            result = DISPATCHED_NOUPDATE;
         break;
       }
     case LFUN_LEFTSEL: sel = true;     
     case LFUN_LEFT:
       {
         result = DISPATCH_RESULT(mathcursor->Left(sel));
+        if (!sel && (result == DISPATCHED))
+            result = DISPATCHED_NOUPDATE;
         break;
       }
     case LFUN_UPSEL: sel = true;  
     case LFUN_UP:
       result = DISPATCH_RESULT(mathcursor->Up(sel));
+      if (!sel && (result == DISPATCHED))
+         result = DISPATCHED_NOUPDATE;
       break;
        
     case LFUN_DOWNSEL: sel = true;  
     case LFUN_DOWN:
       result = DISPATCH_RESULT(mathcursor->Down(sel));
+      if (!sel && (result == DISPATCHED))
+         result = DISPATCHED_NOUPDATE;
       break;
     case LFUN_HOME:
       mathcursor->Home();
+      result = DISPATCHED_NOUPDATE;
       break;
     case LFUN_END:
       mathcursor->End();
+      result = DISPATCHED_NOUPDATE;
       break;
     case LFUN_DELETE_LINE_FORWARD:
            //current_view->lockedInsetStoreUndo(Undo::INSERT);
@@ -1190,7 +1200,7 @@ InsetFormula::LocalDispatch(BufferView * bv,
    if (mathcursor->Selection() || was_selection)
        ToggleInsetSelection(bv);
     
-   if (result == DISPATCHED)
+   if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE))
       ShowInsetCursor(bv);
    else
       bv->unlockInset(this);
index 5cf057ce9c92d502711d328ccb577871dde3ec0f..8eac8d5ddd542b78567231e304c15ff5de6e3bfb 100644 (file)
@@ -4403,8 +4403,8 @@ void LyXParagraph::deleteInsetsLyXText(BufferView * bv)
             cit != insetlist.end(); ++cit) {
                if ((*cit).inset) {
                        if ((*cit).inset->IsTextInset()) {
-                               static_cast<InsetText *>((*cit).inset)->
-                                       deleteLyXText(bv);
+                               static_cast<UpdatableInset *>
+                                       ((*cit).inset)->deleteLyXText(bv);
                        }
                }
        }
index 42853796d89a57ac785d56e06314d7bc1af400c4..feb9c652b79df35aaec89e061df5b9772df3fa66 100644 (file)
@@ -168,7 +168,7 @@ void LyXTabular::Init(int rows_arg, int columns_arg)
     for (i = 0; i < rows_; ++i) {
         for (j = 0; j < columns_; ++j) {
            cell_info[i][j].inset.setOwner(owner_);
-           cell_info[i][j].inset.SetDrawLockedFrame(true);
+           cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
             cell_info[i][j].cellno = cellno++;
         }
     }
index 13ff3232f1cbefd0becf8247a6f3691801b5c189..e769dc96e3aeb02ef6c9f3bc5ce9f2150082423e 100644 (file)
@@ -565,8 +565,9 @@ void LyXText::draw(BufferView * bview, Row const * row,
        } else
 #endif
                if (c == LyXParagraph::META_INSET) {
-               Inset const * tmpinset = row->par()->GetInset(pos);
+               Inset * tmpinset = row->par()->GetInset(pos);
                if (tmpinset) {
+                       tmpinset->update(bview, font);
                        tmpinset->draw(bview, font, offset+row->baseline(), x,
                                       cleared);
                }
@@ -1095,25 +1096,30 @@ LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
                        par->Last();
                // this is the usual handling
                int x = LeftMargin(bview, row);
-               while (x < width && i < last) {
+               bool doitonetime = true;
+               while (doitonetime || ((x < width) && (i < last))) {
+                       doitonetime = false;
                        char c = par->GetChar(i);
                        if (IsNewlineChar(c)) {
                                last_separator = i;
                                x = width; // this means break
                        } else if (c == LyXParagraph::META_INSET &&
-                                  par->GetInset(i) && par->GetInset(i)->display()){
+                                  par->GetInset(i)) {
+                               
                                // check wether a Display() inset is
                                // valid here. if not, change it to
                                // non-display
-                               if (layout.isCommand()
-                                   || (layout.labeltype == LABEL_MANUAL
-                                       && i < BeginningOfMainBody(bview->buffer(), par))){
+                               if (par->GetInset(i)->display() &&
+                                   (layout.isCommand() ||
+                                    ((layout.labeltype == LABEL_MANUAL) &&
+                                     (i < BeginningOfMainBody(bview->buffer(), par))))) {
                                        // display istn't allowd
                                        par->GetInset(i)->display(false);
                                        x += SingleWidth(bview, par, i, c);
-                               } else {
-                                       // inset is display. So break the line here
-                                       if (i == pos){
+                               } else if (par->GetInset(i)->display() ||
+                                        par->GetInset(i)->needFullRow()) {
+                                       // So break the line here
+                                       if (i == pos) {
                                                if (pos < last-1) {
                                                        last_separator = i;
                                                        if (IsLineSeparatorChar(par->GetChar(i+1)))
@@ -1123,6 +1129,13 @@ LyXText::NextBreakPoint(BufferView * bview, Row const * row, int width) const
                                        } else
                                                last_separator = i - 1;
                                        x = width;  // this means break
+                               } else {
+#if 0
+                                       last_separator = i;
+                                       x += width;
+#else
+                                       x += SingleWidth(bview, par, i, c);
+#endif
                                }
                        } else  {
                                if (IsLineSeparatorChar(c))
@@ -2761,7 +2774,8 @@ void LyXText::InsertChar(BufferView * bview, char c)
        // the display inset stuff
        if (cursor.row()->par()->GetChar(cursor.row()->pos()) == LyXParagraph::META_INSET
            && cursor.row()->par()->GetInset(cursor.row()->pos())
-           && cursor.row()->par()->GetInset(cursor.row()->pos())->display())
+           && (cursor.row()->par()->GetInset(cursor.row()->pos())->display() ||
+               cursor.row()->par()->GetInset(cursor.row()->pos())->needFullRow()))
                cursor.row()->fill(-1); // to force a new break  
 
        // get the cursor row fist
@@ -3608,7 +3622,8 @@ void LyXText::Backspace(BufferView * bview)
                                return; 
                        // force complete redo when erasing display insets
                        // this is a cruel method but safe..... Matthias 
-                       if (cursor.par()->GetInset(cursor.pos())->display()){
+                       if (cursor.par()->GetInset(cursor.pos())->display() ||
+                           cursor.par()->GetInset(cursor.pos())->needFullRow()) {
                                cursor.par()->Erase(cursor.pos());
                                RedoParagraph(bview);
                                return;
@@ -3787,7 +3802,7 @@ void LyXText::Backspace(BufferView * bview)
 
 
 void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
-                           Row * row_ptr, long y)
+                           Row * row_ptr, long y, bool cleared)
 {
        /* returns a printed row */
        Painter & pain = bview->painter();
@@ -3810,6 +3825,8 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        PrepareToPrint(bview, row_ptr, x, fill_separator,
                       fill_hfill, fill_label_hfill);
        
+       if (inset_owner && (x < 0))
+               x = 0;
        x += x_offset;
        
        // clear the area where we want to paint/print
@@ -3825,7 +3842,9 @@ void LyXText::GetVisibleRow(BufferView * bview, int y_offset, int x_offset,
        {
                clear_area = inset->doClearArea();
        }
-       if (clear_area) {
+       if (cleared) { // we don't need to clear it's already done!!!
+               clear_area = true;
+       } else if (clear_area) {
                int w;
                if (inset_owner)
                        w = inset_owner->width(bview->painter(), font);