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