4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
17 #include "ColorCode.h"
28 A text inset is like a TeX box to write full text
29 (including styles and other insets) in a given space.
31 class InsetText : public Inset {
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);
43 InsetText(InsetText const &);
45 void setBuffer(Buffer &) override;
48 Dimension const dimensionHelper(BufferView const &) const;
50 /// empty inset to empty par
53 void read(Lexer & lex) override;
55 void write(std::ostream & os) const override;
57 void metrics(MetricsInfo & mi, Dimension & dim) const override;
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 {}
63 bool editable() const override { return true; }
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(); }
69 InsetText * asInsetText() override { return this; }
71 InsetText const * asInsetText() const override { return this; }
73 Text & text() { return text_; }
74 Text const & text() const { return text_; }
76 void latex(otexstream &, OutputParams const &) const override;
78 int plaintext(odocstringstream & ods, OutputParams const & op,
79 size_t max_length = INT_MAX) const override;
81 docstring xhtml(XMLStream &, OutputParams const &) const override;
91 docstring insetAsXHTML(XMLStream &, OutputParams const &,
94 void docbook(XMLStream &, OutputParams const &, XHTMLOptions opts) const;
96 void docbook(XMLStream &, OutputParams const &) const override;
98 void validate(LaTeXFeatures & features) const override;
100 /// return the argument(s) only
101 void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
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;
107 InsetCode lyxCode() const override { return TEXT_CODE; }
109 void setText(docstring const &, Font const &, bool trackChanges);
111 void setDrawFrame(bool);
113 ColorCode frameColor() const;
115 void setFrameColor(ColorCode);
117 Text * getText(int i) const override {
118 return (i == 0) ? const_cast<Text*>(&text_) : 0;
121 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
124 void fixParagraphsFont();
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;
137 /// append text onto the existing text
138 void appendParagraphs(ParagraphList &);
141 void addPreview(DocIterator const &, graphics::PreviewLoader &) const override;
144 void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
146 Inset * editXY(Cursor & cur, int x, int y) override;
148 /// number of cells in this inset
149 size_t nargs() const override { return 1; }
151 ParagraphList & paragraphs();
153 ParagraphList const & paragraphs() const;
155 bool insetAllowed(InsetCode) const override;
157 bool allowSpellCheck() const override { return getLayout().spellcheck() && !getLayout().isPassThru(); }
159 virtual bool isMacroScope() const { return false; }
161 bool allowMultiPar() const override { return getLayout().isMultiPar(); }
163 bool isInTitle() const override { return intitle_context_; }
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(); }
175 /// Update the counters of this inset and of its contents
176 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
178 void setMacrocontextPositionRecursive(DocIterator const & pos);
180 void toString(odocstream &) const override;
182 void forOutliner(docstring &, size_t const, bool const) const override;
184 void addToToc(DocIterator const & di, bool output_active,
185 UpdateType utype, TocBackend & backend) const override;
187 Inset * clone() const override { return new InsetText(*this); }
189 bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
192 bool completionSupported(Cursor const &) const override;
194 bool inlineCompletionSupported(Cursor const & cur) const override;
196 bool automaticInlineCompletion() const override;
198 bool automaticPopupCompletion() const override;
200 bool showCompletionCursor() const override;
202 CompletionList const * createCompletionList(Cursor const & cur) const override;
204 docstring completionPrefix(Cursor const & cur) const override;
206 bool insertCompletion(Cursor & cur, docstring const & s, bool finished) override;
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,
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 prefix = empty_docstring(),
219 size_t len = 400) const;
222 std::string contextMenu(BufferView const &, int, int) const override;
224 std::string contextMenuName() const override;
226 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
229 bool confirmDeletion() const override { return !text().empty(); }
232 bool needsCProtection(bool const maintext = false,
233 bool const fragile = false) const override;
235 bool hasCProtectContent(bool fragile = false) const;
239 void iterateForToc(DocIterator const & cdit, bool output_active,
240 UpdateType utype, TocBackend & backend) const;
242 /// Open the toc item for paragraph pit. Returns the paragraph index where
244 pit_type openAddToTocForParagraph(pit_type pit,
245 DocIterator const & dit,
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;
253 /// true if the inset contains change
254 mutable bool is_changed_;
256 bool intitle_context_;
258 ColorCode frame_color_;
264 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);