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