* qt_helpers.cpp:
[lyx.git] / src / HSpace.cpp
blob5a2b16695fbfcc9f552258d956e82c8b74d13382
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.
6 * \author Jürgen Spitzmüller
7 * \author Uwe Stöhr
9 * Full author contact details are available in file CREDITS.
12 #include <config.h>
14 #include "HSpace.h"
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"
23 #include "support/lstrings.h"
25 #include "support/lassert.h"
27 using namespace std;
28 using namespace lyx::support;
31 namespace lyx {
34 HSpace::HSpace()
35 : kind_(DEFAULT), len_()
39 HSpace::HSpace(HSpaceKind k)
40 : kind_(k), len_()
44 HSpace::HSpace(Length const & l)
45 : kind_(LENGTH), len_(l)
49 HSpace::HSpace(GlueLength const & l)
50 : kind_(LENGTH), len_(l)
54 HSpace::HSpace(string const & data)
55 : kind_(DEFAULT), len_()
57 if (data.empty())
58 return;
60 string input = rtrim(data);
62 if (prefixIs(input, "default"))
63 kind_ = DEFAULT;
64 else if (isValidGlueLength(input, &len_))
65 kind_ = LENGTH;
69 bool HSpace::operator==(HSpace const & other) const
71 if (kind_ != other.kind_)
72 return false;
73 if (len_ != other.len_)
74 return false;
75 return true;
79 string const HSpace::asLyXCommand() const
81 string result;
82 switch (kind_) {
83 case DEFAULT:
84 result = "default";
85 break;
86 case LENGTH:
87 result = len_.asString();
88 break;
90 return result;
94 string const HSpace::asLatexCommand() const
96 switch (kind_) {
97 case DEFAULT:
98 return string();
99 break;
100 case LENGTH: {
101 return len_.asLatexString();
102 break;
104 default: {
105 LASSERT(false, /**/);
106 return string();
112 docstring const HSpace::asGUIName() const
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;
123 return result;
127 string HSpace::asHTMLLength() const
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;
142 return result;
145 int HSpace::inPixels(BufferView const & bv) const
147 switch (kind_) {
148 case DEFAULT:
149 // FIXME: replace by correct length
150 return bv.buffer().params().getIndentation().inPixels(bv);
151 //return 0;
152 break;
153 case LENGTH:
154 return len_.len().inPixels(bv.workWidth());
155 break;
156 default:
157 LASSERT(false, /**/);
158 return 0;
163 } // namespace lyx