]> git.lyx.org Git - lyx.git/blob - src/Spacing.h
several small and larger changes, read the Changelog
[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-2000 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                 space = Single;
41                 value = getValue();
42         }
43         ///
44         float getValue() const {
45                 switch(space) {
46                 case Single: return 1.0;
47                 case Onehalf: return 1.25;
48                 case Double: return 1.667;
49                 case Other: return value;
50                 }
51                 return 1.0;
52         }
53         ///
54         Spacing::Space getSpace() const {
55                 return space;
56         }
57         ///
58         void set(Spacing::Space sp, float val = 1.0) {
59                 space = sp;
60                 if (sp == Other) {
61                         switch(int(val * 1000 + 0.5)) {
62                         case 1000: space = Single; break;
63                         case 1250: space = Onehalf; break;
64                         case 1667: space = Double; break;
65                         default: value = val; break;
66                         }
67                 }
68         }
69         ///
70         void set(Spacing::Space sp, char const * val) {
71                 float fval;
72 #ifdef HAVE_SSTREAM
73                 istringstream istr(val);
74 #else
75                 istrstream istr(val);
76 #endif
77                 istr >> fval;
78                 set(sp, fval);
79         }
80         ///
81         void writeFile(ostream &);
82         ///
83         friend bool operator!=(Spacing const & a, Spacing const & b) {
84                 if (a.space == b.space && a.getValue() == b.getValue())
85                         return false;
86                 return true;
87         }
88 private:
89         ///
90         Space space;
91         ///
92         float value;
93 };
94
95 #endif