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