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"
20 #include "insets/InsetLayout.h"
32 A text inset is like a TeX box to write full text
33 (including styles and other insets) in a given space.
35 class InsetText : public Inset {
42 /// \param useplain whether to use the plain layout
43 /// This is needed because we cannot call the virtual function
44 /// usePlainLayout() from within the constructor.
45 explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
47 InsetText(InsetText const &);
49 void setBuffer(Buffer &);
52 Dimension const dimension(BufferView const &) const;
54 /// empty inset to empty par
57 void read(Lexer & lex);
59 void write(std::ostream & os) const;
61 void metrics(MetricsInfo & mi, Dimension & dim) const;
63 void draw(PainterInfo & pi, int x, int y) const;
65 bool editable() const { return true; }
67 bool canTrackChanges() const { return true; }
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(odocstream &, OutputParams const &) const;
80 int docbook(odocstream &, OutputParams const &) const;
82 docstring xhtml(XHTMLStream &, OutputParams const &) const;
92 docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
95 void validate(LaTeXFeatures & features) const;
97 /// return the optional argument(s) only
98 void getOptArg(otexstream & os, OutputParams const &) const;
100 /// return x,y of given position relative to the inset's baseline
101 void cursorPos(BufferView const & bv, CursorSlice const & sl,
102 bool boundary, int & x, int & y) const;
104 InsetCode lyxCode() const { return TEXT_CODE; }
106 void setText(docstring const &, Font const &, bool trackChanges);
108 void setAutoBreakRows(bool);
110 bool getAutoBreakRows() const { return text_.autoBreakRows_; }
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(); }
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 forToc(docstring &, size_t) const;
176 void addToToc(DocIterator const &) const;
178 Inset * clone() const { return new InsetText(*this); }
180 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
183 bool completionSupported(Cursor const &) const;
185 bool inlineCompletionSupported(Cursor const & cur) const;
187 bool automaticInlineCompletion() const;
189 bool automaticPopupCompletion() const;
191 bool showCompletionCursor() const;
193 CompletionList const * createCompletionList(Cursor const & cur) const;
195 docstring completionPrefix(Cursor const & cur) const;
197 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
199 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
200 /// returns the text to be used as tooltip
201 /// \param prefix: a string that will preced the tooltip,
203 /// \param numlines: the number of lines in the tooltip
204 /// \param len: length of those lines
205 docstring toolTipText(docstring prefix = empty_docstring(),
206 size_t numlines = 5, size_t len = 80) const;
209 std::string contextMenu(BufferView const &, int, int) const;
211 std::string contextMenuName() const;
213 void doDispatch(Cursor & cur, FuncRequest & cmd);
216 InsetCaption const * getCaptionInset() const;
218 docstring getCaptionText(OutputParams const &) const;
220 docstring getCaptionHTML(OutputParams const &) const;
225 ColorCode frame_color_;
227 mutable pit_type old_pit;
233 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);