]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
fc6121acbdf6b7d2c1730f3e193fb95f1cd5faf7
[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         virtual std::auto_ptr<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() const;
92         ///
93         void draw(PainterInfo & pi, int x, int y) const;
94         ///
95         void setUpdateStatus(int what) const;
96         ///
97         string const editMessage() const;
98         ///
99         bool isTextInset() const { return true; }
100         ///
101         void insetUnlock(BufferView *);
102         ///
103         bool lockInsetInInset(BufferView *, UpdatableInset *);
104         ///
105         bool unlockInsetInInset(BufferView *,
106                                 UpdatableInset *, bool lr = false);
107         ///
108         bool updateInsetInInset(BufferView *, InsetOld *);
109         ///
110         RESULT localDispatch(FuncRequest const &);
111         ///
112         int latex(Buffer const *, std::ostream &,
113                   LatexRunParams const &) const;
114         ///
115         int ascii(Buffer const *, std::ostream &, int linelen) const;
116         ///
117         int linuxdoc(Buffer const *, std::ostream &) const ;
118         ///
119         int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
120         ///
121         void validate(LaTeXFeatures & features) const;
122         ///
123         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
124         /// FIXME, document
125         void getCursorPos(BufferView *, int & x, int & y) const;
126         /// Get the absolute document x,y of the cursor
127         virtual void getCursor(BufferView &, int &, int &) const;
128         ///
129         int insetInInsetY() const;
130         ///
131         void fitInsetCursor(BufferView *) const;
132         ///
133         bool insertInset(BufferView *, InsetOld *);
134         ///
135         bool insetAllowed(InsetOld::Code) const;
136         ///
137         UpdatableInset * getLockingInset() const;
138         ///
139         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
140         ///
141         void setFont(BufferView *, LyXFont const &,
142                      bool toggleall = false,
143                      bool selectall = false);
144         ///
145         void init(InsetText const * ins);
146         ///
147         void writeParagraphData(Buffer const *, std::ostream &) const;
148         ///
149         void setParagraphData(ParagraphList const &);
150         ///
151         void setText(string const &, LyXFont const &);
152         ///
153         void setAutoBreakRows(bool);
154         ///
155         bool getAutoBreakRows() const { return autoBreakRows; }
156         ///
157         void setDrawFrame(BufferView *, DrawFrame);
158         ///
159         void setFrameColor(BufferView *, LColor::color);
160         ///
161         LyXText * getLyXText(BufferView const *,
162                              bool const recursive = false) const;
163         ///
164         void setViewCache(BufferView const * bv) const;
165         ///
166         void deleteLyXText(BufferView *, bool recursive = true) const;
167         ///
168         void resizeLyXText(BufferView *, bool force = false) const;
169         ///
170         bool showInsetDialog(BufferView *) const;
171         ///
172         void getLabelList(std::vector<string> &) const;
173         ///
174         int scroll(bool recursive = true) const;
175         ///
176         void scroll(BufferView * bv, float sx) const {
177                 UpdatableInset::scroll(bv, sx);
178         }
179         ///
180         void scroll(BufferView * bv, int offset) const {
181                 UpdatableInset::scroll(bv, offset);
182         }
183         ///
184         void clearSelection(BufferView * bv);
185         ///
186         InsetOld * getInsetFromID(int id) const;
187         ///
188         ParagraphList * getParagraphs(int) const;
189         ///
190         LyXCursor const & cursor(BufferView *) const;
191         ///
192         bool allowSpellcheck() const { return true; }
193         ///
194         WordLangTuple const
195         selectNextWordToSpellcheck(BufferView *, float & value) const;
196         ///
197         void selectSelectedWord(BufferView *);
198
199         /// mark as erased for change tracking
200         void markErased() { clear(true); };
201         /**
202          * Mark as new. Used when pasting in tabular, and adding rows
203          * or columns. Note that pasting will ensure that tracking already
204          * happens, and this just resets the changes for the copied text,
205          * whereas for row/col add, we need to start tracking changes
206          * for the (empty) paragraph contained.
207          */
208         void markNew(bool track_changes = false);
209         /// find next change
210         bool nextChange(BufferView *, lyx::pos_type & length);
211
212         ///
213         bool searchForward(BufferView *, string const &,
214                            bool = true, bool = false);
215         ///
216         bool searchBackward(BufferView *, string const &,
217                             bool = true, bool = false);
218         ///
219         bool checkInsertChar(LyXFont &);
220         ///
221         void getDrawFont(LyXFont &) const;
222         /// append text onto the existing text
223         void appendParagraphs(Buffer * bp, ParagraphList &);
224
225         ///
226         void addPreview(lyx::graphics::PreviewLoader &) const;
227
228         //
229         // Public structures and variables
230         ///
231         mutable int need_update;
232
233         bool haveParagraphs() const {
234                 return true;
235         }
236         ///
237         ParagraphList paragraphs;
238 protected:
239         ///
240         void updateLocal(BufferView *, int what, bool mark_dirty);
241         /// set parameters for an initial lock of this inset
242         void lockInset(BufferView *);
243         /// lock an inset inside this one
244         void lockInset(BufferView *, UpdatableInset *);
245         ///
246         mutable int drawTextXOffset;
247         ///
248         mutable int drawTextYOffset;
249         ///
250         bool autoBreakRows;
251         ///
252         DrawFrame drawFrame_;
253         ///
254         LColor::color frame_color;
255
256 private:
257         ///
258         void lfunMousePress(FuncRequest const &);
259         ///
260         bool lfunMouseRelease(FuncRequest const &);
261         ///
262         void lfunMouseMotion(FuncRequest const &);
263
264         ///
265         RESULT moveRight(BufferView *,
266                                          bool activate_inset = true,
267                                          bool selecting = false);
268         ///
269         RESULT moveLeft(BufferView *,
270                                         bool activate_inset = true,
271                                         bool selecting = false);
272         ///
273         RESULT moveRightIntern(BufferView *, bool front,
274                                                bool activate_inset = true,
275                                                bool selecting = false);
276         ///
277         RESULT moveLeftIntern(BufferView *, bool front,
278                                               bool activate_inset = true,
279                                               bool selecting = false);
280
281         ///
282         RESULT moveUp(BufferView *);
283         ///
284         RESULT moveDown(BufferView *);
285         ///
286         void setCharFont(Buffer const *, int pos, LyXFont const & font);
287         ///
288         bool checkAndActivateInset(BufferView * bv, bool front);
289         ///
290         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
291                                    mouse_button::state button = mouse_button::none);
292         ///
293         void removeNewlines();
294         ///
295         int cx() const;
296         ///
297         int cix() const;
298         ///
299         int cy() const;
300         ///
301         int ciy() const;
302         ///
303         lyx::pos_type cpos() const;
304         ///
305         ParagraphList::iterator cpar() const;
306         ///
307         bool cboundary() const;
308         ///
309         RowList::iterator crow() const;
310         ///
311         void drawFrame(Painter &, int x) const;
312         ///
313         void clearInset(BufferView *, int start_x, int baseline) const;
314         ///
315         void saveLyXTextState() const;
316         ///
317         void restoreLyXTextState() const;
318         ///
319         void collapseParagraphs(BufferView *);
320
321         /* Private structures and variables */
322         ///
323         mutable bool locked;
324         ///
325         mutable int top_y;
326         ///
327         ParagraphList::iterator inset_par;
328         ///
329         lyx::pos_type inset_pos;
330         ///
331         bool inset_boundary;
332         ///
333         mutable int inset_x;
334         ///
335         mutable int inset_y;
336         ///
337         bool no_selection;
338         ///
339         UpdatableInset * the_locking_inset;
340         ///
341         mutable ParagraphList::iterator old_par;
342         ///
343         mutable int last_drawn_width;
344
345         /// some funny 'temporarily saved state'
346         mutable TextCursor sstate;
347
348         ///
349         // to remember old painted frame dimensions to clear it on the right spot!
350         ///
351         mutable int frame_x;
352         mutable int frame_y;
353         mutable int frame_w;
354         mutable int frame_h;
355         mutable bool in_insetAllowed;
356         ///
357         // these are used to check for mouse movement in Motion selection code
358         ///
359         int mouse_x;
360         int mouse_y;
361 public:
362         ///
363         void reinitLyXText() const;
364         ///
365         mutable LyXText text_;
366         ///
367         mutable int textwidth_;
368 };
369 #endif