]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
Make script inset much tighter in texted.
[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         int docbook(odocstream &, OutputParams const &) const;
85         ///
86         docstring xhtml(XHTMLStream &, OutputParams const &) const;
87         ///
88         enum XHTMLOptions {
89                 JustText = 0,
90                 WriteOuterTag = 1,
91                 WriteLabel = 2,
92                 WriteInnerTag = 4,
93                 WriteEverything = 7
94         };
95         ///
96         docstring insetAsXHTML(XHTMLStream &, OutputParams const &,
97                                XHTMLOptions) const;
98         ///
99         void validate(LaTeXFeatures & features) const;
100
101         /// return the argument(s) only
102         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
103
104         /// return x,y of given position relative to the inset's baseline
105         void cursorPos(BufferView const & bv, CursorSlice const & sl,
106                 bool boundary, int & x, int & y) const;
107         ///
108         InsetCode lyxCode() const { return TEXT_CODE; }
109         ///
110         void setText(docstring const &, Font const &, bool trackChanges);
111         ///
112         void setDrawFrame(bool);
113         ///
114         ColorCode frameColor() const;
115         ///
116         void setFrameColor(ColorCode);
117         ///
118         Text * getText(int i) const {
119                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
120         }
121         ///
122         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
123
124         ///
125         void fixParagraphsFont();
126
127         /// does the inset contain changes ?
128         bool isChanged() const { return is_changed_; }
129         /// this is const because value is mutable
130         void isChanged(bool ic) const { is_changed_ = ic; }
131         /// set the change for the entire inset
132         void setChange(Change const & change);
133         /// accept the changes within the inset
134         void acceptChanges();
135         /// reject the changes within the inset
136         void rejectChanges();
137
138         /// append text onto the existing text
139         void appendParagraphs(ParagraphList &);
140
141         ///
142         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
143
144         ///
145         void edit(Cursor & cur, bool front, EntryDirection entry_from);
146         ///
147         Inset * editXY(Cursor & cur, int x, int y);
148
149         /// number of cells in this inset
150         size_t nargs() const { return 1; }
151         ///
152         ParagraphList & paragraphs();
153         ///
154         ParagraphList const & paragraphs() const;
155         ///
156         bool insetAllowed(InsetCode) const;
157         ///
158         bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
159         ///
160         virtual bool isMacroScope() const { return false; }
161         ///
162         virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
163         ///
164         /// should paragraphs be forced to use the empty layout?
165         virtual bool forcePlainLayout(idx_type = 0) const
166                 { return getLayout().forcePlainLayout(); }
167         /// should the user be allowed to customize alignment, etc.?
168         virtual bool allowParagraphCustomization(idx_type = 0) const
169                 { return getLayout().allowParagraphCustomization(); }
170         /// should paragraphs be forced to use a local font language switch?
171         virtual bool forceLocalFontSwitch() const
172                 { return getLayout().forcelocalfontswitch(); }
173
174         /// Update the counters of this inset and of its contents
175         virtual void updateBuffer(ParIterator const &, UpdateType);
176         ///
177         void setMacrocontextPositionRecursive(DocIterator const & pos);
178         ///
179         void toString(odocstream &) const;
180         ///
181         void forOutliner(docstring &, size_t const, bool const) const;
182         ///
183         void addToToc(DocIterator const & di, bool output_active,
184                                   UpdateType utype, TocBackend & backend) const;
185         ///
186         Inset * clone() const { return new InsetText(*this); }
187         ///
188         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
189
190         ///
191         bool completionSupported(Cursor const &) const;
192         ///
193         bool inlineCompletionSupported(Cursor const & cur) const;
194         ///
195         bool automaticInlineCompletion() const;
196         ///
197         bool automaticPopupCompletion() const;
198         ///
199         bool showCompletionCursor() const;
200         ///
201         CompletionList const * createCompletionList(Cursor const & cur) const;
202         ///
203         docstring completionPrefix(Cursor const & cur) const;
204         ///
205         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
206         ///
207         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
208         /// returns the text to be used as tooltip
209         /// \param prefix: a string that will preced the tooltip,
210         /// e.g., "Index: ".
211         /// \param len: length of the resulting string
212         /// NOTE This routine is kind of slow. It's fine to use it within the
213         /// GUI, but definitely do not try to use it in updateBuffer or anything
214         /// of that sort. (Note: unnecessary internal copies have been removed
215         /// since the previous note. The efficiency would have to be assessed
216         /// again by profiling.)
217         docstring toolTipText(docstring prefix = empty_docstring(),
218                               size_t len = 400) const;
219
220         ///
221         std::string contextMenu(BufferView const &, int, int) const;
222         ///
223         std::string contextMenuName() const;
224         ///
225         void doDispatch(Cursor & cur, FuncRequest & cmd);
226
227         ///
228         bool confirmDeletion() const { return !text().empty(); }
229
230         ///
231         bool needsCProtection(bool const maintext = false,
232                               bool const fragile = false) const;
233         ///
234         bool hasCProtectContent(bool fragile = false) const;
235
236 protected:
237         ///
238         void iterateForToc(DocIterator const & cdit, bool output_active,
239                                            UpdateType utype, TocBackend & backend) const;
240 private:
241         /// Open the toc item for paragraph pit. Returns the paragraph index where
242         /// it should end.
243         pit_type openAddToTocForParagraph(pit_type pit,
244                                           DocIterator const & dit,
245                                           bool output_active,
246                                           TocBackend & backend) const;
247         /// Close a toc item opened in start and closed in end
248         void closeAddToTocForParagraph(pit_type start, pit_type end,
249                                        TocBackend & backend) const;
250         ///
251         bool drawFrame_;
252         /// true if the inset contains change
253         mutable bool is_changed_;
254         ///
255         ColorCode frame_color_;
256         ///
257         Text text_;
258 };
259
260
261 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
262
263 } // namespace lyx
264
265 #endif