]> git.lyx.org Git - lyx.git/blob - src/insets/InsetQuotes.h
Do not check again and again for non existing files
[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         /// Returns a descriptive label of a style suitable for dialog and menu
86         docstring const getGuiLabel(QuoteStyle const & qs,
87                                     bool langdef = false);
88         /// Returns a descriptive label of a given char
89         docstring const getShortGuiLabel(docstring const string);
90         ///
91         int stylescount() const;
92         /// Returns the matching style shortcut char
93         char getStyleChar(QuoteStyle const & style) const;
94         /// Returns the quote style from the shortcut string
95         QuoteStyle getQuoteStyle(std::string const & s,
96                 bool const allow_wildcards = false,
97                 QuoteStyle fallback = EnglishQuotes);
98         /// Returns the quote sind from the shortcut string
99         QuoteSide getQuoteSide(std::string const & s,
100                 bool const allow_wildcards = false,
101                 QuoteSide fallback = OpeningQuote);
102         /// Returns the quote level from the shortcut string
103         QuoteLevel getQuoteLevel(std::string const & s,
104                 bool const allow_wildcards = false,
105                 QuoteLevel fallback = PrimaryQuotes);
106 };
107
108 ///
109 extern InsetQuotesParams quoteparams;
110
111 /** Quotes.
112   Used for the various quotes. German, English, French, all either
113   double or single **/
114 class InsetQuotes : public Inset
115 {
116 public:
117         /** The constructor works like this:
118           \begin{itemize}
119             \item fls <- french single quote left
120             \item grd <- german double quote right
121             \item etc.
122           \end{itemize}
123           */
124         explicit InsetQuotes(Buffer * buf, std::string const & str = "eld");
125         /// Direct access to inner/outer quotation marks
126         InsetQuotes(Buffer * buf, char_type c, InsetQuotesParams::QuoteLevel level,
127                     std::string const & side = std::string(),
128                     std::string const & style = std::string());
129         ///
130         docstring layoutName() const;
131         ///
132         void metrics(MetricsInfo &, Dimension &) const;
133         ///
134         void draw(PainterInfo & pi, int x, int y) const;
135         ///
136         void write(std::ostream &) const;
137         ///
138         void read(Lexer & lex);
139         ///
140         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
141         ///
142         void latex(otexstream &, OutputParams const &) const;
143         ///
144         int plaintext(odocstringstream & ods, OutputParams const & op,
145                       size_t max_length = INT_MAX) const;
146         ///
147         int docbook(odocstream &, OutputParams const &) const;
148         ///
149         docstring xhtml(XHTMLStream &, OutputParams const &) const;
150
151         ///
152         void toString(odocstream &) const;
153         ///
154         void forOutliner(docstring &, size_t const maxlen, bool const) const;
155
156         /// Update the contextual information of this inset
157         void updateBuffer(ParIterator const &, UpdateType);
158
159         ///
160         void validate(LaTeXFeatures &) const;
161         ///
162         std::string contextMenuName() const;
163         ///
164         InsetCode lyxCode() const { return QUOTE_CODE; }
165         /// should this inset be handled like a normal character
166         bool isChar() const { return true; }
167
168         /// Returns the current quote type
169         std::string getType() const;
170
171 private:
172         ///
173         Inset * clone() const { return new InsetQuotes(*this); }
174
175         /// Decide whether we need left or right quotation marks
176         void setSide(char_type c);
177         ///
178         void parseString(std::string const &,
179                          bool const allow_wildcards = false);
180         ///
181         docstring displayString() const;
182         ///
183         docstring getQuoteEntity() const;
184         ///
185         InsetQuotesParams::QuoteStyle getStyle(std::string const &);
186
187         ///
188         InsetQuotesParams::QuoteStyle style_;
189         ///
190         InsetQuotesParams::QuoteSide side_;
191         ///
192         InsetQuotesParams::QuoteLevel level_;
193         ///
194         InsetQuotesParams::QuoteStyle global_style_;
195         /// Current font encoding
196         std::string fontenc_;
197         /// Code of the contextual language
198         std::string context_lang_;
199         /// Is this in a pass-thru context?
200         bool pass_thru_;
201         /// Do we use fontspec?
202         bool fontspec_;
203         /// Do we have an internal font encoding?
204         bool internal_fontenc_;
205         /// Are we writing RTL?
206         bool rtl_;
207         ///
208         friend class InsetQuotesParams;
209
210 protected:
211         /// \name Protected functions inherited from Inset class
212         //@{
213         ///
214         void doDispatch(Cursor & cur, FuncRequest & cmd);
215         //@}
216 };
217
218 } // namespace lyx
219
220 #endif