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