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