]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
New DocBook support
[lyx.git] / src / insets / InsetText.h
1 // -*- C++ -*-
2 /**
3  * \file InsetText.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef INSETTEXT_H
13 #define INSETTEXT_H
14
15 #include "Inset.h"
16
17 #include "ColorCode.h"
18 #include "Text.h"
19
20 namespace lyx {
21
22 class CompletionList;
23 class CursorSlice;
24 class Dimension;
25 class ParagraphList;
26 class InsetCaption;
27 class InsetTabular;
28 class TocBuilder;
29
30 /**
31  A text inset is like a TeX box to write full text
32  (including styles and other insets) in a given space.
33  */
34 class InsetText : public Inset {
35 public:
36         enum UsePlain {
37                 DefaultLayout,
38                 PlainLayout
39         };
40         /// \param buffer
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);
45         ///
46         InsetText(InsetText const &);
47         ///
48         void setBuffer(Buffer &);
49
50         ///
51         Dimension const dimensionHelper(BufferView const &) const;
52
53         /// empty inset to empty par
54         void clear();
55         ///
56         void read(Lexer & lex);
57         ///
58         void write(std::ostream & os) const;
59         ///
60         void metrics(MetricsInfo & mi, Dimension & dim) const;
61         ///
62         void draw(PainterInfo & pi, int x, int y) const;
63         /// Drawing background is handled in draw
64         virtual void drawBackground(PainterInfo &, int, int) const {}
65         ///
66         bool editable() const { return true; }
67         ///
68         bool canTrackChanges() const { return true; }
69         /// Rely on RowPainter to draw the cue of inline insets.
70         bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
71         ///
72         InsetText * asInsetText() { return this; }
73         ///
74         InsetText const * asInsetText() const { return this; }
75         ///
76         Text & text() { return text_; }
77         Text const & text() const { return text_; }
78         ///
79         void latex(otexstream &, OutputParams const &) const;
80         ///
81         int plaintext(odocstringstream & ods, OutputParams const & op,
82                       size_t max_length = INT_MAX) const;
83         ///
84         docstring xhtml(XMLStream &, OutputParams const &) const;
85         ///
86         enum XHTMLOptions {
87                 JustText = 0,
88                 WriteOuterTag = 1,
89                 WriteLabel = 2,
90                 WriteInnerTag = 4,
91                 WriteEverything = 7
92         };
93         ///
94         docstring insetAsXHTML(XMLStream &, OutputParams const &,
95                                XHTMLOptions) const;
96         ///
97         void docbook(XMLStream &, OutputParams const &, XHTMLOptions opts) const;
98         ///
99         void docbook(XMLStream &, OutputParams const &) const;
100         ///
101         void validate(LaTeXFeatures & features) const;
102
103         /// return the argument(s) only
104         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
105
106         /// return x,y of given position relative to the inset's baseline
107         void cursorPos(BufferView const & bv, CursorSlice const & sl,
108                 bool boundary, int & x, int & y) const;
109         ///
110         InsetCode lyxCode() const { return TEXT_CODE; }
111         ///
112         void setText(docstring const &, Font const &, bool trackChanges);
113         ///
114         void setDrawFrame(bool);
115         ///
116         ColorCode frameColor() const;
117         ///
118         void setFrameColor(ColorCode);
119         ///
120         Text * getText(int i) const {
121                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
122         }
123         ///
124         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
125
126         ///
127         void fixParagraphsFont();
128
129         /// does the inset contain changes ?
130         bool isChanged() const { return is_changed_; }
131         /// this is const because value is mutable
132         void isChanged(bool ic) const { is_changed_ = ic; }
133         /// set the change for the entire inset
134         void setChange(Change const & change);
135         /// accept the changes within the inset
136         void acceptChanges();
137         /// reject the changes within the inset
138         void rejectChanges();
139
140         /// append text onto the existing text
141         void appendParagraphs(ParagraphList &);
142
143         ///
144         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
145
146         ///
147         void edit(Cursor & cur, bool front, EntryDirection entry_from);
148         ///
149         Inset * editXY(Cursor & cur, int x, int y);
150
151         /// number of cells in this inset
152         size_t nargs() const { return 1; }
153         ///
154         ParagraphList & paragraphs();
155         ///
156         ParagraphList const & paragraphs() const;
157         ///
158         bool insetAllowed(InsetCode) const;
159         ///
160         bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
161         ///
162         virtual bool isMacroScope() const { return false; }
163         ///
164         virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
165         ///
166         bool isInTitle() const { return intitle_context_; }
167         ///
168         /// should paragraphs be forced to use the empty layout?
169         virtual bool forcePlainLayout(idx_type = 0) const
170                 { return getLayout().forcePlainLayout(); }
171         /// should the user be allowed to customize alignment, etc.?
172         virtual bool allowParagraphCustomization(idx_type = 0) const
173                 { return getLayout().allowParagraphCustomization(); }
174         /// should paragraphs be forced to use a local font language switch?
175         virtual bool forceLocalFontSwitch() const
176                 { return getLayout().forcelocalfontswitch(); }
177
178         /// Update the counters of this inset and of its contents
179         virtual void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
180         ///
181         void setMacrocontextPositionRecursive(DocIterator const & pos);
182         ///
183         void toString(odocstream &) const;
184         ///
185         void forOutliner(docstring &, size_t const, bool const) const;
186         ///
187         void addToToc(DocIterator const & di, bool output_active,
188                                   UpdateType utype, TocBackend & backend) const;
189         ///
190         Inset * clone() const { return new InsetText(*this); }
191         ///
192         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
193
194         ///
195         bool completionSupported(Cursor const &) const;
196         ///
197         bool inlineCompletionSupported(Cursor const & cur) const;
198         ///
199         bool automaticInlineCompletion() const;
200         ///
201         bool automaticPopupCompletion() const;
202         ///
203         bool showCompletionCursor() const;
204         ///
205         CompletionList const * createCompletionList(Cursor const & cur) const;
206         ///
207         docstring completionPrefix(Cursor const & cur) const;
208         ///
209         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
210         ///
211         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
212         /// returns the text to be used as tooltip
213         /// \param prefix: a string that will precede the tooltip,
214         /// e.g., "Index: ".
215         /// \param len: length of the resulting string
216         /// NOTE This routine is kind of slow. It's fine to use it within the
217         /// GUI, but definitely do not try to use it in updateBuffer or anything
218         /// of that sort. (Note: unnecessary internal copies have been removed
219         /// since the previous note. The efficiency would have to be assessed
220         /// again by profiling.)
221         docstring toolTipText(docstring prefix = empty_docstring(),
222                               size_t len = 400) const;
223
224         ///
225         std::string contextMenu(BufferView const &, int, int) const;
226         ///
227         std::string contextMenuName() const;
228         ///
229         void doDispatch(Cursor & cur, FuncRequest & cmd);
230
231         ///
232         bool confirmDeletion() const { return !text().empty(); }
233
234         ///
235         bool needsCProtection(bool const maintext = false,
236                               bool const fragile = false) const;
237         ///
238         bool hasCProtectContent(bool fragile = false) const;
239
240 protected:
241         ///
242         void iterateForToc(DocIterator const & cdit, bool output_active,
243                                            UpdateType utype, TocBackend & backend) const;
244 private:
245         /// Open the toc item for paragraph pit. Returns the paragraph index where
246         /// it should end.
247         pit_type openAddToTocForParagraph(pit_type pit,
248                                           DocIterator const & dit,
249                                           bool output_active,
250                                           TocBackend & backend) const;
251         /// Close a toc item opened in start and closed in end
252         void closeAddToTocForParagraph(pit_type start, pit_type end,
253                                        TocBackend & backend) const;
254         ///
255         bool drawFrame_;
256         /// true if the inset contains change
257         mutable bool is_changed_;
258         ///
259         bool intitle_context_;
260         ///
261         ColorCode frame_color_;
262         ///
263         Text text_;
264 };
265
266
267 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
268
269 } // namespace lyx
270
271 #endif