]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
Amend commit e194c9ce279
[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
29 /**
30  A text inset is like a TeX box to write full text
31  (including styles and other insets) in a given space.
32  */
33 class InsetText : public Inset {
34 public:
35         enum UsePlain {
36                 DefaultLayout,
37                 PlainLayout
38         };
39         /// \param buffer
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);
44         ///
45         InsetText(InsetText const &);
46         ///
47         void setBuffer(Buffer &);
48
49         ///
50         Dimension const dimension(BufferView const &) const;
51
52         /// empty inset to empty par
53         void clear();
54         ///
55         void read(Lexer & lex);
56         ///
57         void write(std::ostream & os) const;
58         ///
59         void metrics(MetricsInfo & mi, Dimension & dim) const;
60         ///
61         void draw(PainterInfo & pi, int x, int y) const;
62         /// Drawing background is handled in draw
63         virtual void drawBackground(PainterInfo &, int, int) const {}
64         ///
65         bool editable() const { return true; }
66         ///
67         bool canTrackChanges() const { return true; }
68         /// Rely on RowPainter to draw the cue of inline insets.
69         bool canPaintChange(BufferView const &) const { return allowMultiPar(); }
70         ///
71         InsetText * asInsetText() { return this; }
72         ///
73         InsetText const * asInsetText() const { return this; }
74         ///
75         Text & text() { return text_; }
76         Text const & text() const { return text_; }
77         ///
78         void latex(otexstream &, OutputParams const &) const;
79         ///
80         int plaintext(odocstringstream & ods, OutputParams const & op,
81                       size_t max_length = INT_MAX) const;
82         ///
83         int docbook(odocstream &, OutputParams const &) const;
84         ///
85         docstring xhtml(XHTMLStream &, OutputParams const &) const;
86         ///
87         enum XHTMLOptions {
88                 JustText = 0,
89                 WriteOuterTag = 1,
90                 WriteLabel = 2,
91                 WriteInnerTag = 4,
92                 WriteEverything = 7
93         };
94         ///
95         docstring insetAsXHTML(XHTMLStream &, OutputParams const &, 
96                                XHTMLOptions) const;
97         ///
98         void validate(LaTeXFeatures & features) const;
99         
100         /// return the argument(s) only
101         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
102
103         /// return x,y of given position relative to the inset's baseline
104         void cursorPos(BufferView const & bv, CursorSlice const & sl,
105                 bool boundary, int & x, int & y) const;
106         ///
107         InsetCode lyxCode() const { return TEXT_CODE; }
108         ///
109         void setText(docstring const &, Font const &, bool trackChanges);
110         ///
111         void setDrawFrame(bool);
112         ///
113         ColorCode frameColor() const;
114         ///
115         void setFrameColor(ColorCode);
116         ///
117         Text * getText(int i) const {
118                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
119         }
120         ///
121         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
122
123         ///
124         void fixParagraphsFont();
125
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();
132
133         /// append text onto the existing text
134         void appendParagraphs(ParagraphList &);
135
136         ///
137         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
138
139         ///
140         void edit(Cursor & cur, bool front, EntryDirection entry_from);
141         ///
142         Inset * editXY(Cursor & cur, int x, int y);
143
144         /// number of cells in this inset
145         size_t nargs() const { return 1; }
146         ///
147         ParagraphList & paragraphs();
148         ///
149         ParagraphList const & paragraphs() const;
150         ///
151         bool insetAllowed(InsetCode) const;
152         ///
153         bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
154         ///
155         virtual bool isMacroScope() const { return false; }
156         ///
157         virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
158         ///
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(); }
165         /// should paragraphs be forced to use a local font language switch?
166         virtual bool forceLocalFontSwitch() const
167                 { return getLayout().forcelocalfontswitch(); }
168
169         /// Update the counters of this inset and of its contents
170         virtual void updateBuffer(ParIterator const &, UpdateType);
171         /// 
172         void setMacrocontextPositionRecursive(DocIterator const & pos);
173         ///
174         void toString(odocstream &) const;
175         ///
176         void forOutliner(docstring &, size_t const, bool const) const;
177         ///
178         void addToToc(DocIterator const & di, bool output_active,
179                                   UpdateType utype) const;
180         ///
181         Inset * clone() const { return new InsetText(*this); }
182         ///
183         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
184
185         ///
186         bool completionSupported(Cursor const &) const;
187         ///
188         bool inlineCompletionSupported(Cursor const & cur) const;
189         ///
190         bool automaticInlineCompletion() const;
191         ///
192         bool automaticPopupCompletion() const;
193         ///
194         bool showCompletionCursor() const;
195         ///
196         CompletionList const * createCompletionList(Cursor const & cur) const;
197         ///
198         docstring completionPrefix(Cursor const & cur) const;
199         ///
200         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
201         ///
202         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
203         /// returns the text to be used as tooltip
204         /// \param prefix: a string that will preced the tooltip,
205         /// e.g., "Index: ".
206         /// \param len: length of the resulting string
207         /// NOTE This routine is kind of slow. It's fine to use it within the 
208         /// GUI, but definitely do not try to use it in updateBuffer or anything
209         /// of that sort. (Note: unnecessary internal copies have been removed
210         /// since the previous note. The efficiency would have to be assessed
211         /// again by profiling.)
212         docstring toolTipText(docstring prefix = empty_docstring(),
213                               size_t len = 400) const;
214
215         ///
216         std::string contextMenu(BufferView const &, int, int) const;
217         ///
218         std::string contextMenuName() const;
219         ///
220         void doDispatch(Cursor & cur, FuncRequest & cmd);
221 protected:
222         ///
223         InsetCaption const * getCaptionInset() const;
224         ///
225         docstring getCaptionText(OutputParams const &) const;
226         ///
227         docstring getCaptionHTML(OutputParams const &) const;
228         ///
229         void iterateForToc(DocIterator const & cdit, bool output_active,
230                                            UpdateType utype) const;
231 private:
232         ///
233         bool drawFrame_;
234         ///
235         ColorCode frame_color_;
236         ///
237         Text text_;
238 };
239
240
241 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
242
243 } // namespace lyx
244
245 #endif