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