From 6b22f0e42393c9125281462841d5c5b37872e34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 10 Nov 2003 15:38:20 +0000 Subject: [PATCH] coordinate cache IU git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8071 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/ChangeLog | 3 +++ src/insets/inset.C | 4 ++-- src/insets/inset.h | 8 ++++---- src/insets/insetcollapsable.C | 6 +++--- src/insets/insetcommand.C | 2 ++ src/insets/insettabular.C | 22 +++++++++++----------- src/insets/insettext.C | 12 ++++++------ src/insets/insettoc.C | 4 ---- src/insets/updatableinset.C | 22 +++++++++++----------- src/mathed/formula.C | 10 +++------- src/mathed/formulabase.C | 7 ++----- src/mathed/formulabase.h | 5 ----- 12 files changed, 47 insertions(+), 58 deletions(-) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 6db96b2093..7c6dab1af8 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -3,6 +3,9 @@ * inset.h: remove Inset::id_ + * inset.h: top_x -> xo_, top_baseline -> yo_ to unify with mathed/*.[Ch] + * *.[Ch]: adjust + 2003-11-10 André Pönitz * inset.[Ch]: diff --git a/src/insets/inset.C b/src/insets/inset.C index ea46d9fd8e..f533708967 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -26,14 +26,14 @@ using std::string; InsetOld::InsetOld() : InsetBase(), - top_x(0), top_baseline(0), scx(0), owner_(0), + xo_(0), yo_(0), scx(0), owner_(0), background_color_(LColor::inherit) {} InsetOld::InsetOld(InsetOld const & in) : InsetBase(), - top_x(0), top_baseline(0), scx(0), owner_(0), + xo_(0), yo_(0), scx(0), owner_(0), name_(in.name_), background_color_(in.background_color_) {} diff --git a/src/insets/inset.h b/src/insets/inset.h index c4240756b6..0a477651be 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -213,9 +213,9 @@ public: /// LColor_color backgroundColor() const; /// - int x() const { return top_x; } + int x() const { return xo_; } /// - int y() const { return top_baseline; } + int y() const { return yo_; } /// virtual void deleteLyXText(BufferView *, bool = true) const {} /// returns the actuall scroll-value @@ -288,9 +288,9 @@ public: virtual void addPreview(lyx::graphics::PreviewLoader &) const {} protected: /// - mutable int top_x; + mutable int xo_; /// - mutable int top_baseline; + mutable int yo_; /// mutable int scx; /// diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index c129f3c967..e7313e0ab1 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -146,8 +146,8 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const button_dim.y1 = -aa; button_dim.y2 = -aa + dim_collapsed.height(); - top_x = x; - top_baseline = y; + xo_ = x; + yo_ = y; if (!isOpen()) { draw_collapsed(pi, x, y); @@ -327,7 +327,7 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) int InsetCollapsable::insetInInsetY() const { - return inset.y() - top_baseline + inset.insetInInsetY(); + return inset.y() - yo_ + inset.insetInInsetY(); } diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 207a56d2e7..713fbd3555 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -48,6 +48,8 @@ void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const void InsetCommand::draw(PainterInfo & pi, int x, int y) const { + xo_ = x; + yo_ = y; button_.draw(pi, x, y); } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index d293e1d611..e0fec53c00 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -255,8 +255,8 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const if (!owner()) x += scroll(); - top_x = x; - top_baseline = y; + xo_ = x; + yo_ = y; x += ADD_TO_TABULAR_WIDTH; int cell = 0; @@ -474,7 +474,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y) setPos(bv, x, y); clearSelection(); finishUndo(); - int xx = cursorx_ - top_x + tabular.getBeginningOfTextInCell(actcell); + int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell); bv->cursor().push(this); if (x > xx) activateCellInset(bv, x - xx, y - cursory_); @@ -623,7 +623,7 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) clearSelection(); int column = actcol; if (bv->top_y() + bv->painter().paperHeight() - < top_baseline + tabular.getHeightOfTabular()) + < yo_ + tabular.getHeightOfTabular()) { bv->scrollDocView(bv->top_y() + bv->painter().paperHeight()); actcell = tabular.getCellBelow(first_visible_cell) + column; @@ -638,9 +638,9 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) if (hs) clearSelection(); int column = actcol; - if (top_baseline < 0) { + if (yo_ < 0) { bv->scrollDocView(bv->top_y() - bv->painter().paperHeight()); - if (top_baseline > 0) + if (yo_ > 0) actcell = column; else actcell = tabular.getCellBelow(first_visible_cell) + column; @@ -968,7 +968,7 @@ void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const void InsetTabular::getCursorPos(BufferView *, int & x, int & y) const { - x = TEXT_TO_INSET_OFFSET + cursorx_ - top_x; + x = TEXT_TO_INSET_OFFSET + cursorx_ - xo_; y = TEXT_TO_INSET_OFFSET + cursory_; } @@ -1015,7 +1015,7 @@ void InsetTabular::setPos(BufferView * bv, int x, int y) const lx += tabular.getWidthOfColumn(actcell + 1) + tabular.getAdditionalWidth(actcell); - cursorx_ = lx - tabular.getWidthOfColumn(actcell) + top_x + 2; + cursorx_ = lx - tabular.getWidthOfColumn(actcell) + xo_ + 2; resetPos(bv); } @@ -1030,7 +1030,7 @@ int InsetTabular::getCellXPos(int cell) const for (; c < cell; ++c) lx += tabular.getWidthOfColumn(c); - return lx - tabular.getWidthOfColumn(cell) + top_x; + return lx - tabular.getWidthOfColumn(cell) + xo_; } @@ -1091,8 +1091,8 @@ void InsetTabular::resetPos(BufferView * bv) const } else if (cursorx_ - offset < 20) { scroll(bv, 20 - cursorx_ + offset); updateLocal(bv); - } else if (scroll() && top_x > 20 && - top_x + tabular.getWidthOfTabular() > bv->workWidth() - 20) { + } else if (scroll() && xo_ > 20 && + xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) { scroll(bv, old_x - cursorx_); updateLocal(bv); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index a871874b53..56a718e4e2 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -241,8 +241,8 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const { // update our idea of where we are. Clearly, we should // not have to know this information. - top_x = x; - top_baseline = y; + xo_ = x; + yo_ = y; int const start_x = x; @@ -271,7 +271,7 @@ void InsetText::drawFrame(Painter & pain, int x) const { int const ttoD2 = TEXT_TO_INSET_OFFSET / 2; int const frame_x = x + ttoD2; - int const frame_y = top_baseline - dim_.asc + ttoD2; + int const frame_y = yo_ - dim_.asc + ttoD2; int const frame_w = dim_.wid - TEXT_TO_INSET_OFFSET; int const frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET; pain.rectangle(frame_x, frame_y, frame_w, frame_h, frameColor()); @@ -689,7 +689,7 @@ void InsetText::validate(LaTeXFeatures & features) const void InsetText::getCursorPos(BufferView *, int & x, int & y) const { - x = cx() - top_x; + x = cx() - xo_; y = cy(); } @@ -918,7 +918,7 @@ void InsetText::setFrameColor(LColor_color col) int InsetText::cx() const { - return text_.cursor.x() + top_x + TEXT_TO_INSET_OFFSET; + return text_.cursor.x() + xo_ + TEXT_TO_INSET_OFFSET; } @@ -1006,7 +1006,7 @@ void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const } if (ty + h > pain.paperHeight()) h = pain.paperHeight(); - if (top_x + w > pain.paperWidth()) + if (xo_ + w > pain.paperWidth()) w = pain.paperWidth(); pain.fillRectangle(start_x + 1, ty + 1, w - 3, h - 1, backgroundColor()); } diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index c345421baa..4811e1d1d0 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -80,10 +80,6 @@ InsetTOC::priv_dispatch(FuncRequest const & cmd, { switch (cmd.action) { case LFUN_MOUSE_RELEASE: - if (button().box().contains(cmd.x, cmd.y)) - InsetCommandMailer("toc", *this).showDialog(cmd.view()); - return DispatchResult(true, true); - case LFUN_INSET_DIALOG_SHOW: InsetCommandMailer("toc", *this).showDialog(cmd.view()); return DispatchResult(true, true); diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index 0bc7e235d3..8463104b8d 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -47,37 +47,37 @@ void UpdatableInset::scroll(BufferView * bv, float s) const } int const workW = bv->workWidth(); - int const tmp_top_x = top_x - scx; + int const tmp_xo_ = xo_ - scx; - if (tmp_top_x > 0 && tmp_top_x + width() < workW) + if (tmp_xo_ > 0 && tmp_xo_ + width() < workW) return; - if (s > 0 && top_x > 0) + if (s > 0 && xo_ > 0) return; scx = int(s * workW / 2); #warning metrics? - if (tmp_top_x + scx + width() < workW / 2) - scx = workW / 2 - tmp_top_x - width(); + if (tmp_xo_ + scx + width() < workW / 2) + scx = workW / 2 - tmp_xo_ - width(); } void UpdatableInset::scroll(BufferView * bv, int offset) const { if (offset > 0) { - if (!scx && top_x >= 20) + if (!scx && xo_ >= 20) return; - if (top_x + offset > 20) + if (xo_ + offset > 20) scx = 0; - // scx = - top_x; + // scx = - xo_; else scx += offset; } else { #warning metrics? - if (!scx && top_x + width() < bv->workWidth() - 20) + if (!scx && xo_ + width() < bv->workWidth() - 20) return; - if (top_x - scx + offset + width() < bv->workWidth() - 20) { - scx += bv->workWidth() - width() - top_x - 20; + if (xo_ - scx + offset + width() < bv->workWidth() - 20) { + scx += bv->workWidth() - width() - xo_ - 20; } else { scx += offset; } diff --git a/src/mathed/formula.C b/src/mathed/formula.C index b6d94ee065..5c3a71e493 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -195,6 +195,9 @@ bool editing_inset(InsetFormula const * inset) void InsetFormula::draw(PainterInfo & pi, int x, int y) const { + xo_ = x; + yo_ = y; + // The previews are drawn only when we're not editing the inset. bool const use_preview = !editing_inset(this) && RenderPreview::activated() @@ -224,13 +227,6 @@ void InsetFormula::draw(PainterInfo & pi, int x, int y) const par_->draw(p, x, y); } - - xo_ = x; - yo_ = y; - - top_x = x; - top_baseline = y; - } diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 1ce996a4e5..7ba15987d9 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -78,7 +78,6 @@ bool openNewInset(BufferView * bv, UpdatableInset * inset) InsetFormulaBase::InsetFormulaBase() - : xo_(0), yo_(0) { // This is needed as long the math parser is not re-entrant initMath(); @@ -173,12 +172,10 @@ void InsetFormulaBase::getCursor(BufferView &, int & x, int & y) const void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const { - // calling metrics here destroys the cached xo,yo positions e.g. in - // MathParboxinset. And it would be too expensive anyway... - //metrics(bv); if (!mathcursor) { lyxerr << "getCursorPos - should not happen"; - x = y = 0; + x = 0; + y = 0; return; } mathcursor->getPos(x, y); diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 3f93f4c452..f79f69662d 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -116,11 +116,6 @@ protected: void handleFont(BufferView * bv, std::string const & arg, std::string const & font); /// void handleFont2(BufferView * bv, std::string const & arg); - - /// - mutable int xo_; - /// - mutable int yo_; }; // We don't really mess want around with mathed stuff outside mathed.