]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
fix typo that put too many include paths for most people
[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 "paragraph.h"
26 #include "lyxcursor.h"
27
28 #include <boost/smart_ptr.hpp>
29
30 class Painter;
31 class BufferView;
32 class Buffer;
33 class BufferParams;
34 class LyXCursor;
35 class LyXText;
36 class LyXScreen;
37 class Row;
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                 CLEAR_FRAME = 2,
56                 ///
57                 DRAW_FRAME = 4,
58                 ///
59                 SELECTION = 8,
60                 ///
61                 CURSOR_PAR = 16,
62                 ///
63                 FULL = 32,
64                 ///
65                 INIT = 64
66         };
67         ///
68         enum DrawFrame {
69                 ///
70                 NEVER = 0,
71                 ///
72                 LOCKED,
73                 ///
74                 ALWAYS
75         };
76         ///
77         InsetText(BufferParams const &);
78         ///
79         explicit
80         InsetText(InsetText const &, bool same_id = false);
81         ///
82         ~InsetText();
83         ///
84         Inset * clone(Buffer const &, bool same_id = false) const;
85         ///
86         InsetText & operator=(InsetText const & it);
87         ///
88         void clear();
89         ///
90         void read(Buffer const *, LyXLex &);
91         ///
92         void write(Buffer const *, std::ostream &) const;
93         ///
94         int ascent(BufferView *, LyXFont const &) const;
95         ///
96         int descent(BufferView *, LyXFont const &) const;
97         ///
98         int width(BufferView *, LyXFont const & f) const;
99         ///
100         int textWidth(BufferView *, bool fordraw = false) const;
101         ///
102         void draw(BufferView *, LyXFont const &, int , float &, bool) const;
103         ///
104         void update(BufferView *, LyXFont const &, bool = false);
105         ///
106         void setUpdateStatus(BufferView *, int what) const;
107         ///
108         string const editMessage() const;
109         ///
110         void edit(BufferView *, int, int, unsigned int);
111         ///
112         void edit(BufferView *, bool front = true);
113         ///
114         bool isTextInset() const { return true; }
115         ///
116         bool doClearArea() const;
117         ///
118         void insetUnlock(BufferView *);
119         ///
120         bool lockInsetInInset(BufferView *, UpdatableInset *);
121         ///
122         bool unlockInsetInInset(BufferView *,
123                                 UpdatableInset *, bool lr = false);
124         ///
125         bool updateInsetInInset(BufferView *, Inset *);
126         ///
127         bool insetButtonRelease(BufferView *, int, int, int);
128         ///
129         void insetButtonPress(BufferView *, int, int, int);
130         ///
131         void insetMotionNotify(BufferView *, int, int, int);
132         ///
133         void insetKeyPress(XKeyEvent *);
134         ///
135         UpdatableInset::RESULT localDispatch(BufferView *,
136                                              kb_action, string const &);
137         ///
138         int latex(Buffer const *, std::ostream &,
139                   bool fragile, bool free_spc) const;
140         ///
141         int ascii(Buffer const *, std::ostream &, int linelen) const;
142         ///
143         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
144         ///
145         int docbook(Buffer const *, std::ostream &) const ;
146         ///
147         void validate(LaTeXFeatures & features) const;
148         ///
149         Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
150         ///
151         void getCursorPos(BufferView *, int & x, int & y) const;
152         ///
153         unsigned int insetInInsetY();
154         ///
155         void toggleInsetCursor(BufferView *);
156         ///
157         void showInsetCursor(BufferView *, bool show = true);
158         ///
159         void hideInsetCursor(BufferView *);
160         ///
161         void fitInsetCursor(BufferView *) const;
162         ///
163         bool insertInset(BufferView *, Inset *);
164         ///
165         bool insetAllowed(Inset::Code) const;
166         ///
167         UpdatableInset * getLockingInset() const;
168         ///
169         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
170         ///
171         void setFont(BufferView *, LyXFont const &,
172                      bool toggleall = false,
173                      bool selectall = false);
174         ///
175         int getMaxWidth(BufferView *, UpdatableInset const *) const;
176         ///
177         void init(InsetText const * ins = 0, bool same_id = false);
178         ///
179         void writeParagraphData(Buffer const *, std::ostream &) const;
180         ///
181         void setParagraphData(Paragraph *, bool same_id = false);
182         ///
183         void setText(string const &, LyXFont const &);
184         ///
185         void setAutoBreakRows(bool);
186         ///
187         bool getAutoBreakRows() const { return autoBreakRows; }
188         ///
189         void setDrawFrame(BufferView *, DrawFrame);
190         ///
191         void setFrameColor(BufferView *, LColor::color);
192         ///
193         LyXText * getLyXText(BufferView const *,
194                              bool const recursive = false) const;
195         ///
196         void deleteLyXText(BufferView *, bool recursive = true) const;
197         ///
198         void resizeLyXText(BufferView *, bool force = false) const;
199         ///
200         bool showInsetDialog(BufferView *) const;
201         ///
202         std::vector<string> const getLabelList() const;
203         ///
204         bool nodraw() const;
205         ///
206         int scroll(bool recursive = true) const;
207         ///
208         void scroll(BufferView * bv, float sx) const {
209                 UpdatableInset::scroll(bv, sx);
210         }
211         ///
212         void scroll(BufferView * bv, int offset) const {
213                 UpdatableInset::scroll(bv, offset);
214         }
215         ///
216         void selectAll(BufferView * bv);
217         ///
218         void clearSelection(BufferView * bv);
219         ///
220         Paragraph * getParFromID(int id) const;
221         ///
222         Inset * getInsetFromID(int id) const;
223         ///
224         Paragraph * firstParagraph() const;
225         ///
226         Paragraph * getFirstParagraph(int) const;
227         ///
228         LyXCursor const & cursor(BufferView *) const;
229         ///
230         Paragraph * paragraph() const;
231         ///
232         void paragraph(Paragraph *);
233         ///
234         bool allowSpellcheck() { return true; }
235         ///
236         string const selectNextWordToSpellcheck(BufferView *,
237                                                 float & value) const;
238         void selectSelectedWord(BufferView *);
239         ///
240         void toggleSelection(BufferView *, bool kill_selection);
241         ///
242         bool searchForward(BufferView *, string const &,
243                            bool = true, bool = false);
244         ///
245         bool searchBackward(BufferView *, string const &,
246                             bool = true, bool = false);
247         ///
248         bool checkInsertChar(LyXFont &);
249         ///
250         void getDrawFont(LyXFont &) const;
251         ///
252         void appendParagraphs(BufferParams const & bparams, Paragraph *);
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         ///
263         void lockInset(BufferView *, UpdatableInset *);
264         ///
265         mutable int drawTextXOffset;
266         ///
267         mutable int drawTextYOffset;
268         ///
269         bool autoBreakRows;
270         ///
271         DrawFrame drawFrame_;
272         ///
273         LColor::color frame_color;
274
275 private:
276         ///
277         struct InnerCache {
278                 ///
279                 InnerCache(boost::shared_ptr<LyXText>);
280                 ///
281                 boost::shared_ptr<LyXText> text;
282                 ///
283                 bool remove;
284         };
285         ///
286         typedef std::map<BufferView *, InnerCache> Cache;
287         ///
288         typedef Cache::value_type value_type;
289         ///
290         int beginningOfMainBody(Buffer const *, Paragraph * par) const;
291         ///
292         UpdatableInset::RESULT moveRight(BufferView *,
293                                          bool activate_inset = true,
294                                          bool selecting = false);
295         ///
296         UpdatableInset::RESULT moveLeft(BufferView *,
297                                         bool activate_inset = true,
298                                         bool selecting = false);
299         ///
300         UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
301                                                bool activate_inset = true,
302                                                bool selecting = false);
303         ///
304         UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
305                                               bool activate_inset = true,
306                                               bool selecting = false);
307
308         ///
309         UpdatableInset::RESULT moveUp(BufferView *);
310         ///
311         UpdatableInset::RESULT moveDown(BufferView *);
312         ///
313         void setCharFont(Buffer const *, int pos, LyXFont const & font);
314         ///
315         bool checkAndActivateInset(BufferView * bv, bool behind);
316         ///
317         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
318                                    int button = 0);
319         ///
320         void removeNewlines();
321         ///
322         int cx(BufferView *) const;
323         ///
324         int cy(BufferView *) const;
325         ///
326         lyx::pos_type cpos(BufferView *) const;
327         ///
328         Paragraph * cpar(BufferView *) const;
329         ///
330         bool cboundary(BufferView *) const;
331         ///
332         Row * crow(BufferView *) const;
333         ///
334         void drawFrame(Painter &, bool cleared) const;
335         ///
336         void clearFrame(Painter &, bool cleared) const;
337         ///
338         void clearInset(BufferView *, int baseline, bool & cleared) const;
339         ///
340         void saveLyXTextState(LyXText *) const;
341         ///
342         void restoreLyXTextState(BufferView *, LyXText *) const;
343         ///
344         void reinitLyXText() const;
345         ///
346         void collapseParagraphs(BufferParams const & bparams) const;
347
348         /* Private structures and variables */
349         ///
350         Paragraph * par;
351         ///
352         mutable bool locked;
353         ///
354         mutable int insetAscent;
355         ///
356         mutable int insetDescent;
357         ///
358         mutable int insetWidth;
359         ///
360         mutable int top_y;
361         ///
362         Paragraph * inset_par;
363         ///
364         lyx::pos_type inset_pos;
365         ///
366         bool inset_boundary;
367         ///
368         mutable int inset_x;
369         ///
370         mutable int inset_y;
371         ///
372         mutable int old_max_width;
373         ///
374         bool no_selection;
375         ///
376         mutable float xpos;
377         ///
378         UpdatableInset * the_locking_inset;
379         ///
380         mutable Paragraph * old_par;
381         /// The cache.
382         mutable Cache cache;
383         ///
384         mutable int last_drawn_width;
385         ///
386         mutable bool frame_is_visible;
387         ///
388         mutable BufferView * cached_bview;
389         ///
390         mutable boost::shared_ptr<LyXText> cached_text;
391         ///
392         struct save_state {
393                 Paragraph * lpar;
394                 Paragraph * selstartpar;
395                 Paragraph * selendpar;
396                 lyx::pos_type pos;
397                 lyx::pos_type selstartpos;
398                 lyx::pos_type selendpos;
399                 bool boundary;
400                 bool selstartboundary;
401                 bool selendboundary;
402                 bool selection;
403                 bool mark_set;
404                 bool refresh;
405         };
406         ///
407         mutable save_state sstate;
408
409         ///
410         // this is needed globally so we know that we're using it actually and
411         // so the LyXText-Cache is not erased until used!
412         mutable LyXText * lt;
413         ///
414         // to remember old painted frame dimensions to clear it on the right spot!
415         ///
416         mutable int frame_x;
417         mutable int frame_y;
418         mutable int frame_w;
419         mutable int frame_h;
420         ///
421         bool in_update; /* as update is not reentrant! */
422         mutable BufferView * do_resize;
423         mutable bool do_reinit;
424         mutable bool in_insetAllowed;
425         ///
426         // these are used to check for mouse movement in Motion selection code
427         ///
428         int mouse_x;
429         int mouse_y;
430 };
431 #endif