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