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;
64 bool editable() const { return true; }
66 bool canTrackChanges() const { return true; }
67 /// Rely on RowPainter to draw the cue of inline insets.
68 bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
70 InsetText * asInsetText() { return this; }
72 InsetText const * asInsetText() const { return this; }
74 Text & text() { return text_; }
75 Text const & text() const { return text_; }
77 void latex(otexstream &, OutputParams const &) const;
79 int plaintext(odocstringstream & ods, OutputParams const & op,
80 size_t max_length = INT_MAX) const;
82 int docbook(odocstream &, OutputParams const &) const;
84 docstring xhtml(XHTMLStream &, OutputParams const &) const;
94 docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
97 void validate(LaTeXFeatures & features) const;
99 /// return the argument(s) only
100 void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
102 /// return x,y of given position relative to the inset's baseline
103 void cursorPos(BufferView const & bv, CursorSlice const & sl,
104 bool boundary, int & x, int & y) const;
106 InsetCode lyxCode() const { return TEXT_CODE; }
108 void setText(docstring const &, Font const &, bool trackChanges);
110 void setDrawFrame(bool);
112 ColorCode frameColor() const;
114 void setFrameColor(ColorCode);
116 Text * getText(int i) const {
117 return (i == 0) ? const_cast<Text*>(&text_) : 0;
120 virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
123 void fixParagraphsFont();
125 /// set the change for the entire inset
126 void setChange(Change const & change);
127 /// accept the changes within the inset
128 void acceptChanges();
129 /// reject the changes within the inset
130 void rejectChanges();
132 /// append text onto the existing text
133 void appendParagraphs(ParagraphList &);
136 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
139 void edit(Cursor & cur, bool front, EntryDirection entry_from);
141 Inset * editXY(Cursor & cur, int x, int y);
143 /// number of cells in this inset
144 size_t nargs() const { return 1; }
146 ParagraphList & paragraphs();
148 ParagraphList const & paragraphs() const;
150 bool insetAllowed(InsetCode) const;
152 bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
154 virtual bool isMacroScope() const { return false; }
156 virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
158 /// should paragraphs be forced to use the empty layout?
159 virtual bool forcePlainLayout(idx_type = 0) const
160 { return getLayout().forcePlainLayout(); }
161 /// should the user be allowed to customize alignment, etc.?
162 virtual bool allowParagraphCustomization(idx_type = 0) const
163 { return getLayout().allowParagraphCustomization(); }
164 /// should paragraphs be forced to use a local font language switch?
165 virtual bool forceLocalFontSwitch() const
166 { return getLayout().forcelocalfontswitch(); }
168 /// Update the counters of this inset and of its contents
169 virtual void updateBuffer(ParIterator const &, UpdateType);
171 void setMacrocontextPositionRecursive(DocIterator const & pos);
173 void toString(odocstream &) const;
175 void forOutliner(docstring &, size_t const, bool const) const;
177 void addToToc(DocIterator const & di, bool output_active,
178 UpdateType utype, TocBackend & backend) const;
180 Inset * clone() const { return new InsetText(*this); }
182 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
185 bool completionSupported(Cursor const &) const;
187 bool inlineCompletionSupported(Cursor const & cur) const;
189 bool automaticInlineCompletion() const;
191 bool automaticPopupCompletion() const;
193 bool showCompletionCursor() const;
195 CompletionList const * createCompletionList(Cursor const & cur) const;
197 docstring completionPrefix(Cursor const & cur) const;
199 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
201 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
202 /// returns the text to be used as tooltip
203 /// \param prefix: a string that will preced the tooltip,
205 /// \param len: length of the resulting string
206 /// NOTE This routine is kind of slow. It's fine to use it within the
207 /// GUI, but definitely do not try to use it in updateBuffer or anything
208 /// of that sort. (Note: unnecessary internal copies have been removed
209 /// since the previous note. The efficiency would have to be assessed
210 /// again by profiling.)
211 docstring toolTipText(docstring prefix = empty_docstring(),
212 size_t len = 400) const;
215 std::string contextMenu(BufferView const &, int, int) const;
217 std::string contextMenuName() const;
219 void doDispatch(Cursor & cur, FuncRequest & cmd);
222 bool confirmDeletion() const { return !text().empty(); }
226 void iterateForToc(DocIterator const & cdit, bool output_active,
227 UpdateType utype, TocBackend & backend) const;
229 /// Open the toc item for paragraph pit. Returns the paragraph index where
231 pit_type openAddToTocForParagraph(pit_type pit,
232 DocIterator const & dit,
234 TocBackend & backend) const;
235 /// Close a toc item opened in start and closed in end
236 void closeAddToTocForParagraph(pit_type start, pit_type end,
237 TocBackend & backend) const;
241 ColorCode frame_color_;
247 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);