]> git.lyx.org Git - features.git/blob - src/insets/insettext.h
simpler InsetText:: local updating
[features.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         bool updateInsetInInset(BufferView *, InsetOld *);
88         ///
89         RESULT localDispatch(FuncRequest const &);
90         ///
91         int latex(Buffer const *, std::ostream &,
92                   LatexRunParams const &) const;
93         ///
94         int ascii(Buffer const *, std::ostream &, int linelen) const;
95         ///
96         int linuxdoc(Buffer const *, std::ostream &) const ;
97         ///
98         int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
99         ///
100         void validate(LaTeXFeatures & features) const;
101         ///
102         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
103         /// FIXME, document
104         void getCursorPos(BufferView *, int & x, int & y) const;
105         /// Get the absolute document x,y of the cursor
106         virtual void getCursor(BufferView &, int &, int &) const;
107         ///
108         int insetInInsetY() const;
109         ///
110         void fitInsetCursor(BufferView *) const;
111         ///
112         bool insertInset(BufferView *, InsetOld *);
113         ///
114         bool insetAllowed(InsetOld::Code) const;
115         ///
116         UpdatableInset * getLockingInset() const;
117         ///
118         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
119         ///
120         void setFont(BufferView *, LyXFont const &,
121                      bool toggleall = false,
122                      bool selectall = false);
123         ///
124         void init(InsetText const * ins);
125         ///
126         void writeParagraphData(Buffer const *, std::ostream &) const;
127         ///
128         void setParagraphData(ParagraphList const &);
129         ///
130         void setText(string const &, LyXFont const &);
131         ///
132         void setAutoBreakRows(bool);
133         ///
134         bool getAutoBreakRows() const { return autoBreakRows; }
135         ///
136         void setDrawFrame(BufferView *, DrawFrame);
137         ///
138         void setFrameColor(BufferView *, LColor::color);
139         ///
140         LyXText * getLyXText(BufferView const *,
141                              bool const recursive = false) const;
142         ///
143         void setViewCache(BufferView const * bv) const;
144         ///
145         void deleteLyXText(BufferView *, bool recursive = true) const;
146         ///
147         void resizeLyXText(BufferView *, bool force = false) const;
148         ///
149         bool showInsetDialog(BufferView *) const;
150         ///
151         void getLabelList(std::vector<string> &) const;
152         ///
153         int scroll(bool recursive = true) const;
154         ///
155         void scroll(BufferView * bv, float sx) const {
156                 UpdatableInset::scroll(bv, sx);
157         }
158         ///
159         void scroll(BufferView * bv, int offset) const {
160                 UpdatableInset::scroll(bv, offset);
161         }
162         ///
163         void clearSelection(BufferView * bv);
164         ///
165         InsetOld * getInsetFromID(int id) const;
166         ///
167         ParagraphList * getParagraphs(int) const;
168         ///
169         LyXCursor const & cursor(BufferView *) const;
170         ///
171         bool allowSpellcheck() const { return true; }
172         ///
173         WordLangTuple const
174         selectNextWordToSpellcheck(BufferView *, float & value) const;
175         ///
176         void selectSelectedWord(BufferView *);
177
178         /// mark as erased for change tracking
179         void markErased() { clear(true); };
180         /**
181          * Mark as new. Used when pasting in tabular, and adding rows
182          * or columns. Note that pasting will ensure that tracking already
183          * happens, and this just resets the changes for the copied text,
184          * whereas for row/col add, we need to start tracking changes
185          * for the (empty) paragraph contained.
186          */
187         void markNew(bool track_changes = false);
188         /// find next change
189         bool nextChange(BufferView *, lyx::pos_type & length);
190
191         ///
192         bool searchForward(BufferView *, string const &,
193                            bool = true, bool = false);
194         ///
195         bool searchBackward(BufferView *, string const &,
196                             bool = true, bool = false);
197         ///
198         bool checkInsertChar(LyXFont &);
199         ///
200         void getDrawFont(LyXFont &) const;
201         /// append text onto the existing text
202         void appendParagraphs(Buffer * bp, ParagraphList &);
203
204         ///
205         void addPreview(lyx::graphics::PreviewLoader &) const;
206
207         ///
208         bool haveParagraphs() const {
209                 return true;
210         }
211         ///
212         ParagraphList paragraphs;
213 protected:
214         ///
215         void updateLocal(BufferView *, bool mark_dirty);
216         /// set parameters for an initial lock of this inset
217         void lockInset(BufferView *);
218         /// lock an inset inside this one
219         void lockInset(BufferView *, UpdatableInset *);
220         ///
221         mutable int drawTextXOffset;
222         ///
223         mutable int drawTextYOffset;
224         ///
225         bool autoBreakRows;
226         ///
227         DrawFrame drawFrame_;
228         ///
229         LColor::color frame_color;
230
231 private:
232         ///
233         void lfunMousePress(FuncRequest const &);
234         ///
235         bool lfunMouseRelease(FuncRequest const &);
236         ///
237         void lfunMouseMotion(FuncRequest const &);
238
239         ///
240         RESULT moveRight(BufferView *,
241                                          bool activate_inset = true,
242                                          bool selecting = false);
243         ///
244         RESULT moveLeft(BufferView *,
245                                         bool activate_inset = true,
246                                         bool selecting = false);
247         ///
248         RESULT moveRightIntern(BufferView *, bool front,
249                                                bool activate_inset = true,
250                                                bool selecting = false);
251         ///
252         RESULT moveLeftIntern(BufferView *, bool front,
253                                               bool activate_inset = true,
254                                               bool selecting = false);
255
256         ///
257         RESULT moveUp(BufferView *);
258         ///
259         RESULT moveDown(BufferView *);
260         ///
261         void setCharFont(Buffer const *, int pos, LyXFont const & font);
262         ///
263         bool checkAndActivateInset(BufferView * bv, bool front);
264         ///
265         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
266                                    mouse_button::state button = mouse_button::none);
267         ///
268         void removeNewlines();
269         ///
270         int cx() const;
271         ///
272         int cix() const;
273         ///
274         int cy() const;
275         ///
276         int ciy() const;
277         ///
278         lyx::pos_type cpos() const;
279         ///
280         ParagraphList::iterator cpar() const;
281         ///
282         bool cboundary() const;
283         ///
284         RowList::iterator crow() const;
285         ///
286         void drawFrame(Painter &, int x) const;
287         ///
288         void clearInset(BufferView *, int start_x, int baseline) const;
289         ///
290         void saveLyXTextState() const;
291         ///
292         void restoreLyXTextState() const;
293         ///
294         void collapseParagraphs(BufferView *);
295
296         /* Private structures and variables */
297         ///
298         mutable bool locked;
299         ///
300         mutable int top_y;
301         ///
302         ParagraphList::iterator inset_par;
303         ///
304         lyx::pos_type inset_pos;
305         ///
306         bool inset_boundary;
307         ///
308         mutable int inset_x;
309         ///
310         mutable int inset_y;
311         ///
312         bool no_selection;
313         ///
314         UpdatableInset * the_locking_inset;
315         ///
316         mutable ParagraphList::iterator old_par;
317         ///
318         mutable int last_drawn_width;
319
320         /// some funny 'temporarily saved state'
321         mutable TextCursor sstate;
322
323         ///
324         // to remember old painted frame dimensions to clear it on the right spot!
325         ///
326         mutable int frame_x;
327         mutable int frame_y;
328         mutable int frame_w;
329         mutable int frame_h;
330         mutable bool in_insetAllowed;
331         ///
332         // these are used to check for mouse movement in Motion selection code
333         ///
334         int mouse_x;
335         int mouse_y;
336 public:
337         ///
338         void reinitLyXText() const;
339         ///
340         mutable LyXText text_;
341         ///
342         mutable int textwidth_;
343 };
344 #endif