4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Jean-Marc Lasgouttes
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
13 #ifndef INSET_QUOTES_H
14 #define INSET_QUOTES_H
24 enum class QuoteStyle : int {
60 enum class QuoteSide : int {
68 enum class QuoteLevel : int {
77 Used for the various quotes. German, English, French, all either
79 class InsetQuotesParams {
81 /// Returns the unicode character of a given quote
82 char_type getQuoteChar(QuoteStyle const &, QuoteLevel const &,
83 QuoteSide const &, bool const rtl = false) const;
84 /// Returns a map of quotation marks
85 std::map<std::string, docstring> getTypes() const;
87 docstring getLaTeXQuote(char_type c, std::string const &,
88 bool const rtl = false) const;
90 docstring getHTMLQuote(char_type c) const;
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;
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;
117 extern InsetQuotesParams quoteparams;
120 Used for the various quotes. German, English, French, all either
122 class InsetQuotes : public Inset
125 /** The constructor works like this:
127 \item fls <- french single quote left
128 \item grd <- german double quote right
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());
138 docstring layoutName() const override;
140 void metrics(MetricsInfo &, Dimension &) const override;
142 void draw(PainterInfo & pi, int x, int y) const override;
144 void write(std::ostream &) const override;
146 void read(Lexer & lex) override;
148 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
150 void latex(otexstream &, OutputParams const &) const override;
152 int plaintext(odocstringstream & ods, OutputParams const & op,
153 size_t max_length = INT_MAX) const override;
155 void docbook(XMLStream &, OutputParams const &) const override;
157 docstring xhtml(XMLStream &, OutputParams const &) const override;
160 void toString(odocstream &) const override;
162 void forOutliner(docstring &, size_t const maxlen, bool const) const override;
164 /// Update the contextual information of this inset
165 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
168 void validate(LaTeXFeatures &) const override;
170 std::string contextMenuName() const override;
172 InsetCode lyxCode() const override { return QUOTE_CODE; }
173 /// should this inset be handled like a normal character
174 bool isChar() const override { return true; }
176 /// Returns the current quote type
177 std::string getType() const;
181 Inset * clone() const override { return new InsetQuotes(*this); }
183 /// Decide whether we need left or right quotation marks
184 void setSide(char_type c);
186 void parseString(std::string const &,
187 bool const allow_wildcards = false);
189 docstring displayString() const;
191 docstring getQuoteEntity(bool isHTML) const;
193 QuoteStyle getStyle(std::string const &);
196 QuoteStyle style_ = QuoteStyle::English;
198 QuoteSide side_ = QuoteSide::Opening;
200 QuoteLevel level_ = QuoteLevel::Primary;
202 QuoteStyle global_style_ = QuoteStyle::English;
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?
214 friend class InsetQuotesParams;
217 /// \name Protected functions inherited from Inset class
220 void doDispatch(Cursor & cur, FuncRequest & cmd) override;