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"
29 A text inset is like a TeX box to write full text
30 (including styles and other insets) in a given space.
32 class InsetText : public Inset {
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);
44 InsetText(InsetText const &);
46 void setBuffer(Buffer &) override;
49 Dimension const dimensionHelper(BufferView const &) const;
51 /// empty inset to empty par
54 void read(Lexer & lex) override;
56 void write(std::ostream & os) const override;
58 void metrics(MetricsInfo & mi, Dimension & dim) const override;
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 {}
64 bool editable() const override { return true; }
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(); }
70 InsetText * asInsetText() override { return this; }
72 InsetText const * asInsetText() const override { return this; }
74 Text & text() { return text_; }
75 Text const & text() const { return text_; }
77 void latex(otexstream &, OutputParams const &) const override;
79 int plaintext(odocstringstream & ods, OutputParams const & op,
80 size_t max_length = INT_MAX) const override;
82 docstring xhtml(XMLStream &, OutputParams const &) const override;
92 docstring insetAsXHTML(XMLStream &, OutputParams const &,
95 void docbook(XMLStream &, OutputParams const &, XHTMLOptions opts) const;
97 void docbook(XMLStream &, OutputParams const &) const override;
99 void validate(LaTeXFeatures & features) const override;
101 /// return the argument(s) only
102 void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
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;
108 InsetCode lyxCode() const override { return TEXT_CODE; }
110 void setText(docstring const &, Font const &, bool trackChanges);
112 void setDrawFrame(bool);
114 ColorCode frameColor() const;
116 void setFrameColor(ColorCode);
118 Text * getText(int idx) const override {
119 return (idx == 0) ? const_cast<Text*>(&text_) : nullptr;
122 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
125 void fixParagraphsFont();
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;
138 /// append text onto the existing text
139 void appendParagraphs(ParagraphList &);
142 void addPreview(DocIterator const &, graphics::PreviewLoader &) const override;
145 void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
147 Inset * editXY(Cursor & cur, int x, int y) override;
149 /// number of cells in this inset
150 size_t nargs() const override { return 1; }
152 ParagraphList & paragraphs();
154 ParagraphList const & paragraphs() const;
156 bool insetAllowed(InsetCode) const override;
158 bool allowSpellCheck() const override;
160 virtual bool isMacroScope() const { return false; }
162 bool allowMultiPar() const override;
164 bool isInTitle() const override { return intitle_context_; }
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;
173 /// Update the counters of this inset and of its contents
174 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
176 void setMacrocontextPositionRecursive(DocIterator const & pos);
178 void toString(odocstream &) const override;
180 void forOutliner(docstring &, size_t const, bool const) const override;
182 void addToToc(DocIterator const & di, bool output_active,
183 UpdateType utype, TocBackend & backend) const override;
185 Inset * clone() const override { return new InsetText(*this); }
187 bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
190 bool completionSupported(Cursor const &) const override;
192 bool inlineCompletionSupported(Cursor const & cur) const override;
194 bool automaticInlineCompletion() const override;
196 bool automaticPopupCompletion() const override;
198 bool showCompletionCursor() const override;
200 CompletionList const * createCompletionList(Cursor const & cur) const override;
202 docstring completionPrefix(Cursor const & cur) const override;
204 bool insertCompletion(Cursor & cur, docstring const & s, bool finished) override;
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,
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;
220 std::string contextMenu(BufferView const &, int, int) const override;
222 std::string contextMenuName() const override;
224 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
227 bool confirmDeletion() const override { return !text().empty(); }
230 bool needsCProtection(bool const maintext = false,
231 bool const fragile = false) const override;
233 bool hasCProtectContent(bool fragile = false) const;
237 void iterateForToc(DocIterator const & cdit, bool output_active,
238 UpdateType utype, TocBackend & backend) const;
240 /// Open the toc item for paragraph pit. Returns the paragraph index where
242 pit_type openAddToTocForParagraph(pit_type pit,
243 DocIterator const & dit,
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;
251 /// true if the inset contains change
252 mutable bool is_changed_;
254 bool intitle_context_;
256 ColorCode frame_color_;
262 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);