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