]> git.lyx.org Git - lyx.git/blob - src/insets/InsetSpace.h
c88ba4680bb8ded995333de4d07173120f32921c
[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 class InsetSpaceParams {
27 public:
28         /// The different kinds of spaces we support
29         enum Kind {
30                 /// Normal space ('\ ')
31                 NORMAL,
32                 /// Protected (no break) space ('~')
33                 PROTECTED,
34                 /// Thin space ('\,')
35                 THIN,
36                 /// \quad (1em)
37                 QUAD,
38                 /// \qquad (2em)
39                 QQUAD,
40                 /// \enspace (0.5em unbreakable)
41                 ENSPACE,
42                 /// \enspace (0.5em breakable)
43                 ENSKIP,
44                 /// Negative thin space ('\negthinspace')
45                 NEGTHIN,
46                 /// rubber length
47                 HFILL,
48                 /// \hspace*{\fill}
49                 HFILL_PROTECTED,
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
72 ///  Used to insert different kinds of spaces
73 class InsetSpace : public Inset
74 {
75 public:
76         ///
77         InsetSpace() {}
78         ///
79         explicit InsetSpace(InsetSpaceParams const & par);
80         ///
81         InsetSpaceParams params() const { return params_; }
82         ///
83         InsetSpaceParams::Kind kind() const;
84         ///
85         ~InsetSpace();
86
87         ///
88         static void string2params(std::string const &, InsetSpaceParams &);
89         ///
90         static std::string params2string(InsetSpaceParams const &);
91         ///
92         Length length() const;
93
94 private:
95         ///
96         docstring toolTip(BufferView const & bv, int x, int y) const;
97         ///
98         void metrics(MetricsInfo &, Dimension &) const;
99         ///
100         void draw(PainterInfo & pi, int x, int y) const;
101         ///
102         void write(std::ostream &) const;
103         /// Will not be used when lyxf3
104         void read(Lexer & lex);
105         ///
106         int latex(odocstream &, OutputParams const &) const;
107         ///
108         int plaintext(odocstream &, OutputParams const &) const;
109         ///
110         int docbook(odocstream &, OutputParams const &) const;
111         /// the string that is passed to the TOC
112         void textString(odocstream &) const;
113         ///
114         void edit(Cursor & cur, bool front,
115                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
116         ///
117         EDITABLE editable() const { return IS_EDITABLE; }
118         ///
119         InsetCode lyxCode() const { return SPACE_CODE; }
120         /// is this an expandible space (rubber length)?
121         bool isStretchableSpace() const;
122
123         // should this inset be handled like a normal charater
124         bool isChar() const { return true; }
125         /// is this equivalent to a letter?
126         bool isLetter() const { return false; }
127         /// is this equivalent to a space (which is BTW different from
128         // a line separator)?
129         bool isSpace() const { return true; }
130         ///
131         docstring contextMenu(BufferView const & bv, int x, int y) const;
132         ///
133         Inset * clone() const { return new InsetSpace(*this); }
134         ///
135         void doDispatch(Cursor & cur, FuncRequest & cmd);
136         ///
137         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
138
139         ///
140         InsetSpaceParams params_;
141 };
142
143
144 } // namespace lyx
145
146 #endif // INSET_SPACE_H