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
|
|
|
|
|
* \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
|
|
|
|
*/
|
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-11-01 11:13:07 +00:00
|
|
|
|
#include "InsetMathSqrt.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
|
2007-11-01 11:13:07 +00:00
|
|
|
|
MathMacro(docstring const & name);
|
2001-02-13 17:08:51 +00:00
|
|
|
|
///
|
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; }
|
|
|
|
|
///
|
|
|
|
|
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;
|
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);
|
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;
|
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
|
|
|
|
///
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void maple(MapleStream &) const;
|
2001-11-16 08:26:41 +00:00
|
|
|
|
///
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void mathmlize(MathStream &) const;
|
2001-11-16 08:29:11 +00:00
|
|
|
|
///
|
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;
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
DISPLAY_NORMAL,
|
|
|
|
|
};
|
|
|
|
|
|
2007-04-17 16:49:17 +00:00
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
DisplayMode displayMode() const { return displayMode_; }
|
2007-04-17 16:49:17 +00:00
|
|
|
|
|
2007-05-24 16:29:40 +00:00
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
bool extraBraces() const { return displayMode_ == DISPLAY_NORMAL && arity() > 0; }
|
|
|
|
|
|
2007-05-24 16:29:40 +00:00
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
docstring name() const;
|
2007-06-15 18:26:35 +00:00
|
|
|
|
///
|
2007-11-01 11:13:07 +00:00
|
|
|
|
bool validName() const;
|
|
|
|
|
///
|
|
|
|
|
size_t arity() const {
|
|
|
|
|
if (displayMode_ == DISPLAY_NORMAL )
|
|
|
|
|
return cells_.size();
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///
|
2007-11-01 15:36:27 +00:00
|
|
|
|
size_t optionals() const { return optionals_; }
|
2007-11-01 11:13:07 +00:00
|
|
|
|
///
|
|
|
|
|
void setOptionals(int n) {
|
|
|
|
|
if (n <= int(nargs()))
|
|
|
|
|
optionals_ = n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
void setDisplayMode(DisplayMode mode);
|
|
|
|
|
/// 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
|
2007-12-21 20:42:46 +00:00
|
|
|
|
void updateRepresentation(Cursor const * bvCur);
|
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);
|
|
|
|
|
///
|
|
|
|
|
MacroData const * macro() { return macro_; }
|
2007-12-24 10:54:39 +00:00
|
|
|
|
///
|
|
|
|
|
bool editMetrics(BufferView const * bv) const;
|
|
|
|
|
|
2007-11-01 11:13:07 +00:00
|
|
|
|
private:
|
|
|
|
|
///
|
|
|
|
|
virtual Inset * clone() const;
|
|
|
|
|
///
|
2007-12-24 10:54:39 +00:00
|
|
|
|
bool editMode(BufferView const * bv) const;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
|
|
|
|
|
/// name of macro
|
|
|
|
|
docstring name_;
|
|
|
|
|
/// current display mode
|
|
|
|
|
DisplayMode displayMode_;
|
2008-01-25 21:59:53 +00:00
|
|
|
|
/// expanded macro with ArgumentProxies
|
2007-11-01 11:13:07 +00:00
|
|
|
|
InsetMathSqrt expanded_;
|
2008-01-25 22:07:35 +00:00
|
|
|
|
/// macro definition with #1,#2,.. insets
|
2008-01-25 22:02:38 +00:00
|
|
|
|
MathData definition_;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
/// number of arguments that were really attached
|
|
|
|
|
size_t attachedArgsNum_;
|
|
|
|
|
/// optional argument attached? (only in DISPLAY_NORMAL mode)
|
2007-11-01 15:36:27 +00:00
|
|
|
|
size_t optionals_;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
/// fold mode to be set in next metrics call?
|
|
|
|
|
bool nextFoldMode_;
|
|
|
|
|
/// if macro_ == true, then here is a copy of the macro
|
|
|
|
|
/// don't use it for locking
|
|
|
|
|
MacroData macroBackup_;
|
|
|
|
|
/// if macroNotFound_ == false, then here is a reference to the macro
|
|
|
|
|
/// this might invalidate after metrics was called
|
|
|
|
|
MacroData const * macro_;
|
|
|
|
|
///
|
2007-12-21 20:44:37 +00:00
|
|
|
|
mutable std::map<BufferView const *, bool> editing_;
|
2007-11-01 11:13:07 +00:00
|
|
|
|
///
|
|
|
|
|
std::string requires_;
|
|
|
|
|
/// update macro representation
|
|
|
|
|
bool needsUpdate_;
|
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-21 23:36:02 +00:00
|
|
|
|
CompletionList const * completionList(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
|