]> git.lyx.org Git - features.git/blob - src/insets/InsetText.h
Fix update bug when leaving a wide inset with up or down arrow.
[features.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 #include "Font.h"
17 #include "Text.h"
18
19 #include "support/types.h"
20
21 #include "frontends/mouse_state.h"
22
23
24 namespace lyx {
25
26 class Buffer;
27 class BufferParams;
28 class BufferView;
29 class CursorSlice;
30 class Dimension;
31 class Color_color;
32 class ParagraphList;
33
34
35 /**
36  A text inset is like a TeX box to write full text
37  (including styles and other insets) in a given space.
38  */
39 class InsetText : public Inset {
40 public:
41         ///
42         explicit InsetText(BufferParams const &);
43         ///
44         InsetText();
45
46         /// empty inset to empty par
47         void clear();
48         ///
49         void read(Buffer const & buf, Lexer & lex);
50         ///
51         void write(Buffer const & buf, std::ostream & os) const;
52         ///
53         bool metrics(MetricsInfo & mi, Dimension & dim) const;
54         ///
55         void draw(PainterInfo & pi, int x, int y) const;
56         /// draw inset selection
57         void drawSelection(PainterInfo & pi, int x, int y) const;
58         /// are we inside the area covered by the inset?
59         virtual bool covers(BufferView const & bv, int x, int y) const;
60         ///
61         virtual docstring const editMessage() const;
62         ///
63         EDITABLE editable() const { return HIGHLY_EDITABLE; }
64         ///
65         bool canTrackChanges() const { return true; }
66         ///
67         InsetText * asTextInset() { return this; }
68         ///
69         InsetText const * asTextInset() const { return this; }
70         ///
71         int latex(Buffer const &, odocstream &, OutputParams const &) const;
72         ///
73         int plaintext(Buffer const &, odocstream &, OutputParams const &) const;
74         ///
75         int docbook(Buffer const &, odocstream &, OutputParams const &) const;
76         ///
77         void validate(LaTeXFeatures & features) const;
78         //FIXME The following should be removed when wide is.
79         /// Overridden to force an update if the inset was wide().
80         virtual bool notifyCursorLeaves(Cursor & cur);
81
82         /// return x,y of given position relative to the inset's baseline
83         void cursorPos(BufferView const & bv, CursorSlice const & sl,
84                 bool boundary, int & x, int & y) const;
85         ///
86         Code lyxCode() const { return TEXT_CODE; }
87         ///
88         void setText(docstring const &, Font const &, bool trackChanges);
89         ///
90         void setAutoBreakRows(bool);
91         ///
92         bool getAutoBreakRows() const { return text_.autoBreakRows_; }
93         ///
94         void setDrawFrame(bool);
95         ///
96         Color_color frameColor() const;
97         ///
98         void setFrameColor(Color_color);
99         ///
100         bool showInsetDialog(BufferView *) const;
101         ///
102         Text * getText(int i) const {
103                 return (i == 0) ? const_cast<Text*>(&text_) : 0;
104         }
105         ///
106         virtual bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
107
108         /// set the change for the entire inset
109         void setChange(Change const & change);
110         /// accept the changes within the inset
111         void acceptChanges(BufferParams const & bparams);
112         /// reject the changes within the inset
113         void rejectChanges(BufferParams const & bparams);
114
115         /// append text onto the existing text
116         void appendParagraphs(Buffer * bp, ParagraphList &);
117
118         ///
119         void addPreview(graphics::PreviewLoader &) const;
120
121         ///
122         void edit(Cursor & cur, bool left);
123         ///
124         Inset * editXY(Cursor & cur, int x, int y);
125
126         /// number of cells in this inset
127         size_t nargs() const { return 1; }
128         ///
129         ParagraphList & paragraphs();
130         ///
131         ParagraphList const & paragraphs() const;
132         ///
133         bool insetAllowed(Code) const { return true; }
134         ///
135         bool allowSpellCheck() const { return true; }
136         /// should paragraph indendation be ommitted in any case?
137         bool neverIndent(Buffer const &) const;
138         ///
139         InsetText(InsetText const &);
140         ///
141         virtual bool wide() const { return wide_inset_; }
142         ///
143         void setWide(bool wide_inset) { wide_inset_ = wide_inset; }
144         // Update the counters of this inset and of its contents
145         virtual void updateLabels(Buffer const &, ParIterator const &);
146
147 protected:
148         ///
149         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
150
151 private:
152         ///
153         virtual std::auto_ptr<Inset> doClone() const;
154         ///
155         void init();
156
157         ///
158         bool drawFrame_;
159         /** We store the Color::color value as an int to get Color.h out
160          *  of the header file.
161          */
162         int frame_color_;
163         ///
164         mutable pit_type old_pit;
165         ///
166         bool wide_inset_;
167
168 public:
169         ///
170         mutable Text text_;
171         ///
172         mutable Font font_;
173         ///
174         static int border_;
175 };
176
177 } // namespace lyx
178
179 #endif