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