]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
dont use pragma impementation and interface anymore
[lyx.git] / src / insets / insettext.h
1 // -*- C++ -*-
2 /**
3  * \file insettext.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifndef INSETTEXT_H
13 #define INSETTEXT_H
14
15
16 #include "inset.h"
17 #include "LString.h"
18 #include "LColor.h"
19 #include "ParagraphList.h"
20
21 #include "support/types.h"
22
23 #include <boost/shared_ptr.hpp>
24
25 class Painter;
26 class BufferView;
27 class Buffer;
28 class BufferParams;
29 class LyXCursor;
30 class LyXText;
31 class Row;
32 class Paragraph;
33
34 /**
35  A text inset is like a TeX box to write full text
36  (including styles and other insets) in a given space.
37  @author: Jürgen Vigna
38  */
39 class InsetText : public UpdatableInset {
40 public:
41         ///
42         /// numbers need because of test if codeA < codeB
43         ///
44         enum UpdateCodes {
45                 ///
46                 NONE = 0,
47                 ///
48                 CURSOR = 1,
49                 ///
50                 CLEAR_FRAME = 2,
51                 ///
52                 DRAW_FRAME = 4,
53                 ///
54                 SELECTION = 8,
55                 ///
56                 CURSOR_PAR = 16,
57                 ///
58                 FULL = 32,
59                 ///
60                 INIT = 64
61         };
62         ///
63         enum DrawFrame {
64                 ///
65                 NEVER = 0,
66                 ///
67                 LOCKED,
68                 ///
69                 ALWAYS
70         };
71         ///
72         InsetText(BufferParams const &);
73         ///
74         explicit
75         InsetText(InsetText const &, bool same_id = false);
76         ///
77         ~InsetText();
78         ///
79         Inset * clone(Buffer const &, bool same_id = false) const;
80         ///
81         InsetText & operator=(InsetText const & it);
82         /// empty inset to empty par, or just mark as erased
83         void clear(bool just_mark_erased);
84         ///
85         void read(Buffer const *, LyXLex &);
86         ///
87         void write(Buffer const *, std::ostream &) const;
88         ///
89         int ascent(BufferView *, LyXFont const &) const;
90         ///
91         int descent(BufferView *, LyXFont const &) const;
92         ///
93         int width(BufferView *, LyXFont const & f) const;
94         ///
95         int textWidth(BufferView *, bool fordraw = false) const;
96         ///
97         void draw(BufferView *, LyXFont const &, int , float &, bool) const;
98         ///
99         void update(BufferView *, LyXFont const &, bool = false);
100         ///
101         void setUpdateStatus(BufferView *, int what) const;
102         ///
103         string const editMessage() const;
104         ///
105         void edit(BufferView *, int, int, mouse_button::state);
106         ///
107         void edit(BufferView *, bool front = true);
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         RESULT localDispatch(FuncRequest const &);
123         ///
124         int latex(Buffer const *, std::ostream &,
125                   bool fragile, bool free_spc) const;
126         ///
127         int ascii(Buffer const *, std::ostream &, int linelen) const;
128         ///
129         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
130         ///
131         int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
132         ///
133         void validate(LaTeXFeatures & features) const;
134         ///
135         Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
136         ///
137         void getCursorPos(BufferView *, int & x, int & y) const;
138         ///
139         int insetInInsetY() const;
140         ///
141         void toggleInsetCursor(BufferView *);
142         ///
143         void showInsetCursor(BufferView *, bool show = true);
144         ///
145         void hideInsetCursor(BufferView *);
146         ///
147         void fitInsetCursor(BufferView *) const;
148         ///
149         bool insertInset(BufferView *, Inset *);
150         ///
151         bool insetAllowed(Inset::Code) const;
152         ///
153         UpdatableInset * getLockingInset() const;
154         ///
155         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
156         ///
157         void setFont(BufferView *, LyXFont const &,
158                      bool toggleall = false,
159                      bool selectall = false);
160         ///
161         int getMaxWidth(BufferView *, UpdatableInset const *) const;
162         ///
163         void init(InsetText const * ins = 0, bool same_id = false);
164         ///
165         void writeParagraphData(Buffer const *, std::ostream &) const;
166         ///
167         void setParagraphData(Paragraph *, bool same_id = false);
168         ///
169         void setText(string const &, LyXFont const &);
170         ///
171         void setAutoBreakRows(bool);
172         ///
173         bool getAutoBreakRows() const { return autoBreakRows; }
174         ///
175         void setDrawFrame(BufferView *, DrawFrame);
176         ///
177         void setFrameColor(BufferView *, LColor::color);
178         ///
179         LyXText * getLyXText(BufferView const *,
180                              bool const recursive = false) const;
181         ///
182         void deleteLyXText(BufferView *, bool recursive = true) const;
183         ///
184         void resizeLyXText(BufferView *, bool force = false) const;
185         ///
186         bool showInsetDialog(BufferView *) const;
187         ///
188         std::vector<string> const getLabelList() const;
189         ///
190         bool nodraw() const;
191         ///
192         int scroll(bool recursive = true) const;
193         ///
194         void scroll(BufferView * bv, float sx) const {
195                 UpdatableInset::scroll(bv, sx);
196         }
197         ///
198         void scroll(BufferView * bv, int offset) const {
199                 UpdatableInset::scroll(bv, offset);
200         }
201         ///
202         void selectAll(BufferView * bv);
203         ///
204         void clearSelection(BufferView * bv);
205         ///
206         Paragraph * getParFromID(int id) const;
207         ///
208         Inset * getInsetFromID(int id) const;
209         ///
210         Paragraph * firstParagraph() const;
211         ///
212         Paragraph * getFirstParagraph(int) const;
213         ///
214         LyXCursor const & cursor(BufferView *) const;
215         ///
216         Paragraph * paragraph() const;
217         ///
218         void paragraph(Paragraph *);
219         ///
220         bool allowSpellcheck() const { return true; }
221         ///
222         WordLangTuple const
223         selectNextWordToSpellcheck(BufferView *, float & value) const;
224         ///
225         void selectSelectedWord(BufferView *);
226         ///
227         void toggleSelection(BufferView *, bool kill_selection);
228  
229         /// mark as erased for change tracking
230         void markErased() { clear(true); };
231         /**
232          * Mark as new. Used when pasting in tabular, and adding rows
233          * or columns. Note that pasting will ensure that tracking already
234          * happens, and this just resets the changes for the copied text,
235          * whereas for row/col add, we need to start tracking changes
236          * for the (empty) paragraph contained.
237          */
238         void markNew(bool track_changes = false);
239         /// find next change
240         bool nextChange(BufferView *, lyx::pos_type & length);
241  
242         ///
243         bool searchForward(BufferView *, string const &,
244                            bool = true, bool = false);
245         ///
246         bool searchBackward(BufferView *, string const &,
247                             bool = true, bool = false);
248         ///
249         bool checkInsertChar(LyXFont &);
250         ///
251         void getDrawFont(LyXFont &) const;
252         /// append text onto the existing text
253         void appendParagraphs(BufferParams const & bp, Paragraph *);
254  
255         ///
256         void addPreview(grfx::PreviewLoader &) const;
257
258         //
259         // Public structures and variables
260         ///
261         mutable int need_update;
262
263 protected:
264         ///
265         void updateLocal(BufferView *, int what, bool mark_dirty) const;
266         /// set parameters for an initial lock of this inset
267         void lockInset(BufferView *);
268         /// lock an inset inside this one
269         void lockInset(BufferView *, UpdatableInset *);
270         ///
271         mutable int drawTextXOffset;
272         ///
273         mutable int drawTextYOffset;
274         ///
275         bool autoBreakRows;
276         ///
277         DrawFrame drawFrame_;
278         ///
279         LColor::color frame_color;
280
281 private:
282         ///
283         void lfunMousePress(FuncRequest const &);
284         ///
285         bool lfunMouseRelease(FuncRequest const &);
286         ///
287         void lfunMouseMotion(FuncRequest const &);
288
289         ///
290         struct InnerCache {
291                 ///
292                 InnerCache(boost::shared_ptr<LyXText>);
293                 ///
294                 boost::shared_ptr<LyXText> text;
295                 ///
296                 bool remove;
297         };
298         ///
299         typedef std::map<BufferView *, InnerCache> Cache;
300         ///
301         typedef Cache::value_type value_type;
302         ///
303         int beginningOfMainBody(Paragraph * par) const;
304         ///
305         RESULT moveRight(BufferView *,
306                                          bool activate_inset = true,
307                                          bool selecting = false);
308         ///
309         RESULT moveLeft(BufferView *,
310                                         bool activate_inset = true,
311                                         bool selecting = false);
312         ///
313         RESULT moveRightIntern(BufferView *, bool front,
314                                                bool activate_inset = true,
315                                                bool selecting = false);
316         ///
317         RESULT moveLeftIntern(BufferView *, bool front,
318                                               bool activate_inset = true,
319                                               bool selecting = false);
320
321         ///
322         RESULT moveUp(BufferView *);
323         ///
324         RESULT moveDown(BufferView *);
325         ///
326         void setCharFont(Buffer const *, int pos, LyXFont const & font);
327         ///
328         bool checkAndActivateInset(BufferView * bv, bool front);
329         ///
330         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
331                                    mouse_button::state button = mouse_button::none);
332         ///
333         void removeNewlines();
334         ///
335         int cx(BufferView *) const;
336         ///
337         int cix(BufferView *) const;
338         ///
339         int cy(BufferView *) const;
340         ///
341         int ciy(BufferView *) const;
342         ///
343         lyx::pos_type cpos(BufferView *) const;
344         ///
345         Paragraph * cpar(BufferView *) const;
346         ///
347         bool cboundary(BufferView *) const;
348         ///
349         Row * crow(BufferView *) const;
350         ///
351         void drawFrame(Painter &, bool cleared) const;
352         ///
353         void clearFrame(Painter &, bool cleared) const;
354         ///
355         void clearInset(BufferView *, int baseline, bool & cleared) const;
356         ///
357         void saveLyXTextState(LyXText *) const;
358         ///
359         void restoreLyXTextState(BufferView *, LyXText *) const;
360         ///
361         void reinitLyXText() const;
362         ///
363         void collapseParagraphs(BufferView *) const;
364
365         /* Private structures and variables */
366         ///
367         ParagraphList paragraphs;
368         ///
369         mutable bool locked;
370         ///
371         mutable int insetAscent;
372         ///
373         mutable int insetDescent;
374         ///
375         mutable int insetWidth;
376         ///
377         mutable int top_y;
378         ///
379         Paragraph * inset_par;
380         ///
381         lyx::pos_type inset_pos;
382         ///
383         bool inset_boundary;
384         ///
385         mutable int inset_x;
386         ///
387         mutable int inset_y;
388         ///
389         mutable int old_max_width;
390         ///
391         bool no_selection;
392         ///
393         UpdatableInset * the_locking_inset;
394         ///
395         mutable Paragraph * old_par;
396         /// The cache.
397         mutable Cache cache;
398         ///
399         mutable int last_drawn_width;
400         ///
401         mutable bool frame_is_visible;
402         ///
403         mutable BufferView * cached_bview;
404         ///
405         mutable boost::shared_ptr<LyXText> cached_text;
406         ///
407         struct save_state {
408                 Paragraph * lpar;
409                 Paragraph * selstartpar;
410                 Paragraph * selendpar;
411                 lyx::pos_type pos;
412                 lyx::pos_type selstartpos;
413                 lyx::pos_type selendpos;
414                 bool boundary;
415                 bool selstartboundary;
416                 bool selendboundary;
417                 bool selection;
418                 bool mark_set;
419                 bool refresh;
420         };
421         ///
422         mutable save_state sstate;
423
424         ///
425         // this is needed globally so we know that we're using it actually and
426         // so the LyXText-Cache is not erased until used!
427         mutable LyXText * lt;
428         ///
429         // to remember old painted frame dimensions to clear it on the right spot!
430         ///
431         mutable int frame_x;
432         mutable int frame_y;
433         mutable int frame_w;
434         mutable int frame_h;
435         ///
436         bool in_update; /* as update is not reentrant! */
437         mutable BufferView * do_resize;
438         mutable bool do_reinit;
439         mutable bool in_insetAllowed;
440         ///
441         // these are used to check for mouse movement in Motion selection code
442         ///
443         int mouse_x;
444         int mouse_y;
445 };
446 #endif