X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FMathMacroTemplate.h;h=b0c301897761a0caeb9124c91270386b960875a9;hb=2de30c62f8d671a8c8d4d52a6a7310e2c5ca84de;hp=c14bfcb3ebade4af9ebeb024efc737c91634ced1;hpb=36dbec45069bf3d9db923200835e44f44d904eb8;p=lyx.git diff --git a/src/mathed/MathMacroTemplate.h b/src/mathed/MathMacroTemplate.h index c14bfcb3eb..b0c3018977 100644 --- a/src/mathed/MathMacroTemplate.h +++ b/src/mathed/MathMacroTemplate.h @@ -5,7 +5,7 @@ * Licence details can be found in the file COPYING. * * \author Alejandro Aguilar Sierra - * \author André Pönitz + * \author André Pönitz * * Full author contact details are available in file CREDITS. */ @@ -17,40 +17,46 @@ #include "MacroTable.h" #include "MathData.h" -#include "support/types.h" - namespace lyx { +class OutputParams; +class XHTMLStream; + /// This class contains the macro definition. class MathMacroTemplate : public InsetMathNest { public: /// - MathMacroTemplate(); + MathMacroTemplate(Buffer * buf); /// - MathMacroTemplate(docstring const & name, int nargs, int optional, - MacroType type, + MathMacroTemplate(Buffer * buf, docstring const & name, int nargs, + int optional, MacroType type, std::vector const & optionalValues = std::vector(), MathData const & def = MathData(), MathData const & display = MathData()); + /// parses from string, returns false if failed + bool fromString (const docstring & str); + /// + bool editable() const { return true; } /// - explicit MathMacroTemplate(const docstring & str); + void edit(Cursor & cur, bool front, EntryDirection entry_from); /// - EDITABLE editable() const { return HIGHLY_EDITABLE; } + bool notifyCursorLeaves(Cursor const & old, Cursor & cur); /// - void read(Buffer const &, Lexer & lex); + void read(Lexer & lex); /// - void write(Buffer const &, std::ostream & os) const; + void write(std::ostream & os) const; /// void write(WriteStream & os) const; /// Output LaTeX code, but assume that the macro is not definied yet /// if overwriteRedefinition is true - void write(WriteStream & os, bool overwriteRedefinition) const; + int write(WriteStream & os, bool overwriteRedefinition) const; + /// Nothing happens. This is simply to suppress the default output. + docstring xhtml(XHTMLStream &, OutputParams const &) const; /// - int plaintext(Buffer const &, odocstream &, - OutputParams const &) const; + int plaintext(odocstringstream &, OutputParams const &, size_t) const; /// - bool noFontChange() const { return true; } + bool inheritFont() const { return false; } /// docstring name() const; @@ -76,9 +82,12 @@ public: /// Remove everything from the name which makes it invalid /// and return true iff it is valid. bool fixNameAndCheckIfValid(); + + /// request "external features" + virtual void validate(LaTeXFeatures &) const; /// decide whether its a redefinition - void updateToContext(MacroContext const & mc) const; + void updateToContext(MacroContext const & mc); /// void draw(PainterInfo & pi, int x, int y) const; @@ -90,7 +99,13 @@ public: MathMacroTemplate const * asMacroTemplate() const { return this; } /// InsetCode lyxCode() const { return MATHMACRO_CODE; } - + /// + void infoize(odocstream & os) const; + /// + std::string contextMenuName() const; + /// + void addToToc(DocIterator const & di, bool output_active, + UpdateType utype) const; protected: /// virtual void doDispatch(Cursor & cur, FuncRequest & cmd); @@ -99,31 +114,51 @@ protected: FuncStatus & status) const; private: + friend class InsetLabelBox; + friend class DisplayLabelBox; + + /// virtual Inset * clone() const; /// remove #n with from<=n<=to - void removeArguments(Cursor & cur, int from, int to); + void removeArguments(Cursor & cur, DocIterator const & inset_pos, + int from, int to); /// shift every #n with from<=n, i.e. #n -> #(n-by) void shiftArguments(size_t from, int by); /// - void insertParameter(Cursor & cur, int pos, bool greedy = false); + void insertParameter(Cursor & cur, DocIterator const & inset_pos, + int pos, bool greedy = false, bool addarg = true); /// - void removeParameter(Cursor & cur, int pos, bool greedy = false ); + void removeParameter(Cursor & cur, DocIterator const & inset_pos, + int pos, bool greedy = false); /// - void makeOptional(Cursor & cur); + void makeOptional(Cursor & cur, DocIterator const & inset_pos); /// - void makeNonOptional(Cursor & cur); + void makeNonOptional(Cursor & cur, DocIterator const & inset_pos); /// idx_type defIdx() const { return optionals_ + 1; } /// index of default value cell of optional parameter (#1 -> n=0) idx_type optIdx(idx_type n) const { return n + 1; } /// idx_type displayIdx() const { return optionals_ + 2; } - /// The label with some holes to edit - mutable MathData label_; + /// + void updateLook() const; + /// look through the macro for #n arguments + int maxArgumentInDefinition() const; + /// add missing #n arguments up to \c maxArg + void insertMissingArguments(int maxArg); + /// change the arity + void changeArity(Cursor & cur, DocIterator const & inset_pos, + int newNumArg); + /// find arguments in definition and adapt the arity accordingly + void commitEditChanges(Cursor & cur, DocIterator const & inset_pos); + /// The representation of the macro template, with some holes to edit + mutable MathData look_; /// mutable int numargs_; /// + mutable int argsInLook_; + /// int optionals_; /// keeps the old optional default value when an /// optional argument is disabled @@ -132,7 +167,23 @@ private: /// (re)newcommand or def mutable MacroType type_; /// defined before already? - mutable bool redefinition_; + bool redefinition_; + /// + void createLook(int args) const; + /// + mutable bool lookOutdated_; + /// true if in pre-calculations of metrics to get height of boxes + mutable bool premetrics_; + /// + mutable int labelBoxAscent_; + /// + mutable int labelBoxDescent_; + /// + bool premetrics() const { return premetrics_; } + /// + int commonLabelBoxAscent() const { return labelBoxAscent_; } + /// + int commonLabelBoxDescent() const { return labelBoxDescent_; } };