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
18 #include "support/docstring.h"
24 Used for the various quotes. German, English, French, all either
26 class InsetQuotesParams {
75 /// Returns the unicode character of a given quote
76 char_type getQuoteChar(QuoteStyle const &, QuoteLevel const &,
77 QuoteSide const &, bool const rtl = false) const;
78 /// Returns a map of quotation marks
79 std::map<std::string, docstring> getTypes() const;
81 docstring getLaTeXQuote(char_type c, std::string const &,
82 bool const rtl = false) const;
84 docstring getHTMLQuote(char_type c) const;
86 docstring getXMLQuote(char_type c) const;
87 /// Returns a descriptive label of a style suitable for dialog and menu
88 docstring const getGuiLabel(QuoteStyle const & qs,
89 bool langdef = false) const;
90 /// Returns a descriptive label of a given char
91 docstring const getShortGuiLabel(docstring const & str) const;
93 int stylescount() const;
94 /// Returns the matching style shortcut char
95 char getStyleChar(QuoteStyle const & style) const;
96 /// Returns the quote style from the shortcut string
97 QuoteStyle getQuoteStyle(std::string const & s,
98 bool const allow_wildcards = false,
99 QuoteStyle fallback = EnglishQuotes) const;
100 /// Returns the quote sind from the shortcut string
101 QuoteSide getQuoteSide(std::string const & s,
102 bool const allow_wildcards = false,
103 QuoteSide fallback = OpeningQuote) const;
104 /// Returns the quote level from the shortcut string
105 QuoteLevel getQuoteLevel(std::string const & s,
106 bool const allow_wildcards = false,
107 QuoteLevel fallback = PrimaryQuotes) const;
111 extern InsetQuotesParams quoteparams;
114 Used for the various quotes. German, English, French, all either
116 class InsetQuotes : public Inset
119 /** The constructor works like this:
121 \item fls <- french single quote left
122 \item grd <- german double quote right
126 explicit InsetQuotes(Buffer * buf, std::string const & str = "eld");
127 /// Direct access to inner/outer quotation marks
128 InsetQuotes(Buffer * buf, char_type c, InsetQuotesParams::QuoteLevel level,
129 std::string const & side = std::string(),
130 std::string const & style = std::string());
132 docstring layoutName() const override;
134 void metrics(MetricsInfo &, Dimension &) const override;
136 void draw(PainterInfo & pi, int x, int y) const override;
138 void write(std::ostream &) const override;
140 void read(Lexer & lex) override;
142 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
144 void latex(otexstream &, OutputParams const &) const override;
146 int plaintext(odocstringstream & ods, OutputParams const & op,
147 size_t max_length = INT_MAX) const override;
149 void docbook(XMLStream &, OutputParams const &) const override;
151 docstring xhtml(XMLStream &, OutputParams const &) const override;
154 void toString(odocstream &) const override;
156 void forOutliner(docstring &, size_t const maxlen, bool const) const override;
158 /// Update the contextual information of this inset
159 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
162 void validate(LaTeXFeatures &) const override;
164 std::string contextMenuName() const override;
166 InsetCode lyxCode() const override { return QUOTE_CODE; }
167 /// should this inset be handled like a normal character
168 bool isChar() const override { return true; }
170 /// Returns the current quote type
171 std::string getType() const;
175 Inset * clone() const override { return new InsetQuotes(*this); }
177 /// Decide whether we need left or right quotation marks
178 void setSide(char_type c);
180 void parseString(std::string const &,
181 bool const allow_wildcards = false);
183 docstring displayString() const;
185 docstring getQuoteEntity(bool isHTML) const;
187 InsetQuotesParams::QuoteStyle getStyle(std::string const &);
190 InsetQuotesParams::QuoteStyle style_;
192 InsetQuotesParams::QuoteSide side_;
194 InsetQuotesParams::QuoteLevel level_;
196 InsetQuotesParams::QuoteStyle global_style_;
197 /// Current font encoding
198 std::string fontenc_;
199 /// Code of the contextual language
200 std::string context_lang_;
201 /// Is this in a pass-thru context?
203 /// Do we use fontspec?
205 /// Do we have an internal font encoding?
206 bool internal_fontenc_;
207 /// Are we writing RTL?
210 friend class InsetQuotesParams;
213 /// \name Protected functions inherited from Inset class
216 void doDispatch(Cursor & cur, FuncRequest & cmd) override;