]> git.lyx.org Git - lyx.git/blob - src/mathed/MathData.h
Check path of Qt tools if qtchooser is detected
[lyx.git] / src / mathed / MathData.h
1 // -*- C++ -*-
2 /**
3  * \file MathData.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author André Pönitz
9  * \author Lars Gullik Bjønnes
10  * \author Stefan Schimanski
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef MATH_DATA_H
16 #define MATH_DATA_H
17
18 #include "Dimension.h"
19 #include "MathAtom.h"
20
21 #include "OutputEnums.h"
22
23 #include "support/strfwd.h"
24
25 #include <cstddef>
26 #include <vector>
27
28
29 namespace lyx {
30
31 class Buffer;
32 class BufferView;
33 class Cursor;
34 class DocIterator;
35 class LaTeXFeatures;
36 class ReplaceData;
37 class MacroContext;
38 class MathMacro;
39 class MetricsInfo;
40 class PainterInfo;
41 class ParIterator;
42 class TextMetricsInfo;
43 class TextPainter;
44
45
46 class MathData : private std::vector<MathAtom> {
47 public:
48         /// re-use inhertited stuff
49         typedef std::vector<MathAtom> base_type;
50         using base_type::const_iterator;
51         using base_type::iterator;
52         using base_type::size_type;
53         using base_type::difference_type;
54         using base_type::size;
55         using base_type::empty;
56         using base_type::clear;
57         using base_type::begin;
58         using base_type::end;
59         using base_type::push_back;
60         using base_type::pop_back;
61         using base_type::back;
62         using base_type::front;
63         ///
64         typedef size_type idx_type;
65         typedef size_type pos_type;
66
67 public:
68         ///
69         MathData(Buffer * buf = 0) : minasc_(0), mindes_(0), slevel_(0),
70                                      sshift_(0), kerning_(0), buffer_(buf) {}
71         ///
72         MathData(Buffer * buf, const_iterator from, const_iterator to);
73         ///
74         Buffer * buffer() { return buffer_; }
75         ///
76         Buffer const * buffer() const { return buffer_; }
77         ///
78         void append(MathData const & ar);
79
80         /// inserts single atom at position pos
81         void insert(size_type pos, MathAtom const & at);
82         /// inserts multiple atoms at position pos
83         void insert(size_type pos, MathData const & ar);
84
85         /// erase range from pos1 to pos2
86         void erase(iterator pos1, iterator pos2);
87         /// erase single atom
88         void erase(iterator pos);
89         /// erase range from pos1 to pos2
90         void erase(size_type pos1, size_type pos2);
91         /// erase single atom
92         void erase(size_type pos);
93
94         ///
95         void dump() const;
96         ///
97         void dump2() const;
98         ///
99         void replace(ReplaceData &);
100         ///
101         void substitute(MathData const & m);
102
103         /// looks for exact match
104         bool match(MathData const & ar) const;
105         /// looks for inclusion match starting at pos
106         bool matchpart(MathData const & ar, pos_type pos) const;
107         /// looks for containment, return == size mean not found
108         size_type find(MathData const & ar) const;
109         /// looks for containment, return == size mean not found
110         size_type find_last(MathData const & ar) const;
111         ///
112         bool contains(MathData const & ar) const;
113         ///
114         void validate(LaTeXFeatures &) const;
115
116         /// checked write access
117         MathAtom & operator[](pos_type);
118         /// checked read access
119         MathAtom const & operator[](pos_type) const;
120         /// rebuild cached metrics information
121         void metrics(MetricsInfo & mi, Dimension & dim) const;
122         ///
123         Dimension const & dimension(BufferView const &) const;
124
125         /// redraw cell using cache metrics information
126         void draw(PainterInfo & pi, int x, int y) const;
127         /// rebuild cached metrics information
128         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
129         /// redraw cell using cache metrics information
130         void drawT(TextPainter & pi, int x, int y) const;
131         /// mark cell for re-drawing
132         void touch() const;
133
134         /// access to cached x coordinate of last drawing
135         int xo(BufferView const & bv) const;
136         /// access to cached y coordinate of last drawing
137         int yo(BufferView const & bv) const;
138         /// access to cached x coordinate of mid point of last drawing
139         int xm(BufferView const & bv) const;
140         /// access to cached y coordinate of mid point of last drawing
141         int ym(BufferView const & bv) const;
142         /// write access to coordinate;
143         void setXY(BufferView & bv, int x, int y) const;
144         /// returns x coordinate of given position in the array
145         int pos2x(BufferView const * bv, size_type pos) const;
146         /// returns position of given x coordinate
147         int pos2x(BufferView const * bv, size_type pos, int glue) const;
148         /// returns position of given x coordinate
149         size_type x2pos(BufferView const * bv, int targetx) const;
150         /// returns position of given x coordinate starting from a certain pos
151         size_type x2pos(BufferView const * bv, int targetx, int glue) const;
152         /// returns distance of this cell to the point given by x and y
153         // assumes valid position and size cache
154         int dist(BufferView const & bv, int x, int y) const;
155
156         /// minimum ascent offset for superscript
157         int minasc() const { return minasc_; }
158         /// minimum descent offset for subscript
159         int mindes() const { return mindes_; }
160         /// level above/below which super/subscript should extend
161         int slevel() const { return slevel_; }
162         /// additional super/subscript shift
163         int sshift() const { return sshift_; }
164         /// superscript kerning
165         int kerning(BufferView const *) const { return kerning_; }
166         ///
167         void swap(MathData & ar) { base_type::swap(ar); }
168
169         /// attach/detach arguments to macros, updating the cur to
170         /// stay visually at the same position (cur==0 is allowed)
171         void updateMacros(Cursor * cur, MacroContext const & mc, UpdateType);
172         ///
173         void updateBuffer(ParIterator const &, UpdateType);
174
175 protected:
176         /// cached values for super/subscript placement
177         mutable int minasc_;
178         mutable int mindes_;
179         mutable int slevel_;
180         mutable int sshift_;
181         mutable int kerning_;
182         Buffer * buffer_;
183
184 private:
185         /// is this an exact match at this position?
186         bool find1(MathData const & ar, size_type pos) const;
187
188         ///
189         void detachMacroParameters(DocIterator * dit, const size_type macroPos);
190         ///
191         void attachMacroParameters(Cursor * cur, const size_type macroPos, 
192                 const size_type macroNumArgs, const int macroOptionals,
193                 const bool fromInitToNormalMode, const bool interactiveInit,
194                 const size_t appetite);
195         ///
196         void collectOptionalParameters(Cursor * cur, 
197                 const size_type numOptionalParams, std::vector<MathData> & params, 
198                 size_t & pos, MathAtom & scriptToPutAround,
199                 const pos_type macroPos, const int thisPos, const int thisSlice);
200         ///
201         void collectParameters(Cursor * cur, 
202                 const size_type numParams, std::vector<MathData> & params, 
203                 size_t & pos, MathAtom & scriptToPutAround,
204                 const pos_type macroPos, const int thisPos, const int thisSlice,
205                 const size_t appetite);
206 };
207
208 ///
209 std::ostream & operator<<(std::ostream & os, MathData const & ar);
210 ///
211 odocstream & operator<<(odocstream & os, MathData const & ar);
212
213
214 } // namespace lyx
215
216 #endif