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"
30 A text inset is like a TeX box to write full text
31 (including styles and other insets) in a given space.
33 class InsetText : public Inset {
40 /// \param useplain whether to use the plain layout
41 /// This is needed because we cannot call the virtual function
42 /// usePlainLayout() from within the constructor.
43 explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
45 InsetText(InsetText const &);
47 void setBuffer(Buffer &);
50 Dimension const dimension(BufferView const &) const;
52 /// empty inset to empty par
55 void read(Lexer & lex);
57 void write(std::ostream & os) const;
59 void metrics(MetricsInfo & mi, Dimension & dim) const;
61 void draw(PainterInfo & pi, int x, int y) const;
63 bool editable() const { return true; }
65 bool canTrackChanges() const { return true; }
66 /// Rely on RowPainter to draw the cue of inline insets.
67 bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
69 InsetText * asInsetText() { return this; }
71 InsetText const * asInsetText() const { return this; }
73 Text & text() { return text_; }
74 Text const & text() const { return text_; }
76 void latex(otexstream &, OutputParams const &) const;
78 int plaintext(odocstringstream & ods, OutputParams const & op,
79 size_t max_length = INT_MAX) const;
81 int docbook(odocstream &, OutputParams const &) const;
83 docstring xhtml(XHTMLStream &, OutputParams const &) const;
93 docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
96 void validate(LaTeXFeatures & features) const;
98 /// return the argument(s) only
99 void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
101 /// return x,y of given position relative to the inset's baseline
102 void cursorPos(BufferView const & bv, CursorSlice const & sl,
103 bool boundary, int & x, int & y) const;
105 InsetCode lyxCode() const { return TEXT_CODE; }
107 void setText(docstring const &, Font const &, bool trackChanges);
109 void setDrawFrame(bool);
111 ColorCode frameColor() const;
113 void setFrameColor(ColorCode);
115 Text * getText(int i) const {
116 return (i == 0) ? const_cast<Text*>(&text_) : 0;
119 virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
122 void fixParagraphsFont();
124 /// set the change for the entire inset
125 void setChange(Change const & change);
126 /// accept the changes within the inset
127 void acceptChanges();
128 /// reject the changes within the inset
129 void rejectChanges();
131 /// append text onto the existing text
132 void appendParagraphs(ParagraphList &);
135 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
138 void edit(Cursor & cur, bool front, EntryDirection entry_from);
140 Inset * editXY(Cursor & cur, int x, int y);
142 /// number of cells in this inset
143 size_t nargs() const { return 1; }
145 ParagraphList & paragraphs();
147 ParagraphList const & paragraphs() const;
149 bool insetAllowed(InsetCode) const;
151 bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
153 virtual bool isMacroScope() const { return false; }
155 virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
157 /// should paragraphs be forced to use the empty layout?
158 virtual bool forcePlainLayout(idx_type = 0) const
159 { return getLayout().forcePlainLayout(); }
160 /// should the user be allowed to customize alignment, etc.?
161 virtual bool allowParagraphCustomization(idx_type = 0) const
162 { return getLayout().allowParagraphCustomization(); }
163 /// should paragraphs be forced to use a local font language switch?
164 virtual bool forceLocalFontSwitch() const
165 { return getLayout().forcelocalfontswitch(); }
167 /// Update the counters of this inset and of its contents
168 virtual void updateBuffer(ParIterator const &, UpdateType);
170 void setMacrocontextPositionRecursive(DocIterator const & pos);
172 void toString(odocstream &) const;
174 void forOutliner(docstring &, size_t const, bool const) const;
176 void addToToc(DocIterator const & di, bool output_active,
177 UpdateType utype) const;
179 Inset * clone() const { return new InsetText(*this); }
181 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
184 bool completionSupported(Cursor const &) const;
186 bool inlineCompletionSupported(Cursor const & cur) const;
188 bool automaticInlineCompletion() const;
190 bool automaticPopupCompletion() const;
192 bool showCompletionCursor() const;
194 CompletionList const * createCompletionList(Cursor const & cur) const;
196 docstring completionPrefix(Cursor const & cur) const;
198 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
200 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
201 /// returns the text to be used as tooltip
202 /// \param prefix: a string that will preced the tooltip,
204 /// \param len: length of the resulting string
205 /// NOTE This routine is kind of slow. It's fine to use it within the
206 /// GUI, but definitely do not try to use it in updateBuffer or anything
207 /// of that sort. (Note: unnecessary internal copies have been removed
208 /// since the previous note. The efficiency would have to be assessed
209 /// again by profiling.)
210 docstring toolTipText(docstring prefix = empty_docstring(),
211 size_t len = 400) const;
214 std::string contextMenu(BufferView const &, int, int) const;
216 std::string contextMenuName() const;
218 void doDispatch(Cursor & cur, FuncRequest & cmd);
221 InsetCaption const * getCaptionInset() const;
223 docstring getCaptionText(OutputParams const &) const;
225 docstring getCaptionHTML(OutputParams const &) const;
227 void iterateForToc(DocIterator const & cdit, bool output_active,
228 UpdateType utype) const;
233 ColorCode frame_color_;
239 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);