several small fixes for mathed

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8614 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-04-06 19:25:39 +00:00
parent 5b992e53e5
commit 57501b9306
17 changed files with 68 additions and 79 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -78,9 +78,7 @@ auto_ptr<InsetBase> 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);
}

View File

@ -40,9 +40,9 @@ auto_ptr<InsetBase> 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;
}

View File

@ -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);
}
}
*/
}

View File

@ -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?

View File

@ -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 <fstream>

View File

@ -12,13 +12,12 @@
#ifndef MATH_FACTORY_H
#define MATH_FACTORY_H
#include <string>
class MathAtom;
class MathArray;
MathAtom createMathInset(std::string const &);
/** Fills ar with the contents of str.

View File

@ -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);
}

View File

@ -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");

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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());

View File

@ -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);
}