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