]> git.lyx.org Git - lyx.git/blob - src/insets/InsetText.h
Move code responsible to set TextMetrics outer font to InsetText
[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
21 namespace lyx {
22
23 class CompletionList;
24 class CursorSlice;
25 class Dimension;
26 class ParagraphList;
27
28 /**
29  A text inset is like a TeX box to write full text
30  (including styles and other insets) in a given space.
31  */
32 class InsetText : public Inset {
33 public:
34         enum UsePlain {
35                 DefaultLayout,
36                 PlainLayout
37         };
38         /// \param buffer
39         /// \param useplain whether to use the plain layout
40         /// This is needed because we cannot call the virtual function
41         /// usePlainLayout() from within the constructor.
42         explicit InsetText(Buffer * buffer, UsePlain type = DefaultLayout);
43         ///
44         InsetText(InsetText const &);
45         ///
46         void setBuffer(Buffer &) override;
47
48         ///
49         Dimension const dimensionHelper(BufferView const &) const;
50
51         /// empty inset to empty par
52         void clear();
53         ///
54         void read(Lexer & lex) override;
55         ///
56         void write(std::ostream & os) const override;
57         /// Let the inset compute and store its reference font from \c outer.
58         void setOuterFont(BufferView & bv, FontInfo const & outer) const;
59         ///
60         void metrics(MetricsInfo & mi, Dimension & dim) const override;
61         ///
62         void draw(PainterInfo & pi, int x, int y) const override;
63         /// Drawing background is handled in draw
64         void drawBackground(PainterInfo &, int, int) const override {}
65         ///
66         bool editable() const override { return true; }
67         ///
68         bool canTrackChanges() const override { return true; }
69         /// Rely on RowPainter to draw the cue of inline insets.
70         bool canPaintChange(BufferView const &) const override { return allowMultiPar(); }
71         ///
72         InsetText * asInsetText() override { return this; }
73         ///
74         InsetText const * asInsetText() const override { return this; }
75         ///
76         Text & text() { return text_; }
77         Text const & text() const { return text_; }
78         ///
79         void latex(otexstream &, OutputParams const &) const override;
80         ///
81         int plaintext(odocstringstream & ods, OutputParams const & op,
82                       size_t max_length = INT_MAX) const override;
83         ///
84         docstring xhtml(XMLStream &, OutputParams const &) const override;
85         ///
86         enum XHTMLOptions {
87                 JustText = 0,
88                 WriteOuterTag = 1,
89                 WriteLabel = 2,
90                 WriteInnerTag = 4,
91                 WriteEverything = 7
92         };
93         ///
94         docstring insetAsXHTML(XMLStream &, OutputParams const &,
95                                XHTMLOptions) const;
96         ///
97         void docbook(XMLStream &, OutputParams const &, XHTMLOptions opts) const;
98         ///
99         void docbook(XMLStream &, OutputParams const &) const override;
100         ///
101         void validate(LaTeXFeatures & features) const override;
102
103         /// return the argument(s) only
104         void getArgs(otexstream & os, OutputParams const &, bool const post = false) const;
105
106         /// return x,y of given position relative to the inset's baseline
107         void cursorPos(BufferView const & bv, CursorSlice const & sl,
108                 bool boundary, int & x, int & y) const override;
109         ///
110         InsetCode lyxCode() const override { return TEXT_CODE; }
111         ///
112         void setText(docstring const &, Font const &, bool trackChanges);
113         ///
114         void setDrawFrame(bool);
115         ///
116         ColorCode frameColor() const;
117         ///
118         void setFrameColor(ColorCode);
119         ///
120         Text * getText(int idx) const override {
121                 return (idx == 0) ? const_cast<Text*>(&text_) : nullptr;
122         }
123         ///
124         bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const override;
125
126         ///
127         void fixParagraphsFont();
128
129         /// does the inset contain changes ?
130         bool isChanged() const override { return is_changed_; }
131         /// this is const because value is mutable
132         void isChanged(bool ic) const { is_changed_ = ic; }
133         /// set the change for the entire inset
134         void setChange(Change const & change) override;
135         /// accept the changes within the inset
136         void acceptChanges() override;
137         /// reject the changes within the inset
138         void rejectChanges() override;
139
140         /// append text onto the existing text
141         void appendParagraphs(ParagraphList &);
142
143         ///
144         void addPreview(DocIterator const &, graphics::PreviewLoader &) const override;
145
146         ///
147         void edit(Cursor & cur, bool front, EntryDirection entry_from) override;
148         ///
149         Inset * editXY(Cursor & cur, int x, int y) override;
150
151         /// number of cells in this inset
152         size_t nargs() const override { return 1; }
153         ///
154         ParagraphList & paragraphs();
155         ///
156         ParagraphList const & paragraphs() const;
157         ///
158         bool insetAllowed(InsetCode) const override;
159         ///
160         bool allowSpellCheck() const override;
161         ///
162         virtual bool isMacroScope() const { return false; }
163         ///
164         bool allowMultiPar() const override;
165         ///
166         bool isInTitle() const override { return intitle_context_; }
167         ///
168         /// should paragraphs be forced to use the empty layout?
169         bool forcePlainLayout(idx_type = 0) const override;
170         /// should the user be allowed to customize alignment, etc.?
171         bool allowParagraphCustomization(idx_type = 0) const override;
172         /// should paragraphs be forced to use a local font language switch?
173         bool forceLocalFontSwitch() const override;
174
175         /// Update the counters of this inset and of its contents
176         void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false) override;
177         ///
178         void setMacrocontextPositionRecursive(DocIterator const & pos);
179         ///
180         void toString(odocstream &) const override;
181         ///
182         void forOutliner(docstring &, size_t const, bool const) const override;
183         ///
184         void addToToc(DocIterator const & di, bool output_active,
185                                   UpdateType utype, TocBackend & backend) const override;
186         ///
187         Inset * clone() const override { return new InsetText(*this); }
188         ///
189         bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
190
191         ///
192         bool completionSupported(Cursor const &) const override;
193         ///
194         bool inlineCompletionSupported(Cursor const & cur) const override;
195         ///
196         bool automaticInlineCompletion() const override;
197         ///
198         bool automaticPopupCompletion() const override;
199         ///
200         bool showCompletionCursor() const override;
201         ///
202         CompletionList const * createCompletionList(Cursor const & cur) const override;
203         ///
204         docstring completionPrefix(Cursor const & cur) const override;
205         ///
206         bool insertCompletion(Cursor & cur, docstring const & s, bool finished) override;
207         ///
208         void completionPosAndDim(Cursor const &, int & x, int & y, Dimension & dim) const override;
209         /// returns the text to be used as tooltip
210         /// \param prefix: a string that will precede the tooltip,
211         /// e.g., "Index: ".
212         /// \param len: length of the resulting string
213         /// NOTE This routine is kind of slow. It's fine to use it within the
214         /// GUI, but definitely do not try to use it in updateBuffer or anything
215         /// of that sort. (Note: unnecessary internal copies have been removed
216         /// since the previous note. The efficiency would have to be assessed
217         /// again by profiling.)
218         docstring toolTipText(docstring const & prefix = empty_docstring(),
219                               size_t len = 400) const;
220
221         ///
222         std::string contextMenu(BufferView const &, int, int) const override;
223         ///
224         std::string contextMenuName() const override;
225         ///
226         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
227
228         ///
229         bool confirmDeletion() const override { return !text().empty(); }
230
231         ///
232         bool needsCProtection(bool const maintext = false,
233                               bool const fragile = false) const override;
234         ///
235         bool hasCProtectContent(bool fragile = false) const;
236
237 protected:
238         ///
239         void iterateForToc(DocIterator const & cdit, bool output_active,
240                                            UpdateType utype, TocBackend & backend) const;
241 private:
242         /// Open the toc item for paragraph pit. Returns the paragraph index where
243         /// it should end.
244         pit_type openAddToTocForParagraph(pit_type pit,
245                                           DocIterator const & dit,
246                                           bool output_active,
247                                           TocBackend & backend) const;
248         /// Close a toc item opened in start and closed in end
249         void closeAddToTocForParagraph(pit_type start, pit_type end,
250                                        TocBackend & backend) const;
251         ///
252         bool drawFrame_;
253         /// true if the inset contains change
254         mutable bool is_changed_;
255         ///
256         bool intitle_context_;
257         ///
258         ColorCode frame_color_;
259         ///
260         Text text_;
261 };
262
263
264 InsetText::XHTMLOptions operator|(InsetText::XHTMLOptions a1, InsetText::XHTMLOptions a2);
265
266 } // namespace lyx
267
268 #endif