]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
Re-add the RasterImage template.
[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 "lyxtext.h"
19
20 #include "support/types.h"
21
22 #include "frontends/mouse_state.h"
23
24 #include "support/std_string.h"
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         InsetText(BufferParams const &);
54         ///
55         explicit InsetText(InsetText const &);
56         ///
57         virtual std::auto_ptr<InsetBase> clone() const;
58         ///
59         InsetText & 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 &, LyXLex &);
64         ///
65         void write(Buffer const &, std::ostream &) const;
66         ///
67         void metrics(MetricsInfo &, Dimension &) const;
68         ///
69         int textWidth() const;
70         ///
71         void draw(PainterInfo & pi, int x, int y) const;
72         ///
73         string const editMessage() const;
74         ///
75         bool isTextInset() const { return true; }
76         ///
77         void insetUnlock(BufferView *);
78         ///
79         bool lockInsetInInset(BufferView *, UpdatableInset *);
80         ///
81         bool unlockInsetInInset(BufferView *,
82                                 UpdatableInset *, bool lr = false);
83         ///
84         RESULT localDispatch(FuncRequest const &);
85         ///
86         int latex(Buffer const &, std::ostream &,
87                   LatexRunParams const &) const;
88         ///
89         int ascii(Buffer const &, std::ostream &, int linelen) const;
90         ///
91         int linuxdoc(Buffer const &, std::ostream &) const ;
92         ///
93         int docbook(Buffer const &, std::ostream &, bool mixcont) const ;
94         ///
95         void validate(LaTeXFeatures & features) const;
96         ///
97         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
98         /// FIXME, document
99         void getCursorPos(BufferView *, int & x, int & y) const;
100         /// Get the absolute document x,y of the cursor
101         virtual void getCursor(BufferView &, int &, int &) const;
102         ///
103         int insetInInsetY() const;
104         ///
105         void fitInsetCursor(BufferView *) const;
106         ///
107         bool insertInset(BufferView *, InsetOld *);
108         ///
109         bool insetAllowed(InsetOld::Code) const;
110         ///
111         UpdatableInset * getLockingInset() const;
112         ///
113         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
114         ///
115         void setFont(BufferView *, LyXFont const &,
116                      bool toggleall = false,
117                      bool selectall = false);
118         ///
119         void init(InsetText const * ins);
120         ///
121         void writeParagraphData(Buffer const &, std::ostream &) const;
122         ///
123         void setText(string const &, LyXFont const &);
124         ///
125         void setAutoBreakRows(bool);
126         ///
127         bool getAutoBreakRows() const { return autoBreakRows_; }
128         ///
129         void setDrawFrame(DrawFrame);
130         ///
131         LColor_color frameColor() const;
132         void setFrameColor(LColor_color);
133         ///
134         LyXText * getLyXText(BufferView const *,
135                              bool const recursive = false) const;
136         ///
137         void setViewCache(BufferView const * bv) const;
138         ///
139         void deleteLyXText(BufferView *, bool recursive = true) const;
140         ///
141         bool showInsetDialog(BufferView *) const;
142         /// Appends \c list with all labels found within this inset.
143         void getLabelList(Buffer const &, std::vector<string> & list) const;
144         ///
145         int scroll(bool recursive = true) const;
146         ///
147         void scroll(BufferView * bv, float sx) const {
148                 UpdatableInset::scroll(bv, sx);
149         }
150         ///
151         void scroll(BufferView * bv, int offset) const {
152                 UpdatableInset::scroll(bv, offset);
153         }
154         ///
155         void clearSelection(BufferView * bv);
156         ///
157         InsetOld * getInsetFromID(int id) const;
158         ///
159         ParagraphList * getParagraphs(int) const;
160         ///
161         LyXCursor const & cursor(BufferView *) const;
162         ///
163         bool allowSpellcheck() const { return true; }
164         ///
165         WordLangTuple const
166         selectNextWordToSpellcheck(BufferView *, float & value) const;
167         ///
168         void selectSelectedWord(BufferView *);
169
170         /// mark as erased for change tracking
171         void markErased() { clear(true); };
172         /**
173          * Mark as new. Used when pasting in tabular, and adding rows
174          * or columns. Note that pasting will ensure that tracking already
175          * happens, and this just resets the changes for the copied text,
176          * whereas for row/col add, we need to start tracking changes
177          * for the (empty) paragraph contained.
178          */
179         void markNew(bool track_changes = false);
180         /// find next change
181         bool nextChange(BufferView *, lyx::pos_type & length);
182
183         ///
184         bool searchForward(BufferView *, string const &,
185                            bool = true, bool = false);
186         ///
187         bool searchBackward(BufferView *, string const &,
188                             bool = true, bool = false);
189         ///
190         bool checkInsertChar(LyXFont &);
191         ///
192         void getDrawFont(LyXFont &) const;
193         /// append text onto the existing text
194         void appendParagraphs(Buffer * bp, ParagraphList &);
195
196         ///
197         void addPreview(lyx::graphics::PreviewLoader &) const;
198
199         ///
200         bool haveParagraphs() const {
201                 return true;
202         }
203         ///
204         mutable ParagraphList paragraphs;
205 protected:
206         ///
207         void updateLocal(BufferView *, bool mark_dirty);
208         /// set parameters for an initial lock of this inset
209         void lockInset(BufferView *);
210         /// lock an inset inside this one
211         void lockInset(BufferView *, UpdatableInset *);
212
213 private:
214         ///
215         void lfunMousePress(FuncRequest const &);
216         ///
217         bool lfunMouseRelease(FuncRequest const &);
218         ///
219         void lfunMouseMotion(FuncRequest const &);
220
221         ///
222         RESULT moveRight(BufferView *);
223         ///
224         RESULT moveLeft(BufferView *);
225         ///
226         RESULT moveRightIntern(BufferView *, bool front,
227                                                bool activate_inset = true,
228                                                bool selecting = false);
229         ///
230         RESULT moveLeftIntern(BufferView *, bool front,
231                                               bool activate_inset = true,
232                                               bool selecting = false);
233
234         ///
235         RESULT moveUp(BufferView *);
236         ///
237         RESULT moveDown(BufferView *);
238         ///
239         void setCharFont(Buffer const &, int pos, LyXFont const & font);
240         ///
241         bool checkAndActivateInset(BufferView * bv, bool front);
242         ///
243         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
244                                    mouse_button::state button = mouse_button::none);
245         ///
246         void removeNewlines();
247         ///
248         int cx() const;
249         ///
250         int cy() const;
251         ///
252         lyx::pos_type cpos() const;
253         ///
254         ParagraphList::iterator cpar() const;
255         ///
256         bool cboundary() const;
257         ///
258         RowList::iterator crow() const;
259         ///
260         void drawFrame(Painter &, int x) const;
261         ///
262         void clearInset(BufferView *, int start_x, int baseline) const;
263         ///
264         void collapseParagraphs(BufferView *);
265
266         /* Private structures and variables */
267         ///
268         bool autoBreakRows_;
269         ///
270         DrawFrame drawFrame_;
271         /** We store the LColor::color value as an int to get LColor.h out
272          *  of the header file.
273          */
274         int frame_color_;
275         ///
276         mutable bool locked;
277         ///
278         mutable int top_y;
279         ///
280         ParagraphList::iterator inset_par;
281         ///
282         lyx::pos_type inset_pos;
283         ///
284         bool inset_boundary;
285         ///
286         mutable int inset_x;
287         ///
288         mutable int inset_y;
289         ///
290         bool no_selection;
291         ///
292         UpdatableInset * the_locking_inset;
293         ///
294         mutable ParagraphList::iterator old_par;
295
296         ///
297         // to remember old painted frame dimensions to clear it on the right spot!
298         ///
299         mutable bool in_insetAllowed;
300         ///
301         // these are used to check for mouse movement in Motion selection code
302         ///
303         int mouse_x;
304         int mouse_y;
305 public:
306         ///
307         mutable LyXText text_;
308         ///
309         mutable int textwidth_;
310 };
311 #endif