]> git.lyx.org Git - lyx.git/blob - src/insets/InsetSpace.h
InsetInfo: enable inset dissolve
[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 #include "Inset.h"
19 #include "Length.h"
20
21
22 namespace lyx {
23
24 class LaTeXFeatures;
25
26 struct InsetSpaceParams {
27         /// The different kinds of spaces we support
28         enum Kind {
29                 /// Normal space ('\ ')
30                 NORMAL,
31                 /// Protected (no break) space ('~')
32                 PROTECTED,
33                 /// Visible ("open box") space ('\textvisiblespace')
34                 VISIBLE,
35                 /// Thin space ('\,')
36                 THIN,
37                 /// Medium space ('\:')
38                 MEDIUM,
39                 /// Thick space ('\;')
40                 THICK,
41                 /// \quad (1em)
42                 QUAD,
43                 /// \qquad (2em)
44                 QQUAD,
45                 /// \enskip (0.5em unbreakable)
46                 ENSPACE,
47                 /// \enspace (0.5em breakable)
48                 ENSKIP,
49                 /// Negative thin space ('\negthinspace')
50                 NEGTHIN,
51                 /// Negative medium space ('\negmedspace')
52                 NEGMEDIUM,
53                 /// Negative thick space ('\negthickspace')
54                 NEGTHICK,
55                 /// rubber length
56                 HFILL,
57                 /// \hspace*{\fill}
58                 HFILL_PROTECTED,
59                 /// rubber length, filled with dots
60                 DOTFILL,
61                 /// rubber length, filled with a rule
62                 HRULEFILL,
63                 /// rubber length, filled with a left arrow
64                 LEFTARROWFILL,
65                 /// rubber length, filled with a right arrow
66                 RIGHTARROWFILL,
67                 // rubber length, filled with an up brace
68                 UPBRACEFILL,
69                 // rubber length, filled with a down brace
70                 DOWNBRACEFILL,
71                 /// \hspace{length}
72                 CUSTOM,
73                 /// \hspace*{length}
74                 CUSTOM_PROTECTED
75         };
76         ///
77         InsetSpaceParams(bool m = false) : kind(NORMAL), math(m) {}
78         ///
79         void write(std::ostream & os) const;
80         ///
81         void read(Lexer & lex);
82         ///
83         Kind kind;
84         ///
85         GlueLength length;
86         /**
87          * Whether these params are to be used in mathed.
88          * This determines the set of valid kinds.
89          */
90         bool math;
91 };
92
93
94 ///  Used to insert different kinds of spaces
95 class InsetSpace : public Inset
96 {
97 public:
98         ///
99         InsetSpace() : Inset(0) {}
100         ///
101         explicit InsetSpace(InsetSpaceParams const & par);
102         ///
103         InsetSpaceParams const & params() const { return params_; }
104         ///
105         InsetSpaceParams::Kind kind() const;
106
107         ///
108         static void string2params(std::string const &, InsetSpaceParams &);
109         ///
110         static std::string params2string(InsetSpaceParams const &);
111         ///
112         GlueLength length() const;
113
114         ///
115         docstring toolTip(BufferView const & bv, int x, int y) const;
116         ///
117         void metrics(MetricsInfo &, Dimension &) const;
118         ///
119         void draw(PainterInfo & pi, int x, int y) const;
120         ///
121         void write(std::ostream &) const;
122         /// Will not be used when lyxf3
123         void read(Lexer & lex);
124         ///
125         void latex(otexstream &, OutputParams const &) const;
126         ///
127         int plaintext(odocstringstream & ods, OutputParams const & op,
128                       size_t max_length = INT_MAX) const;
129         ///
130         int docbook(odocstream &, OutputParams const &) const;
131         ///
132         docstring xhtml(XHTMLStream &, OutputParams const &) const;
133         ///
134         void validate(LaTeXFeatures & features) const;
135         ///
136         void toString(odocstream &) const;
137         ///
138         void forOutliner(docstring &, size_t const, bool const) const;
139         ///
140         bool hasSettings() const { return true; }
141         ///
142         bool clickable(BufferView const &, int, int) const { return true; }
143         ///
144         InsetCode lyxCode() const { return SPACE_CODE; }
145         /// does this inset try to use all available space (like \\hfill does)?
146         bool isHfill() const;
147         /// should this inset be handled like a normal character?
148         bool isChar() const { return true; }
149         /// is this equivalent to a letter?
150         bool isLetter() const { return false; }
151         /// is this equivalent to a space (which is BTW different from
152         // a line separator)?
153         bool isSpace() const { return true; }
154         ///
155         std::string contextMenuName() const;
156 protected:
157         ///
158         Inset * clone() const { return new InsetSpace(*this); }
159         ///
160         void doDispatch(Cursor & cur, FuncRequest & cmd);
161 public:
162         ///
163         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
164
165 private:
166         ///
167         InsetSpaceParams params_;
168 };
169
170
171 } // namespace lyx
172
173 #endif // INSET_SPACE_H