]> git.lyx.org Git - features.git/blob - src/vspace.h
Hopefully fixed the redo problems with insets!
[features.git] / src / vspace.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *      
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef VSPACE_H
13 #define VSPACE_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "LString.h"
20
21 class BufferParams;
22 class BufferView;
23
24
25 //
26 ///  LyXLength Class
27 //
28 class LyXLength {
29 public:
30         /// length units
31         enum UNIT {
32                 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
33                 SP,
34                 /// Point = 1/72.27in = 0.351mm
35                 PT,
36                 /// Big point (72bp = 1in), also PostScript point
37                 BP,
38                 /// Didot point = 1/72 of a French inch, = 0.376mm
39                 DD,
40                 /// Millimeter = 2.845pt
41                 MM,
42                 /// Pica = 12pt = 4.218mm
43                 PC,
44                 /// Cicero = 12dd = 4.531mm
45                 CC,
46                 /// Centimeter = 10mm = 2.371pc
47                 CM,
48                 /// Inch = 25.4mm = 72.27pt = 6.022pc
49                 IN,
50                 /// Height of a small "x" for the current font.
51                 EX,
52                 /// Width of capital "M" in current font.
53                 EM,
54                 /// Math unit (18mu = 1em) for positioning in math mode
55                 MU,
56                 /// Percent of columnwidth both "%" or "%c"
57                 PW,
58                 ///
59                 PE,
60                 /// Percent of pagewidth
61                 PP,
62                 /// Percent of linewidth
63                 PL,
64                 /// no unit
65                 UNIT_NONE
66         };
67
68         ///
69         LyXLength();
70         ///
71         LyXLength(double v, LyXLength::UNIT u);
72
73         /// "data" must be a decimal number, followed by a unit
74         explicit LyXLength(string const & data);
75         
76         ///
77         double value() const;
78         ///
79         LyXLength::UNIT unit() const;
80
81         /// conversion
82         virtual string const asString() const;
83         ///
84         virtual string const asLatexString() const;
85
86         /** If "data" is valid, the length represented by it is
87           stored into "result", if that is not 0. */
88         friend bool isValidLength(string const & data, LyXLength * result = 0);
89
90 protected:
91         ///
92         double          val_;
93         ///
94         LyXLength::UNIT unit_;
95 };
96
97 ///
98 bool operator==(LyXLength const & l1, LyXLength const & l2);
99 ///
100 LyXLength::UNIT unitFromString (string const & data);
101 ///
102 bool isValidLength(string const & data, LyXLength * result);
103 ///
104 const char * stringFromUnit(int unit);
105
106
107
108 //
109 /// LyXGlueLength class
110 //
111 class LyXGlueLength : public LyXLength {
112 public:
113         ///
114         LyXGlueLength(double v,
115                       LyXLength::UNIT u,
116                       double pv = 0.0,
117                       LyXLength::UNIT pu = LyXLength::UNIT_NONE,
118                       double mv = 0.0,
119                       LyXLength::UNIT mu = LyXLength::UNIT_NONE);
120
121         /** "data" must be a decimal number, followed by a unit, and
122           optional "glue" indicated by "+" and "-".  You may abbreviate
123           reasonably.  Examples:
124           1.2 cm  //  4mm +2pt  //  2cm -4mm +2mm  //  4+0.1-0.2cm
125           The traditional Latex format is also accepted, like
126           4cm plus 10pt minus 10pt */
127         explicit LyXGlueLength(string const & data);
128         
129         ///
130         double plusValue() const;
131         ///
132         LyXLength::UNIT plusUnit() const;
133         ///
134         double minusValue() const;
135         ///
136         LyXLength::UNIT minusUnit() const;
137
138         /// conversion
139         virtual string const asString() const;
140         ///
141         virtual string const asLatexString() const;
142
143
144         /** If "data" is valid, the length represented by it is
145           stored into "result", if that is not 0. */
146         friend bool isValidGlueLength(string const & data,
147                                       LyXGlueLength* result = 0);
148
149 protected:
150         ///
151         double plus_val_;
152         ///
153         double minus_val_;
154         ///
155         LyXLength::UNIT plus_unit_;
156         ///
157         LyXLength::UNIT minus_unit_;
158 };
159
160 ///
161 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2);
162 ///
163 bool isValidGlueLength(string const & data, LyXGlueLength * result);
164
165
166 //
167 ///  VSpace class
168 //
169 class VSpace {
170 public:
171         /// The different kinds of spaces.
172         enum vspace_kind {
173                 ///
174                 NONE,
175                 ///
176                 DEFSKIP,
177                 ///
178                 SMALLSKIP,
179                 ///
180                 MEDSKIP,
181                 ///
182                 BIGSKIP,
183                 ///
184                 VFILL,
185                 ///
186                 LENGTH
187         };
188         /// Constructor
189         VSpace();
190         /// Constructor
191         explicit VSpace(vspace_kind k);
192         /// Constructor
193         explicit VSpace(LyXGlueLength l);
194         /// Constructor
195         explicit VSpace(double v, LyXLength::UNIT u);
196
197         /// Constructor for reading from a .lyx file
198         explicit VSpace(string const & data);
199         
200         /// access functions
201         vspace_kind kind() const;
202         ///
203         LyXGlueLength  length() const;
204
205         // a flag that switches between \vspace and \vspace*
206         bool keep() const;
207         ///
208         void setKeep(bool val);
209         ///
210         bool operator==(VSpace const &) const;
211
212         // conversion
213         /// how it goes into the LyX file
214         string const asLyXCommand() const; 
215         ///
216         string const asLatexCommand(BufferParams const & params) const;
217         ///
218         int inPixels(BufferView * bv) const;
219         ///
220         int inPixels(int default_height, int default_skip, int default_width=0) const;
221 private:
222         /// This VSpace kind
223         vspace_kind kind_;
224         ///
225         LyXGlueLength len_;
226         ///
227         bool keep_;
228 };
229
230 #endif