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