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"
31 A text inset is like a TeX box to write full text
32 (including styles and other insets) in a given space.
34 class InsetText : public Inset {
41 /// \param useplain whether to use the plain layout
42 /// This is needed because we cannot call the virtual function
43 /// usePlainLayout() from within the constructor.
44 explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
46 InsetText(InsetText const &);
48 void setBuffer(Buffer &);
51 Dimension const dimensionHelper(BufferView const &) const;
53 /// empty inset to empty par
56 void read(Lexer & lex);
58 void write(std::ostream & os) const;
60 void metrics(MetricsInfo & mi, Dimension & dim) const;
62 void draw(PainterInfo & pi, int x, int y) const;
63 /// Drawing background is handled in draw
64 virtual void drawBackground(PainterInfo &, int, int) const {}
66 bool editable() const { return true; }
68 bool canTrackChanges() const { return true; }
69 /// Rely on RowPainter to draw the cue of inline insets.
70 bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
72 InsetText * asInsetText() { return this; }
74 InsetText const * asInsetText() const { return this; }
76 Text & text() { return text_; }
77 Text const & text() const { return text_; }
79 void latex(otexstream &, OutputParams const &) const;
81 int plaintext(odocstringstream & ods, OutputParams const & op,
82 size_t max_length = INT_MAX) const;
84 int docbook(odocstream &, OutputParams const &) const;
86 docstring xhtml(XMLStream &, OutputParams const &) const;
96 docstring insetAsXHTML(XMLStream &, OutputParams const &,
99 void validate(LaTeXFeatures & features) const;
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;
108 InsetCode lyxCode() const { 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 i) const {
119 return (i == 0) ? const_cast<Text*>(&text_) : 0;
122 virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
125 void fixParagraphsFont();
127 /// does the inset contain changes ?
128 bool isChanged() const { 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);
133 /// accept the changes within the inset
134 void acceptChanges();
135 /// reject the changes within the inset
136 void rejectChanges();
138 /// append text onto the existing text
139 void appendParagraphs(ParagraphList &);
142 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
145 void edit(Cursor & cur, bool front, EntryDirection entry_from);
147 Inset * editXY(Cursor & cur, int x, int y);
149 /// number of cells in this inset
150 size_t nargs() const { return 1; }
152 ParagraphList & paragraphs();
154 ParagraphList const & paragraphs() const;
156 bool insetAllowed(InsetCode) const;
158 bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
160 virtual bool isMacroScope() const { return false; }
162 virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
164 bool isInTitle() const { return intitle_context_; }
166 /// should paragraphs be forced to use the empty layout?
167 virtual bool forcePlainLayout(idx_type = 0) const
168 { return getLayout().forcePlainLayout(); }
169 /// should the user be allowed to customize alignment, etc.?
170 virtual bool allowParagraphCustomization(idx_type = 0) const
171 { return getLayout().allowParagraphCustomization(); }
172 /// should paragraphs be forced to use a local font language switch?
173 virtual bool forceLocalFontSwitch() const
174 { return getLayout().forcelocalfontswitch(); }
176 /// Update the counters of this inset and of its contents
177 virtual void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
179 void setMacrocontextPositionRecursive(DocIterator const & pos);
181 void toString(odocstream &) const;
183 void forOutliner(docstring &, size_t const, bool const) const;
185 void addToToc(DocIterator const & di, bool output_active,
186 UpdateType utype, TocBackend & backend) const;
188 Inset * clone() const { return new InsetText(*this); }
190 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
193 bool completionSupported(Cursor const &) const;
195 bool inlineCompletionSupported(Cursor const & cur) const;
197 bool automaticInlineCompletion() const;
199 bool automaticPopupCompletion() const;
201 bool showCompletionCursor() const;
203 CompletionList const * createCompletionList(Cursor const & cur) const;
205 docstring completionPrefix(Cursor const & cur) const;
207 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
209 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
210 /// returns the text to be used as tooltip
211 /// \param prefix: a string that will precede the tooltip,
213 /// \param len: length of the resulting string
214 /// NOTE This routine is kind of slow. It's fine to use it within the
215 /// GUI, but definitely do not try to use it in updateBuffer or anything
216 /// of that sort. (Note: unnecessary internal copies have been removed
217 /// since the previous note. The efficiency would have to be assessed
218 /// again by profiling.)
219 docstring toolTipText(docstring prefix = empty_docstring(),
220 size_t len = 400) const;
223 std::string contextMenu(BufferView const &, int, int) const;
225 std::string contextMenuName() const;
227 void doDispatch(Cursor & cur, FuncRequest & cmd);
230 bool confirmDeletion() const { return !text().empty(); }
233 bool needsCProtection(bool const maintext = false,
234 bool const fragile = false) const;
236 bool hasCProtectContent(bool fragile = false) const;
240 void iterateForToc(DocIterator const & cdit, bool output_active,
241 UpdateType utype, TocBackend & backend) const;
243 /// Open the toc item for paragraph pit. Returns the paragraph index where
245 pit_type openAddToTocForParagraph(pit_type pit,
246 DocIterator const & dit,
248 TocBackend & backend) const;
249 /// Close a toc item opened in start and closed in end
250 void closeAddToTocForParagraph(pit_type start, pit_type end,
251 TocBackend & backend) const;
254 /// true if the inset contains change
255 mutable bool is_changed_;
257 bool intitle_context_;
259 ColorCode frame_color_;
265 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);