From a8286011b8527ed92d857a2de7d0de1381c8434a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 21 May 2003 08:22:25 +0000 Subject: [PATCH] fix drawing bug I forgot that insettext caches its dimensions, so the cache was 0 all the time... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6990 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/ChangeLog | 4 ++++ src/insets/insettext.C | 48 +++++++++++++++++++----------------------- src/insets/insettext.h | 7 ++---- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 955b15835b..9e13ba024e 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,4 +1,8 @@ +2003-05-21 André Pönitz + + * insettext.[Ch]: fix drawing bug introduced earlier + 2003-05-19 André Pönitz * insetspecialchar.C: fix bug introduced yesterday diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 73612da99d..539e6f1f77 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -181,9 +181,6 @@ void InsetText::init(InsetText const * ins, bool same_id) autoBreakRows = false; } top_y = 0; - insetAscent = 0; - insetDescent = 0; - insetWidth = 0; old_max_width = 0; no_selection = true; need_update = FULL; @@ -306,6 +303,8 @@ void InsetText::dimension(BufferView * bv, LyXFont const &, dim.d = text->height - dim.a + TEXT_TO_INSET_OFFSET; dim.w = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET; dim.w = max(dim.w, 10); + // cache it + dim_ = dim; } @@ -339,11 +338,8 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, Painter & pain = bv->painter(); - // call these methods so that insetWidth, insetAscent and - // insetDescent have the right values. - width(bv, f); - ascent(bv, f); - descent(bv, f); + // call this method so that dim_ has the right value + dimension(bv, f, dim_); // repaint the background if needed if (backgroundColor() != LColor::background) @@ -361,11 +357,11 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, x += static_cast(scroll()); top_baseline = baseline; - top_y = baseline - insetAscent; + top_y = baseline - dim_.a; - if (last_drawn_width != insetWidth) { + if (last_drawn_width != dim_.w) { need_update |= FULL; - last_drawn_width = insetWidth; + last_drawn_width = dim_.w; } if (the_locking_inset && (cpar(bv) == inset_par) @@ -421,7 +417,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f, drawFrame(pain, int(start_x)); } - x += insetWidth - TEXT_TO_INSET_OFFSET; + x += dim_.w - TEXT_TO_INSET_OFFSET; if (need_update != INIT) { need_update = NONE; @@ -435,9 +431,9 @@ void InsetText::drawFrame(Painter & pain, int x) const { static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2; frame_x = x + ttoD2; - frame_y = top_baseline - insetAscent + ttoD2; - frame_w = insetWidth - TEXT_TO_INSET_OFFSET; - frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET; + frame_y = top_baseline - dim_.a + ttoD2; + frame_w = dim_.w - TEXT_TO_INSET_OFFSET; + frame_h = dim_.a + dim_.d - TEXT_TO_INSET_OFFSET; pain.rectangle(frame_x, frame_y, frame_w, frame_h, frame_color); } @@ -811,7 +807,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd) lockInset(bv); int tmp_x = cmd.x - drawTextXOffset; - int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y(); + int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y(); Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y); if (the_locking_inset) { @@ -854,7 +850,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd) int old_top_y = lt->top_y(); lt->setCursorFromCoordinates(cmd.x - drawTextXOffset, - cmd.y + insetAscent); + cmd.y + dim_.a); // set the selection cursor! lt->selection.cursor = lt->cursor; lt->cursor.x_fix(lt->cursor.x()); @@ -903,7 +899,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd) return the_locking_inset->localDispatch(cmd1); int tmp_x = cmd.x - drawTextXOffset; - int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y(); + int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y(); Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y); bool ret = false; if (inset) { @@ -954,7 +950,7 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd) } LyXCursor cur = lt->cursor; lt->setCursorFromCoordinates - (cmd.x - drawTextXOffset, cmd.y + insetAscent); + (cmd.x - drawTextXOffset, cmd.y + dim_.a); lt->cursor.x_fix(lt->cursor.x()); if (cur == lt->cursor) { if (clear) @@ -1016,7 +1012,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd) // FIXME: GUII I've changed this to none: probably WRONG if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) { lt->setCursorFromCoordinates(cmd.x - drawTextXOffset, - cmd.y + insetAscent); + cmd.y + dim_.a); lt->cursor.x_fix(lt->cursor.x()); } } @@ -1897,7 +1893,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, { x -= drawTextXOffset; int dummyx = x; - int dummyy = y + insetAscent; + int dummyy = y + dim_.a; Inset * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy); // we only do the edit() call if the inset was hit by the mouse // or if it is a highly editable inset. So we should call this @@ -1909,9 +1905,9 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, if (inset) { if (x < 0) - x = insetWidth; + x = dim_.w; if (y < 0) - y = insetDescent; + y = dim_.d; inset_x = cix(bv) - top_x + drawTextXOffset; inset_y = ciy(bv) + drawTextYOffset; FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button); @@ -2319,9 +2315,9 @@ void InsetText::clearSelection(BufferView * bv) void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const { Painter & pain = bv->painter(); - int w = insetWidth; - int h = insetAscent + insetDescent; - int ty = baseline - insetAscent; + int w = dim_.w; + int h = dim_.a + dim_.d; + int ty = baseline - dim_.a; if (ty < 0) { h += ty; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 82d9dbbb64..06054ba373 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -17,6 +17,7 @@ #include "LColor.h" #include "ParagraphList.h" #include "RowList.h" +#include "dimension.h" #include "frontends/mouse_state.h" #include "support/types.h" @@ -347,11 +348,7 @@ private: /// mutable bool locked; /// - mutable int insetAscent; - /// - mutable int insetDescent; - /// - mutable int insetWidth; + mutable Dimension dim_; /// mutable int top_y; /// -- 2.39.5