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;
57 /// Let the inset compute and store its reference font from \c outer.
58 void setOuterFont(BufferView & bv, FontInfo const & outer) const;
60 void metrics(MetricsInfo & mi, Dimension & dim) const override;
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 {}
66 bool editable() const override { return true; }
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(); }
72 InsetText * asInsetText() override { return this; }
74 InsetText const * asInsetText() const override { return this; }
76 Text & text() { return text_; }
77 Text const & text() const { return text_; }
79 void latex(otexstream &, OutputParams const &) const override;
81 int plaintext(odocstringstream & ods, OutputParams const & op,
82 size_t max_length = INT_MAX) const override;
84 docstring xhtml(XMLStream &, OutputParams const &) const override;
94 docstring insetAsXHTML(XMLStream &, OutputParams const &,
97 void docbook(XMLStream &, OutputParams const &, XHTMLOptions opts) const;
99 void docbook(XMLStream &, OutputParams const &) const override;
101 void validate(LaTeXFeatures & features) const override;
103 /// return the argument(s) only
104 void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
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;
110 InsetCode lyxCode() const override { return TEXT_CODE; }
112 void setText(docstring const &, Font const &, bool trackChanges);
114 void setDrawFrame(bool);
116 ColorCode frameColor() const;
118 void setFrameColor(ColorCode);
120 Text * getText(int idx) const override {
121 return (idx == 0) ? const_cast<Text*>(&text_) : nullptr;
124 bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
127 void fixParagraphsFont();
129 /// does the inset contain changes ?
130 bool isChanged() const override { return is_changed_; }
131 /// this is const because value is mutable
132 void isChanged(bool ic) const { is_changed_ = ic; }
133 /// set the change for the entire inset
134 void setChange(Change const & change) override;
135 /// accept the changes within the inset
136 void acceptChanges() override;
137 /// reject the changes within the inset
138 void rejectChanges() override;
140 /// append text onto the existing text
141 void appendParagraphs(ParagraphList &);
144 void addPreview(DocIterator const &, graphics::PreviewLoader &) const override;
147 void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
149 Inset * editXY(Cursor & cur, int x, int y) override;
151 /// number of cells in this inset
152 size_t nargs() const override { return 1; }
154 ParagraphList & paragraphs();
156 ParagraphList const & paragraphs() const;
158 bool insetAllowed(InsetCode) const override;
160 bool allowSpellCheck() const override;
162 virtual bool isMacroScope() const { return false; }
164 bool allowMultiPar() const override;
166 bool isInTitle() const override { return intitle_context_; }
168 /// should paragraphs be forced to use the empty layout?
169 bool forcePlainLayout(idx_type = 0) const override;
170 /// should the user be allowed to customize alignment, etc.?
171 bool allowParagraphCustomization(idx_type = 0) const override;
172 /// should paragraphs be forced to use a local font language switch?
173 bool forceLocalFontSwitch() const override;
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 const & 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);