]> git.lyx.org Git - lyx.git/blob - src/mathed/MathData.h
Some more cleanup of LyXView:
[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 "support/strfwd.h"
22
23 #include <vector>
24
25
26 namespace lyx {
27
28 class BufferView;
29 class Cursor;
30 class LaTeXFeatures;
31 class ReplaceData;
32 class MathMacro;
33 class MetricsInfo;
34 class PainterInfo;
35 class TextMetricsInfo;
36 class TextPainter;
37
38
39 class MathData : private std::vector<MathAtom> {
40 public:
41         /// re-use inhertited stuff
42         typedef std::vector<MathAtom> base_type;
43         using base_type::const_iterator;
44         using base_type::iterator;
45         using base_type::size_type;
46         using base_type::difference_type;
47         using base_type::size;
48         using base_type::empty;
49         using base_type::clear;
50         using base_type::begin;
51         using base_type::end;
52         using base_type::push_back;
53         using base_type::pop_back;
54         using base_type::back;
55         using base_type::front;
56         ///
57         typedef size_type idx_type;
58         typedef size_type pos_type;
59
60 public:
61         ///
62         MathData() {}
63         ///
64         MathData(const_iterator from, const_iterator to);
65         ///
66         void append(MathData const & ar);
67
68         /// inserts single atom at position pos
69         void insert(size_type pos, MathAtom const & at);
70         /// inserts multiple atoms at position pos
71         void insert(size_type pos, MathData const & ar);
72
73         /// erase range from pos1 to pos2
74         void erase(iterator pos1, iterator pos2);
75         /// erase single atom
76         void erase(iterator pos);
77         /// erase range from pos1 to pos2
78         void erase(size_type pos1, size_type pos2);
79         /// erase single atom
80         void erase(size_type pos);
81
82         ///
83         void dump() const;
84         ///
85         void dump2() const;
86         ///
87         void replace(ReplaceData &);
88         ///
89         void substitute(MathData const & m);
90
91         /// looks for exact match
92         bool match(MathData const & ar) const;
93         /// looks for inclusion match starting at pos
94         bool matchpart(MathData const & ar, pos_type pos) const;
95         /// looks for containment, return == size mean not found
96         size_type find(MathData const & ar) const;
97         /// looks for containment, return == size mean not found
98         size_type find_last(MathData const & ar) const;
99         ///
100         bool contains(MathData const & ar) const;
101         ///
102         void validate(LaTeXFeatures &) const;
103
104         /// checked write access
105         MathAtom & operator[](pos_type);
106         /// checked read access
107         MathAtom const & operator[](pos_type) const;
108         /// rebuild cached metrics information
109         void metrics(MetricsInfo & mi, Dimension & dim) const;
110         ///
111         Dimension const & dimension(BufferView const &) const;
112
113         /// redraw cell using cache metrics information
114         void draw(PainterInfo & pi, int x, int y) const;
115         /// rebuild cached metrics information
116         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
117         /// redraw cell using cache metrics information
118         void drawT(TextPainter & pi, int x, int y) const;
119         /// mark cell for re-drawing
120         void touch() const;
121
122         /// access to cached x coordinate of last drawing
123         int xo(BufferView const & bv) const;
124         /// access to cached y coordinate of last drawing
125         int yo(BufferView const & bv) const;
126         /// access to cached x coordinate of mid point of last drawing
127         int xm(BufferView const & bv) const;
128         /// access to cached y coordinate of mid point of last drawing
129         int ym(BufferView const & bv) const;
130         /// write access to coordinate;
131         void setXY(BufferView & bv, int x, int y) const;
132         /// returns x coordinate of given position in the array
133         int pos2x(size_type pos) const;
134         /// returns position of given x coordinate
135         int pos2x(size_type pos, int glue) const;
136         /// returns position of given x coordinate
137         size_type x2pos(int pos) const;
138         /// returns position of given x coordinate fstarting from a certain pos
139         size_type x2pos(int targetx, int glue) const;
140         /// returns distance of this cell to the point given by x and y
141         // assumes valid position and size cache
142         int dist(BufferView const & bv, int x, int y) const;
143
144         /// minimum ascent offset for superscript
145         int minasc() const { return minasc_; }
146         /// minimum descent offset for subscript
147         int mindes() const { return mindes_; }
148         /// level above/below which super/subscript should extend
149         int slevel() const { return slevel_; }
150         /// additional super/subscript shift
151         int sshift() const { return sshift_; }
152         /// superscript kerning
153         int kerning() const { return kerning_; }
154         ///
155         void swap(MathData & ar) { base_type::swap(ar); }
156
157 protected:
158         /// cached values for super/subscript placement
159         mutable int minasc_;
160         mutable int mindes_;
161         mutable int slevel_;
162         mutable int sshift_;
163         mutable int kerning_;
164         
165 private:
166         /// is this an exact match at this position?
167         bool find1(MathData const & ar, size_type pos) const;
168
169         /// attach/detach arguments to macros
170         void updateMacros(MetricsInfo & mi);
171         ///
172         void detachMacroParameters(Cursor & cur, const size_type macroPos);
173         ///
174         void attachMacroParameters(Cursor & cur, const size_type macroPos, 
175                 const size_type macroNumArgs, const int macroOptionals,
176                 const bool fromInitToNormalMode, const bool interactiveInit);
177         ///
178         void collectOptionalParameters(Cursor & cur, 
179                 const size_type numOptionalParams, std::vector<MathData> & params, 
180                 size_t & pos, const pos_type macroPos, const int thisPos, const int thisSlice);
181         ///
182         void collectParameters(Cursor & cur, 
183                 const size_type numParams, std::vector<MathData> & params, 
184                 size_t & pos, MathAtom & scriptToPutAround,
185                 const pos_type macroPos, const int thisPos, const int thisSlice);
186         ///
187         mutable std::vector<Dimension> atom_dims_;
188 };
189
190 ///
191 std::ostream & operator<<(std::ostream & os, MathData const & ar);
192 ///
193 odocstream & operator<<(odocstream & os, MathData const & ar);
194
195
196 } // namespace lyx
197
198 #endif