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