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