]> git.lyx.org Git - lyx.git/blob - src/Spacing.h
some new (not extensive) changes, some fixes, will probably reverto to .la libs later...
[lyx.git] / src / Spacing.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-1999 The LyX Team.
9  *
10  * ====================================================== */
11
12 #ifndef SPACING_H
13 #define SPACING_H
14
15 #ifdef HAVE_SSTREAM
16 #include <sstream>
17 using std::istringstream;
18 #else
19 #include <strstream>
20 #endif
21
22 #include "support/LOstream.h"
23
24 ///
25 class Spacing {
26 public:
27         ///
28         enum Space {
29                 ///
30                 Single,
31                 ///
32                 Onehalf,
33                 ///
34                 Double,
35                 ///
36                 Other
37         };
38         ///
39         Spacing()
40         {
41                 space = Single;
42                 value = getValue();
43         }
44         ///
45         float getValue() const
46         {
47                 switch(space) {
48                 case Single: return 1.0;
49                 case Onehalf: return 1.25;
50                 case Double: return 1.667;
51                 case Other: return value;
52                 }
53                 return 1.0;
54         }
55         ///
56         Spacing::Space getSpace() const
57         {
58                 return space;
59         }
60         ///
61         void set(Spacing::Space sp, float val = 1.0)
62         {
63                 space = sp;
64                 if (sp == Other) {
65                         switch(int(val * 1000 + 0.5)) {
66                         case 1000: space = Single; break;
67                         case 1250: space = Onehalf; break;
68                         case 1667: space = Double; break;
69                         default: value = val; break;
70                         }
71                 }
72         }
73         ///
74         void set(Spacing::Space sp, char const * val)
75         {
76                 float fval;
77 #ifdef HAVE_SSTREAM
78                 istringstream istr(val);
79 #else
80                 istrstream istr(val);
81 #endif
82                 istr >> fval;
83                 set(sp, fval);
84         }
85         ///
86         void writeFile(ostream &);
87         ///
88         friend bool operator!=(Spacing const & a, Spacing const & b)
89         {
90                 if (a.space == b.space && a.getValue() == b.getValue())
91                         return false;
92                 return true;
93         }
94 private:
95         ///
96         Space space;
97         ///
98         float value;
99 };
100
101 #endif