1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2002-09-11 08:26:02 +00:00
|
|
|
|
/**
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \file math_inset.h
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#ifndef MATH_INSET_H
|
|
|
|
|
#define MATH_INSET_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-02-17 17:12:50 +00:00
|
|
|
|
#include "insets/insetbase.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
Abstract base class for all math objects. A math insets is for use of the
|
|
|
|
|
math editor only, it isn't a general LyX inset. It's used to represent all
|
2002-03-21 17:42:56 +00:00
|
|
|
|
the math objects.
|
2001-12-03 16:24:50 +00:00
|
|
|
|
|
|
|
|
|
Math insets do not know there parents, a cursor position or things
|
|
|
|
|
like that. The are dumb object that are contained in other math insets
|
2003-06-02 10:03:27 +00:00
|
|
|
|
(MathNestInsets, in fact) thus forming a tree. The root of this tree is
|
|
|
|
|
always a MathHullInset, which provides an interface to the Outer World by
|
2001-12-03 16:24:50 +00:00
|
|
|
|
inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
|
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
|
*/
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2003-11-05 12:06:20 +00:00
|
|
|
|
class OutputParams;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
class MathArrayInset;
|
2002-04-24 17:07:42 +00:00
|
|
|
|
class MathAMSArrayInset;
|
2001-08-17 13:18:10 +00:00
|
|
|
|
class MathCharInset;
|
2001-11-09 08:35:57 +00:00
|
|
|
|
class MathDelimInset;
|
2001-11-13 18:33:48 +00:00
|
|
|
|
class MathFracInset;
|
2002-10-29 08:23:32 +00:00
|
|
|
|
class MathFontInset;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
class MathGridInset;
|
2001-11-08 12:28:33 +00:00
|
|
|
|
class MathHullInset;
|
2001-11-09 08:35:57 +00:00
|
|
|
|
class MathMatrixInset;
|
|
|
|
|
class MathNestInset;
|
2002-07-08 11:29:51 +00:00
|
|
|
|
class MathParboxInset;
|
2001-10-19 11:25:48 +00:00
|
|
|
|
class MathScriptInset;
|
2001-11-09 12:01:10 +00:00
|
|
|
|
class MathStringInset;
|
2001-10-12 12:02:49 +00:00
|
|
|
|
class MathSpaceInset;
|
2001-11-09 14:23:44 +00:00
|
|
|
|
class MathSymbolInset;
|
2002-02-01 17:01:30 +00:00
|
|
|
|
class MathUnknownInset;
|
2002-07-08 06:39:40 +00:00
|
|
|
|
|
2003-02-25 18:21:48 +00:00
|
|
|
|
class RefInset;
|
2001-07-13 14:54:56 +00:00
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
class MathArray;
|
|
|
|
|
class MathAtom;
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
class NormalStream;
|
|
|
|
|
class OctaveStream;
|
|
|
|
|
class MapleStream;
|
2002-10-28 17:15:19 +00:00
|
|
|
|
class MaximaStream;
|
2002-07-01 11:17:14 +00:00
|
|
|
|
class MathematicaStream;
|
2001-11-09 08:35:57 +00:00
|
|
|
|
class MathMLStream;
|
|
|
|
|
class WriteStream;
|
2002-01-16 14:24:38 +00:00
|
|
|
|
class InfoStream;
|
2001-11-09 08:35:57 +00:00
|
|
|
|
|
2001-10-24 19:09:31 +00:00
|
|
|
|
class BufferView;
|
|
|
|
|
class UpdatableInset;
|
2001-11-09 14:23:44 +00:00
|
|
|
|
class MathMacroTemplate;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
class MathMacro;
|
2001-12-05 17:50:18 +00:00
|
|
|
|
class MathPosFinder;
|
2002-07-11 11:27:24 +00:00
|
|
|
|
class Dimension;
|
2002-08-12 09:53:04 +00:00
|
|
|
|
class FuncRequest;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
class TextPainter;
|
|
|
|
|
class TextMetricsInfo;
|
|
|
|
|
class ReplaceData;
|
2001-10-19 11:25:48 +00:00
|
|
|
|
|
|
|
|
|
|
2003-02-17 17:12:50 +00:00
|
|
|
|
class MathInset : public InsetBase {
|
2002-03-21 17:42:56 +00:00
|
|
|
|
public:
|
2001-12-03 16:24:50 +00:00
|
|
|
|
/// our members behave nicely...
|
|
|
|
|
MathInset() {}
|
2004-01-15 11:58:35 +00:00
|
|
|
|
/// identification as math inset
|
|
|
|
|
MathInset * asMathInset() { return this; }
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// substitutes macro arguments if necessary
|
2001-09-11 15:46:51 +00:00
|
|
|
|
virtual void substitute(MathMacro const & macro);
|
2002-07-26 17:23:44 +00:00
|
|
|
|
/// draw selection between two positions
|
2003-03-21 14:20:48 +00:00
|
|
|
|
virtual void drawSelection(PainterInfo & pi,
|
2002-07-26 17:23:44 +00:00
|
|
|
|
idx_type idx1, pos_type pos1, idx_type idx2, pos_type pos2) const;
|
2002-03-18 11:45:53 +00:00
|
|
|
|
/// the ascent of the inset above the baseline
|
|
|
|
|
/// compute the size of the object for text based drawing
|
2003-05-28 13:22:36 +00:00
|
|
|
|
virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
|
2002-03-18 11:45:53 +00:00
|
|
|
|
/// draw the object as text
|
2002-03-21 06:57:13 +00:00
|
|
|
|
virtual void drawT(TextPainter &, int x, int y) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-03-21 09:48:46 +00:00
|
|
|
|
/// Where should we go when we press the up or down cursor key?
|
2002-07-30 13:56:02 +00:00
|
|
|
|
virtual bool idxUpDown(idx_type & idx, pos_type & pos, bool up,
|
|
|
|
|
int targetx) const;
|
2003-04-14 06:17:19 +00:00
|
|
|
|
/// Where should we go when we press the up or down cursor key?
|
|
|
|
|
virtual bool idxUpDown2(idx_type & idx, pos_type & pos, bool up,
|
|
|
|
|
int targetx) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
/// The left key
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxLeft(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
/// The right key
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxRight(idx_type & idx, pos_type & pos) const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
|
/// Move one physical cell up
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxNext(idx_type & idx, pos_type & pos) const;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
/// Move one physical cell down
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxPrev(idx_type & idx, pos_type & pos) const;
|
2001-07-06 12:09:32 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
/// Target pos when we enter the inset from the left by pressing "Right"
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxFirst(idx_type & idx, pos_type & pos) const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
/// Target pos when we enter the inset from the right by pressing "Left"
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxLast(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
|
|
/// Where should we go if we press home?
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxHome(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
/// Where should we go if we press end?
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual bool idxEnd(idx_type & idx, pos_type & pos) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
/// Delete a cell and move cursor
|
2002-03-25 12:11:25 +00:00
|
|
|
|
virtual bool idxDelete(idx_type &) { return false; }
|
|
|
|
|
/// pulls cell after pressing erase
|
|
|
|
|
virtual void idxGlue(idx_type) {}
|
2001-07-16 15:53:25 +00:00
|
|
|
|
// returns list of cell indices that are "between" from and to for
|
2001-08-03 17:10:22 +00:00
|
|
|
|
// selection purposes
|
2002-08-02 13:35:05 +00:00
|
|
|
|
virtual bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// the number of nested cells this inset owns
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual idx_type nargs() const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// return cell given its number
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual MathArray & cell(idx_type);
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// return cell given its number
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual MathArray const & cell(idx_type) const;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// the number of columns of this inset if it is grid-like
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual col_type ncols() const { return 1; }
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// the number of rows of this inset if it is grid-like
|
2001-09-26 16:52:34 +00:00
|
|
|
|
virtual row_type nrows() const { return 1; }
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// to which column belongs a cell with a given index?
|
|
|
|
|
virtual col_type col(idx_type) const { return 0; }
|
|
|
|
|
/// to which row belongs a cell with a given index?
|
|
|
|
|
virtual row_type row(idx_type) const { return 0; }
|
2001-12-15 16:13:11 +00:00
|
|
|
|
/// cell idex corresponding to row and column;
|
|
|
|
|
virtual idx_type index(row_type row, col_type col) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// any additional x-offset when drawing a cell?
|
|
|
|
|
virtual int cellXOffset(idx_type) const { return 0; }
|
|
|
|
|
/// any additional y-offset when drawing a cell?
|
|
|
|
|
virtual int cellYOffset(idx_type) const { return 0; }
|
2002-03-18 11:45:53 +00:00
|
|
|
|
/// can we enter this cell?
|
|
|
|
|
virtual bool validCell(idx_type) const { return true; }
|
2002-07-26 13:13:20 +00:00
|
|
|
|
/// get coordinates
|
2004-01-15 11:58:35 +00:00
|
|
|
|
virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-11-09 12:01:10 +00:00
|
|
|
|
/// identifies certain types of insets
|
2002-08-09 10:22:35 +00:00
|
|
|
|
virtual MathAMSArrayInset * asAMSArrayInset() { return 0; }
|
|
|
|
|
virtual MathAMSArrayInset const * asAMSArrayInset() const { return 0; }
|
|
|
|
|
virtual MathArrayInset * asArrayInset() { return 0; }
|
|
|
|
|
virtual MathArrayInset const * asArrayInset() const { return 0; }
|
|
|
|
|
virtual MathCharInset const * asCharInset() const { return 0; }
|
|
|
|
|
virtual MathDelimInset * asDelimInset() { return 0; }
|
|
|
|
|
virtual MathDelimInset const * asDelimInset() const { return 0; }
|
|
|
|
|
virtual MathFracInset * asFracInset() { return 0; }
|
|
|
|
|
virtual MathFracInset const * asFracInset() const { return 0; }
|
2002-10-29 08:23:32 +00:00
|
|
|
|
virtual MathFontInset * asFontInset() { return 0; }
|
|
|
|
|
virtual MathFontInset const * asFontInset() const { return 0; }
|
2002-08-09 10:22:35 +00:00
|
|
|
|
virtual MathGridInset * asGridInset() { return 0; }
|
|
|
|
|
virtual MathGridInset const * asGridInset() const { return 0; }
|
|
|
|
|
virtual MathHullInset * asHullInset() { return 0; }
|
|
|
|
|
virtual MathHullInset const * asHullInset() const { return 0; }
|
|
|
|
|
virtual MathMacroTemplate * asMacroTemplate() { return 0; }
|
|
|
|
|
virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
|
|
|
|
|
virtual MathMatrixInset const * asMatrixInset() const { return 0; }
|
|
|
|
|
virtual MathNestInset * asNestInset() { return 0; }
|
|
|
|
|
virtual MathNestInset const * asNestInset() const { return 0; }
|
|
|
|
|
virtual MathParboxInset * asParboxInset() { return 0; }
|
|
|
|
|
virtual MathScriptInset * asScriptInset() { return 0; }
|
|
|
|
|
virtual MathScriptInset const * asScriptInset() const { return 0; }
|
|
|
|
|
virtual MathSpaceInset * asSpaceInset() { return 0; }
|
|
|
|
|
virtual MathSpaceInset const * asSpaceInset() const { return 0; }
|
|
|
|
|
virtual MathStringInset * asStringInset() { return 0; }
|
|
|
|
|
virtual MathStringInset const * asStringInset() const { return 0; }
|
|
|
|
|
virtual MathSymbolInset const * asSymbolInset() const { return 0; }
|
|
|
|
|
virtual MathUnknownInset * asUnknownInset() { return 0; }
|
|
|
|
|
virtual MathUnknownInset const * asUnknownInset() const { return 0; }
|
2003-02-25 18:21:48 +00:00
|
|
|
|
virtual RefInset * asRefInset() { return 0; }
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
|
|
/// identifies things that can get scripts
|
|
|
|
|
virtual bool isScriptable() const { return false; }
|
2001-11-09 10:44:24 +00:00
|
|
|
|
/// thing that can be moved into
|
2001-06-27 14:10:35 +00:00
|
|
|
|
virtual bool isActive() const { return nargs() > 0; }
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// is the a relational operator (used for splitting equations)
|
2001-08-09 08:53:16 +00:00
|
|
|
|
virtual bool isRelOp() const { return false; }
|
2002-07-18 11:02:33 +00:00
|
|
|
|
/// -1: text mode, 1: math mode, 0 undecided
|
2002-10-29 08:23:32 +00:00
|
|
|
|
enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE};
|
2002-08-13 17:43:40 +00:00
|
|
|
|
|
2002-07-18 11:02:33 +00:00
|
|
|
|
virtual mode_type currentMode() const { return UNDECIDED_MODE; }
|
2002-07-10 07:15:36 +00:00
|
|
|
|
/// will this get written as a single block in {..}
|
|
|
|
|
virtual bool extraBraces() const { return false; }
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// return the content as char if the inset is able to do so
|
2001-08-03 17:10:22 +00:00
|
|
|
|
virtual char getChar() const { return 0; }
|
2001-09-11 10:58:17 +00:00
|
|
|
|
/// identifies things that can get \limits or \nolimits
|
|
|
|
|
virtual bool takesLimits() const { return false; }
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// char char code if possible
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual void handleFont(std::string const &) {}
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// replace things by other things
|
2001-11-16 09:55:37 +00:00
|
|
|
|
virtual void replace(ReplaceData &) {}
|
2002-02-01 17:01:30 +00:00
|
|
|
|
/// do we contain a given subsequence?
|
2002-08-08 16:08:11 +00:00
|
|
|
|
virtual bool contains(MathArray const &) const { return false; }
|
2002-05-30 07:09:54 +00:00
|
|
|
|
/// access to the lock (only nest array have one)
|
|
|
|
|
virtual bool lock() const { return false; }
|
|
|
|
|
/// access to the lock (only nest array have one)
|
|
|
|
|
virtual void lock(bool) {}
|
2002-06-27 18:12:50 +00:00
|
|
|
|
/// get notification when the cursor leaves this inset
|
2002-10-29 08:23:32 +00:00
|
|
|
|
virtual void notifyCursorLeaves(idx_type) {}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2002-01-11 15:23:10 +00:00
|
|
|
|
/// write LaTeX and Lyx code
|
|
|
|
|
virtual void write(WriteStream & os) const;
|
2001-11-08 12:06:56 +00:00
|
|
|
|
/// write normalized content
|
2001-11-09 08:35:57 +00:00
|
|
|
|
virtual void normalize(NormalStream &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// write content as something readable by Maple
|
2003-02-14 14:30:09 +00:00
|
|
|
|
virtual void maple(MapleStream &) const;
|
2002-10-28 17:15:19 +00:00
|
|
|
|
/// write content as something readable by Maxima
|
2003-02-14 14:30:09 +00:00
|
|
|
|
virtual void maxima(MaximaStream &) const;
|
2002-07-01 11:17:14 +00:00
|
|
|
|
/// write content as something readable by Mathematica
|
2003-02-14 14:30:09 +00:00
|
|
|
|
virtual void mathematica(MathematicaStream &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// write content as something resembling MathML
|
2001-11-07 17:30:26 +00:00
|
|
|
|
virtual void mathmlize(MathMLStream &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
|
/// write content as something readable by Octave
|
2003-02-14 14:30:09 +00:00
|
|
|
|
virtual void octave(OctaveStream &) const;
|
2003-01-07 11:24:43 +00:00
|
|
|
|
/// describe content if cursor inside
|
2002-01-16 14:24:38 +00:00
|
|
|
|
virtual void infoize(std::ostream &) const {}
|
2003-01-07 11:24:43 +00:00
|
|
|
|
/// describe content if cursor behind
|
|
|
|
|
virtual void infoize2(std::ostream &) const {}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
/// plain ascii output
|
2003-11-05 12:06:20 +00:00
|
|
|
|
virtual int plaintext(std::ostream & os, OutputParams const &) const;
|
2002-06-24 15:37:14 +00:00
|
|
|
|
/// linuxdoc output
|
2003-11-05 12:06:20 +00:00
|
|
|
|
virtual int linuxdoc(std::ostream & os, OutputParams const &) const;
|
2002-06-24 15:37:14 +00:00
|
|
|
|
/// docbook output
|
2003-11-05 12:06:20 +00:00
|
|
|
|
virtual int docbook(std::ostream & os, OutputParams const &) const;
|
2001-11-22 09:48:57 +00:00
|
|
|
|
|
|
|
|
|
/// dump content to stderr for debugging
|
|
|
|
|
virtual void dump() const;
|
2002-07-08 06:39:40 +00:00
|
|
|
|
|
|
|
|
|
/// LyXInset stuff
|
|
|
|
|
virtual bool numberedType() const { return false; }
|
|
|
|
|
/// hull type
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::string const & getType() const;
|
2002-07-08 06:39:40 +00:00
|
|
|
|
/// change type
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual void mutate(std::string const &) {}
|
2002-07-08 06:39:40 +00:00
|
|
|
|
/// how is the inset called in the .lyx file?
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::string fileInsetLabel() const;
|
2002-08-01 15:53:46 +00:00
|
|
|
|
/// usually the latex name
|
2003-10-06 15:43:21 +00:00
|
|
|
|
virtual std::string name() const;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-05-24 08:29:16 +00:00
|
|
|
|
std::ostream & operator<<(std::ostream &, MathAtom const &);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
2002-10-22 13:56:40 +00:00
|
|
|
|
// initialize math
|
2002-07-12 14:24:47 +00:00
|
|
|
|
void initMath();
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#endif
|