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