]> git.lyx.org Git - lyx.git/blob - src/vspace.h
small changes to ButtonController usage
[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 asString() const;
73         ///
74         virtual string asLatexString() const { return this->asString(); };
75
76
77         /** If "data" is valid, the length represented by it is
78           stored into "result", if that is not 0. */
79         friend bool isValidLength(string const & data, 
80                                   LyXLength * result= 0);
81
82 protected:
83         ///
84         float           val;
85         ///
86         LyXLength::UNIT uni;
87 };
88
89 ///
90 inline
91 bool operator==(LyXLength const & l1, LyXLength const & l2)
92 {
93         return l1.value() == l2.value()
94                 && l1.unit() == l2.unit();
95 }
96         
97 ///
98 extern LyXLength::UNIT unitFromString (string const & data);
99 ///
100 extern bool isValidLength(string const & data, LyXLength * result);
101
102 /// LyXGlueLength class
103 class LyXGlueLength : public LyXLength {
104 public:
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         float plusValue() const         { return plus_val; };
127         ///
128         LyXLength::UNIT plusUnit() const { return plus_uni; };
129         ///
130         float minusValue() const         { return minus_val; };
131         ///
132         LyXLength::UNIT minusUnit() const { return minus_uni; };
133
134         /// conversion
135         virtual string asString() const;
136         ///
137         virtual string asLatexString() const;
138
139
140         /** If "data" is valid, the length represented by it is
141           stored into "result", if that is not 0. */
142         friend bool isValidGlueLength(string const & data, 
143                                       LyXGlueLength* result= 0);
144
145 protected:
146         ///
147         float           plus_val, minus_val;
148         ///
149         LyXLength::UNIT plus_uni, minus_uni;
150 };
151
152 ///
153 inline
154 bool operator==(LyXGlueLength const & l1, LyXGlueLength const & l2)
155 {
156         return l1.value() == l2.value()
157                 && l1.unit() == l2.unit()
158                 && l1.plusValue() == l2.plusValue()
159                 && l1.plusUnit() == l2.plusUnit()
160                 && l1.minusValue() == l2.minusValue()
161                 && l1.minusUnit() == l2.minusUnit();
162 }
163
164
165 ///
166 extern bool isValidGlueLength(string const & data, LyXGlueLength * result);
167
168 ///  VSpace class
169 class VSpace {
170 public:
171         ///
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         /// constructors
189         VSpace() : 
190                 kin (NONE), 
191                 len(0.0, LyXLength::PT),
192                 kp (false) {}
193         ///
194         explicit
195         VSpace(vspace_kind k) : 
196                 kin (k), 
197                 len (0.0, LyXLength::PT),
198                 kp (false) {}
199         ///
200         explicit
201         VSpace(LyXGlueLength l) :
202                 kin (LENGTH),
203                 len (l),
204                 kp (false) {}
205
206         ///
207         explicit
208         VSpace(float v, LyXLength::UNIT u) : 
209                 kin (LENGTH), 
210                 len (v, u),
211                 kp (false) {}
212
213         /// this constructor is for reading from a .lyx file
214         explicit
215         VSpace(string const & data);
216         
217         // access functions
218         vspace_kind kind() const  { return  kin; }
219         ///
220         LyXLength   length() const { return len; }
221
222         // a flag that switches between \vspace and \vspace*
223         bool keep() const      { return kp; }
224         ///
225         void setKeep(bool val) { kp = val; } 
226         ///
227         bool operator == (VSpace const &) const;
228
229         // conversion
230         ///
231         string asLyXCommand() const;  // how it goes into the LyX file
232         ///
233         string asLatexCommand(BufferParams const & params) const;
234         ///
235         int inPixels(BufferView * bv) const;
236         ///
237         int inPixels(int default_height, int default_skip) const;
238 private:
239         ///
240         vspace_kind  kin;
241         ///
242         LyXGlueLength    len;
243         ///
244         bool kp;
245 };
246
247 #endif