]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
2382a35461d119d2b7e886e3b7b8ff9c191750a6
[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 *, UpdatableInset *, bool lr = false);
117         ///
118         bool UpdateInsetInInset(BufferView *, Inset *);
119         ///
120         void InsetButtonRelease(BufferView *, int, int, int);
121         ///
122         void InsetButtonPress(BufferView *, int, int, int);
123         ///
124         void InsetMotionNotify(BufferView *, int, int, int);
125         ///
126         void InsetKeyPress(XKeyEvent *);
127         ///
128         UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action, string const &);
129         ///
130         int Latex(Buffer const *, std::ostream &,
131                   bool fragile, bool free_spc) const;
132         ///
133         int Ascii(Buffer const *, std::ostream &, int linelen) const;
134         ///
135         int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
136         ///
137         int DocBook(Buffer const *, std::ostream &) const ;
138         ///
139         void Validate(LaTeXFeatures & features) const;
140         ///
141         Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
142         ///
143         void GetCursorPos(BufferView *, int & x, int & y) const;
144         ///
145         unsigned int InsetInInsetY();
146         ///
147         void ToggleInsetCursor(BufferView *);
148         ///
149         bool InsertInset(BufferView *, Inset *);
150         ///
151         UpdatableInset * GetLockingInset();
152         ///
153         UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
154         ///
155         void SetFont(BufferView *, LyXFont const &, bool toggleall = false,
156                      bool selectall = false);
157         ///
158         int getMaxWidth(BufferView *, UpdatableInset const *) const;
159         ///
160         void init(InsetText const * ins = 0);
161         ///
162         void WriteParagraphData(Buffer const *, std::ostream &) const;
163         ///
164         void SetParagraphData(Paragraph *);
165         ///
166         void SetText(string const &);
167         ///
168         void SetAutoBreakRows(bool);
169         ///
170         void SetDrawFrame(BufferView *, DrawFrame);
171         ///
172         void SetFrameColor(BufferView *, LColor::color);
173         ///
174         LyXText * getLyXText(BufferView const *,
175                              bool const recursive = false) const;
176         ///
177         void deleteLyXText(BufferView *, bool recursive = true) const;
178         ///
179         void resizeLyXText(BufferView *, bool force = false) const;
180         ///
181         bool ShowInsetDialog(BufferView *) const;
182         ///
183         std::vector<string> const getLabelList() const;
184         ///
185         bool nodraw() const;
186         ///
187         int scroll(bool recursive=true) const;
188         ///
189         void scroll(BufferView *bv, float sx) const {
190                 UpdatableInset::scroll(bv, sx);
191         }
192         ///
193         void scroll(BufferView *bv, int offset) const {
194                 UpdatableInset::scroll(bv, offset);
195         }
196         ///
197         void selectAll(BufferView *bv);
198         ///
199         void clearSelection(BufferView *bv);
200
201         Paragraph * par;
202         ///
203         mutable int need_update;
204
205 protected:
206         ///
207         void UpdateLocal(BufferView *, int what, bool mark_dirty);
208         ///
209         mutable int drawTextXOffset;
210         ///
211         mutable int drawTextYOffset;
212         ///
213         bool autoBreakRows;
214         ///
215         DrawFrame drawFrame_;
216         ///
217         LColor::color frame_color;
218
219 private:
220         ///
221         typedef std::map<BufferView *, LyXText *> Cache;
222         ///
223         typedef Cache::value_type value_type;
224         ///
225         int BeginningOfMainBody(Buffer const *, Paragraph * par) const;
226         ///
227         void ShowInsetCursor(BufferView *, bool show=true);
228         ///
229         void HideInsetCursor(BufferView *);
230         ///
231         UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
232                                          bool selecting = false);
233         ///
234         UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
235                                         bool selecting = false);
236         ///
237         UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
238                                                bool activate_inset = true,
239                                                bool selecting = false);
240         ///
241         UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind, 
242                                               bool activate_inset = true,
243                                               bool selecting = false);
244
245         ///
246         UpdatableInset::RESULT moveUp(BufferView *);
247         ///
248         UpdatableInset::RESULT moveDown(BufferView *);
249         ///
250         void SetCharFont(Buffer const *, int pos, LyXFont const & font);
251         ///
252         string const getText(int);
253         ///
254         bool checkAndActivateInset(BufferView * bv, bool behind);
255         ///
256         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
257                                    int button = 0);
258         ///
259         void removeNewlines();
260         ///
261         int cx(BufferView *) const;
262         ///
263         int cy(BufferView *) const;
264         ///
265         Paragraph::size_type cpos(BufferView *) const;
266         ///
267         Paragraph * cpar(BufferView *) const;
268         ///
269         bool cboundary(BufferView *) const;
270         ///
271         Row * crow(BufferView *) const;
272         ///
273         /// This instead of a macro
274         LyXText * TEXT(BufferView * bv) const {
275                 return getLyXText(bv);
276         }
277         ///
278         void drawFrame(Painter &, bool cleared) const;
279         void clearFrame(Painter &, bool cleared) const;
280         ///
281         void clearInset(Painter &, int baseline, bool & cleared) const;
282         
283         /* Private structures and variables */
284         ///
285         mutable bool locked;
286         ///
287         mutable int insetAscent;
288         ///
289         mutable int insetDescent;
290         ///
291         mutable int insetWidth;
292         ///
293         mutable int last_width;
294         ///
295         mutable int last_height;
296         ///
297         mutable int top_y;
298         ///
299         Paragraph * inset_par;
300         ///
301         Paragraph::size_type inset_pos;
302         ///
303         bool inset_boundary;
304         ///
305         mutable int inset_x;
306         ///
307         mutable int inset_y;
308         ///
309         mutable unsigned int old_max_width;
310         ///
311         bool no_selection;
312         ///
313         mutable float xpos;
314         ///
315         UpdatableInset * the_locking_inset;
316         ///
317         Paragraph * old_par;
318         /// The cache.
319         mutable Cache cache;
320         ///
321         mutable int last_drawn_width;
322         ///
323         mutable bool frame_is_visible;
324 };
325 #endif