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; }
67 InsetText * asInsetText() { return this; }
69 InsetText const * asInsetText() const { return this; }
71 Text & text() { return text_; }
72 Text const & text() const { return text_; }
74 void latex(otexstream &, OutputParams const &) const;
76 int plaintext(odocstringstream & ods, OutputParams const & op,
77 size_t max_length = INT_MAX) const;
79 int docbook(odocstream &, OutputParams const &) const;
81 docstring xhtml(XHTMLStream &, OutputParams const &) const;
91 docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
94 void validate(LaTeXFeatures & features) const;
96 /// return the argument(s) only
97 void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
99 /// return x,y of given position relative to the inset's baseline
100 void cursorPos(BufferView const & bv, CursorSlice const & sl,
101 bool boundary, int & x, int & y) const;
103 InsetCode lyxCode() const { return TEXT_CODE; }
105 void setText(docstring const &, Font const &, bool trackChanges);
107 void setAutoBreakRows(bool);
109 bool getAutoBreakRows() const { return text_.autoBreakRows_; }
111 void setDrawFrame(bool);
113 ColorCode frameColor() const;
115 void setFrameColor(ColorCode);
117 Text * getText(int i) const {
118 return (i == 0) ? const_cast<Text*>(&text_) : 0;
121 virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
124 void fixParagraphsFont();
126 /// set the change for the entire inset
127 void setChange(Change const & change);
128 /// accept the changes within the inset
129 void acceptChanges();
130 /// reject the changes within the inset
131 void rejectChanges();
133 /// append text onto the existing text
134 void appendParagraphs(ParagraphList &);
137 void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
140 void edit(Cursor & cur, bool front, EntryDirection entry_from);
142 Inset * editXY(Cursor & cur, int x, int y);
144 /// number of cells in this inset
145 size_t nargs() const { return 1; }
147 ParagraphList & paragraphs();
149 ParagraphList const & paragraphs() const;
151 bool insetAllowed(InsetCode) const;
153 bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
155 virtual bool isMacroScope() const { return false; }
157 virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
159 /// should paragraphs be forced to use the empty layout?
160 virtual bool forcePlainLayout(idx_type = 0) const
161 { return getLayout().forcePlainLayout(); }
162 /// should the user be allowed to customize alignment, etc.?
163 virtual bool allowParagraphCustomization(idx_type = 0) const
164 { return getLayout().allowParagraphCustomization(); }
166 /// Update the counters of this inset and of its contents
167 virtual void updateBuffer(ParIterator const &, UpdateType);
169 void setMacrocontextPositionRecursive(DocIterator const & pos);
171 void toString(odocstream &) const;
173 void forToc(docstring &, size_t) const;
175 void addToToc(DocIterator const & di, bool output_active) const;
177 Inset * clone() const { return new InsetText(*this); }
179 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
182 bool completionSupported(Cursor const &) const;
184 bool inlineCompletionSupported(Cursor const & cur) const;
186 bool automaticInlineCompletion() const;
188 bool automaticPopupCompletion() const;
190 bool showCompletionCursor() const;
192 CompletionList const * createCompletionList(Cursor const & cur) const;
194 docstring completionPrefix(Cursor const & cur) const;
196 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
198 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
199 /// returns the text to be used as tooltip
200 /// \param prefix: a string that will preced the tooltip,
202 /// \param numlines: the number of lines in the tooltip
203 /// \param len: length of those lines
204 docstring toolTipText(docstring prefix = empty_docstring(),
205 size_t numlines = 5, size_t len = 80) const;
208 std::string contextMenu(BufferView const &, int, int) const;
210 std::string contextMenuName() const;
212 void doDispatch(Cursor & cur, FuncRequest & cmd);
215 InsetCaption const * getCaptionInset() const;
217 docstring getCaptionText(OutputParams const &) const;
219 docstring getCaptionHTML(OutputParams const &) const;
224 ColorCode frame_color_;
230 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);