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