]> git.lyx.org Git - features.git/blob - src/insets/InsetQuotes.h
Restructure InsetQuotes for better extensibilty
[features.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                 FrenchQuotes,
40                 ///
41                 DanishQuotes,
42                 ///
43                 PlainQuotes
44         };
45         ///
46         enum QuoteSide {
47                 ///
48                 LeftQuote,
49                 ///
50                 RightQuote
51         };
52         ///
53         enum QuoteLevel {
54                 ///
55                 SingleQuotes,
56                 ///
57                 DoubleQuotes
58         };
59         /// Returns the unicode character of a given quote
60         char_type getQuoteChar(QuoteStyle const &, QuoteLevel const &,
61                                QuoteSide const &) const;
62         /// Returns a map of quotation marks
63         std::map<std::string, docstring> getTypes() const;
64         ///
65         docstring getLaTeXQuote(char_type c, std::string const &) const;
66         ///
67         docstring getHTMLQuote(char_type c) const;
68         /// Returns a label suitable for dialog and menu
69         docstring const getGuiLabel(QuoteStyle const & qs);
70         ///
71         int stylescount() const;
72 };
73
74 ///
75 extern InsetQuotesParams quoteparams;
76
77 /** Quotes.
78   Used for the various quotes. German, English, French, all either
79   double or single **/
80 class InsetQuotes : public Inset
81 {
82 public:
83         /** The constructor works like this:
84           \begin{itemize}
85             \item fls <- french single quote left
86             \item grd <- german double quote right
87             \item etc.
88           \end{itemize}
89           */
90         explicit InsetQuotes(Buffer * buf, std::string const & str = "eld");
91         /// Direct access to inner/outer quotation marks
92         InsetQuotes(Buffer * buf, char_type c, InsetQuotesParams::QuoteLevel level,
93                     std::string const & side = std::string(),
94                     std::string const & style = std::string());
95         ///
96         docstring layoutName() const;
97         ///
98         void metrics(MetricsInfo &, Dimension &) const;
99         ///
100         void draw(PainterInfo & pi, int x, int y) const;
101         ///
102         void write(std::ostream &) const;
103         ///
104         void read(Lexer & lex);
105         ///
106         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
107         ///
108         void latex(otexstream &, OutputParams const &) const;
109         ///
110         int plaintext(odocstringstream & ods, OutputParams const & op,
111                       size_t max_length = INT_MAX) const;
112         ///
113         int docbook(odocstream &, OutputParams const &) const;
114         ///
115         docstring xhtml(XHTMLStream &, OutputParams const &) const;
116
117         /// 
118         void toString(odocstream &) const;
119         ///
120         void forOutliner(docstring &, size_t const maxlen, bool const) const;
121
122         /// Update the contextual information of this inset
123         void updateBuffer(ParIterator const &, UpdateType);
124
125         ///
126         void validate(LaTeXFeatures &) const;
127         ///
128         std::string contextMenuName() const;
129         ///
130         InsetCode lyxCode() const { return QUOTE_CODE; }
131         /// should this inset be handled like a normal character
132         bool isChar() const { return true; }
133
134         /// Returns the current quote type
135         std::string getType() const;
136
137 private:
138         ///
139         Inset * clone() const { return new InsetQuotes(*this); }
140
141         /// Decide whether we need left or right quotation marks
142         void setSide(char_type c);
143         ///
144         void parseString(std::string const &,
145                          bool const allow_wildcards = false);
146         ///
147         docstring displayString() const;
148         ///
149         docstring getQuoteEntity() const;
150         ///
151         InsetQuotesParams::QuoteStyle getStyle(std::string const &);
152
153         ///
154         InsetQuotesParams::QuoteStyle style_;
155         ///
156         InsetQuotesParams::QuoteSide side_;
157         ///
158         InsetQuotesParams::QuoteLevel level_;
159         ///
160         std::string fontenc_;
161         /// Code of the contextual language
162         std::string context_lang_;
163         /// Is this in a pass-thru context?
164         bool pass_thru_;
165         ///
166         friend class InsetQuotesParams;
167
168 protected:
169         /// \name Protected functions inherited from Inset class
170         //@{
171         ///
172         void doDispatch(Cursor & cur, FuncRequest & cmd);
173         //@}
174 };
175
176 } // namespace lyx
177
178 #endif