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