]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
90d246719ccc7410788d21e8fe365a44915e4d37
[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 Buffer;
23 class BufferParams;
24 class BufferView;
25 class CompletionList;
26 class CursorSlice;
27 class Dimension;
28 class ParagraphList;
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 const & 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         docstring editMessage() const;
66         ///
67         EDITABLE editable() const { return HIGHLY_EDITABLE; }
68         ///
69         bool canTrackChanges() const { return true; }
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         int latex(odocstream &, OutputParams const &) const;
79         ///
80         int plaintext(odocstream &, OutputParams const &) const;
81         ///
82         int docbook(odocstream &, OutputParams const &) const;
83         ///
84         void validate(LaTeXFeatures & features) const;
85
86         /// return x,y of given position relative to the inset's baseline
87         void cursorPos(BufferView const & bv, CursorSlice const & sl,
88                 bool boundary, int & x, int & y) const;
89         ///
90         InsetCode lyxCode() const { return TEXT_CODE; }
91         ///
92         void setText(docstring const &, Font const &, bool trackChanges);
93         ///
94         void setAutoBreakRows(bool);
95         ///
96         bool getAutoBreakRows() const { return text_.autoBreakRows_; }
97         ///
98         void setDrawFrame(bool);
99         ///
100         ColorCode frameColor() const;
101         ///
102         void setFrameColor(ColorCode);
103         ///
104         bool showInsetDialog(BufferView *) const;
105         ///
106         Text * getText(int i) const {
107                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
108         }
109         ///
110         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
111
112         /// set the change for the entire inset
113         void setChange(Change const & change);
114         /// accept the changes within the inset
115         void acceptChanges(BufferParams const & bparams);
116         /// reject the changes within the inset
117         void rejectChanges(BufferParams const & bparams);
118
119         /// append text onto the existing text
120         void appendParagraphs(ParagraphList &);
121
122         ///
123         void addPreview(graphics::PreviewLoader &) const;
124
125         ///
126         void edit(Cursor & cur, bool front, EntryDirection entry_from);
127         ///
128         Inset * editXY(Cursor & cur, int x, int y);
129
130         /// number of cells in this inset
131         size_t nargs() const { return 1; }
132         ///
133         ParagraphList & paragraphs();
134         ///
135         ParagraphList const & paragraphs() const;
136         ///
137         bool insetAllowed(InsetCode) const { return true; }
138         ///
139         bool allowSpellCheck() const { return true; }
140         ///
141         virtual bool isMacroScope() const { return false; }
142         ///
143         virtual bool allowMultiPar() const { return true; }
144
145         // Update the counters of this inset and of its contents
146         void updateLabels(ParIterator const &);
147         ///
148         void addToToc(DocIterator const &);
149         ///
150         Inset * clone() const { return new InsetText(*this); }
151         ///
152         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
153
154         ///
155         bool completionSupported(Cursor const &) const;
156         ///
157         bool inlineCompletionSupported(Cursor const & cur) const;
158         ///
159         bool automaticInlineCompletion() const;
160         ///
161         bool automaticPopupCompletion() const;
162         ///
163         bool showCompletionCursor() const;
164         ///
165         CompletionList const * createCompletionList(Cursor const & cur) const;
166         ///
167         docstring completionPrefix(Cursor const & cur) const;
168         ///
169         bool insertCompletion(Cursor & cur, docstring const & s, bool finished);
170         ///
171         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const;
172
173         ///
174         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
175         ///
176         void doDispatch(Cursor & cur, FuncRequest & cmd);
177 private:
178         ///
179         void initParagraphs(UsePlain type);
180         ///
181         void setParagraphOwner();
182         ///
183         bool drawFrame_;
184         ///
185         ColorCode frame_color_;
186         ///
187         mutable pit_type old_pit;
188         ///
189         mutable Text text_;
190 };
191
192 } // namespace lyx
193
194 #endif