]> git.lyx.org Git - features.git/blob - src/insets/insettext.h
parlist-a-1.diff
[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
16 #include "updatableinset.h"
17 #include "LString.h"
18 #include "LColor.h"
19 #include "ParagraphList.h"
20 #include "RowList.h"
21
22 #include "support/types.h"
23
24 #include <boost/shared_ptr.hpp>
25
26 class Painter;
27 class BufferView;
28 class Buffer;
29 class BufferParams;
30 class LyXCursor;
31 class LyXText;
32 class Row;
33 class Paragraph;
34
35 /**
36  A text inset is like a TeX box to write full text
37  (including styles and other insets) in a given space.
38  @author: Jürgen Vigna
39  */
40 class InsetText : public UpdatableInset {
41 public:
42         ///
43         /// numbers need because of test if codeA < codeB
44         ///
45         enum UpdateCodes {
46                 ///
47                 NONE = 0,
48                 ///
49                 CURSOR = 1,
50                 ///
51                 DRAW_FRAME = 2,
52                 ///
53                 SELECTION = 4,
54                 ///
55                 CURSOR_PAR = 8,
56                 ///
57                 FULL = 16,
58                 ///
59                 INIT = 32
60         };
61         ///
62         enum DrawFrame {
63                 ///
64                 NEVER = 0,
65                 ///
66                 LOCKED,
67                 ///
68                 ALWAYS
69         };
70         ///
71         InsetText(BufferParams const &);
72         ///
73         explicit
74         InsetText(InsetText const &, bool same_id = false);
75         ///
76         ~InsetText();
77         ///
78         Inset * clone(Buffer const &, bool same_id = false) const;
79         ///
80         InsetText & operator=(InsetText const & it);
81         /// empty inset to empty par, or just mark as erased
82         void clear(bool just_mark_erased);
83         ///
84         void read(Buffer const *, LyXLex &);
85         ///
86         void write(Buffer const *, std::ostream &) const;
87         ///
88         int ascent(BufferView *, LyXFont const &) const;
89         ///
90         int descent(BufferView *, LyXFont const &) const;
91         ///
92         int width(BufferView *, LyXFont const & f) const;
93         ///
94         int textWidth(BufferView *, bool fordraw = false) const;
95         ///
96         void draw(BufferView *, LyXFont const &, int , float &) const;
97         ///
98         void update(BufferView *, bool = false);
99         ///
100         void setUpdateStatus(BufferView *, int what) const;
101         ///
102         string const editMessage() const;
103         ///
104         void edit(BufferView *, int, int, mouse_button::state);
105         ///
106         void edit(BufferView *, bool front = true);
107         ///
108         bool isTextInset() const { return true; }
109         ///
110         void insetUnlock(BufferView *);
111         ///
112         bool lockInsetInInset(BufferView *, UpdatableInset *);
113         ///
114         bool unlockInsetInInset(BufferView *,
115                                 UpdatableInset *, bool lr = false);
116         ///
117         bool updateInsetInInset(BufferView *, Inset *);
118         ///
119         RESULT localDispatch(FuncRequest const &);
120         ///
121         int latex(Buffer const *, std::ostream &,
122                   bool fragile, bool free_spc) const;
123         ///
124         int ascii(Buffer const *, std::ostream &, int linelen) const;
125         ///
126         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
127         ///
128         int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
129         ///
130         void validate(LaTeXFeatures & features) const;
131         ///
132         Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
133         ///
134         void getCursorPos(BufferView *, int & x, int & y) const;
135         ///
136         int insetInInsetY() const;
137         ///
138         void toggleInsetCursor(BufferView *);
139         ///
140         void showInsetCursor(BufferView *, bool show = true);
141         ///
142         void hideInsetCursor(BufferView *);
143         ///
144         void fitInsetCursor(BufferView *) const;
145         ///
146         bool insertInset(BufferView *, Inset *);
147         ///
148         bool insetAllowed(Inset::Code) const;
149         ///
150         UpdatableInset * getLockingInset() const;
151         ///
152         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
153         ///
154         void setFont(BufferView *, LyXFont const &,
155                      bool toggleall = false,
156                      bool selectall = false);
157         ///
158         int getMaxWidth(BufferView *, UpdatableInset const *) const;
159         ///
160         void init(InsetText const * ins = 0, bool same_id = false);
161         ///
162         void writeParagraphData(Buffer const *, std::ostream &) const;
163         ///
164         void setParagraphData(Paragraph *, bool same_id = false);
165         ///
166         void setText(string const &, LyXFont const &);
167         ///
168         void setAutoBreakRows(bool);
169         ///
170         bool getAutoBreakRows() const { return autoBreakRows; }
171         ///
172         void setDrawFrame(BufferView *, DrawFrame);
173         ///
174         void setFrameColor(BufferView *, LColor::color);
175         ///
176         LyXText * getLyXText(BufferView const *,
177                              bool const recursive = false) const;
178         ///
179         void deleteLyXText(BufferView *, bool recursive = true) const;
180         ///
181         void resizeLyXText(BufferView *, bool force = false) const;
182         ///
183         bool showInsetDialog(BufferView *) const;
184         ///
185         std::vector<string> const getLabelList() const;
186         ///
187         bool nodraw() const;
188         ///
189         int scroll(bool recursive = true) const;
190         ///
191         void scroll(BufferView * bv, float sx) const {
192                 UpdatableInset::scroll(bv, sx);
193         }
194         ///
195         void scroll(BufferView * bv, int offset) const {
196                 UpdatableInset::scroll(bv, offset);
197         }
198         ///
199         void selectAll(BufferView * bv);
200         ///
201         void clearSelection(BufferView * bv);
202         ///
203         Inset * getInsetFromID(int id) const;
204         ///
205         Paragraph * firstParagraph() const;
206         ///
207         Paragraph * getFirstParagraph(int) const;
208         ///
209         LyXCursor const & cursor(BufferView *) const;
210         ///
211         void paragraph(Paragraph *);
212         ///
213         bool allowSpellcheck() const { return true; }
214         ///
215         WordLangTuple const
216         selectNextWordToSpellcheck(BufferView *, float & value) const;
217         ///
218         void selectSelectedWord(BufferView *);
219         ///
220         void toggleSelection(BufferView *, bool kill_selection);
221
222         /// mark as erased for change tracking
223         void markErased() { clear(true); };
224         /**
225          * Mark as new. Used when pasting in tabular, and adding rows
226          * or columns. Note that pasting will ensure that tracking already
227          * happens, and this just resets the changes for the copied text,
228          * whereas for row/col add, we need to start tracking changes
229          * for the (empty) paragraph contained.
230          */
231         void markNew(bool track_changes = false);
232         /// find next change
233         bool nextChange(BufferView *, lyx::pos_type & length);
234
235         ///
236         bool searchForward(BufferView *, string const &,
237                            bool = true, bool = false);
238         ///
239         bool searchBackward(BufferView *, string const &,
240                             bool = true, bool = false);
241         ///
242         bool checkInsertChar(LyXFont &);
243         ///
244         void getDrawFont(LyXFont &) const;
245         /// append text onto the existing text
246         void appendParagraphs(Buffer * bp, Paragraph *);
247
248         ///
249         void addPreview(grfx::PreviewLoader &) const;
250
251         //
252         // Public structures and variables
253         ///
254         mutable int need_update;
255
256         ///
257         ParagraphList paragraphs;
258 protected:
259         ///
260         void updateLocal(BufferView *, int what, bool mark_dirty);
261         /// set parameters for an initial lock of this inset
262         void lockInset(BufferView *);
263         /// lock an inset inside this one
264         void lockInset(BufferView *, UpdatableInset *);
265         ///
266         mutable int drawTextXOffset;
267         ///
268         mutable int drawTextYOffset;
269         ///
270         bool autoBreakRows;
271         ///
272         DrawFrame drawFrame_;
273         ///
274         LColor::color frame_color;
275
276 private:
277         ///
278         void lfunMousePress(FuncRequest const &);
279         ///
280         bool lfunMouseRelease(FuncRequest const &);
281         ///
282         void lfunMouseMotion(FuncRequest const &);
283
284         ///
285         struct InnerCache {
286                 ///
287                 InnerCache(boost::shared_ptr<LyXText>);
288                 ///
289                 boost::shared_ptr<LyXText> text;
290                 ///
291                 bool remove;
292         };
293         ///
294         typedef std::map<BufferView *, InnerCache> Cache;
295         ///
296         typedef Cache::value_type value_type;
297         ///
298         RESULT moveRight(BufferView *,
299                                          bool activate_inset = true,
300                                          bool selecting = false);
301         ///
302         RESULT moveLeft(BufferView *,
303                                         bool activate_inset = true,
304                                         bool selecting = false);
305         ///
306         RESULT moveRightIntern(BufferView *, bool front,
307                                                bool activate_inset = true,
308                                                bool selecting = false);
309         ///
310         RESULT moveLeftIntern(BufferView *, bool front,
311                                               bool activate_inset = true,
312                                               bool selecting = false);
313
314         ///
315         RESULT moveUp(BufferView *);
316         ///
317         RESULT moveDown(BufferView *);
318         ///
319         void setCharFont(Buffer const *, int pos, LyXFont const & font);
320         ///
321         bool checkAndActivateInset(BufferView * bv, bool front);
322         ///
323         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
324                                    mouse_button::state button = mouse_button::none);
325         ///
326         void removeNewlines();
327         ///
328         int cx(BufferView *) const;
329         ///
330         int cix(BufferView *) const;
331         ///
332         int cy(BufferView *) const;
333         ///
334         int ciy(BufferView *) const;
335         ///
336         lyx::pos_type cpos(BufferView *) const;
337         ///
338         Paragraph * cpar(BufferView *) const;
339         ///
340         bool cboundary(BufferView *) const;
341         ///
342         RowList::iterator crow(BufferView *) const;
343         ///
344         void drawFrame(Painter &, int x) const;
345         ///
346         void clearInset(BufferView *, int start_x, int baseline) const;
347         ///
348         void saveLyXTextState(LyXText *) const;
349         ///
350         void restoreLyXTextState(LyXText *) const;
351         ///
352         void reinitLyXText() const;
353         ///
354         void collapseParagraphs(BufferView *);
355
356         /* Private structures and variables */
357         ///
358         mutable bool locked;
359         ///
360         mutable int insetAscent;
361         ///
362         mutable int insetDescent;
363         ///
364         mutable int insetWidth;
365         ///
366         mutable int top_y;
367         ///
368         Paragraph * inset_par;
369         ///
370         lyx::pos_type inset_pos;
371         ///
372         bool inset_boundary;
373         ///
374         mutable int inset_x;
375         ///
376         mutable int inset_y;
377         ///
378         mutable int old_max_width;
379         ///
380         bool no_selection;
381         ///
382         UpdatableInset * the_locking_inset;
383         ///
384         mutable Paragraph * old_par;
385         /// The cache.
386         mutable Cache cache;
387         ///
388         mutable int last_drawn_width;
389         ///
390         mutable BufferView * cached_bview;
391         ///
392         mutable boost::shared_ptr<LyXText> cached_text;
393         ///
394         struct save_state {
395                 Paragraph * lpar;
396                 Paragraph * selstartpar;
397                 Paragraph * selendpar;
398                 lyx::pos_type pos;
399                 lyx::pos_type selstartpos;
400                 lyx::pos_type selendpos;
401                 bool boundary;
402                 bool selstartboundary;
403                 bool selendboundary;
404                 bool selection;
405                 bool mark_set;
406         };
407         ///
408         mutable save_state sstate;
409
410         ///
411         // this is needed globally so we know that we're using it actually and
412         // so the LyXText-Cache is not erased until used!
413         mutable LyXText * lt;
414         ///
415         // to remember old painted frame dimensions to clear it on the right spot!
416         ///
417         mutable int frame_x;
418         mutable int frame_y;
419         mutable int frame_w;
420         mutable int frame_h;
421         ///
422         bool in_update; /* as update is not reentrant! */
423         mutable BufferView * do_resize;
424         mutable bool do_reinit;
425         mutable bool in_insetAllowed;
426         ///
427         // these are used to check for mouse movement in Motion selection code
428         ///
429         int mouse_x;
430         int mouse_y;
431 };
432 #endif