3 * \file InsetMathNest.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef MATH_NESTINSET_H
13 #define MATH_NESTINSET_H
15 #include "InsetMath.h"
18 #include "support/docstring.h"
22 /** Abstract base class for all math objects that contain nested items.
23 This is basically everything that is not a single character or a
27 class InsetMathNest
: public InsetMath
{
29 /// nestinsets have a fixed size to start with
30 InsetMathNest(Buffer
* buf
, idx_type ncells
);
32 virtual ~InsetMathNest() {}
34 void setBuffer(Buffer
&);
36 /// the size is usually some sort of convex hull of the cells
37 /// hides inset::metrics() intentionally!
38 void metrics(MetricsInfo
const & mi
) const;
39 /// draw background if locked
40 void draw(PainterInfo
& pi
, int x
, int y
) const;
41 /// draw selection background
42 void drawSelection(PainterInfo
& pi
, int x
, int y
) const;
44 void drawDecoration(PainterInfo
& pi
, int x
, int y
) const
45 { drawMarkers(pi
, x
, y
); }
46 /// identifies NestInsets
47 InsetMathNest
* asNestInset() { return this; }
48 /// identifies NestInsets
49 InsetMathNest
const * asNestInset() const { return this; }
50 /// get cursor position
51 void cursorPos(BufferView
const & bv
, CursorSlice
const & sl
,
52 bool boundary
, int & x
, int & y
) const;
54 void edit(Cursor
& cur
, bool front
,
55 EntryDirection entry_from
= ENTRY_DIRECTION_IGNORE
);
57 Inset
* editXY(Cursor
& cur
, int x
, int y
);
59 /// order of movement through the cells when moving backwards
60 bool idxBackward(Cursor
&) const;
61 /// order of movement through the cells when moving forward
62 bool idxForward(Cursor
&) const;
65 bool idxNext(Cursor
&) const;
66 /// move to previous cell
67 bool idxPrev(Cursor
&) const;
69 /// target pos when we enter the inset while moving forward
70 bool idxFirst(Cursor
&) const;
71 /// target pos when we enter the inset while moving backwards
72 bool idxLast(Cursor
&) const;
74 /// number of cells currently governed by us
75 idx_type
nargs() const;
76 /// access to the lock
78 /// access to the lock
80 /// get notification when the cursor leaves this inset
81 bool notifyCursorLeaves(Cursor
const & old
, Cursor
& cur
);
83 /// direct access to the cell.
84 /// inlined because shows in profile.
86 MathData
& cell(idx_type i
) { return cells_
[i
]; }
87 MathData
const & cell(idx_type i
) const { return cells_
[i
]; }
90 /// can we move into this cell (see macroarg.h)
91 bool isActive() const;
92 /// request "external features"
93 void validate(LaTeXFeatures
& features
) const;
95 /// replace in all cells
96 void replace(ReplaceData
&);
97 /// do we contain a given pattern?
98 bool contains(MathData
const &) const;
99 /// glue everything to a single cell
100 MathData
glue() const;
105 /// writes \\, name(), and args in braces and '\\lyxlock' if necessary
106 void write(WriteStream
& os
) const;
107 /// writes [, name(), and args in []
108 void normalize(NormalStream
& os
) const;
110 int latex(odocstream
& os
, OutputParams
const & runparams
) const;
112 bool setMouseHover(bool mouse_hover
);
114 bool mouseHovered() const { return mouse_hover_
; }
117 bool completionSupported(Cursor
const &) const;
119 bool inlineCompletionSupported(Cursor
const & cur
) const;
121 bool automaticInlineCompletion() const;
123 bool automaticPopupCompletion() const;
125 CompletionList
const * createCompletionList(Cursor
const & cur
) const;
127 docstring
completionPrefix(Cursor
const & cur
) const;
129 bool insertCompletion(Cursor
& cur
, docstring
const & s
, bool finished
);
131 void completionPosAndDim(Cursor
const &, int & x
, int & y
, Dimension
& dim
) const;
133 InsetCode
lyxCode() const { return MATH_NEST_CODE
; }
137 InsetMathNest(InsetMathNest
const & inset
);
139 InsetMathNest
& operator=(InsetMathNest
const &);
142 virtual void doDispatch(Cursor
& cur
, FuncRequest
& cmd
);
143 /// do we want to handle this event?
144 bool getStatus(Cursor
& cur
, FuncRequest
const & cmd
,
145 FuncStatus
& status
) const;
147 void handleFont(Cursor
& cur
,
148 docstring
const & arg
, docstring
const & font
);
149 void handleFont(Cursor
& cur
,
150 docstring
const & arg
, char const * const font
);
152 void handleFont2(Cursor
& cur
, docstring
const & arg
);
153 /// Grab and erase selection and insert the InsetMathNest atom in every
154 /// previously selected cell, insert the grabbed former data and \c arg
155 /// in the first cell of the inserted atom.
156 void handleNest(Cursor
& cur
, MathAtom
const & nest
);
157 void handleNest(Cursor
& cur
, MathAtom
const & nest
, docstring
const & arg
);
159 /// interpret \p c and insert the result at the current position of
160 /// of \p cur. Return whether the cursor should stay in the formula.
161 bool interpretChar(Cursor
& cur
, char_type c
);
163 bool script(Cursor
& cur
, bool);
164 bool script(Cursor
& cur
, bool, docstring
const & save_selection
);
167 /// interpret \p str and insert the result at the current position of
168 /// \p cur if it is something known. Return whether \p cur was
170 bool interpretString(Cursor
& cur
, docstring
const & str
);
174 void lfunMousePress(Cursor
&, FuncRequest
&);
176 void lfunMouseRelease(Cursor
&, FuncRequest
&);
178 void lfunMouseMotion(Cursor
&, FuncRequest
&);
179 /// Find a macro to fold or unfold, starting at searchCur and searchCur.nextInset() pointing to a macro
180 /// afterwards if found
181 bool findMacroToFoldUnfold(Cursor
& searchCur
, bool fold
) const;
182 /// move cursor forward
183 bool cursorMathForward(Cursor
& cur
);
184 /// move cursor backwards
185 bool cursorMathBackward(Cursor
& cur
);
188 /// we store the cells in a vector
189 typedef std::vector
<MathData
> cells_type
;
192 /// if the inset is locked, it can't be entered with the cursor