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