]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
e5adc0a13589ecabbd69538c0e13d92d4d0df9a4
[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 "textcursor.h"
17 #include "LString.h"
18 #include "LColor.h"
19 #include "ParagraphList.h"
20 #include "RowList.h"
21 #include "dimension.h"
22 #include "lyxtext.h"
23
24 #include "support/types.h"
25
26 #include "frontends/mouse_state.h"
27
28 #include <boost/shared_ptr.hpp>
29
30 class Painter;
31 class BufferView;
32 class Buffer;
33 class BufferParams;
34 class LyXCursor;
35 class LyXText;
36 class Row;
37 class Paragraph;
38
39 /**
40  A text inset is like a TeX box to write full text
41  (including styles and other insets) in a given space.
42  @author: Jürgen Vigna
43  */
44 class InsetText : public UpdatableInset {
45 public:
46         ///
47         enum DrawFrame {
48                 ///
49                 NEVER = 0,
50                 ///
51                 LOCKED,
52                 ///
53                 ALWAYS
54         };
55         ///
56         InsetText(BufferParams const &);
57         ///
58         explicit InsetText(InsetText const &);
59         ///
60         virtual std::auto_ptr<InsetBase> clone() const;
61         ///
62         InsetText & operator=(InsetText const & it);
63         /// empty inset to empty par, or just mark as erased
64         void clear(bool just_mark_erased);
65         ///
66         void read(Buffer const *, LyXLex &);
67         ///
68         void write(Buffer const *, std::ostream &) const;
69         ///
70         void metrics(MetricsInfo &, Dimension &) const;
71         ///
72         int textWidth() const;
73         ///
74         void draw(PainterInfo & pi, int x, int y) const;
75         ///
76         string const editMessage() const;
77         ///
78         bool isTextInset() const { return true; }
79         ///
80         void insetUnlock(BufferView *);
81         ///
82         bool lockInsetInInset(BufferView *, UpdatableInset *);
83         ///
84         bool unlockInsetInInset(BufferView *,
85                                 UpdatableInset *, bool lr = false);
86         ///
87         RESULT localDispatch(FuncRequest const &);
88         ///
89         int latex(Buffer const *, std::ostream &,
90                   LatexRunParams const &) const;
91         ///
92         int ascii(Buffer const *, std::ostream &, int linelen) const;
93         ///
94         int linuxdoc(Buffer const *, std::ostream &) const ;
95         ///
96         int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
97         ///
98         void validate(LaTeXFeatures & features) const;
99         ///
100         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
101         /// FIXME, document
102         void getCursorPos(BufferView *, int & x, int & y) const;
103         /// Get the absolute document x,y of the cursor
104         virtual void getCursor(BufferView &, int &, int &) const;
105         ///
106         int insetInInsetY() const;
107         ///
108         void fitInsetCursor(BufferView *) const;
109         ///
110         bool insertInset(BufferView *, InsetOld *);
111         ///
112         bool insetAllowed(InsetOld::Code) const;
113         ///
114         UpdatableInset * getLockingInset() const;
115         ///
116         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
117         ///
118         void setFont(BufferView *, LyXFont const &,
119                      bool toggleall = false,
120                      bool selectall = false);
121         ///
122         void init(InsetText const * ins);
123         ///
124         void writeParagraphData(Buffer const *, std::ostream &) const;
125         ///
126         void setParagraphData(ParagraphList const &);
127         ///
128         void setText(string const &, LyXFont const &);
129         ///
130         void setAutoBreakRows(bool);
131         ///
132         bool getAutoBreakRows() const { return autoBreakRows; }
133         ///
134         void setDrawFrame(BufferView *, DrawFrame);
135         ///
136         void setFrameColor(BufferView *, LColor::color);
137         ///
138         LyXText * getLyXText(BufferView const *,
139                              bool const recursive = false) const;
140         ///
141         void setViewCache(BufferView const * bv) const;
142         ///
143         void deleteLyXText(BufferView *, bool recursive = true) const;
144         ///
145         void resizeLyXText(BufferView *, bool force = false) const;
146         ///
147         bool showInsetDialog(BufferView *) const;
148         ///
149         void getLabelList(std::vector<string> &) const;
150         ///
151         int scroll(bool recursive = true) const;
152         ///
153         void scroll(BufferView * bv, float sx) const {
154                 UpdatableInset::scroll(bv, sx);
155         }
156         ///
157         void scroll(BufferView * bv, int offset) const {
158                 UpdatableInset::scroll(bv, offset);
159         }
160         ///
161         void clearSelection(BufferView * bv);
162         ///
163         InsetOld * getInsetFromID(int id) const;
164         ///
165         ParagraphList * getParagraphs(int) const;
166         ///
167         LyXCursor const & cursor(BufferView *) const;
168         ///
169         bool allowSpellcheck() const { return true; }
170         ///
171         WordLangTuple const
172         selectNextWordToSpellcheck(BufferView *, float & value) const;
173         ///
174         void selectSelectedWord(BufferView *);
175
176         /// mark as erased for change tracking
177         void markErased() { clear(true); };
178         /**
179          * Mark as new. Used when pasting in tabular, and adding rows
180          * or columns. Note that pasting will ensure that tracking already
181          * happens, and this just resets the changes for the copied text,
182          * whereas for row/col add, we need to start tracking changes
183          * for the (empty) paragraph contained.
184          */
185         void markNew(bool track_changes = false);
186         /// find next change
187         bool nextChange(BufferView *, lyx::pos_type & length);
188
189         ///
190         bool searchForward(BufferView *, string const &,
191                            bool = true, bool = false);
192         ///
193         bool searchBackward(BufferView *, string const &,
194                             bool = true, bool = false);
195         ///
196         bool checkInsertChar(LyXFont &);
197         ///
198         void getDrawFont(LyXFont &) const;
199         /// append text onto the existing text
200         void appendParagraphs(Buffer * bp, ParagraphList &);
201
202         ///
203         void addPreview(lyx::graphics::PreviewLoader &) const;
204
205         ///
206         bool haveParagraphs() const {
207                 return true;
208         }
209         ///
210         ParagraphList paragraphs;
211 protected:
212         ///
213         void updateLocal(BufferView *, bool mark_dirty);
214         /// set parameters for an initial lock of this inset
215         void lockInset(BufferView *);
216         /// lock an inset inside this one
217         void lockInset(BufferView *, UpdatableInset *);
218         ///
219         mutable int drawTextXOffset;
220         ///
221         mutable int drawTextYOffset;
222         ///
223         bool autoBreakRows;
224         ///
225         DrawFrame drawFrame_;
226         ///
227         LColor::color frame_color;
228
229 private:
230         ///
231         void lfunMousePress(FuncRequest const &);
232         ///
233         bool lfunMouseRelease(FuncRequest const &);
234         ///
235         void lfunMouseMotion(FuncRequest const &);
236
237         ///
238         RESULT moveRight(BufferView *,
239                                          bool activate_inset = true,
240                                          bool selecting = false);
241         ///
242         RESULT moveLeft(BufferView *,
243                                         bool activate_inset = true,
244                                         bool selecting = false);
245         ///
246         RESULT moveRightIntern(BufferView *, bool front,
247                                                bool activate_inset = true,
248                                                bool selecting = false);
249         ///
250         RESULT moveLeftIntern(BufferView *, bool front,
251                                               bool activate_inset = true,
252                                               bool selecting = false);
253
254         ///
255         RESULT moveUp(BufferView *);
256         ///
257         RESULT moveDown(BufferView *);
258         ///
259         void setCharFont(Buffer const *, int pos, LyXFont const & font);
260         ///
261         bool checkAndActivateInset(BufferView * bv, bool front);
262         ///
263         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
264                                    mouse_button::state button = mouse_button::none);
265         ///
266         void removeNewlines();
267         ///
268         int cx() const;
269         ///
270         int cix() const;
271         ///
272         int cy() const;
273         ///
274         int ciy() const;
275         ///
276         lyx::pos_type cpos() const;
277         ///
278         ParagraphList::iterator cpar() const;
279         ///
280         bool cboundary() const;
281         ///
282         RowList::iterator crow() const;
283         ///
284         void drawFrame(Painter &, int x) const;
285         ///
286         void clearInset(BufferView *, int start_x, int baseline) const;
287         ///
288         void saveLyXTextState() const;
289         ///
290         void restoreLyXTextState() const;
291         ///
292         void collapseParagraphs(BufferView *);
293
294         /* Private structures and variables */
295         ///
296         mutable bool locked;
297         ///
298         mutable int top_y;
299         ///
300         ParagraphList::iterator inset_par;
301         ///
302         lyx::pos_type inset_pos;
303         ///
304         bool inset_boundary;
305         ///
306         mutable int inset_x;
307         ///
308         mutable int inset_y;
309         ///
310         bool no_selection;
311         ///
312         UpdatableInset * the_locking_inset;
313         ///
314         mutable ParagraphList::iterator old_par;
315         ///
316         mutable int last_drawn_width;
317
318         /// some funny 'temporarily saved state'
319         mutable TextCursor sstate;
320
321         ///
322         // to remember old painted frame dimensions to clear it on the right spot!
323         ///
324         mutable int frame_x;
325         mutable int frame_y;
326         mutable int frame_w;
327         mutable int frame_h;
328         mutable bool in_insetAllowed;
329         ///
330         // these are used to check for mouse movement in Motion selection code
331         ///
332         int mouse_x;
333         int mouse_y;
334 public:
335         ///
336         void reinitLyXText() const;
337         ///
338         mutable LyXText text_;
339         ///
340         mutable int textwidth_;
341 };
342 #endif