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