]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
1544aafcf4341f340a870cb2b5e86fcf23425bd4
[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         int latex(Buffer const &, std::ostream &,
84                   LatexRunParams const &) const;
85         ///
86         int ascii(Buffer const &, std::ostream &,
87                   LatexRunParams const &) const;
88         ///
89         int linuxdoc(Buffer const &, std::ostream &,
90                      LatexRunParams const &) const ;
91         ///
92         int docbook(Buffer const &, std::ostream &,
93                     LatexRunParams const &) 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 writeParagraphData(Buffer const &, std::ostream &) const;
120         ///
121         void setText(std::string const &, LyXFont const &);
122         ///
123         void setAutoBreakRows(bool);
124         ///
125         bool getAutoBreakRows() const { return autoBreakRows_; }
126         ///
127         void setDrawFrame(DrawFrame);
128         ///
129         LColor_color frameColor() const;
130         void setFrameColor(LColor_color);
131         ///
132         LyXText * getLyXText(BufferView const *,
133                              bool const recursive = false) const;
134         ///
135         void setViewCache(BufferView const * bv) const;
136         ///
137         void deleteLyXText(BufferView *, bool recursive = true) const;
138         ///
139         bool showInsetDialog(BufferView *) const;
140         /// Appends \c list with all labels found within this inset.
141         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
142         ///
143         int scroll(bool recursive = true) const;
144         ///
145         void scroll(BufferView * bv, float sx) const {
146                 UpdatableInset::scroll(bv, sx);
147         }
148         ///
149         void scroll(BufferView * bv, int offset) const {
150                 UpdatableInset::scroll(bv, offset);
151         }
152         ///
153         void clearSelection(BufferView * bv);
154         ///
155         InsetOld * getInsetFromID(int id) const;
156         ///
157         ParagraphList * getParagraphs(int) const;
158         ///
159         LyXText * getText(int) const;
160         ///
161         LyXCursor const & cursor(BufferView *) const;
162         ///
163         bool allowSpellcheck() const { return true; }
164         ///
165         WordLangTuple const
166         selectNextWordToSpellcheck(BufferView *, float & value) const;
167         ///
168         void selectSelectedWord(BufferView *);
169
170         /// mark as erased for change tracking
171         void markErased() { clear(true); };
172         /**
173          * Mark as new. Used when pasting in tabular, and adding rows
174          * or columns. Note that pasting will ensure that tracking already
175          * happens, and this just resets the changes for the copied text,
176          * whereas for row/col add, we need to start tracking changes
177          * for the (empty) paragraph contained.
178          */
179         void markNew(bool track_changes = false);
180         /// find next change
181         bool nextChange(BufferView *, lyx::pos_type & length);
182
183         ///
184         bool searchForward(BufferView *, std::string const &,
185                            bool = true, bool = false);
186         ///
187         bool searchBackward(BufferView *, std::string const &,
188                             bool = true, bool = false);
189         ///
190         bool checkInsertChar(LyXFont &);
191         ///
192         void getDrawFont(LyXFont &) const;
193         /// append text onto the existing text
194         void appendParagraphs(Buffer * bp, ParagraphList &);
195
196         ///
197         void addPreview(lyx::graphics::PreviewLoader &) const;
198
199         ///
200         bool haveParagraphs() const {
201                 return true;
202         }
203         ///
204         mutable ParagraphList paragraphs;
205 protected:
206         ///
207         virtual
208         DispatchResult
209         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
210         ///
211         void updateLocal(BufferView *, bool mark_dirty);
212         /// set parameters for an initial lock of this inset
213         void lockInset(BufferView *);
214         /// lock an inset inside this one
215         void lockInset(BufferView *, UpdatableInset *);
216
217 private:
218         ///
219         void init();
220         ///
221         void lfunMousePress(FuncRequest const &);
222         ///
223         bool lfunMouseRelease(FuncRequest const &);
224         ///
225         void lfunMouseMotion(FuncRequest const &);
226
227         ///
228         DispatchResult moveRight(BufferView *);
229         ///
230         DispatchResult moveLeft(BufferView *);
231         ///
232         DispatchResult moveRightIntern(BufferView *, bool front,
233                                                bool activate_inset = true,
234                                                bool selecting = false);
235         ///
236         DispatchResult moveLeftIntern(BufferView *, bool front,
237                                               bool activate_inset = true,
238                                               bool selecting = false);
239
240         ///
241         DispatchResult moveUp(BufferView *);
242         ///
243         DispatchResult moveDown(BufferView *);
244         ///
245         void setCharFont(Buffer const &, int pos, LyXFont const & font);
246         ///
247         bool checkAndActivateInset(BufferView * bv, bool front);
248         ///
249         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
250                                    mouse_button::state button = mouse_button::none);
251         ///
252         void removeNewlines();
253         ///
254         int cx() const;
255         ///
256         int cy() const;
257         ///
258         lyx::pos_type cpos() const;
259         ///
260         ParagraphList::iterator cpar() const;
261         ///
262         bool cboundary() const;
263         ///
264         RowList::iterator crow() const;
265         ///
266         void drawFrame(Painter &, int x) const;
267         ///
268         void clearInset(BufferView *, int start_x, int baseline) const;
269         ///
270         void collapseParagraphs(BufferView *);
271
272         /* Private structures and variables */
273         ///
274         bool autoBreakRows_;
275         ///
276         DrawFrame drawFrame_;
277         /** We store the LColor::color value as an int to get LColor.h out
278          *  of the header file.
279          */
280         int frame_color_;
281         ///
282         mutable bool locked;
283         ///
284         mutable int top_y;
285         ///
286         lyx::paroffset_type inset_par;
287         ///
288         lyx::pos_type inset_pos;
289         ///
290         bool inset_boundary;
291         ///
292         mutable int inset_x;
293         ///
294         mutable int inset_y;
295         ///
296         bool no_selection;
297         ///
298         UpdatableInset * the_locking_inset;
299         ///
300         mutable lyx::paroffset_type old_par;
301
302         ///
303         // to remember old painted frame dimensions to clear it on the right spot!
304         ///
305         mutable bool in_insetAllowed;
306         ///
307         // these are used to check for mouse movement in Motion selection code
308         ///
309         int mouse_x;
310         int mouse_y;
311 public:
312         ///
313         mutable LyXText text_;
314         ///
315         mutable int textwidth_;
316 };
317 #endif