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