2001-06-25 00:06:33 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
* \file InsetMathScript.h
|
2003-08-19 13:00:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifndef MATH_SCRIPTINSET_H
|
|
|
|
#define MATH_SCRIPTINSET_H
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathNest.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
// An inset for super- and subscripts or both. The 'nucleus' is always
|
|
|
|
// cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
|
|
|
|
// is set accordingly. If both are used, cell 1 is up and cell 2 is down.
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
class InsetMathScript : public InsetMathNest {
|
2001-06-25 00:06:33 +00:00
|
|
|
public:
|
2001-11-26 13:35:08 +00:00
|
|
|
/// create inset without scripts
|
2019-09-15 21:56:17 +00:00
|
|
|
explicit InsetMathScript(Buffer * buf);
|
2001-11-26 13:35:08 +00:00
|
|
|
/// create inset with single script
|
2009-11-08 11:45:46 +00:00
|
|
|
explicit InsetMathScript(Buffer * buf, bool up);
|
2002-07-30 13:56:02 +00:00
|
|
|
/// create inset with single script and given nucleus
|
2009-11-08 11:45:46 +00:00
|
|
|
InsetMathScript(Buffer * buf, MathAtom const & at, bool up);
|
2001-06-25 00:06:33 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
mode_type currentMode() const override { return MATH_MODE; }
|
2020-12-09 08:39:49 +00:00
|
|
|
/// whether the inset has limit-like sub/superscript
|
|
|
|
Limits limits() const override;
|
|
|
|
/// sets types of sub/superscripts
|
|
|
|
void limits(Limits lim) override;
|
2005-11-28 10:23:19 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
MathClass mathClass() const override;
|
2016-05-30 08:33:35 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim) const override;
|
2001-07-26 06:46:50 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const override;
|
2002-03-18 11:45:53 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void metricsT(TextMetricsInfo const & mi, Dimension & dim) const override;
|
2002-03-18 11:45:53 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void drawT(TextPainter & pi, int x, int y) const override;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
2007-11-05 19:44:03 +00:00
|
|
|
/// move cursor backwards
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxBackward(Cursor & cur) const override;
|
2007-11-05 19:44:03 +00:00
|
|
|
/// move cursor forward
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxForward(Cursor & cur) const override;
|
2004-01-26 10:13:15 +00:00
|
|
|
/// move cursor up or down
|
2020-10-01 07:42:11 +00:00
|
|
|
bool idxUpDown(Cursor & cur, bool up) const override;
|
2018-04-04 16:24:14 +00:00
|
|
|
/// The index of the cell entered while moving backward
|
2020-10-03 12:42:14 +00:00
|
|
|
size_type lastIdx() const override { return 0; }
|
2004-01-26 10:13:15 +00:00
|
|
|
|
2002-07-30 13:56:02 +00:00
|
|
|
/// write LaTeX and Lyx code
|
2020-12-26 19:04:36 +00:00
|
|
|
void write(TeXMathStream & os) const override;
|
2002-07-30 13:56:02 +00:00
|
|
|
/// write normalized content
|
2020-10-01 07:42:11 +00:00
|
|
|
void normalize(NormalStream &) const override;
|
2002-07-30 13:56:02 +00:00
|
|
|
/// write content as something readable by Maple
|
2020-10-01 07:42:11 +00:00
|
|
|
void maple(MapleStream &) const override;
|
2002-07-30 13:56:02 +00:00
|
|
|
/// write content as something readable by Mathematica
|
2020-10-01 07:42:11 +00:00
|
|
|
void mathematica(MathematicaStream &) const override;
|
2010-03-30 01:31:25 +00:00
|
|
|
/// write content as MathML
|
2020-12-26 19:02:46 +00:00
|
|
|
void mathmlize(MathMLStream &) const override;
|
2010-03-30 01:31:25 +00:00
|
|
|
/// write content as HTML
|
2020-10-01 07:42:11 +00:00
|
|
|
void htmlize(HtmlStream &) const override;
|
2002-07-30 13:56:02 +00:00
|
|
|
/// write content as something readable by Octave
|
2020-10-01 07:42:11 +00:00
|
|
|
void octave(OctaveStream &) const override;
|
2001-10-12 15:38:58 +00:00
|
|
|
|
2001-11-26 13:35:08 +00:00
|
|
|
/// identifies scriptinsets
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetMathScript const * asScriptInset() const override;
|
2001-09-24 16:25:06 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetMathScript * asScriptInset() override;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
2004-04-05 16:31:52 +00:00
|
|
|
/// returns subscript. Always run 'hasDown' or 'has(false)' before!
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData const & down() const;
|
2004-04-05 16:31:52 +00:00
|
|
|
/// returns subscript. Always run 'hasDown' or 'has(false)' before!
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & down();
|
2004-04-05 16:31:52 +00:00
|
|
|
/// returns superscript. Always run 'hasUp' or 'has(true)' before!
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData const & up() const;
|
2004-04-05 16:31:52 +00:00
|
|
|
/// returns superscript. Always run 'hasUp' or 'has(true)' before!
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & up();
|
2002-07-30 13:56:02 +00:00
|
|
|
/// returns nucleus
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData const & nuc() const;
|
2002-07-30 13:56:02 +00:00
|
|
|
/// returns nucleus
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & nuc();
|
2001-10-12 12:02:49 +00:00
|
|
|
/// do we have a superscript?
|
|
|
|
bool hasUp() const;
|
|
|
|
/// do we have a subscript?
|
|
|
|
bool hasDown() const;
|
|
|
|
/// do we have a script?
|
|
|
|
bool has(bool up) const;
|
2004-03-25 09:16:36 +00:00
|
|
|
/// what idx has super/subscript?
|
|
|
|
idx_type idxOfScript(bool up) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// remove script
|
|
|
|
void removeScript(bool up);
|
2001-11-26 13:35:08 +00:00
|
|
|
/// make sure a script is accessible
|
2001-10-12 12:02:49 +00:00
|
|
|
void ensure(bool up);
|
2003-01-07 11:24:43 +00:00
|
|
|
/// say that we have scripts
|
2020-10-01 07:42:11 +00:00
|
|
|
void infoize(odocstream & os) const override;
|
2003-01-07 11:24:43 +00:00
|
|
|
/// say whether we have displayed limits
|
2020-10-01 07:42:11 +00:00
|
|
|
void infoize2(odocstream & os) const override;
|
2009-07-16 19:00:24 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
InsetCode lyxCode() const override { return MATH_SCRIPT_CODE; }
|
2010-03-30 01:31:25 +00:00
|
|
|
///
|
2020-10-01 07:42:11 +00:00
|
|
|
void validate(LaTeXFeatures &features) const override;
|
2002-07-30 13:56:02 +00:00
|
|
|
private:
|
2020-10-01 07:42:11 +00:00
|
|
|
Inset * clone() const override;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns x offset for main part
|
2007-09-23 22:39:49 +00:00
|
|
|
int dxx(BufferView const & bv) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns width of nucleus if any
|
2007-09-24 13:52:04 +00:00
|
|
|
int nwid(BufferView const &) const;
|
2007-03-18 15:00:57 +00:00
|
|
|
/// returns y offset for either superscript or subscript
|
2007-09-24 13:52:04 +00:00
|
|
|
int dy01(BufferView const &, int asc, int des, int what) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns y offset for superscript
|
2007-09-24 13:52:04 +00:00
|
|
|
int dy0(BufferView const &) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns y offset for subscript
|
2007-09-24 13:52:04 +00:00
|
|
|
int dy1(BufferView const &) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns x offset for superscript
|
2007-09-23 22:39:49 +00:00
|
|
|
int dx0(BufferView const & bv) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns x offset for subscript
|
2007-09-23 22:39:49 +00:00
|
|
|
int dx1(BufferView const & bv) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns ascent of nucleus if any
|
2007-09-24 13:52:04 +00:00
|
|
|
int nasc(BufferView const &) const;
|
2001-10-12 12:02:49 +00:00
|
|
|
/// returns descent of nucleus if any
|
2007-09-24 13:52:04 +00:00
|
|
|
int ndes(BufferView const &) const;
|
2016-11-27 21:45:51 +00:00
|
|
|
/// Italic correction: amount of displacement between subscript and
|
|
|
|
/// superscript in math mode as per Appendix G, rule 18f. A positive value
|
|
|
|
/// shifts the superscript to the right, and a negative value shifts the
|
|
|
|
/// subscript to the left.
|
2007-12-22 14:39:22 +00:00
|
|
|
int nker(BufferView const * bv) const;
|
2020-07-19 17:56:07 +00:00
|
|
|
/// do we we have to draw the scripts above/below nucleus?
|
|
|
|
bool hasLimits(FontInfo const &) const;
|
2006-08-17 21:32:04 +00:00
|
|
|
/// clean up empty cells and return true if a cell has been deleted.
|
2020-10-01 07:42:11 +00:00
|
|
|
bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
/// possible subscript (index 0) and superscript (index 1)
|
2004-03-25 09:16:36 +00:00
|
|
|
bool cell_1_is_up_;
|
2020-07-19 17:56:07 +00:00
|
|
|
/// remember whether we are in display mode (used by mathml output)
|
|
|
|
mutable bool has_limits_ = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
};
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
2009-05-12 21:03:47 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#endif
|