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