]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
reversed jug-bug, will apply pieces later
[lyx.git] / src / insets / insettext.C
index 2d19e5e4ea630d9037a0e94e4f1d20e05439f545..6107391f1f2eef76f17f654ecc604a0cbdbb2f9c 100644 (file)
@@ -46,7 +46,6 @@
 #include "trans_mgr.h"
 #include "lyxscreen.h"
 #include "WorkArea.h"
-#include "lyxfunc.h"
 #include "gettext.h"
 
 using std::ostream;
@@ -98,19 +97,18 @@ void InsetText::init(InsetText const * ins)
        drawTextXOffset = 0;
        drawTextYOffset = 0;
        autoBreakRows = false;
-       drawFrame_ = NEVER;
+       drawFrame = NEVER;
        xpos = 0.0;
        if (ins) {
-               SetParagraphData(ins->par);
-               autoBreakRows = ins->autoBreakRows;
-               drawFrame_ = ins->drawFrame_;
+       SetParagraphData(ins->par);
+       autoBreakRows = ins->autoBreakRows;
+       drawFrame = ins->drawFrame;
        }
        par->SetInsetOwner(this);
        frame_color = LColor::insetframe;
        locked = false;
        old_par = 0;
        last_drawn_width = -1;
-       frame_is_visible = false;
 }
 
 
@@ -299,29 +297,26 @@ int InsetText::textWidth(BufferView * bv) const
 void InsetText::draw(BufferView * bv, LyXFont const & f,
                      int baseline, float & x, bool cleared) const
 {
-       if (nodraw())
-               return;
-
        Painter & pain = bv->painter();
 
        // no draw is necessary !!!
-       if ((drawFrame_ == LOCKED) && !locked && !par->size()) {
-               top_x = int(x);
-               top_baseline = baseline;
-               x += width(bv, f);
-               if (!cleared && (need_update & CLEAR_FRAME))
-                       clearFrame(pain, cleared);
-               need_update = NONE;
-               return;
+       if ((drawFrame == LOCKED) && !locked && !par->size()) {
+                       if (!cleared && (need_update & CLEAR_FRAME)) {
+                                       pain.rectangle(top_x + 1, baseline - insetAscent + 1,
+                                                                  width(bv, f) - 1,
+                                                                  insetAscent + insetDescent - 1,
+                                                                  LColor::background);
+                       }
+                       top_x = int(x);
+                       top_baseline = baseline;
+                       x += width(bv, f);
+                       need_update = NONE;
+                       return;
        }
 
        xpos = x;
-#if 0
        UpdatableInset::draw(bv, f, baseline, x, cleared);
-#else
-       if (!owner())
-               x += static_cast<float>(scroll());
-#endif
+       
        // update insetWidth and insetHeight with dummy calls
        (void)ascent(bv, f);
        (void)descent(bv, f);
@@ -329,9 +324,8 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        // if top_x differs we have a rule down and we don't have to clear anything
        if (!cleared && (top_x == int(x)) &&
-               ((need_update&(INIT|FULL)) || (top_baseline!=baseline) ||
-                (last_drawn_width!=insetWidth)))
-       {
+           ((need_update == INIT) || (need_update == FULL) || (top_baseline != baseline) ||
+                (last_drawn_width!=insetWidth))) {
                int w =  insetWidth;
                int h = insetAscent + insetDescent;
                int ty = baseline - insetAscent;
@@ -352,14 +346,11 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                return;
 
        if (top_x != int(x)) {
-               need_update |= INIT;
+               need_update = INIT;
                top_x = int(x);
                bv->text->status = LyXText::CHANGED_IN_DRAW;
                return;
        }
-
-//     lyxerr << "InsetText::draw[" << this << "](" << need_update << ":" << int(x) << ":" << top_x << ")\n";
-
        if (cleared || (last_drawn_width != insetWidth)) {
                need_update |= FULL;
                last_drawn_width = insetWidth;
@@ -375,7 +366,6 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                inset_y = cy(bv) + drawTextYOffset;
        }
        if (!cleared && (need_update == CURSOR) && !TEXT(bv)->selection) {
-               drawFrame(pain, cleared);
                x += width(bv, f);
                need_update = NONE;
                return;
@@ -385,6 +375,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 #ifdef WITH_WARNINGS
 #warning Jürgen, why is this a block of its own? (Lgb)
 #warning because you told me to define variables only in local context (Jug)!
+#warning then make it a function/method of its own. (Lgb)
 #endif
        {
        int y = 0;
@@ -401,7 +392,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        if (y_offset < 0)
                y_offset = y;
        TEXT(bv)->first = first;
-       if (cleared) {
+       if (cleared) { // (need_update&FULL) || (need_update&INIT)
                int yf = y_offset;
                y = 0;
                while ((row != 0) && (yf < ph)) {
@@ -434,46 +425,30 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
        TEXT(bv)->refresh_y = 0;
        TEXT(bv)->status = LyXText::UNCHANGED;
        if ((need_update != CURSOR_PAR) &&
-               ((drawFrame_ == ALWAYS) || ((drawFrame_ == LOCKED) && locked)))
-               drawFrame(pain, cleared);
-       else if (need_update & CLEAR_FRAME)
-               clearFrame(pain, cleared);
+               ((drawFrame == ALWAYS) || ((drawFrame == LOCKED) && locked)))
+       {
+               pain.rectangle(top_x + 1, baseline - insetAscent + 1,
+                              width(bv, f) - 1,
+                              insetAscent + insetDescent - 1,
+                              frame_color);
+       } else if (need_update & CLEAR_FRAME) {
+               pain.rectangle(top_x + 1, baseline - insetAscent + 1,
+                              width(bv, f) - 1,
+                              insetAscent + insetDescent - 1,
+                              LColor::background);
+       }
        x += width(bv, f) - TEXT_TO_INSET_OFFSET;
        if (bv->text->status==LyXText::CHANGED_IN_DRAW) {
-               need_update |= INIT;
+               need_update = INIT;
        } else if (need_update != INIT)
                need_update = NONE;
 }
 
 
-void InsetText::drawFrame(Painter & pain, bool cleared) const
-{
-       if (!frame_is_visible || cleared) {
-               pain.rectangle(top_x + 1, top_baseline - insetAscent + 1,
-                              insetWidth - 1, insetAscent + insetDescent - 1,
-                              frame_color);
-               frame_is_visible = true;
-       }
-}
-
-
-void InsetText::clearFrame(Painter & pain, bool cleared) const
-{
-       if (frame_is_visible) {
-               if (!cleared) {
-                       pain.rectangle(top_x + 1, top_baseline - insetAscent + 1,
-                                      insetWidth - 1, insetAscent + insetDescent - 1,
-                                      LColor::background);
-               }
-               frame_is_visible = false;
-       }
-}
-
-
 void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
 {
-       if (reinit) {
-               need_update |= INIT;
+       if (reinit) {  // && (need_update != CURSOR)) {
+               need_update = INIT;
                resizeLyXText(bv);
                if (owner())
                        owner()->update(bv, font, true);
@@ -484,39 +459,47 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit)
                inset_y = cy(bv) + drawTextYOffset;
                the_locking_inset->update(bv, font, reinit);
        }
-#if 0
        if (need_update == INIT) {
                resizeLyXText(bv);
-               need_update |= FULL;
+               need_update = FULL;
        }
-#endif
        int oldw = insetWidth;
+#if 1
        insetWidth = TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET);
+       // max(textWidth(bv->painter()),
+       // static_cast<int>(TEXT(bv)->width) + drawTextXOffset) +
+       // (2 * TEXT_TO_INSET_OFFSET);
+#else
+       insetWidth = textWidth(bv);
+       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));
                resizeLyXText(bv);
-               need_update |= FULL;
-//             update(bv, font, reinit);
+               need_update = FULL;
+               update(bv, font, reinit);
                return;
        }
-       if ((need_update&CURSOR_PAR) && (TEXT(bv)->status==LyXText::UNCHANGED) &&
+       if ((need_update == CURSOR_PAR) && (TEXT(bv)->status == LyXText::UNCHANGED) &&
                the_locking_inset)
        {
                TEXT(bv)->UpdateInset(bv, the_locking_inset);
        }
        
        if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
-               need_update |= FULL;
-#if 0
+               need_update = FULL;
+
        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;
-#endif
 }
 
 
-void InsetText::SetUpdateStatus(BufferView * bv, int what) const
+void InsetText::SetUpdateStatus(BufferView * bv, int what)
 {
        need_update |= what;
        if (TEXT(bv)->status == LyXText::NEED_MORE_REFRESH)
@@ -573,7 +556,7 @@ void InsetText::Edit(BufferView * bv, int x, int y, unsigned int button)
        TEXT(bv)->sel_cursor = TEXT(bv)->cursor;
        bv->text->FinishUndo();
        ShowInsetCursor(bv);
-       UpdateLocal(bv, CURSOR, false);
+       UpdateLocal(bv, FULL, false);
 
        // If the inset is empty set the language of the current font to the
        // language to the surronding text.
@@ -659,10 +642,7 @@ bool InsetText::UnlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                if (lr)
                        moveRight(bv, false);
                old_par = 0; // force layout setting
-               if (scroll())
-                       scroll(bv, 0.0F);
-               else
-                       UpdateLocal(bv, CURSOR, false);
+               UpdateLocal(bv, CURSOR_PAR, false);
                return true;
        }
        return the_locking_inset->UnlockInsetInInset(bv, inset, lr);
@@ -1098,8 +1078,8 @@ InsetText::LocalDispatch(BufferView * bv,
                        // and current buffer's textclass (number). */    
                        LyXTextClassList::ClassList::size_type tclass =
                                bv->buffer()->params.textclass;
-                       std::pair <bool, LyXTextClass::size_type> layout = 
-                               textclasslist.NumberOfLayout(tclass, arg);
+                       std::pair<bool, LyXTextClass::size_type> layout = 
+                                       textclasslist.NumberOfLayout(tclass, arg);
 
                        // If the entry is obsolete, use the new one instead.
                        if (layout.first) {
@@ -1112,8 +1092,7 @@ InsetText::LocalDispatch(BufferView * bv,
                        // see if we found the layout number:
                        if (!layout.first) {
                                string const msg = string(N_("Layout ")) + arg + N_(" not known");
-                               bv->owner()->getLyXFunc()
-                                       ->Dispatch(LFUN_MESSAGE, msg);
+                               bv->owner()->message(msg);
                                break;
                        }
 
@@ -1536,7 +1515,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
                inset->Edit(bv, x, y, 0);
                if (!the_locking_inset)
                        return false;
-               UpdateLocal(bv, CURSOR, false);
+               UpdateLocal(bv, CURSOR_PAR, false);
                return true;
        }
        return false;
@@ -1546,10 +1525,8 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool behind)
 bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
                                      int button)
 {
-       int dummyx, dummyy;
-
-       dummyx = x = x - drawTextXOffset;
-       dummyy = y + insetAscent;
+       int dummyx = x = x - drawTextXOffset;
+       int dummyy = y + insetAscent;
        Inset * inset = bv->checkInsetHit(TEXT(bv), dummyx, dummyy, button);
 
        if (inset) {
@@ -1562,7 +1539,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
                inset->Edit(bv, x - inset_x, y - inset_y, button);
                if (!the_locking_inset)
                        return false;
-               UpdateLocal(bv, CURSOR, false);
+               UpdateLocal(bv, CURSOR_PAR, false);
                return true;
        }
        return false;
@@ -1659,8 +1636,8 @@ void InsetText::SetAutoBreakRows(bool flag)
 
 void InsetText::SetDrawFrame(BufferView * bv, DrawFrame how)
 {
-       if (how != drawFrame_) {
-               drawFrame_ = how;
+       if (how != drawFrame) {
+               drawFrame = how;
                if (bv)
                        UpdateLocal(bv, DRAW_FRAME, false);
        }
@@ -1863,31 +1840,3 @@ void InsetText::removeNewlines()
                }
        }
 }
-
-bool InsetText::nodraw() const
-{
-       if (the_locking_inset)
-               return the_locking_inset->nodraw();
-       return UpdatableInset::nodraw();
-}
-
-int InsetText::scroll(bool recursive) const
-{
-       int sx = UpdatableInset::scroll(false);
-
-       if (recursive && the_locking_inset)
-               sx += the_locking_inset->scroll(recursive);
-
-       return sx;
-}
-
-bool InsetText::doClearArea() const
-{
-       return !locked || (need_update & (FULL|INIT));
-}
-/* Emacs:
- * Local variables:
- * tab-width: 4
- * End:
- * vi:set tabstop=4:
- */