]> git.lyx.org Git - lyx.git/blob - src/insets/InsetQuotes.h
Rename XHTMLStream to XMLStream, move it to another file, and prepare for DocBook...
[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 /** Quotes.
24   Used for the various quotes. German, English, French, all either
25   double or single **/
26 class InsetQuotesParams {
27 public:
28         ///
29         enum QuoteStyle {
30                 ///
31                 EnglishQuotes,
32                 ///
33                 SwedishQuotes,
34                 ///
35                 GermanQuotes,
36                 ///
37                 PolishQuotes,
38                 ///
39                 SwissQuotes,
40                 ///
41                 DanishQuotes,
42                 ///
43                 PlainQuotes,
44                 ///
45                 BritishQuotes,
46                 ///
47                 SwedishGQuotes,
48                 ///
49                 FrenchQuotes,
50                 ///
51                 FrenchINQuotes,
52                 ///
53                 RussianQuotes,
54                 ///
55                 CJKQuotes,
56                 ///
57                 CJKAngleQuotes,
58                 ///
59                 DynamicQuotes
60         };
61         ///
62         enum QuoteSide {
63                 ///
64                 OpeningQuote,
65                 ///
66                 ClosingQuote
67         };
68         ///
69         enum QuoteLevel {
70                 ///
71                 SecondaryQuotes,
72                 ///
73                 PrimaryQuotes
74         };
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;
80         ///
81         docstring getLaTeXQuote(char_type c, std::string const &,
82                                 bool const rtl = false) const;
83         ///
84         docstring getHTMLQuote(char_type c) const;
85         ///
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);
90         /// Returns a descriptive label of a given char
91         docstring const getShortGuiLabel(docstring const & str);
92         ///
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);
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);
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);
108 };
109
110 ///
111 extern InsetQuotesParams quoteparams;
112
113 /** Quotes.
114   Used for the various quotes. German, English, French, all either
115   double or single **/
116 class InsetQuotes : public Inset
117 {
118 public:
119         /** The constructor works like this:
120           \begin{itemize}
121             \item fls <- french single quote left
122             \item grd <- german double quote right
123             \item etc.
124           \end{itemize}
125           */
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());
131         ///
132         docstring layoutName() const;
133         ///
134         void metrics(MetricsInfo &, Dimension &) const;
135         ///
136         void draw(PainterInfo & pi, int x, int y) const;
137         ///
138         void write(std::ostream &) const;
139         ///
140         void read(Lexer & lex);
141         ///
142         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
143         ///
144         void latex(otexstream &, OutputParams const &) const;
145         ///
146         int plaintext(odocstringstream & ods, OutputParams const & op,
147                       size_t max_length = INT_MAX) const;
148         ///
149         int docbook(odocstream &, OutputParams const &) const;
150         ///
151         docstring xhtml(XMLStream &, OutputParams const &) const;
152
153         ///
154         void toString(odocstream &) const;
155         ///
156         void forOutliner(docstring &, size_t const maxlen, bool const) const;
157
158         /// Update the contextual information of this inset
159         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
160
161         ///
162         void validate(LaTeXFeatures &) const;
163         ///
164         std::string contextMenuName() const;
165         ///
166         InsetCode lyxCode() const { return QUOTE_CODE; }
167         /// should this inset be handled like a normal character
168         bool isChar() const { return true; }
169
170         /// Returns the current quote type
171         std::string getType() const;
172
173 private:
174         ///
175         Inset * clone() const { return new InsetQuotes(*this); }
176
177         /// Decide whether we need left or right quotation marks
178         void setSide(char_type c);
179         ///
180         void parseString(std::string const &,
181                          bool const allow_wildcards = false);
182         ///
183         docstring displayString() const;
184         ///
185         docstring getQuoteEntity(bool isHTML) const;
186         ///
187         InsetQuotesParams::QuoteStyle getStyle(std::string const &);
188
189         ///
190         InsetQuotesParams::QuoteStyle style_;
191         ///
192         InsetQuotesParams::QuoteSide side_;
193         ///
194         InsetQuotesParams::QuoteLevel level_;
195         ///
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?
202         bool pass_thru_;
203         /// Do we use fontspec?
204         bool fontspec_;
205         /// Do we have an internal font encoding?
206         bool internal_fontenc_;
207         /// Are we writing RTL?
208         bool rtl_;
209         ///
210         friend class InsetQuotesParams;
211
212 protected:
213         /// \name Protected functions inherited from Inset class
214         //@{
215         ///
216         void doDispatch(Cursor & cur, FuncRequest & cmd);
217         //@}
218 };
219
220 } // namespace lyx
221
222 #endif