]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
some reindentation, revert workarea xpos++, constify, remove all traces of LyXParagra...
[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 "lyxinset.h"
23 #include "LString.h"
24 #include "lyxcursor.h"
25
26 class Painter;
27 class BufferView;
28 class Buffer;
29 class LyXCursor;
30 class LyXParagraph;
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         ///
157         int getMaxWidth(BufferView *, UpdatableInset const *) const;
158         ///
159         void init(InsetText const * ins = 0);
160         ///
161         void WriteParagraphData(Buffer const *, std::ostream &) const;
162         ///
163         void SetParagraphData(LyXParagraph *);
164         ///
165         void SetText(string const &);
166         ///
167         void SetAutoBreakRows(bool);
168         ///
169         void SetDrawFrame(BufferView *, DrawFrame);
170         ///
171         void SetFrameColor(BufferView *, LColor::color);
172         ///
173         LyXText * getLyXText(BufferView const *, bool const recursive=false) const;
174         ///
175         void deleteLyXText(BufferView *, bool recursive=true) const;
176         ///
177         void resizeLyXText(BufferView *) const;
178         ///
179         bool ShowInsetDialog(BufferView *) const;
180         ///
181         std::vector<string> const getLabelList() const;
182         ///
183         bool nodraw() const;
184         ///
185         int scroll(bool recursive=true) const;
186         void scroll(BufferView *bv, float sx) const {
187                 UpdatableInset::scroll(bv, sx);
188         }
189         void scroll(BufferView *bv, int offset) const {
190                 UpdatableInset::scroll(bv, offset);
191         }
192
193         LyXParagraph * par;
194         ///
195         mutable int need_update;
196
197 protected:
198         ///
199         void UpdateLocal(BufferView *, int what, bool mark_dirty);
200         ///
201         mutable int drawTextXOffset;
202         ///
203         mutable int drawTextYOffset;
204         ///
205         bool autoBreakRows;
206         ///
207         DrawFrame drawFrame_;
208         ///
209         LColor::color frame_color;
210
211 private:
212         ///
213         typedef std::map<BufferView *, LyXText *> Cache;
214         ///
215         typedef Cache::value_type value_type;
216         ///
217         int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
218         ///
219         void ShowInsetCursor(BufferView *, bool show=true);
220         ///
221         void HideInsetCursor(BufferView *);
222         ///
223         UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
224                                          bool selecting = false);
225         ///
226         UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
227                                         bool selecting = false);
228         ///
229         UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
230                                                bool activate_inset = true,
231                                                bool selecting = false);
232         ///
233         UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind, 
234                                               bool activate_inset = true,
235                                               bool selecting = false);
236
237         ///
238         UpdatableInset::RESULT moveUp(BufferView *);
239         ///
240         UpdatableInset::RESULT moveDown(BufferView *);
241         ///
242         void SetCharFont(Buffer const *, int pos, LyXFont const & font);
243         ///
244         string const getText(int);
245         ///
246         bool checkAndActivateInset(BufferView * bv, bool behind);
247         ///
248         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
249                                    int button = 0);
250         ///
251         void removeNewlines();
252         ///
253         int cx(BufferView *) const;
254         ///
255         int cy(BufferView *) const;
256         ///
257         LyXParagraph::size_type cpos(BufferView *) const;
258         ///
259         LyXParagraph * cpar(BufferView *) const;
260         ///
261         bool cboundary(BufferView *) const;
262         ///
263         Row * crow(BufferView *) const;
264         ///
265         /// This instead of a macro
266         LyXText * TEXT(BufferView * bv) const {
267                 return getLyXText(bv);
268         }
269         ///
270         void drawFrame(Painter &, bool cleared) const;
271         void clearFrame(Painter &, bool cleared) const;
272         ///
273         
274         /* Private structures and variables */
275         ///
276         mutable bool locked;
277         ///
278         mutable int insetAscent;
279         ///
280         mutable int insetDescent;
281         ///
282         mutable int insetWidth;
283         ///
284         mutable int last_width;
285         ///
286         mutable int last_height;
287         ///
288         mutable int top_y;
289         ///
290         LyXParagraph * inset_par;
291         ///
292         LyXParagraph::size_type inset_pos;
293         ///
294         bool inset_boundary;
295         ///
296         mutable int inset_x;
297         ///
298         mutable int inset_y;
299         ///
300         int interline_space;
301         ///
302         bool no_selection;
303         ///
304         mutable float xpos;
305         ///
306         UpdatableInset * the_locking_inset;
307         ///
308         LyXParagraph * old_par;
309         /// The cache.
310         mutable Cache cache;
311         ///
312         mutable int last_drawn_width;
313         ///
314         mutable bool frame_is_visible;
315 };
316 #endif