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