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