]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
Minor code shuffle.
[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         bool insertInsetAllowed(Inset::Code) const;
157         ///
158         UpdatableInset * getLockingInset() const;
159         ///
160         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
161         ///
162         void setFont(BufferView *, LyXFont const &,
163                      bool toggleall = false,
164                      bool selectall = false);
165         ///
166         int getMaxWidth(BufferView *, UpdatableInset const *) const;
167         ///
168         void init(InsetText const * ins = 0, bool same_id = false);
169         ///
170         void writeParagraphData(Buffer const *, std::ostream &) const;
171         ///
172         void setParagraphData(Paragraph *);
173         ///
174         void setText(string const &);
175         ///
176         void setAutoBreakRows(bool);
177         ///
178         void setDrawFrame(BufferView *, DrawFrame);
179         ///
180         void setFrameColor(BufferView *, LColor::color);
181         ///
182         LyXText * getLyXText(BufferView const *,
183                              bool const recursive = false) const;
184         ///
185         void deleteLyXText(BufferView *, bool recursive = true) const;
186         ///
187         void resizeLyXText(BufferView *, bool force = false) const;
188         ///
189         bool showInsetDialog(BufferView *) const;
190         ///
191         std::vector<string> const getLabelList() const;
192         ///
193         bool nodraw() const;
194         ///
195         int scroll(bool recursive=true) const;
196         ///
197         void scroll(BufferView *bv, float sx) const {
198                 UpdatableInset::scroll(bv, sx);
199         }
200         ///
201         void scroll(BufferView *bv, int offset) const {
202                 UpdatableInset::scroll(bv, offset);
203         }
204         ///
205         void selectAll(BufferView *bv);
206         ///
207         void clearSelection(BufferView *bv);
208         ///
209         Paragraph * getParFromID(int id) const;
210         ///
211         Inset * getInsetFromID(int id) const;
212         ///
213         Paragraph * firstParagraph() const;
214         ///
215         LyXCursor const & cursor(BufferView *) const;
216         ///
217         Paragraph * paragraph() const;
218         ///
219         void paragraph(Paragraph *);
220         ///
221         mutable int need_update;
222
223 protected:
224         ///
225         void updateLocal(BufferView *, int what, bool mark_dirty);
226         ///
227         mutable int drawTextXOffset;
228         ///
229         mutable int drawTextYOffset;
230         ///
231         bool autoBreakRows;
232         ///
233         DrawFrame drawFrame_;
234         ///
235         LColor::color frame_color;
236
237 private:
238         struct InnerCache {
239                 InnerCache(boost::shared_ptr<LyXText>);
240
241                 boost::shared_ptr<LyXText> text;
242                 bool remove;
243         };
244         ///
245         typedef std::map<BufferView *, struct InnerCache > Cache;
246         ///
247         typedef Cache::value_type value_type;
248         ///
249         int beginningOfMainBody(Buffer const *, Paragraph * par) const;
250         ///
251         void showInsetCursor(BufferView *, bool show=true);
252         ///
253         void hideInsetCursor(BufferView *);
254         ///
255         UpdatableInset::RESULT moveRight(BufferView *,
256                                          bool activate_inset = true,
257                                          bool selecting = false);
258         ///
259         UpdatableInset::RESULT moveLeft(BufferView *,
260                                         bool activate_inset = true,
261                                         bool selecting = false);
262         ///
263         UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
264                                                bool activate_inset = true,
265                                                bool selecting = false);
266         ///
267         UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind, 
268                                               bool activate_inset = true,
269                                               bool selecting = false);
270
271         ///
272         UpdatableInset::RESULT moveUp(BufferView *);
273         ///
274         UpdatableInset::RESULT moveDown(BufferView *);
275         ///
276         void setCharFont(Buffer const *, int pos, LyXFont const & font);
277         ///
278         string const getText(int);
279         ///
280         bool checkAndActivateInset(BufferView * bv, bool behind);
281         ///
282         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
283                                    int button = 0);
284         ///
285         void removeNewlines();
286         ///
287         int cx(BufferView *) const;
288         ///
289         int cy(BufferView *) const;
290         ///
291         Paragraph::size_type cpos(BufferView *) const;
292         ///
293         Paragraph * cpar(BufferView *) const;
294         ///
295         bool cboundary(BufferView *) const;
296         ///
297         Row * crow(BufferView *) const;
298         ///
299         void drawFrame(Painter &, bool cleared) const;
300         ///
301         void clearFrame(Painter &, bool cleared) const;
302         ///
303         void clearInset(Painter &, int baseline, bool & cleared) const;
304         ///
305         void saveLyXTextState(LyXText *) const;
306         void restoreLyXTextState(BufferView *, LyXText *) const;
307         
308         /* Private structures and variables */
309         ///
310         Paragraph * par;
311         ///
312         mutable bool locked;
313         ///
314         mutable int insetAscent;
315         ///
316         mutable int insetDescent;
317         ///
318         mutable int insetWidth;
319         ///
320         mutable int last_width;
321         ///
322         mutable int last_height;
323         ///
324         mutable int top_y;
325         ///
326         Paragraph * inset_par;
327         ///
328         Paragraph::size_type inset_pos;
329         ///
330         bool inset_boundary;
331         ///
332         mutable int inset_x;
333         ///
334         mutable int inset_y;
335         ///
336         mutable unsigned int old_max_width;
337         ///
338         bool no_selection;
339         ///
340         mutable float xpos;
341         ///
342         UpdatableInset * the_locking_inset;
343         ///
344         Paragraph * old_par;
345         /// The cache.
346         mutable Cache cache;
347         ///
348         mutable int last_drawn_width;
349         ///
350         mutable bool frame_is_visible;
351         ///
352         mutable BufferView * cached_bview;
353         ///
354         mutable boost::shared_ptr<LyXText> cached_text;
355         ///
356         mutable struct save_state {
357                 Paragraph * lpar;
358                 Paragraph * selstartpar;
359                 Paragraph * selendpar;
360                 Paragraph::size_type pos;
361                 Paragraph::size_type selstartpos;
362                 Paragraph::size_type selendpos;
363                 bool boundary;
364                 bool selstartboundary;
365                 bool selendboundary;
366                 bool selection;
367                 bool mark_set;
368         } sstate;
369         ///
370         // this is needed globally so we know that we're using it actually and
371         // so the LyXText-Cache is not erased until used!
372         mutable LyXText * lt;
373 };
374 #endif