]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
a11eee25152a54eec7a846691f45e5d93fafe4d3
[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 "lyxcursor.h"
25
26 class Painter;
27 class BufferView;
28 class Buffer;
29 class LyXCursor;
30 class Paragraph;
31 class LColor;
32 class LyXText;
33 class LyXScreen;
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                 CLEAR_FRAME = 2,
52                 ///
53                 DRAW_FRAME = 4,
54                 ///
55                 SELECTION = 8,
56                 ///
57                 CURSOR_PAR = 16,
58                 ///
59                 FULL = 32,
60                 ///
61                 INIT = 64
62         };
63         ///
64         enum DrawFrame {
65                 ///
66                 NEVER = 0,
67                 ///
68                 LOCKED,
69                 ///
70                 ALWAYS
71         };
72         ///
73         InsetText();
74         ///
75         explicit
76         InsetText(InsetText const &);
77         ///
78         ~InsetText();
79         ///
80         Inset * clone(Buffer const &) const;
81         ///
82         InsetText & operator=(InsetText const & it);
83         ///
84         void clear();
85         ///
86         void read(Buffer const *, LyXLex &);
87         ///
88         void write(Buffer const *, std::ostream &) const;
89         ///
90         int ascent(BufferView *, LyXFont const &) const;
91         ///
92         int descent(BufferView *, LyXFont const &) const;
93         ///
94         int width(BufferView *, LyXFont const & f) const;
95         ///
96         int textWidth(BufferView *) const;
97         ///
98         void draw(BufferView *, LyXFont const &, int , float &, bool) const;
99         ///
100         void update(BufferView *, LyXFont const &, bool =false);
101         ///
102         void setUpdateStatus(BufferView *, int what) const;
103         ///
104         string const editMessage() const;
105         ///
106         void edit(BufferView *, int, int, unsigned int);
107         ///
108         bool isTextInset() const { return true; }
109         ///
110         bool doClearArea() const;
111         ///
112         void insetUnlock(BufferView *);
113         ///
114         bool lockInsetInInset(BufferView *, UpdatableInset *);
115         ///
116         bool unlockInsetInInset(BufferView *,
117                                 UpdatableInset *, bool lr = false);
118         ///
119         bool updateInsetInInset(BufferView *, Inset *);
120         ///
121         void insetButtonRelease(BufferView *, int, int, int);
122         ///
123         void insetButtonPress(BufferView *, int, int, int);
124         ///
125         void insetMotionNotify(BufferView *, int, int, int);
126         ///
127         void insetKeyPress(XKeyEvent *);
128         ///
129         UpdatableInset::RESULT localDispatch(BufferView *,
130                                              kb_action, string const &);
131         ///
132         int latex(Buffer const *, std::ostream &,
133                   bool fragile, bool free_spc) const;
134         ///
135         int ascii(Buffer const *, std::ostream &, int linelen) const;
136         ///
137         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
138         ///
139         int docBook(Buffer const *, std::ostream &) const ;
140         ///
141         void validate(LaTeXFeatures & features) const;
142         ///
143         Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
144         ///
145         void getCursorPos(BufferView *, int & x, int & y) const;
146         ///
147         unsigned int insetInInsetY();
148         ///
149         void toggleInsetCursor(BufferView *);
150         ///
151         bool insertInset(BufferView *, Inset *);
152         ///
153         UpdatableInset * getLockingInset();
154         ///
155         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
156         ///
157         void setFont(BufferView *, LyXFont const &,
158                      bool toggleall = false,
159                      bool selectall = false);
160         ///
161         int getMaxWidth(BufferView *, UpdatableInset const *) const;
162         ///
163         void init(InsetText const * ins = 0);
164         ///
165         void writeParagraphData(Buffer const *, std::ostream &) const;
166         ///
167         void setParagraphData(Paragraph *);
168         ///
169         void setText(string const &);
170         ///
171         void setAutoBreakRows(bool);
172         ///
173         void setDrawFrame(BufferView *, DrawFrame);
174         ///
175         void setFrameColor(BufferView *, LColor::color);
176         ///
177         LyXText * getLyXText(BufferView const *,
178                              bool const recursive = false) const;
179         ///
180         void deleteLyXText(BufferView *, bool recursive = true) const;
181         ///
182         void resizeLyXText(BufferView *, bool force = false) const;
183         ///
184         bool showInsetDialog(BufferView *) const;
185         ///
186         std::vector<string> const getLabelList() const;
187         ///
188         bool nodraw() const;
189         ///
190         int scroll(bool recursive=true) const;
191         ///
192         void scroll(BufferView *bv, float sx) const {
193                 UpdatableInset::scroll(bv, sx);
194         }
195         ///
196         void scroll(BufferView *bv, int offset) const {
197                 UpdatableInset::scroll(bv, offset);
198         }
199         ///
200         void selectAll(BufferView *bv);
201         ///
202         void clearSelection(BufferView *bv);
203
204         Paragraph * par;
205         ///
206         mutable int need_update;
207
208 protected:
209         ///
210         void updateLocal(BufferView *, int what, bool mark_dirty);
211         ///
212         mutable int drawTextXOffset;
213         ///
214         mutable int drawTextYOffset;
215         ///
216         bool autoBreakRows;
217         ///
218         DrawFrame drawFrame_;
219         ///
220         LColor::color frame_color;
221
222 private:
223         ///
224         typedef std::map<BufferView *, LyXText *> Cache;
225         ///
226         typedef Cache::value_type value_type;
227         ///
228         int beginningOfMainBody(Buffer const *, Paragraph * par) const;
229         ///
230         void showInsetCursor(BufferView *, bool show=true);
231         ///
232         void hideInsetCursor(BufferView *);
233         ///
234         UpdatableInset::RESULT moveRight(BufferView *,
235                                          bool activate_inset = true,
236                                          bool selecting = false);
237         ///
238         UpdatableInset::RESULT moveLeft(BufferView *,
239                                         bool activate_inset = true,
240                                         bool selecting = false);
241         ///
242         UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
243                                                bool activate_inset = true,
244                                                bool selecting = false);
245         ///
246         UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind, 
247                                               bool activate_inset = true,
248                                               bool selecting = false);
249
250         ///
251         UpdatableInset::RESULT moveUp(BufferView *);
252         ///
253         UpdatableInset::RESULT moveDown(BufferView *);
254         ///
255         void setCharFont(Buffer const *, int pos, LyXFont const & font);
256         ///
257         string const getText(int);
258         ///
259         bool checkAndActivateInset(BufferView * bv, bool behind);
260         ///
261         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
262                                    int button = 0);
263         ///
264         void removeNewlines();
265         ///
266         int cx(BufferView *) const;
267         ///
268         int cy(BufferView *) const;
269         ///
270         Paragraph::size_type cpos(BufferView *) const;
271         ///
272         Paragraph * cpar(BufferView *) const;
273         ///
274         bool cboundary(BufferView *) const;
275         ///
276         Row * crow(BufferView *) const;
277         ///
278         void drawFrame(Painter &, bool cleared) const;
279         ///
280         void clearFrame(Painter &, bool cleared) const;
281         ///
282         void clearInset(Painter &, int baseline, bool & cleared) const;
283         
284         /* Private structures and variables */
285         ///
286         mutable bool locked;
287         ///
288         mutable int insetAscent;
289         ///
290         mutable int insetDescent;
291         ///
292         mutable int insetWidth;
293         ///
294         mutable int last_width;
295         ///
296         mutable int last_height;
297         ///
298         mutable int top_y;
299         ///
300         Paragraph * inset_par;
301         ///
302         Paragraph::size_type inset_pos;
303         ///
304         bool inset_boundary;
305         ///
306         mutable int inset_x;
307         ///
308         mutable int inset_y;
309         ///
310         mutable unsigned int old_max_width;
311         ///
312         bool no_selection;
313         ///
314         mutable float xpos;
315         ///
316         UpdatableInset * the_locking_inset;
317         ///
318         Paragraph * old_par;
319         /// The cache.
320         mutable Cache cache;
321         ///
322         mutable int last_drawn_width;
323         ///
324         mutable bool frame_is_visible;
325         ///
326         mutable BufferView * cached_bview;
327         mutable LyXText * cached_text;
328 };
329 #endif