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