1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
2002-09-11 08:26:02 +00:00
|
|
|
/**
|
2007-04-25 16:11:45 +00:00
|
|
|
* \file MathMacro.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.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pö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
|
|
|
*/
|
2003-08-19 13:00:56 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#ifndef MATH_MACRO_H
|
|
|
|
#define MATH_MACRO_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMathNest.h"
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "MacroTable.h"
|
2007-11-01 11:13:07 +00:00
|
|
|
#include "MathData.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2007-12-21 20:44:37 +00:00
|
|
|
#include <map>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2007-12-21 20:44:37 +00:00
|
|
|
namespace lyx {
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2003-08-19 13:00:56 +00:00
|
|
|
/// This class contains the data for a macro.
|
2006-09-16 18:11:38 +00:00
|
|
|
class MathMacro : public InsetMathNest {
|
2000-03-07 01:14:37 +00:00
|
|
|
public:
|
2001-04-24 16:13:38 +00:00
|
|
|
/// A macro can be built from an existing template
|
2009-11-08 11:45:46 +00:00
|
|
|
MathMacro(Buffer * buf, docstring const & name);
|
2001-02-13 17:08:51 +00:00
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
MathMacro(MathMacro const &);
|
|
|
|
///
|
|
|
|
MathMacro & operator=(MathMacro const &);
|
|
|
|
///
|
|
|
|
~MathMacro();
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
virtual MathMacro * asMacro() { return this; }
|
2001-02-13 17:08:51 +00:00
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
virtual MathMacro const * asMacro() const { return this; }
|
|
|
|
///
|
2016-11-16 14:07:00 +00:00
|
|
|
/// If the macro is in normal edit mode, dissolve its contents in
|
|
|
|
/// the row. Otherwise, just insert the inset.
|
2016-10-04 22:25:38 +00:00
|
|
|
bool addToMathRow(MathRow &, MetricsInfo & mi) const;
|
2016-11-16 14:07:00 +00:00
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
void draw(PainterInfo & pi, int x, int y) const;
|
2005-10-05 21:19:32 +00:00
|
|
|
/// draw selection background
|
|
|
|
void drawSelection(PainterInfo & pi, int x, int y) const;
|
2007-01-20 00:55:24 +00:00
|
|
|
/// draw decorations.
|
|
|
|
void drawDecoration(PainterInfo & pi, int x, int y) const
|
|
|
|
{ drawMarkers2(pi, x, y); }
|
2001-02-13 17:08:51 +00:00
|
|
|
///
|
2007-09-21 20:39:47 +00:00
|
|
|
void metrics(MetricsInfo & mi, Dimension & dim) const;
|
2016-11-16 14:07:00 +00:00
|
|
|
/// was the macro in edit mode when computing metrics?
|
|
|
|
bool editMetrics(BufferView const * bv) const;
|
2007-11-01 11:13:07 +00:00
|
|
|
///
|
2007-12-22 14:39:22 +00:00
|
|
|
int kerning(BufferView const * bv) const;
|
2005-10-05 21:19:32 +00:00
|
|
|
/// get cursor position
|
2006-10-17 16:23:27 +00:00
|
|
|
void cursorPos(BufferView const & bv, CursorSlice const & sl,
|
|
|
|
bool boundary, int & x, int & y) const;
|
2005-10-05 21:19:32 +00:00
|
|
|
///
|
2008-02-11 08:20:13 +00:00
|
|
|
void edit(Cursor & cur, bool front, EntryDirection entry_from);
|
2007-11-01 11:13:07 +00:00
|
|
|
///
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset * editXY(Cursor & cur, int x, int y);
|
2007-11-01 11:13:07 +00:00
|
|
|
|
2007-11-05 19:41:16 +00:00
|
|
|
/// target pos when we enter the inset while moving forward
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxFirst(Cursor &) const;
|
2007-11-05 19:41:16 +00:00
|
|
|
/// target pos when we enter the inset while moving backwards
|
2007-04-26 14:56:30 +00:00
|
|
|
bool idxLast(Cursor &) const;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
2007-06-14 20:57:56 +00:00
|
|
|
///
|
2008-02-22 20:45:18 +00:00
|
|
|
virtual bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
|
2015-03-30 20:03:03 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
/// Remove cell (starting from 0)
|
2007-11-01 15:36:27 +00:00
|
|
|
void removeArgument(pos_type pos);
|
2007-11-01 11:13:07 +00:00
|
|
|
/// Insert empty cell (starting from 0)
|
2007-11-01 15:36:27 +00:00
|
|
|
void insertArgument(pos_type pos);
|
2007-04-17 16:49:17 +00:00
|
|
|
|
2001-07-13 14:54:56 +00:00
|
|
|
///
|
2001-07-26 06:56:43 +00:00
|
|
|
void validate(LaTeXFeatures &) const;
|
2016-09-24 23:11:16 +00:00
|
|
|
///
|
|
|
|
mode_type currentMode() const;
|
2001-07-13 14:54:56 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
///
|
2007-11-01 14:06:58 +00:00
|
|
|
void write(WriteStream & os) const;
|
2001-11-16 08:26:41 +00:00
|
|
|
///
|
2011-04-01 20:03:41 +00:00
|
|
|
void normalize(NormalStream & os) const;
|
|
|
|
///
|
2003-02-14 14:30:09 +00:00
|
|
|
void maple(MapleStream &) const;
|
2001-11-16 08:26:41 +00:00
|
|
|
///
|
2015-03-29 11:53:01 +00:00
|
|
|
void maxima(MaximaStream &) const;
|
|
|
|
///
|
|
|
|
void mathematica(MathematicaStream &) const;
|
|
|
|
///
|
2009-12-31 15:46:39 +00:00
|
|
|
void mathmlize(MathStream &) const;
|
2001-11-16 08:29:11 +00:00
|
|
|
///
|
2010-03-30 00:18:24 +00:00
|
|
|
void htmlize(HtmlStream &) const;
|
|
|
|
///
|
2003-02-14 14:30:09 +00:00
|
|
|
void octave(OctaveStream &) const;
|
2003-01-07 11:24:43 +00:00
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
void infoize(odocstream &) const;
|
2003-01-07 11:24:43 +00:00
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
void infoize2(odocstream &) const;
|
2001-11-16 08:26:41 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
/// fold the macro in the next metrics call
|
|
|
|
void fold(Cursor & cur);
|
|
|
|
/// unfold the macro in the next metrics call
|
|
|
|
void unfold(Cursor & cur);
|
|
|
|
/// will it be folded or unfolded in the next metric call?
|
|
|
|
bool folded() const;
|
2015-03-30 20:03:03 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
enum DisplayMode {
|
|
|
|
DISPLAY_INIT,
|
2007-11-14 17:33:49 +00:00
|
|
|
DISPLAY_INTERACTIVE_INIT,
|
2007-11-01 11:13:07 +00:00
|
|
|
DISPLAY_UNFOLDED,
|
2010-12-17 20:51:44 +00:00
|
|
|
DISPLAY_NORMAL
|
2007-11-01 11:13:07 +00:00
|
|
|
};
|
|
|
|
|
2007-04-17 16:49:17 +00:00
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
DisplayMode displayMode() const;
|
2007-04-17 16:49:17 +00:00
|
|
|
|
2007-05-24 16:29:40 +00:00
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
bool extraBraces() const;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
2007-05-24 16:29:40 +00:00
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
docstring name() const;
|
2016-12-12 00:17:41 +00:00
|
|
|
/// FIXME: Often dangling.
|
2016-11-16 14:07:00 +00:00
|
|
|
MacroData const * macro() const;
|
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
docstring macroName() const;
|
2016-11-28 12:13:36 +00:00
|
|
|
/// Level of nesting in macros (including this one)
|
|
|
|
int nesting() const;
|
2015-04-02 19:20:32 +00:00
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
bool validName() const;
|
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
size_t arity() const;
|
2015-03-30 20:03:03 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
size_t optionals() const;
|
2007-11-01 11:13:07 +00:00
|
|
|
///
|
2015-04-02 19:20:32 +00:00
|
|
|
void setOptionals(int n);
|
2008-03-04 14:49:03 +00:00
|
|
|
/// Return the maximal number of arguments the macro is greedy for.
|
2015-04-02 19:20:32 +00:00
|
|
|
size_t appetite() const;
|
2009-07-16 19:00:24 +00:00
|
|
|
///
|
|
|
|
InsetCode lyxCode() const { return MATH_MACRO_CODE; }
|
2008-03-04 14:49:03 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
protected:
|
|
|
|
friend class MathData;
|
|
|
|
friend class ArgumentProxy;
|
2007-11-01 14:40:15 +00:00
|
|
|
friend class Cursor;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
/// update the display mode (should only be called after detaching arguments)
|
2008-03-04 14:49:03 +00:00
|
|
|
void setDisplayMode(DisplayMode mode, int appetite = -1);
|
2007-11-01 11:13:07 +00:00
|
|
|
/// compute the next display mode
|
2007-12-21 20:42:46 +00:00
|
|
|
DisplayMode computeDisplayMode() const;
|
2007-11-01 11:13:07 +00:00
|
|
|
/// update macro definition
|
2007-12-21 20:42:46 +00:00
|
|
|
void updateMacro(MacroContext const & mc);
|
2007-11-01 11:13:07 +00:00
|
|
|
/// check if macro definition changed, argument changed etc. and adapt
|
2016-11-28 12:13:36 +00:00
|
|
|
void updateRepresentation(Cursor * cur, MacroContext const & mc,
|
|
|
|
UpdateType, int nesting);
|
2007-11-01 11:13:07 +00:00
|
|
|
/// empty macro, put arguments into args, possibly strip arity-attachedArgsNum_ empty ones.
|
|
|
|
/// Includes the optional arguments.
|
|
|
|
void detachArguments(std::vector<MathData> & args, bool strip);
|
|
|
|
/// attach arguments (maybe less than arity at the end of an MathData),
|
|
|
|
/// including the optional ones (even if it can be empty here)
|
|
|
|
void attachArguments(std::vector<MathData> const & args, size_t arity, int optionals);
|
2008-03-04 14:49:03 +00:00
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
private:
|
2016-12-12 00:17:41 +00:00
|
|
|
/// Math mode for output and display. UNDECIDED for user macros: they could
|
|
|
|
/// be either.
|
|
|
|
mode_type modeToEnsure() const;
|
|
|
|
/// This function is needed for now because of two shortfalls of the current
|
|
|
|
/// implementation: the macro() pointer is often dangling, in which case we
|
|
|
|
/// fall back to a backup copy, and the macro is not known at inset
|
|
|
|
/// creation, in which case we fall back to the global macro with this name.
|
|
|
|
MacroData const * macroBackup() const;
|
2007-11-01 11:13:07 +00:00
|
|
|
///
|
|
|
|
virtual Inset * clone() const;
|
|
|
|
///
|
2007-12-24 10:54:39 +00:00
|
|
|
bool editMode(BufferView const * bv) const;
|
2015-03-30 20:03:03 +00:00
|
|
|
|
2015-04-02 19:20:32 +00:00
|
|
|
///
|
|
|
|
class Private;
|
|
|
|
///
|
|
|
|
Private * d;
|
2014-03-05 23:45:42 +00:00
|
|
|
/// update lock to avoid loops
|
|
|
|
class UpdateLocker;
|
|
|
|
friend class UpdateLocker;
|
2008-02-21 19:42:34 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
bool completionSupported(Cursor const &) const;
|
|
|
|
///
|
|
|
|
bool inlineCompletionSupported(Cursor const & cur) const;
|
|
|
|
///
|
|
|
|
bool automaticInlineCompletion() const;
|
|
|
|
///
|
|
|
|
bool automaticPopupCompletion() const;
|
|
|
|
///
|
2008-02-22 21:11:19 +00:00
|
|
|
CompletionList const * createCompletionList(Cursor const & cur) const;
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
|
|
|
docstring completionPrefix(Cursor const & cur) const;
|
|
|
|
///
|
|
|
|
bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
|
|
|
|
///
|
|
|
|
void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
|
2007-11-01 11:13:07 +00:00
|
|
|
};
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|