]> git.lyx.org Git - lyx.git/blob - src/insets/InsetSpace.h
e6f5bce98640d6524f236300b92c446859719764
[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                 /// \hspace*{\fill}
51                 HFILL_PROTECTED,
52                 /// rubber length, filled with dots
53                 DOTFILL,
54                 /// rubber length, filled with a rule
55                 HRULEFILL,
56                 /// \hspace{length}
57                 CUSTOM,
58                 /// \hspace*{length}
59                 CUSTOM_PROTECTED
60         };
61         ///
62         InsetSpaceParams() : kind(NORMAL), length(Length()) {}
63         ///
64         void write(std::ostream & os) const;
65         ///
66         void read(Lexer & lex);
67         ///
68         Kind kind;
69         ///
70         Length length;
71 };
72
73 ///  Used to insert different kinds of spaces
74 class InsetSpace : public Inset {
75 public:
76         ///
77         InsetSpace();
78         ///
79         ~InsetSpace();
80
81         ///
82         explicit
83         InsetSpace(InsetSpaceParams par);
84         ///
85         InsetSpaceParams params() const { return params_; }
86         ///
87         InsetSpaceParams::Kind kind() const;
88         ///
89         Length length() const;
90         ///
91         docstring toolTip(BufferView const & bv, int x, int y) const;
92         ///
93         void metrics(MetricsInfo &, Dimension &) const;
94         ///
95         void draw(PainterInfo & pi, int x, int y) const;
96         ///
97         void write(std::ostream &) const;
98         /// Will not be used when lyxf3
99         void read(Lexer & lex);
100         ///
101         int latex(odocstream &, OutputParams const &) const;
102         ///
103         int plaintext(odocstream &, OutputParams const &) const;
104         ///
105         int docbook(odocstream &, OutputParams const &) const;
106         /// the string that is passed to the TOC
107         void textString(odocstream &) const;
108         ///
109         void edit(Cursor & cur, bool front,
110                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
111         ///
112         EDITABLE editable() const { return IS_EDITABLE; }
113         ///
114         InsetCode lyxCode() const { return SPACE_CODE; }
115         /// is this an expandible space (rubber length)?
116         bool isStretchableSpace() const;
117
118         // should this inset be handled like a normal charater
119         bool isChar() const { return true; }
120         /// is this equivalent to a letter?
121         bool isLetter() const { return false; }
122         /// is this equivalent to a space (which is BTW different from
123         // a line separator)?
124         bool isSpace() const { return true; }
125         ///
126         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
127 private:
128         virtual Inset * clone() const { return new InsetSpace(*this); }
129         ///
130         void doDispatch(Cursor & cur, FuncRequest & cmd);
131
132         ///
133         InsetSpaceParams params_;
134 };
135
136
137 class InsetSpaceMailer : public MailInset {
138 public:
139         ///
140         InsetSpaceMailer(InsetSpace & inset);
141         ///
142         virtual Inset & inset() const { return inset_; }
143         ///
144         virtual std::string const & name() const { return name_; }
145         ///
146         virtual std::string const inset2string(Buffer const &) const;
147         ///
148         static void string2params(std::string const &, InsetSpaceParams &);
149         ///
150         static std::string const params2string(InsetSpaceParams const &);
151 private:
152         ///
153         static std::string const name_;
154         ///
155         InsetSpace & inset_;
156 };
157
158
159 } // namespace lyx
160
161 #endif // INSET_SPACE_H