]> git.lyx.org Git - lyx.git/blob - src/insets/InsetSpace.h
d68aceeb092a884b7182dcf7153d15500a2cae00
[lyx.git] / src / insets / InsetSpace.h
1 // -*- C++ -*-
2 /**
3  * \file InsetSpace.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup Nielsen
8  * \author Jean-Marc Lasgouttes
9  * \author Lars Gullik Bjønnes
10  * \author Jürgen Spitzmüller
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef INSET_SPACE_H
16 #define INSET_SPACE_H
17
18
19 #include "Inset.h"
20 #include "Length.h"
21 #include "MailInset.h"
22
23
24 namespace lyx {
25
26 class LaTeXFeatures;
27
28 class InsetSpaceParams {
29 public:
30         /// The different kinds of spaces we support
31         enum Kind {
32                 /// Normal space ('\ ')
33                 NORMAL,
34                 /// Protected (no break) space ('~')
35                 PROTECTED,
36                 /// Thin space ('\,')
37                 THIN,
38                 /// \quad (1em)
39                 QUAD,
40                 /// \qquad (2em)
41                 QQUAD,
42                 /// \enspace (0.5em unbreakable)
43                 ENSPACE,
44                 /// \enspace (0.5em breakable)
45                 ENSKIP,
46                 /// Negative thin space ('\negthinspace')
47                 NEGTHIN,
48                 /// rubber length
49                 HFILL,
50                 /// rubber length, filled with dots
51                 DOTFILL,
52                 /// rubber length, filled with a rule
53                 HRULEFILL,
54                 /// \hspace{length}
55                 CUSTOM,
56                 /// \hspace*{length}
57                 CUSTOM_PROTECTED
58         };
59         ///
60         InsetSpaceParams() : kind(NORMAL), length(Length()) {}
61         ///
62         void write(std::ostream & os) const;
63         ///
64         void read(Lexer & lex);
65         ///
66         Kind kind;
67         ///
68         Length length;
69 };
70
71 ///  Used to insert different kinds of spaces
72 class InsetSpace : public Inset {
73 public:
74         ///
75         InsetSpace();
76         ///
77         ~InsetSpace();
78
79         ///
80         explicit
81         InsetSpace(InsetSpaceParams par);
82         ///
83         InsetSpaceParams params() const { return params_; }
84         ///
85         InsetSpaceParams::Kind kind() const;
86         ///
87         Length length() const;
88         ///
89         docstring toolTip(BufferView const & bv, int x, int y) const;
90         ///
91         void metrics(MetricsInfo &, Dimension &) const;
92         ///
93         void draw(PainterInfo & pi, int x, int y) const;
94         ///
95         void write(std::ostream &) const;
96         /// Will not be used when lyxf3
97         void read(Lexer & lex);
98         ///
99         int latex(odocstream &, OutputParams const &) const;
100         ///
101         int plaintext(odocstream &, OutputParams const &) const;
102         ///
103         int docbook(odocstream &, OutputParams const &) const;
104         /// the string that is passed to the TOC
105         void textString(odocstream &) const;
106         ///
107         InsetCode lyxCode() const { return SPACE_CODE; }
108         /// is this an expandible space (rubber length)?
109         bool isStretchableSpace() const;
110
111         // should this inset be handled like a normal charater
112         bool isChar() const { return true; }
113         /// is this equivalent to a letter?
114         bool isLetter() const { return false; }
115         /// is this equivalent to a space (which is BTW different from
116         // a line separator)?
117         bool isSpace() const { return true; }
118 private:
119         virtual Inset * clone() const { return new InsetSpace(*this); }
120         ///
121         void doDispatch(Cursor & cur, FuncRequest & cmd);
122
123         ///
124         InsetSpaceParams params_;
125 };
126
127
128 class InsetSpaceMailer : public MailInset {
129 public:
130         ///
131         InsetSpaceMailer(InsetSpace & inset);
132         ///
133         virtual Inset & inset() const { return inset_; }
134         ///
135         virtual std::string const & name() const { return name_; }
136         ///
137         virtual std::string const inset2string(Buffer const &) const;
138         ///
139         static void string2params(std::string const &, InsetSpaceParams &);
140         ///
141         static std::string const params2string(InsetSpaceParams const &);
142 private:
143         ///
144         static std::string const name_;
145         ///
146         InsetSpace & inset_;
147 };
148
149
150 } // namespace lyx
151
152 #endif // INSET_SPACE_H