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