]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
Add Nomenclature to the TOC.
[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 #include "insets/InsetLayout.h"
21
22 namespace lyx {
23
24 class CompletionList;
25 class CursorSlice;
26 class Dimension;
27 class ParagraphList;
28 class InsetCaption;
29 class InsetTabular;
30
31 /**
32  A text inset is like a TeX box to write full text
33  (including styles and other insets) in a given space.
34  */
35 class InsetText : public Inset {
36 public:
37         enum UsePlain {
38                 DefaultLayout,
39                 PlainLayout
40         };
41         /// \param buffer
42         /// \param useplain whether to use the plain layout
43         /// This is needed because we cannot call the virtual function
44         /// usePlainLayout() from within the constructor.
45         explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
46         ///
47         InsetText(InsetText const &);
48         ///
49         void setBuffer(Buffer &);
50
51         ///
52         Dimension const dimension(BufferView const &) const;
53
54         /// empty inset to empty par
55         void clear();
56         ///
57         void read(Lexer & lex);
58         ///
59         void write(std::ostream & os) const;
60         ///
61         void metrics(MetricsInfo & mi, Dimension & dim) const;
62         ///
63         void draw(PainterInfo & pi, int x, int y) const;
64         ///
65         bool editable() const { return true; }
66         ///
67         bool canTrackChanges() const { return true; }
68         ///
69         InsetText * asInsetText() { return this; }
70         ///
71         InsetText const * asInsetText() const { return this; }
72         ///
73         Text & text() { return text_; }
74         Text const & text() const { return text_; }
75         ///
76         void latex(otexstream &, OutputParams const &) const;
77         ///
78         int plaintext(odocstringstream & ods, OutputParams const & op,
79                       size_t max_length = INT_MAX) const;
80         ///
81         int docbook(odocstream &, OutputParams const &) const;
82         ///
83         docstring xhtml(XHTMLStream &, OutputParams const &) const;
84         ///
85         enum XHTMLOptions {
86                 JustText = 0,
87                 WriteOuterTag = 1,
88                 WriteLabel = 2,
89                 WriteInnerTag = 4,
90                 WriteEverything = 7
91         };
92         ///
93         docstring insetAsXHTML(XHTMLStream &, OutputParams const &, 
94                                XHTMLOptions) const;
95         ///
96         void validate(LaTeXFeatures & features) const;
97         
98         /// return the argument(s) only
99         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
100
101         /// return x,y of given position relative to the inset's baseline
102         void cursorPos(BufferView const & bv, CursorSlice const & sl,
103                 bool boundary, int & x, int & y) const;
104         ///
105         InsetCode lyxCode() const { return TEXT_CODE; }
106         ///
107         void setText(docstring const &, Font const &, bool trackChanges);
108         ///
109         void setAutoBreakRows(bool);
110         ///
111         bool getAutoBreakRows() const { return text_.autoBreakRows_; }
112         ///
113         void setDrawFrame(bool);
114         ///
115         ColorCode frameColor() const;
116         ///
117         void setFrameColor(ColorCode);
118         ///
119         Text * getText(int i) const {
120                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
121         }
122         ///
123         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
124
125         ///
126         void fixParagraphsFont();
127
128         /// set the change for the entire inset
129         void setChange(Change const & change);
130         /// accept the changes within the inset
131         void acceptChanges();
132         /// reject the changes within the inset
133         void rejectChanges();
134
135         /// append text onto the existing text
136         void appendParagraphs(ParagraphList &);
137
138         ///
139         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
140
141         ///
142         void edit(Cursor & cur, bool front, EntryDirection entry_from);
143         ///
144         Inset * editXY(Cursor & cur, int x, int y);
145
146         /// number of cells in this inset
147         size_t nargs() const { return 1; }
148         ///
149         ParagraphList & paragraphs();
150         ///
151         ParagraphList const & paragraphs() const;
152         ///
153         bool insetAllowed(InsetCode) const;
154         ///
155         bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
156         ///
157         virtual bool isMacroScope() const { return false; }
158         ///
159         virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
160         ///
161         /// should paragraphs be forced to use the empty layout?
162         virtual bool forcePlainLayout(idx_type = 0) const 
163                 { return getLayout().forcePlainLayout(); }
164         /// should the user be allowed to customize alignment, etc.?
165         virtual bool allowParagraphCustomization(idx_type = 0) const 
166                 { return getLayout().allowParagraphCustomization(); }
167
168         /// Update the counters of this inset and of its contents
169         virtual void updateBuffer(ParIterator const &, UpdateType);
170         /// 
171         void setMacrocontextPositionRecursive(DocIterator const & pos);
172         ///
173         void toString(odocstream &) const;
174         ///
175         void forToc(docstring &, size_t) const;
176         ///
177         void addToToc(DocIterator const & di, bool output_active) const;
178         ///
179         Inset * clone() const { return new InsetText(*this); }
180         ///
181         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
182
183         ///
184         bool completionSupported(Cursor const &) const;
185         ///
186         bool inlineCompletionSupported(Cursor const & cur) const;
187         ///
188         bool automaticInlineCompletion() const;
189         ///
190         bool automaticPopupCompletion() const;
191         ///
192         bool showCompletionCursor() const;
193         ///
194         CompletionList const * createCompletionList(Cursor const & cur) const;
195         ///
196         docstring completionPrefix(Cursor const & cur) const;
197         ///
198         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
199         ///
200         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
201         /// returns the text to be used as tooltip
202         /// \param prefix: a string that will preced the tooltip,
203         /// e.g., "Index: ".
204         /// \param numlines: the number of lines in the tooltip
205         /// \param len: length of those lines
206         docstring toolTipText(docstring prefix = empty_docstring(),
207                         size_t numlines = 5, size_t len = 80) const;
208
209         ///
210         std::string contextMenu(BufferView const &, int, int) const;
211         ///
212         std::string contextMenuName() const;
213         ///
214         void doDispatch(Cursor & cur, FuncRequest & cmd);
215 protected:
216         ///
217         InsetCaption const * getCaptionInset() const;
218         ///
219         docstring getCaptionText(OutputParams const &) const;
220         ///
221         docstring getCaptionHTML(OutputParams const &) const;
222 private:
223         ///
224         bool drawFrame_;
225         ///
226         ColorCode frame_color_;
227         ///
228         mutable pit_type old_pit;
229         ///
230         mutable Text text_;
231 };
232
233
234 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
235
236 } // namespace lyx
237
238 #endif