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"
33 A text inset is like a TeX box to write full text
34 (including styles and other insets) in a given space.
36 class InsetText : public Inset {
43 /// \param useplain whether to use the plain layout
44 /// This is needed because we cannot call the virtual function
45 /// usePlainLayout() from within the constructor.
46 explicit InsetText(Buffer const & buffer, UsePlain type = DefaultLayout);
48 InsetText(InsetText const &);
50 void setBuffer(Buffer &);
53 Dimension const dimension(BufferView const &) const;
55 /// empty inset to empty par
58 void read(Lexer & lex);
60 void write(std::ostream & os) const;
62 void metrics(MetricsInfo & mi, Dimension & dim) const;
64 void draw(PainterInfo & pi, int x, int y) const;
66 bool editable() const { return true; }
68 bool canTrackChanges() const { return true; }
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 int latex(odocstream &, OutputParams const &) const;
79 int plaintext(odocstream &, OutputParams const &) const;
81 int docbook(odocstream &, OutputParams const &) const;
83 docstring xhtml(odocstream &, OutputParams const &) const;
85 void validate(LaTeXFeatures & features) const;
87 /// return x,y of given position relative to the inset's baseline
88 void cursorPos(BufferView const & bv, CursorSlice const & sl,
89 bool boundary, int & x, int & y) const;
91 InsetCode lyxCode() const { return TEXT_CODE; }
93 void setText(docstring const &, Font const &, bool trackChanges);
95 void setAutoBreakRows(bool);
97 bool getAutoBreakRows() const { return text_.autoBreakRows_; }
99 void setDrawFrame(bool);
101 ColorCode frameColor() const;
103 void setFrameColor(ColorCode);
105 bool showInsetDialog(BufferView *) const;
107 Text * getText(int i) const {
108 return (i == 0) ? const_cast<Text*>(&text_) : 0;
111 virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
114 void fixParagraphsFont();
116 /// set the change for the entire inset
117 void setChange(Change const & change);
118 /// accept the changes within the inset
119 void acceptChanges(BufferParams const & bparams);
120 /// reject the changes within the inset
121 void rejectChanges(BufferParams const & bparams);
123 /// append text onto the existing text
124 void appendParagraphs(ParagraphList &);
127 void addPreview(graphics::PreviewLoader &) const;
130 void edit(Cursor & cur, bool front, EntryDirection entry_from);
132 Inset * editXY(Cursor & cur, int x, int y);
134 /// number of cells in this inset
135 size_t nargs() const { return 1; }
137 ParagraphList & paragraphs();
139 ParagraphList const & paragraphs() const;
141 bool insetAllowed(InsetCode) const { return !getLayout().isPassThru(); }
142 /// Allow spellchecking, except for insets with latex_language
143 bool allowSpellCheck() const { return !getLayout().isPassThru(); }
145 virtual bool isMacroScope() const { return false; }
147 virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
149 /// should paragraphs be forced to use the empty layout?
150 virtual bool forcePlainLayout(idx_type = 0) const
151 { return getLayout().forcePlainLayout(); }
152 /// should the user be allowed to customize alignment, etc.?
153 virtual bool allowParagraphCustomization(idx_type = 0) const
154 { return getLayout().allowParagraphCustomization(); }
156 /// Update the counters of this inset and of its contents
157 virtual void updateLabels(ParIterator const &);
158 /// the string that is passed to the TOC
159 void tocString(odocstream &) const;
161 void addToToc(DocIterator const &);
163 Inset * clone() const { return new InsetText(*this); }
165 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
168 bool completionSupported(Cursor const &) const;
170 bool inlineCompletionSupported(Cursor const & cur) const;
172 bool automaticInlineCompletion() const;
174 bool automaticPopupCompletion() const;
176 bool showCompletionCursor() const;
178 CompletionList const * createCompletionList(Cursor const & cur) const;
180 docstring completionPrefix(Cursor const & cur) const;
182 bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
184 void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
187 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
189 void doDispatch(Cursor & cur, FuncRequest & cmd);
192 InsetCaption const * getCaptionInset() const;
194 docstring getCaptionText(OutputParams const &) const;
196 docstring getCaptionHTML(OutputParams const &) const;
199 void initParagraphs(UsePlain type);
201 void setParagraphOwner();
205 ColorCode frame_color_;
207 mutable pit_type old_pit;