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(XHTMLStream &, OutputParams const &) const;
96 docstring insetAsXHTML(XHTMLStream &, 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 /// set the change for the entire inset
128 void setChange(Change const & change);
129 /// accept the changes within the inset
130 void acceptChanges();
131 /// reject the changes within the inset
132 void rejectChanges();
134 /// append text onto the existing text
135 void appendParagraphs(ParagraphList &);
138 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
141 void edit(Cursor & cur, bool front, EntryDirection entry_from);
143 Inset * editXY(Cursor & cur, int x, int y);
145 /// number of cells in this inset
146 size_t nargs() const { return 1; }
148 ParagraphList & paragraphs();
150 ParagraphList const & paragraphs() const;
152 bool insetAllowed(InsetCode) const;
154 bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
156 virtual bool isMacroScope() const { return false; }
158 virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
160 /// should paragraphs be forced to use the empty layout?
161 virtual bool forcePlainLayout(idx_type = 0) const
162 { return getLayout().forcePlainLayout(); }
163 /// should the user be allowed to customize alignment, etc.?
164 virtual bool allowParagraphCustomization(idx_type = 0) const
165 { return getLayout().allowParagraphCustomization(); }
166 /// should paragraphs be forced to use a local font language switch?
167 virtual bool forceLocalFontSwitch() const
168 { return getLayout().forcelocalfontswitch(); }
170 /// Update the counters of this inset and of its contents
171 virtual void updateBuffer(ParIterator const &, UpdateType);
173 void setMacrocontextPositionRecursive(DocIterator const & pos);
175 void toString(odocstream &) const;
177 void forOutliner(docstring &, size_t const, bool const) const;
179 void addToToc(DocIterator const & di, bool output_active,
180 UpdateType utype, TocBackend & backend) const;
182 Inset * clone() const { return new InsetText(*this); }
184 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
187 bool completionSupported(Cursor const &) const;
189 bool inlineCompletionSupported(Cursor const & cur) const;
191 bool automaticInlineCompletion() const;
193 bool automaticPopupCompletion() const;
195 bool showCompletionCursor() const;
197 CompletionList const * createCompletionList(Cursor const & cur) const;
199 docstring completionPrefix(Cursor const & cur) const;
201 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
203 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
204 /// returns the text to be used as tooltip
205 /// \param prefix: a string that will preced the tooltip,
207 /// \param len: length of the resulting string
208 /// NOTE This routine is kind of slow. It's fine to use it within the
209 /// GUI, but definitely do not try to use it in updateBuffer or anything
210 /// of that sort. (Note: unnecessary internal copies have been removed
211 /// since the previous note. The efficiency would have to be assessed
212 /// again by profiling.)
213 docstring toolTipText(docstring prefix = empty_docstring(),
214 size_t len = 400) const;
217 std::string contextMenu(BufferView const &, int, int) const;
219 std::string contextMenuName() const;
221 void doDispatch(Cursor & cur, FuncRequest & cmd);
224 bool confirmDeletion() const { return !text().empty(); }
227 bool needsCProtection() const;
231 void iterateForToc(DocIterator const & cdit, bool output_active,
232 UpdateType utype, TocBackend & backend) const;
234 /// Open the toc item for paragraph pit. Returns the paragraph index where
236 pit_type openAddToTocForParagraph(pit_type pit,
237 DocIterator const & dit,
239 TocBackend & backend) const;
240 /// Close a toc item opened in start and closed in end
241 void closeAddToTocForParagraph(pit_type start, pit_type end,
242 TocBackend & backend) const;
244 bool hasCProtectContent() const;
248 ColorCode frame_color_;
254 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);