]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
* inset.h:
[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 "updatableinset.h"
16 #include "ParagraphList_fwd.h"
17 #include "RowList_fwd.h"
18 #include "lyxfont.h"
19 #include "lyxtext.h"
20
21 #include "support/types.h"
22
23 #include "frontends/mouse_state.h"
24
25
26 class Buffer;
27 class BufferParams;
28 class BufferView;
29 class Dimension;
30 class LColor_color;
31 class LyXCursor;
32 class Painter;
33 class Paragraph;
34 class Row;
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  @author: Jürgen Vigna
40  */
41 class InsetText : public UpdatableInset {
42 public:
43         ///
44         enum DrawFrame {
45                 ///
46                 NEVER = 0,
47                 ///
48                 LOCKED,
49                 ///
50                 ALWAYS
51         };
52         ///
53         explicit InsetText(BufferParams const &);
54         ///
55         InsetText(InsetText const &);
56         ///
57         virtual std::auto_ptr<InsetBase> clone() const;
58         ///
59         void operator=(InsetText const & it);
60         /// empty inset to empty par, or just mark as erased
61         void clear(bool just_mark_erased);
62         ///
63         void read(Buffer const & buf, LyXLex & lex);
64         ///
65         void write(Buffer const & buf, std::ostream & os) const;
66         ///
67         void metrics(MetricsInfo & mi, Dimension & dim) const;
68         ///
69         void draw(PainterInfo & pi, int x, int y) const;
70         ///
71         std::string const editMessage() const;
72         ///
73         bool isTextInset() const { return true; }
74         ///
75         int latex(Buffer const &, std::ostream &,
76                   OutputParams const &) const;
77         ///
78         int plaintext(Buffer const &, std::ostream &,
79                   OutputParams const &) const;
80         ///
81         int linuxdoc(Buffer const &, std::ostream &,
82                      OutputParams const &) const ;
83         ///
84         int docbook(Buffer const &, std::ostream &,
85                     OutputParams const &) const ;
86         ///
87         void validate(LaTeXFeatures & features) const;
88         ///
89         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
90         /// FIXME, document
91         void getCursorPos(int & x, int & y) const;
92         ///
93         bool insetAllowed(InsetOld::Code) const;
94         ///
95         void setFont(BufferView *, LyXFont const &,
96                      bool toggleall = false,
97                      bool selectall = false);
98         ///
99         void setText(std::string const &, LyXFont const &);
100         ///
101         void setAutoBreakRows(bool);
102         ///
103         bool getAutoBreakRows() const { return autoBreakRows_; }
104         ///
105         void setDrawFrame(DrawFrame);
106         ///
107         LColor_color frameColor() const;
108         ///
109         void setFrameColor(LColor_color);
110         ///
111         void setViewCache(BufferView const * bv) const;
112         ///
113         bool showInsetDialog(BufferView *) const;
114         /// Appends \c list with all labels found within this inset.
115         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
116         ///
117         int scroll(bool recursive = true) const;
118         ///
119         void scroll(BufferView * bv, float sx) const {
120                 UpdatableInset::scroll(bv, sx);
121         }
122         ///
123         void scroll(BufferView * bv, int offset) const {
124                 UpdatableInset::scroll(bv, offset);
125         }
126         ///
127         LyXText * getText(int) const;
128
129         /// mark as erased for change tracking
130         void markErased() { clear(true); };
131         /**
132          * Mark as new. Used when pasting in tabular, and adding rows
133          * or columns. Note that pasting will ensure that tracking already
134          * happens, and this just resets the changes for the copied text,
135          * whereas for row/col add, we need to start tracking changes
136          * for the (empty) paragraph contained.
137          */
138         void markNew(bool track_changes = false);
139
140         /// append text onto the existing text
141         void appendParagraphs(Buffer * bp, ParagraphList &);
142
143         ///
144         void addPreview(lyx::graphics::PreviewLoader &) const;
145
146         ///
147         void edit(BufferView *, bool);
148         ///
149         void edit(BufferView *, int, int);
150
151         ///
152         int numParagraphs() const { return 1; }
153         ///
154         ParagraphList & paragraphs() const;
155
156 private:
157         ///
158         DispatchResult
159         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
160         ///
161         void updateLocal(BufferView *);
162         ///
163         void init();
164         // If the inset is empty set the language of the current font to the
165         // language to the surronding text (if different).
166         void sanitizeEmptyText(BufferView *);
167         ///
168         void setCharFont(Buffer const &, int pos, LyXFont const & font);
169         ///
170         void removeNewlines();
171         ///
172         void drawFrame(Painter &, int x) const;
173         ///
174         void clearInset(Painter &, int x, int y) const;
175         ///
176         void collapseParagraphs(BufferView *);
177
178         /* Private structures and variables */
179         ///
180         bool autoBreakRows_;
181         ///
182         DrawFrame drawFrame_;
183         /** We store the LColor::color value as an int to get LColor.h out
184          *  of the header file.
185          */
186         int frame_color_;
187         ///
188         mutable lyx::paroffset_type old_par;
189
190         /** to remember old painted frame dimensions to clear it on
191          *  the right spot!
192          */
193         mutable bool in_insetAllowed;
194 public:
195         ///
196         mutable LyXText text_;
197         ///
198         mutable LyXFont font_;
199 };
200 #endif