]> git.lyx.org Git - lyx.git/blob - src/insets/InsetQuotes.h
Move Lexer to support/ directory (and lyx::support namespace)
[lyx.git] / src / insets / InsetQuotes.h
1 // -*- C++ -*-
2 /**
3  * \file InsetQuotes.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  *  \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef INSET_QUOTES_H
14 #define INSET_QUOTES_H
15
16 #include "Inset.h"
17
18 #include <map>
19
20
21 namespace lyx {
22
23 ///
24 enum class QuoteStyle : int {
25         ///
26         English,
27         ///
28         Swedish,
29         ///
30         German,
31         ///
32         Polish,
33         ///
34         Swiss,
35         ///
36         Danish,
37         ///
38         Plain,
39         ///
40         British,
41         ///
42         SwedishG,
43         ///
44         French,
45         ///
46         FrenchIN,
47         ///
48         Russian,
49         ///
50         CJK,
51         ///
52         CJKAngle,
53         ///
54         Hungarian,
55         ///
56         Hebrew,
57         ///
58         Dynamic
59 };
60
61 ///
62 enum class QuoteSide : int {
63         ///
64         Opening,
65         ///
66         Closing
67 };
68
69 ///
70 enum class QuoteLevel : int {
71         ///
72         Secondary,
73         ///
74         Primary
75 };
76
77
78 /** Quotes.
79   Used for the various quotes. German, English, French, all either
80   double or single **/
81 class InsetQuotesParams {
82 public:
83         /// Returns the unicode character of a given quote
84         char_type getQuoteChar(QuoteStyle const &, QuoteLevel const &,
85                                QuoteSide const &, bool const rtl = false) const;
86         /// Returns a map of quotation marks
87         std::map<std::string, docstring> getTypes() const;
88         ///
89         docstring getLaTeXQuote(char_type c, std::string const &,
90                                 bool const rtl = false) const;
91         ///
92         docstring getXMLQuote(char_type c) const;
93         /// Returns a descriptive label of a style suitable for dialog and menu
94         docstring const getGuiLabel(QuoteStyle const & qs,
95                                     bool langdef = false) const;
96         /// Returns a descriptive label of a given char
97         docstring const getShortGuiLabel(docstring const & str) const;
98         ///
99         int stylescount() const;
100         /// Returns the matching style shortcut char
101         char getStyleChar(QuoteStyle const & style) const;
102         /// Returns the quote style from the shortcut string
103         QuoteStyle getQuoteStyle(std::string const & s,
104                 bool const allow_wildcards = false,
105                 QuoteStyle fallback = QuoteStyle::English) const;
106         /// Returns the quote sind from the shortcut string
107         QuoteSide getQuoteSide(std::string const & s,
108                 bool const allow_wildcards = false,
109                 QuoteSide fallback = QuoteSide::Opening) const;
110         /// Returns the quote level from the shortcut string
111         QuoteLevel getQuoteLevel(std::string const & s,
112                 bool const allow_wildcards = false,
113                 QuoteLevel fallback = QuoteLevel::Primary) const;
114 };
115
116 ///
117 extern InsetQuotesParams quoteparams;
118
119 /** Quotes.
120   Used for the various quotes. German, English, French, all either
121   double or single **/
122 class InsetQuotes : public Inset
123 {
124 public:
125         /** The constructor works like this:
126           \begin{itemize}
127             \item fls <- french single quote left
128             \item grd <- german double quote right
129             \item etc.
130           \end{itemize}
131           */
132         explicit InsetQuotes(Buffer * buf, std::string const & str = "eld");
133         /// Direct access to inner/outer quotation marks
134         InsetQuotes(Buffer * buf, char_type c, QuoteLevel level,
135                     std::string const & side = std::string(),
136                     std::string const & style = std::string());
137         ///
138         docstring layoutName() const override;
139         ///
140         void metrics(MetricsInfo &, Dimension &) const override;
141         ///
142         void draw(PainterInfo & pi, int x, int y) const override;
143         ///
144         void write(std::ostream &) const override;
145         ///
146         void read(support::Lexer & lex) override;
147         ///
148         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
149         ///
150         void latex(otexstream &, OutputParams const &) const override;
151         ///
152         int plaintext(odocstringstream & ods, OutputParams const & op,
153                       size_t max_length = INT_MAX) const override;
154         ///
155         void docbook(XMLStream &, OutputParams const &) const override;
156         ///
157         docstring xhtml(XMLStream &, OutputParams const &) const override;
158
159         ///
160         bool findUsesToString() const override { return true; }
161         ///
162         void toString(odocstream &) const override;
163         ///
164         void forOutliner(docstring &, size_t const maxlen, bool const) const override;
165
166         /// Update the contextual information of this inset
167         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
168
169         ///
170         void validate(LaTeXFeatures &) const override;
171         ///
172         std::string contextMenuName() const override;
173         ///
174         InsetCode lyxCode() const override { return QUOTE_CODE; }
175         /// should this inset be handled like a normal character
176         bool isChar() const override { return true; }
177
178         /// Returns the current quote type
179         std::string getType() const;
180         ///
181         std::pair<int, int> isWords() const override;
182
183 private:
184         ///
185         Inset * clone() const override { return new InsetQuotes(*this); }
186
187         /// Decide whether we need left or right quotation marks
188         void setSide(char_type c);
189         ///
190         void parseString(std::string const &,
191                          bool const allow_wildcards = false);
192         ///
193         docstring displayString() const;
194         ///
195         docstring getQuoteXMLEntity() const;
196         ///
197         QuoteStyle getStyle(std::string const &);
198
199         ///
200         QuoteStyle style_ = QuoteStyle::English;
201         ///
202         QuoteSide side_ = QuoteSide::Opening;
203         ///
204         QuoteLevel level_ = QuoteLevel::Primary;
205         ///
206         QuoteStyle global_style_ = QuoteStyle::English;
207         /// Code of the contextual language
208         std::string context_lang_;
209         /// Is this in a pass-thru context?
210         bool pass_thru_ = false;
211         /// Do we use fontspec?
212         bool fontspec_ = false;
213         /// Do we have an internal font encoding?
214         bool internal_fontenc_ = false;
215         /// Are we writing RTL?
216         bool rtl_ = false;
217         ///
218         friend class InsetQuotesParams;
219
220 protected:
221         /// \name Protected functions inherited from Inset class
222         //@{
223         ///
224         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
225         //@}
226 };
227
228 } // namespace lyx
229
230 #endif