]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
bfaee44241ea5db1b108ce387a5cbf6806d4e7d0
[lyx.git] / src / insets / InsetText.h
1 // -*- C++ -*-
2 /**
3  * \file InsetText.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETTEXT_H
13 #define INSETTEXT_H
14
15 #include "Inset.h"
16
17 #include "ColorCode.h"
18 #include "Text.h"
19
20 namespace lyx {
21
22 class CompletionList;
23 class CursorSlice;
24 class Dimension;
25 class ParagraphList;
26 class InsetCaption;
27 class InsetTabular;
28 class TocBuilder;
29
30 /**
31  A text inset is like a TeX box to write full text
32  (including styles and other insets) in a given space.
33  */
34 class InsetText : public Inset {
35 public:
36         enum UsePlain {
37                 DefaultLayout,
38                 PlainLayout
39         };
40         /// \param buffer
41         /// \param useplain whether to use the plain layout
42         /// This is needed because we cannot call the virtual function
43         /// usePlainLayout() from within the constructor.
44         explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
45         ///
46         InsetText(InsetText const &);
47         ///
48         void setBuffer(Buffer &);
49
50         ///
51         Dimension const dimensionHelper(BufferView const &) const;
52
53         /// empty inset to empty par
54         void clear();
55         ///
56         void read(Lexer & lex);
57         ///
58         void write(std::ostream & os) const;
59         ///
60         void metrics(MetricsInfo & mi, Dimension & dim) const;
61         ///
62         void draw(PainterInfo & pi, int x, int y) const;
63         ///
64         bool editable() const { return true; }
65         ///
66         bool canTrackChanges() const { return true; }
67         /// Rely on RowPainter to draw the cue of inline insets.
68         bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
69         ///
70         InsetText * asInsetText() { return this; }
71         ///
72         InsetText const * asInsetText() const { return this; }
73         ///
74         Text & text() { return text_; }
75         Text const & text() const { return text_; }
76         ///
77         void latex(otexstream &, OutputParams const &) const;
78         ///
79         int plaintext(odocstringstream & ods, OutputParams const & op,
80                       size_t max_length = INT_MAX) const;
81         ///
82         int docbook(odocstream &, OutputParams const &) const;
83         ///
84         docstring xhtml(XHTMLStream &, OutputParams const &) const;
85         ///
86         enum XHTMLOptions {
87                 JustText = 0,
88                 WriteOuterTag = 1,
89                 WriteLabel = 2,
90                 WriteInnerTag = 4,
91                 WriteEverything = 7
92         };
93         ///
94         docstring insetAsXHTML(XHTMLStream &, OutputParams const &, 
95                                XHTMLOptions) const;
96         ///
97         void validate(LaTeXFeatures & features) const;
98         
99         /// return the argument(s) only
100         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
101
102         /// return x,y of given position relative to the inset's baseline
103         void cursorPos(BufferView const & bv, CursorSlice const & sl,
104                 bool boundary, int & x, int & y) const;
105         ///
106         InsetCode lyxCode() const { return TEXT_CODE; }
107         ///
108         void setText(docstring const &, Font const &, bool trackChanges);
109         ///
110         void setDrawFrame(bool);
111         ///
112         ColorCode frameColor() const;
113         ///
114         void setFrameColor(ColorCode);
115         ///
116         Text * getText(int i) const {
117                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
118         }
119         ///
120         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
121
122         ///
123         void fixParagraphsFont();
124
125         /// set the change for the entire inset
126         void setChange(Change const & change);
127         /// accept the changes within the inset
128         void acceptChanges();
129         /// reject the changes within the inset
130         void rejectChanges();
131
132         /// append text onto the existing text
133         void appendParagraphs(ParagraphList &);
134
135         ///
136         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
137
138         ///
139         void edit(Cursor & cur, bool front, EntryDirection entry_from);
140         ///
141         Inset * editXY(Cursor & cur, int x, int y);
142
143         /// number of cells in this inset
144         size_t nargs() const { return 1; }
145         ///
146         ParagraphList & paragraphs();
147         ///
148         ParagraphList const & paragraphs() const;
149         ///
150         bool insetAllowed(InsetCode) const;
151         ///
152         bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
153         ///
154         virtual bool isMacroScope() const { return false; }
155         ///
156         virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
157         ///
158         /// should paragraphs be forced to use the empty layout?
159         virtual bool forcePlainLayout(idx_type = 0) const
160                 { return getLayout().forcePlainLayout(); }
161         /// should the user be allowed to customize alignment, etc.?
162         virtual bool allowParagraphCustomization(idx_type = 0) const
163                 { return getLayout().allowParagraphCustomization(); }
164         /// should paragraphs be forced to use a local font language switch?
165         virtual bool forceLocalFontSwitch() const
166                 { return getLayout().forcelocalfontswitch(); }
167
168         /// Update the counters of this inset and of its contents
169         virtual void updateBuffer(ParIterator const &, UpdateType);
170         /// 
171         void setMacrocontextPositionRecursive(DocIterator const & pos);
172         ///
173         void toString(odocstream &) const;
174         ///
175         void forOutliner(docstring &, size_t const, bool const) const;
176         ///
177         void addToToc(DocIterator const & di, bool output_active,
178                                   UpdateType utype, TocBackend & backend) const;
179         ///
180         Inset * clone() const { return new InsetText(*this); }
181         ///
182         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
183
184         ///
185         bool completionSupported(Cursor const &) const;
186         ///
187         bool inlineCompletionSupported(Cursor const & cur) const;
188         ///
189         bool automaticInlineCompletion() const;
190         ///
191         bool automaticPopupCompletion() const;
192         ///
193         bool showCompletionCursor() const;
194         ///
195         CompletionList const * createCompletionList(Cursor const & cur) const;
196         ///
197         docstring completionPrefix(Cursor const & cur) const;
198         ///
199         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
200         ///
201         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
202         /// returns the text to be used as tooltip
203         /// \param prefix: a string that will preced the tooltip,
204         /// e.g., "Index: ".
205         /// \param len: length of the resulting string
206         /// NOTE This routine is kind of slow. It's fine to use it within the 
207         /// GUI, but definitely do not try to use it in updateBuffer or anything
208         /// of that sort. (Note: unnecessary internal copies have been removed
209         /// since the previous note. The efficiency would have to be assessed
210         /// again by profiling.)
211         docstring toolTipText(docstring prefix = empty_docstring(),
212                               size_t len = 400) const;
213
214         ///
215         std::string contextMenu(BufferView const &, int, int) const;
216         ///
217         std::string contextMenuName() const;
218         ///
219         void doDispatch(Cursor & cur, FuncRequest & cmd);
220
221         ///
222         bool confirmDeletion() const { return !text().empty(); }
223
224 protected:
225         ///
226         void iterateForToc(DocIterator const & cdit, bool output_active,
227                                            UpdateType utype, TocBackend & backend) const;
228 private:
229         /// Open the toc item for paragraph pit. Returns the paragraph index where
230         /// it should end.
231         pit_type openAddToTocForParagraph(pit_type pit,
232                                           DocIterator const & dit,
233                                           bool output_active,
234                                           TocBackend & backend) const;
235         /// Close a toc item opened in start and closed in end
236         void closeAddToTocForParagraph(pit_type start, pit_type end,
237                                        TocBackend & backend) const;
238         ///
239         bool drawFrame_;
240         ///
241         ColorCode frame_color_;
242         ///
243         Text text_;
244 };
245
246
247 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
248
249 } // namespace lyx
250
251 #endif