]> git.lyx.org Git - lyx.git/blob - src/vspace.h
Fixed undo handling for tabular-insets and update TabularLayout on
[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         //@Man: constructors
58         //@{
59         ///
60         LyXLength() : val(0), uni(LyXLength::PT) {}
61         LyXLength(float v, LyXLength::UNIT u) : val(v), uni(u) {}
62
63         /** "data" must be a decimal number, followed by a unit. */
64         explicit
65         LyXLength(string const & data);
66         //@}
67         
68         //@Man: selectors
69         //@{
70         ///
71         float value() const         { return val; };
72         ///
73         LyXLength::UNIT unit() const { return uni; };
74         //@}
75
76         ///
77         bool operator== (LyXLength const &) const;
78
79         /// conversion
80         virtual string asString() const;
81         ///
82         virtual string asLatexString() const { return this->asString(); };
83
84
85         /** If "data" is valid, the length represented by it is
86           stored into "result", if that is not 0. */
87         friend bool isValidLength(string const & data, 
88                                   LyXLength * result= 0);
89
90 protected:
91         ///
92         float           val;
93         ///
94         LyXLength::UNIT uni;
95 };
96
97 extern LyXLength::UNIT unitFromString (string const & data);
98 extern bool isValidLength(string const & data, LyXLength * result);
99
100 /// LyXGlueLength class
101 class LyXGlueLength : public LyXLength {
102 public:
103         //@Man: constructors
104         //@{
105         ///
106         LyXGlueLength(float v,
107                       LyXLength::UNIT u, 
108                       float pv = 0.0,
109                       LyXLength::UNIT pu = LyXLength::UNIT_NONE, 
110                       float mv = 0.0,
111                       LyXLength::UNIT mu = LyXLength::UNIT_NONE) 
112                 : LyXLength (v, u), 
113                   plus_val(pv), minus_val(mv), 
114                   plus_uni(pu), minus_uni(mu) {}
115
116         /** "data" must be a decimal number, followed by a unit, and 
117           optional "glue" indicated by "+" and "-".  You may abbreviate
118           reasonably.  Examples:
119           1.2 cm  //  4mm +2pt  //  2cm -4mm +2mm  //  4+0.1-0.2cm
120           The traditional Latex format is also accepted, like  
121           4cm plus 10pt minus 10pt */
122         explicit
123         LyXGlueLength(string const & data);
124         //@}
125         
126         //@Man: selectors
127         //@{
128         ///
129         float plusValue() const         { return plus_val; };
130         ///
131         LyXLength::UNIT plusUnit() const { return plus_uni; };
132         ///
133         float minusValue() const         { return minus_val; };
134         ///
135         LyXLength::UNIT minusUnit() const { return minus_uni; };
136         //@}
137
138         ///
139         bool operator == (LyXGlueLength const &) const;
140
141         /// conversion
142         virtual string asString() const;
143         ///
144         virtual string asLatexString() const;
145
146
147         /** If "data" is valid, the length represented by it is
148           stored into "result", if that is not 0. */
149         friend bool isValidGlueLength(string const & data, 
150                                       LyXGlueLength* result= 0);
151
152 protected:
153         ///
154         float           plus_val, minus_val;
155         ///
156         LyXLength::UNIT plus_uni, minus_uni;
157 };
158
159 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
160
161 ///  VSpace class
162 class VSpace {
163 public:
164         ///
165         enum vspace_kind { NONE, DEFSKIP, 
166                            SMALLSKIP, MEDSKIP, BIGSKIP, 
167                            VFILL, LENGTH };
168         /// constructors
169         VSpace() : 
170                 kin (NONE), 
171                 len(0.0, LyXLength::PT),
172                 kp (false) {}
173         ///
174         explicit
175         VSpace(vspace_kind k) : 
176                 kin (k), 
177                 len (0.0, LyXLength::PT),
178                 kp (false) {}
179         ///
180         explicit
181         VSpace(LyXGlueLength l) :
182                 kin (LENGTH),
183                 len (l),
184                 kp (false) {}
185
186         VSpace(float v, LyXLength::UNIT u) : 
187                 kin (LENGTH), 
188                 len (v, u),
189                 kp (false) {}
190
191         /// this constructor is for reading from a .lyx file
192         explicit
193         VSpace(string const & data);
194         
195         // access functions
196         vspace_kind kind() const  { return  kin; }
197         ///
198         LyXLength   length() const { return len; }
199
200         // a flag that switches between \vspace and \vspace*
201         bool keep() const      { return kp; }
202         ///
203         void setKeep(bool val) { kp = val; } 
204         ///
205         bool operator == (VSpace const &) const;
206
207         // conversion
208         ///
209         string asLyXCommand() const;  // how it goes into the LyX file
210         ///
211         string asLatexCommand(BufferParams const & params) const;
212         ///
213         int inPixels(BufferView * bv) const;
214         ///
215         int inPixels(int default_height, int default_skip) const;
216 private:
217         ///
218         vspace_kind  kin;
219         ///
220         LyXGlueLength    len;
221         ///
222         bool kp;
223 };
224
225 #endif