]> git.lyx.org Git - lyx.git/blob - src/HSpace.cpp
Rename Path.h to PathChanger.h (actual name of the class)
[lyx.git] / src / HSpace.cpp
1 /**
2  * \file HSpace.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jürgen Spitzmüller
7  * \author Uwe Stöhr
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "HSpace.h"
15
16 #include "Buffer.h"
17 #include "BufferParams.h"
18 #include "BufferView.h"
19 #include "support/gettext.h"
20 #include "Length.h"
21 #include "Text.h"
22
23 #include "support/lstrings.h"
24
25 #include "support/lassert.h"
26
27 using namespace std;
28 using namespace lyx::support;
29
30
31 namespace lyx {
32
33
34 HSpace::HSpace()
35         : kind_(DEFAULT), len_()
36 {}
37
38
39 HSpace::HSpace(HSpaceKind k)
40         : kind_(k), len_()
41 {}
42
43
44 HSpace::HSpace(Length const & l)
45         : kind_(LENGTH), len_(l)
46 {}
47
48
49 HSpace::HSpace(GlueLength const & l)
50         : kind_(LENGTH), len_(l)
51 {}
52
53
54 HSpace::HSpace(string const & data)
55         : kind_(DEFAULT), len_()
56 {
57         if (data.empty())
58                 return;
59
60         string input = rtrim(data);
61
62         if (prefixIs(input, "default"))
63                 kind_ = DEFAULT;
64         else if (isValidGlueLength(input, &len_))
65                 kind_ = LENGTH;
66 }
67
68
69 bool HSpace::operator==(HSpace const & other) const
70 {
71         if (kind_ != other.kind_)
72                 return false;
73         if (len_ != other.len_)
74                 return false;
75         return true;
76 }
77
78
79 string const HSpace::asLyXCommand() const
80 {
81         string result;
82         switch (kind_) {
83         case DEFAULT:
84                 result = "default";
85                 break;
86         case LENGTH:
87                 result = len_.asString();
88                 break;
89         }
90         return result;
91 }
92
93
94 string const HSpace::asLatexCommand() const
95 {
96         switch (kind_) {
97         case DEFAULT:
98                 return string();
99                 break;
100         case LENGTH: {
101                 return len_.asLatexString();
102                 break;
103                                  }
104         default: {
105                 LASSERT(false, /**/);
106                 return string();
107                          }
108         }
109 }
110
111
112 docstring const HSpace::asGUIName() const
113 {
114         docstring result;
115         switch (kind_) {
116         case DEFAULT:
117                 result = _("Default");
118                 break;
119         case LENGTH:
120                 result = from_ascii(len_.asString());
121                 break;
122         }
123         return result;
124 }
125
126
127 string HSpace::asHTMLLength() const 
128 {
129         string result;
130         switch (kind_) {
131         case DEFAULT:
132                 // 30pt are LaTeX's default
133                 result = "30pt";
134                 break;
135         case LENGTH: {
136                 Length tmp = len_.len();
137                 if (tmp.value() > 0)
138                         result = tmp.asHTMLString();
139                 break;
140                 }
141         }
142         return result;
143 }
144
145
146 int HSpace::inPixels(BufferView const & bv) const
147 {
148         switch (kind_) {
149         case DEFAULT:
150                 // FIXME: replace by correct length
151                 return bv.buffer().params().getIndentation().inPixels(bv);
152                 //return 0;
153                 break;
154         case LENGTH:
155                 return len_.len().inPixels(bv.workWidth());
156                 break;
157         default:
158                 LASSERT(false, /**/);
159                 return 0;
160         }
161 }
162
163
164 } // namespace lyx