]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
Consistency of ellipses across the UI
[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         ///
63         bool editable() const { return true; }
64         ///
65         bool canTrackChanges() const { return true; }
66         ///
67         InsetText * asInsetText() { return this; }
68         ///
69         InsetText const * asInsetText() const { return this; }
70         ///
71         Text & text() { return text_; }
72         Text const & text() const { return text_; }
73         ///
74         void latex(otexstream &, OutputParams const &) const;
75         ///
76         int plaintext(odocstringstream & ods, OutputParams const & op,
77                       size_t max_length = INT_MAX) const;
78         ///
79         int docbook(odocstream &, OutputParams const &) const;
80         ///
81         docstring xhtml(XHTMLStream &, OutputParams const &) const;
82         ///
83         enum XHTMLOptions {
84                 JustText = 0,
85                 WriteOuterTag = 1,
86                 WriteLabel = 2,
87                 WriteInnerTag = 4,
88                 WriteEverything = 7
89         };
90         ///
91         docstring insetAsXHTML(XHTMLStream &, OutputParams const &, 
92                                XHTMLOptions) const;
93         ///
94         void validate(LaTeXFeatures & features) const;
95         
96         /// return the argument(s) only
97         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
98
99         /// return x,y of given position relative to the inset's baseline
100         void cursorPos(BufferView const & bv, CursorSlice const & sl,
101                 bool boundary, int & x, int & y) const;
102         ///
103         InsetCode lyxCode() const { return TEXT_CODE; }
104         ///
105         void setText(docstring const &, Font const &, bool trackChanges);
106         ///
107         void setDrawFrame(bool);
108         ///
109         ColorCode frameColor() const;
110         ///
111         void setFrameColor(ColorCode);
112         ///
113         Text * getText(int i) const {
114                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
115         }
116         ///
117         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
118
119         ///
120         void fixParagraphsFont();
121
122         /// set the change for the entire inset
123         void setChange(Change const & change);
124         /// accept the changes within the inset
125         void acceptChanges();
126         /// reject the changes within the inset
127         void rejectChanges();
128
129         /// append text onto the existing text
130         void appendParagraphs(ParagraphList &);
131
132         ///
133         void addPreview(DocIterator const &, graphics::PreviewLoader &) const;
134
135         ///
136         void edit(Cursor & cur, bool front, EntryDirection entry_from);
137         ///
138         Inset * editXY(Cursor & cur, int x, int y);
139
140         /// number of cells in this inset
141         size_t nargs() const { return 1; }
142         ///
143         ParagraphList & paragraphs();
144         ///
145         ParagraphList const & paragraphs() const;
146         ///
147         bool insetAllowed(InsetCode) const;
148         ///
149         bool allowSpellCheck() const { return getLayout().spellcheck() && !getLayout().isPassThru(); }
150         ///
151         virtual bool isMacroScope() const { return false; }
152         ///
153         virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
154         ///
155         /// should paragraphs be forced to use the empty layout?
156         virtual bool forcePlainLayout(idx_type = 0) const
157                 { return getLayout().forcePlainLayout(); }
158         /// should the user be allowed to customize alignment, etc.?
159         virtual bool allowParagraphCustomization(idx_type = 0) const
160                 { return getLayout().allowParagraphCustomization(); }
161         /// should paragraphs be forced to use a local font language switch?
162         virtual bool forceLocalFontSwitch() const
163                 { return getLayout().forcelocalfontswitch(); }
164
165         /// Update the counters of this inset and of its contents
166         virtual void updateBuffer(ParIterator const &, UpdateType);
167         /// 
168         void setMacrocontextPositionRecursive(DocIterator const & pos);
169         ///
170         void toString(odocstream &) const;
171         ///
172         void forOutliner(docstring &, size_t const, bool const) const;
173         ///
174         void addToToc(DocIterator const & di, bool output_active,
175                                   UpdateType utype) const;
176         ///
177         Inset * clone() const { return new InsetText(*this); }
178         ///
179         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
180
181         ///
182         bool completionSupported(Cursor const &) const;
183         ///
184         bool inlineCompletionSupported(Cursor const & cur) const;
185         ///
186         bool automaticInlineCompletion() const;
187         ///
188         bool automaticPopupCompletion() const;
189         ///
190         bool showCompletionCursor() const;
191         ///
192         CompletionList const * createCompletionList(Cursor const & cur) const;
193         ///
194         docstring completionPrefix(Cursor const & cur) const;
195         ///
196         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
197         ///
198         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
199         /// returns the text to be used as tooltip
200         /// \param prefix: a string that will preced the tooltip,
201         /// e.g., "Index: ".
202         /// \param numlines: the number of lines in the tooltip
203         /// \param len: length of those lines
204         docstring toolTipText(docstring prefix = empty_docstring(),
205                         size_t numlines = 5, size_t len = 80) const;
206
207         ///
208         std::string contextMenu(BufferView const &, int, int) const;
209         ///
210         std::string contextMenuName() const;
211         ///
212         void doDispatch(Cursor & cur, FuncRequest & cmd);
213 protected:
214         ///
215         InsetCaption const * getCaptionInset() const;
216         ///
217         docstring getCaptionText(OutputParams const &) const;
218         ///
219         docstring getCaptionHTML(OutputParams const &) const;
220         ///
221         void iterateForToc(DocIterator const & cdit, bool output_active,
222                                            UpdateType utype) const;
223 private:
224         ///
225         bool drawFrame_;
226         ///
227         ColorCode frame_color_;
228         ///
229         mutable Text text_;
230 };
231
232
233 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
234
235 } // namespace lyx
236
237 #endif