]> git.lyx.org Git - lyx.git/blob - src/vspace.h
More fixes to insettabular/text (and some missing features added).
[lyx.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-2000 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 ///  LyXLength Class
25 class LyXLength {
26 public:
27         /// length units
28         enum UNIT {
29                 /// Scaled point (65536sp = 1pt) TeX's smallest unit.
30                 SP,
31                 /// Point = 1/72.27in = 0.351mm
32                 PT,
33                 /// Big point (72bp = 1in), also PostScript point
34                 BP,
35                 /// Didot point = 1/72 of a French inch, = 0.376mm
36                 DD,
37                 /// Millimeter = 2.845pt
38                 MM,
39                 /// Pica = 12pt = 4.218mm
40                 PC,
41                 /// Cicero = 12dd = 4.531mm
42                 CC,
43                 /// Centimeter = 10mm = 2.371pc
44                 CM,
45                 /// Inch = 25.4mm = 72.27pt = 6.022pc
46                 IN,
47                 /// Height of a small "x" for the current font.
48                 EX,
49                 /// Width of capital "M" in current font.
50                 EM,
51                 /// Math unit (18mu = 1em) for positioning in math mode
52                 MU,
53                 /// no unit
54                 UNIT_NONE
55         };
56
57         ///
58         LyXLength() : val(0), uni(LyXLength::PT) {}
59         ///
60         LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
61
62         /** "data" must be a decimal number, followed by a unit. */
63         explicit
64         LyXLength(string const & data);
65         
66         ///
67         float value() const         { return val; }
68         ///
69         LyXLength::UNIT unit() const { return uni; }
70
71         /// conversion
72         virtual string const asString() const;
73         ///
74         virtual string const asLatexString() const {
75                 return this->asString();
76         }
77
78         /** If "data" is valid, the length represented by it is
79           stored into "result", if that is not 0. */
80         friend bool isValidLength(string const & data, 
81                                   LyXLength * result = 0);
82
83 protected:
84         ///
85         float           val;
86         ///
87         LyXLength::UNIT uni;
88 };
89
90 ///
91 inline
92 bool operator==(LyXLength const & l1, LyXLength const & l2)
93 {
94         return l1.value() == l2.value()
95                 && l1.unit() == l2.unit();
96 }
97         
98 ///
99 extern LyXLength::UNIT unitFromString (string const & data);
100 ///
101 extern bool isValidLength(string const & data, LyXLength * result);
102
103 /// LyXGlueLength class
104 class LyXGlueLength : public LyXLength {
105 public:
106         ///
107         LyXGlueLength(float v,
108                       LyXLength::UNIT u, 
109                       float pv = 0.0,
110                       LyXLength::UNIT pu = LyXLength::UNIT_NONE, 
111                       float mv = 0.0,
112                       LyXLength::UNIT mu = LyXLength::UNIT_NONE) 
113                 : LyXLength (v, u), 
114                   plus_val(pv), minus_val(mv), 
115                   plus_uni(pu), minus_uni(mu) {}
116
117         /** "data" must be a decimal number, followed by a unit, and 
118           optional "glue" indicated by "+" and "-".  You may abbreviate
119           reasonably.  Examples:
120           1.2 cm  //  4mm +2pt  //  2cm -4mm +2mm  //  4+0.1-0.2cm
121           The traditional Latex format is also accepted, like  
122           4cm plus 10pt minus 10pt */
123         explicit
124         LyXGlueLength(string const & data);
125         
126         ///
127         float plusValue() const         { return plus_val; }
128         ///
129         LyXLength::UNIT plusUnit() const { return plus_uni; }
130         ///
131         float minusValue() const         { return minus_val; }
132         ///
133         LyXLength::UNIT minusUnit() const { return minus_uni; }
134
135         /// conversion
136         virtual string const asString() const;
137         ///
138         virtual string const asLatexString() const;
139
140
141         /** If "data" is valid, the length represented by it is
142           stored into "result", if that is not 0. */
143         friend bool isValidGlueLength(string const & data, 
144                                       LyXGlueLength* result = 0);
145
146 protected:
147         ///
148         float plus_val;
149         ///
150         float minus_val;
151         ///
152         LyXLength::UNIT plus_uni;
153         ///
154         LyXLength::UNIT minus_uni;
155 };
156
157 ///
158 inline
159 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
160 {
161         return l1.value() == l2.value()
162                 && l1.unit() == l2.unit()
163                 && l1.plusValue() == l2.plusValue()
164                 && l1.plusUnit() == l2.plusUnit()
165                 && l1.minusValue() == l2.minusValue()
166                 && l1.minusUnit() == l2.minusUnit();
167 }
168
169
170 ///
171 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
172
173 ///  VSpace class
174 class VSpace {
175 public:
176         ///
177         enum vspace_kind {
178                 ///
179                 NONE,
180                 ///
181                 DEFSKIP,
182                 ///
183                 SMALLSKIP,
184                 ///
185                 MEDSKIP,
186                 ///
187                 BIGSKIP,
188                 ///
189                 VFILL,
190                 ///
191                 LENGTH
192         };
193         /// constructors
194         VSpace() : 
195                 kin (NONE), 
196                 len(0.0, LyXLength::PT),
197                 kp (false) {}
198         ///
199         explicit
200         VSpace(vspace_kind k) : 
201                 kin (k), 
202                 len (0.0, LyXLength::PT),
203                 kp (false) {}
204         ///
205         explicit
206         VSpace(LyXGlueLength l) :
207                 kin (LENGTH),
208                 len (l),
209                 kp (false) {}
210
211         ///
212         explicit
213         VSpace(float v, LyXLength::UNIT u) : 
214                 kin (LENGTH), 
215                 len (v, u),
216                 kp (false) {}
217
218         /// this constructor is for reading from a .lyx file
219         explicit
220         VSpace(string const & data);
221         
222         // access functions
223         vspace_kind kind() const  { return  kin; }
224         ///
225         LyXGlueLength   length() const { return len; }
226
227         // a flag that switches between \vspace and \vspace*
228         bool keep() const      { return kp; }
229         ///
230         void setKeep(bool val) { kp = val; } 
231         ///
232         bool operator==(VSpace const &) const;
233
234         // conversion
235         ///
236         string const asLyXCommand() const;  // how it goes into the LyX file
237         ///
238         string const asLatexCommand(BufferParams const & params) const;
239         ///
240         int inPixels(BufferView * bv) const;
241         ///
242         int inPixels(int default_height, int default_skip) const;
243 private:
244         ///
245         vspace_kind kin;
246         ///
247         LyXGlueLength len;
248         ///
249         bool kp;
250 };
251
252 #endif