From 57501b93064a6deed43e415beed45606054d86ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 6 Apr 2004 19:25:39 +0000 Subject: [PATCH] several small fixes for mathed git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8614 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulamacro.C | 3 +- src/mathed/math_amsarrayinset.C | 6 ++-- src/mathed/math_arrayinset.C | 5 +--- src/mathed/math_commentinset.C | 6 ++-- src/mathed/math_data.C | 31 +------------------- src/mathed/math_data.h | 2 -- src/mathed/math_factory.C | 2 ++ src/mathed/math_factory.h | 3 +- src/mathed/math_gridinset.C | 2 ++ src/mathed/math_hullinset.C | 50 ++++++++++++++++++++++++--------- src/mathed/math_hullinset.h | 5 ++++ src/mathed/math_inset.C | 7 ----- src/mathed/math_inset.h | 3 -- src/mathed/math_macro.C | 13 ++++----- src/mathed/math_macrotemplate.C | 3 +- src/mathed/math_nestinset.C | 4 +++ src/mathed/math_substackinset.C | 2 -- 17 files changed, 68 insertions(+), 79 deletions(-) diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index adbd153a89..9d72784403 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -77,7 +77,7 @@ void InsetFormulaMacro::write(Buffer const &, ostream & os) const int InsetFormulaMacro::latex(Buffer const &, ostream & os, OutputParams const & runparams) const { - lyxerr << "InsetFormulaMacro::latex" << endl; + //lyxerr << "InsetFormulaMacro::latex" << endl; WriteStream wi(os, runparams.moving_arg, true); tmpl()->write(wi); return 2; @@ -129,6 +129,7 @@ string InsetFormulaMacro::prefix() const void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const { + //lyxerr << "InsetFormulaMacro: " << this << " -- " << &tmpl() << endl; tmpl()->metrics(mi, dim); dim.asc += 5; dim.des += 5; diff --git a/src/mathed/math_amsarrayinset.C b/src/mathed/math_amsarrayinset.C index 1287d99a3f..561faa2248 100644 --- a/src/mathed/math_amsarrayinset.C +++ b/src/mathed/math_amsarrayinset.C @@ -73,9 +73,9 @@ void MathAMSArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const MetricsInfo m = mi; if (m.base.style == LM_ST_DISPLAY) m.base.style = LM_ST_TEXT; - MathGridInset::metrics(m); - dim_.wid += 12; - dim = dim_; + MathGridInset::metrics(m, dim); + dim.wid += 12; + dim_ = dim; } diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index 5794ee7913..1520ec5385 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -78,9 +78,7 @@ auto_ptr MathArrayInset::clone() const void MathArrayInset::metrics(MetricsInfo & mi, Dimension & dim) const { ArrayChanger dummy(mi.base); - MathGridInset::metrics(mi); - metricsMarkers2(dim_); - dim = dim_; + MathGridInset::metrics(mi, dim); } @@ -88,7 +86,6 @@ void MathArrayInset::draw(PainterInfo & pi, int x, int y) const { ArrayChanger dummy(pi.base); MathGridInset::draw(pi, x + 1, y); - drawMarkers2(pi, x, y); } diff --git a/src/mathed/math_commentinset.C b/src/mathed/math_commentinset.C index 232710c83c..0d82240115 100644 --- a/src/mathed/math_commentinset.C +++ b/src/mathed/math_commentinset.C @@ -40,9 +40,9 @@ auto_ptr MathCommentInset::clone() const void MathCommentInset::metrics(MetricsInfo & mi, Dimension & dim) const { - cell(0).metrics(mi); - metricsMarkers(dim_); - dim = dim_; + cell(0).metrics(mi, dim); + metricsMarkers(dim); + dim_ = dim; } diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 7617621047..e684db5650 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -264,6 +264,7 @@ void MathArray::draw(PainterInfo & pi, int x, int y) const for (const_iterator it = begin(), et = end(); it != et; ++it) { //pi.width = it->width_; + (*it)->drawSelection(pi, x, y); (*it)->draw(pi, x, y); x += (*it)->width(); } @@ -406,33 +407,3 @@ void MathArray::setXY(int x, int y) const xo_ = x; yo_ = y; } - - -void MathArray::notifyCursorLeaves() -{ - // do not recurse! - -/* - // remove base-only "scripts" - for (pos_type i = 0; i + 1 < size(); ++i) { - MathScriptInset * p = operator[](i).nucleus()->asScriptInset(); - if (p && p->cell(0).empty() && p->cell(1).empty()) { - MathArray ar = p->nuc(); - erase(i); - insert(i, ar); - mathcursor->adjust(i, ar.size() - 1); - } - } - - // glue adjacent font insets of the same kind - for (pos_type i = 0; i + 1 < size(); ++i) { - MathFontInset * p = operator[](i).nucleus()->asFontInset(); - MathFontInset const * q = operator[](i + 1)->asFontInset(); - if (p && q && p->name() == q->name()) { - p->cell(0).append(q->cell(0)); - erase(i + 1); - mathcursor->adjust(i, -1); - } - } -*/ -} diff --git a/src/mathed/math_data.h b/src/mathed/math_data.h index 87ed99c495..89c116cce3 100644 --- a/src/mathed/math_data.h +++ b/src/mathed/math_data.h @@ -154,8 +154,6 @@ public: void center(int & x, int & y) const; /// adjust (x,y) to point on boundary on a straight line from the center void towards(int & x, int & y) const; - /// clean up if necessary - void notifyCursorLeaves(); private: /// is this an exact match at this position? diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index dbf0223d3d..cc76614ab5 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -55,9 +55,11 @@ #include "debug.h" #include "math_support.h" + #include "support/std_sstream.h" #include "support/filetools.h" // LibFileSearch #include "support/lstrings.h" + #include "frontends/lyx_gui.h" #include diff --git a/src/mathed/math_factory.h b/src/mathed/math_factory.h index 6ff6af41bd..e5aac336b0 100644 --- a/src/mathed/math_factory.h +++ b/src/mathed/math_factory.h @@ -12,13 +12,12 @@ #ifndef MATH_FACTORY_H #define MATH_FACTORY_H - #include - class MathAtom; class MathArray; + MathAtom createMathInset(std::string const &); /** Fills ar with the contents of str. diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 230c80144c..e93297b9ae 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -458,6 +458,7 @@ void MathGridInset::metrics(MetricsInfo & mi) const cxrow->setBaseline(cxrow->getBaseline() - ascent); } */ + metricsMarkers2(dim_); } @@ -490,6 +491,7 @@ void MathGridInset::draw(PainterInfo & pi, int x, int y) const xx, y + dim_.descent() - 1, LColor::foreground); } + drawMarkers2(pi, x, y); } diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 3cb51fbbbd..4be4d74974 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -224,8 +224,6 @@ void MathHullInset::metrics(MetricsInfo & mi, Dimension & dim) const dim.asc = max(dim.asc, asc); dim.des = max(dim.des, des); - // for markers - metricsMarkers2(dim); dim_ = dim; } @@ -244,8 +242,6 @@ void MathHullInset::draw(PainterInfo & pi, int x, int y) const drawStr(pi, pi.base.font, xx, yy, nicelabel(row)); } } - - drawMarkers2(pi, x, y); } @@ -787,7 +783,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest & func) void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) { - //lyxerr << "*** MathHullInset: request: " << cmd << endl; + lyxerr << "*** MathHullInset: request: " << cmd << endl; switch (cmd.action) { case LFUN_BREAKLINE: @@ -796,10 +792,10 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) cur.idx() = 1; cur.pos() = 0; //cur.dispatched(FINISHED); - return; + break; } MathGridInset::priv_dispatch(cur, cmd); - return; + break; case LFUN_MATH_NUMBER: //lyxerr << "toggling all numbers" << endl; @@ -813,7 +809,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) numbered(row, !old); cur.message(old ? _("No number") : _("Number")); } - return; + break; case LFUN_MATH_NONUMBER: if (display()) { @@ -823,7 +819,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) cur.message(old ? _("No number") : _("Number")); numbered(r, !old); } - return; + break; case LFUN_INSERT_LABEL: { row_type r = (type_ == "multline") ? nrows() - 1 : cur.row(); @@ -842,13 +838,13 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) if (!new_label.empty()) numbered(r, true); label(r, new_label); - return; + break; } case LFUN_MATH_EXTERN: doExtern(cur, cmd); //cur.dispatched(FINISHED); - return; + break; case LFUN_MATH_MUTATE: { lyxerr << "Hull: MUTATE: " << cmd.argument << endl; @@ -863,7 +859,7 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) if (cur.pos() > cur.lastpos()) cur.pos() = cur.lastpos(); //cur.dispatched(FINISHED); - return; + break; } case LFUN_MATH_DISPLAY: { @@ -871,12 +867,31 @@ void MathHullInset::priv_dispatch(LCursor & cur, FuncRequest & cmd) cur.idx() = 0; cur.pos() = cur.lastpos(); //cur.dispatched(FINISHED); - return; + break; } default: MathGridInset::priv_dispatch(cur, cmd); - return; + break; + } +} + + +bool MathHullInset::getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & flag) const +{ + switch (cmd.action) { + case LFUN_BREAKLINE: + case LFUN_MATH_NUMBER: + case LFUN_MATH_NONUMBER: + case LFUN_INSERT_LABEL: + case LFUN_MATH_EXTERN: + case LFUN_MATH_MUTATE: + case LFUN_MATH_DISPLAY: + // we handle these + return true; + default: + return MathGridInset::getStatus(cur, cmd, flag); } } @@ -960,6 +975,13 @@ void MathHullInset::handleFont2(LCursor & cur, string const & arg) } +void MathHullInset::edit(LCursor & cur, bool left) +{ + lyxerr << "MathHullInset: edit left/right" << endl; + cur.push(*this); +} + + string const MathHullInset::editMessage() const { return _("Math editor mode"); diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 8981910fb5..f8ac234db3 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -118,6 +118,9 @@ public: protected: /// void priv_dispatch(LCursor & cur, FuncRequest & cmd); + /// do we want to handle this event? + bool getStatus(LCursor & cur, FuncRequest const & cmd, + FuncStatus & status) const; /// std::string eolString(row_type row, bool fragile) const; @@ -177,6 +180,8 @@ public: /// virtual EDITABLE editable() const { return HIGHLY_EDITABLE; } /// + void edit(LCursor & cur, bool left); + /// bool display() const; /// Code lyxCode() const; diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 0d25b77716..a8ce515c52 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -51,13 +51,6 @@ void MathInset::dump() const } -void MathInset::drawSelection(PainterInfo &, - idx_type, pos_type, idx_type, pos_type) const -{ - lyxerr << "MathInset::drawSelection() called directly!" << endl; -} - - void MathInset::metricsT(TextMetricsInfo const &, Dimension &) const { #ifdef WITH_WARNINGS diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 36ee2b1ac6..11716f1382 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -82,9 +82,6 @@ public: /// substitutes macro arguments if necessary virtual void substitute(MathMacro const & macro); - /// draw selection between two positions - virtual void drawSelection(PainterInfo & pi, - idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const; /// the ascent of the inset above the baseline /// compute the size of the object for text based drawing virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const; diff --git a/src/mathed/math_macro.C b/src/mathed/math_macro.C index eba161e677..98b792fbc2 100644 --- a/src/mathed/math_macro.C +++ b/src/mathed/math_macro.C @@ -55,8 +55,8 @@ string MathMacro::name() const bool MathMacro::defining() const { - return 0; - //return mathcursor && mathcursor->formula()->getInsetName() == name(); + return false; + //return mathcursor->formula()->getInsetName() == name(); } @@ -78,7 +78,7 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const } else if (editing(mi.base.bv)) { expand(); - expanded_.metrics(mi_, dim); + expanded_.metrics(mi, dim); metricsMarkers(dim); dim.wid += mathed_string_width(font_, name()) + 10; @@ -87,17 +87,16 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const for (idx_type i = 0; i < nargs(); ++i) { MathArray const & c = cell(i); - c.metrics(mi_); + c.metrics(mi); dim.wid = max(dim.wid, c.width() + ww); - dim.des += max(c.ascent(), dim.asc) + 5; - dim.des += max(c.descent(), dim.des) + 5; + dim.des += c.height() + 10; } } else { expand(); expanded_.substitute(*this); - expanded_.metrics(mi_, dim); + expanded_.metrics(mi, dim); } diff --git a/src/mathed/math_macrotemplate.C b/src/mathed/math_macrotemplate.C index 90e0e49ac0..30290a466c 100644 --- a/src/mathed/math_macrotemplate.C +++ b/src/mathed/math_macrotemplate.C @@ -17,12 +17,12 @@ #include "debug.h" #include "LColor.h" - using std::string; using std::auto_ptr; using std::endl; + MathMacroTemplate::MathMacroTemplate() : MathNestInset(2), numargs_(0), name_(), type_("newcommand") {} @@ -81,6 +81,7 @@ string MathMacroTemplate::name() const void MathMacroTemplate::metrics(MetricsInfo & mi, Dimension & dim) const { + lyxerr << "drawing template " << name() << ' ' << this << std::endl; cell(0).metrics(mi); cell(1).metrics(mi); dim.wid = cell(0).width() + cell(1).width() + 10; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 704685389c..0a9fd56874 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -194,6 +194,8 @@ void MathNestInset::draw(PainterInfo &, int, int) const void MathNestInset::drawSelection(PainterInfo & pi, int, int) const { + //lyxerr << "MathNestInset::drawing selection: " + // << " x: " << x << " y: " << y << endl; // this should use the x/y values given, not the cached values LCursor & cur = pi.base.bv->cursor(); if (!cur.selection()) @@ -202,6 +204,8 @@ void MathNestInset::drawSelection(PainterInfo & pi, int, int) const return; CursorSlice s1 = cur.selBegin(); CursorSlice s2 = cur.selEnd(); + lyxerr << "MathNestInset::drawing selection: " + << " s1: " << s1 << " s2: " << s2 << endl; if (s1.idx() == s2.idx()) { MathArray const & c = cell(s1.idx()); int x1 = c.xo() + c.pos2x(s1.pos()); diff --git a/src/mathed/math_substackinset.C b/src/mathed/math_substackinset.C index ce15a19a48..696a9986e9 100644 --- a/src/mathed/math_substackinset.C +++ b/src/mathed/math_substackinset.C @@ -37,7 +37,6 @@ void MathSubstackInset::metrics(MetricsInfo & mi, Dimension & dim) const } else { MathGridInset::metrics(mi, dim); } - metricsMarkers(dim); dim_ = dim; } @@ -45,7 +44,6 @@ void MathSubstackInset::metrics(MetricsInfo & mi, Dimension & dim) const void MathSubstackInset::draw(PainterInfo & pi, int x, int y) const { MathGridInset::draw(pi, x + 1, y); - drawMarkers(pi, x, y); } -- 2.39.2