]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
863288d56e77228bf3e1d5c18165285e6754a166
[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         int latex(Buffer const &, std::ostream &,
77                   OutputParams const &) const;
78         ///
79         int plaintext(Buffer const &, std::ostream &,
80                   OutputParams const &) const;
81         ///
82         int linuxdoc(Buffer const &, std::ostream &,
83                      OutputParams const &) const ;
84         ///
85         int docbook(Buffer const &, std::ostream &,
86                     OutputParams const &) const ;
87         ///
88         void validate(LaTeXFeatures & features) const;
89         ///
90         InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
91         /// FIXME, document
92         void getCursorPos(BufferView *, int & x, int & y) const;
93         ///
94         int insetInInsetY() const;
95         ///
96         void fitInsetCursor(BufferView *) const;
97         ///
98         bool insertInset(BufferView *, InsetOld *);
99         ///
100         bool insetAllowed(InsetOld::Code) const;
101         ///
102         void setFont(BufferView *, LyXFont const &,
103                      bool toggleall = false,
104                      bool selectall = false);
105         ///
106         void writeParagraphData(Buffer const &, std::ostream &) const;
107         ///
108         void setText(std::string const &, LyXFont const &);
109         ///
110         void setAutoBreakRows(bool);
111         ///
112         bool getAutoBreakRows() const { return autoBreakRows_; }
113         ///
114         void setDrawFrame(DrawFrame);
115         ///
116         LColor_color frameColor() const;
117         ///
118         void setFrameColor(LColor_color);
119         ///
120         void setViewCache(BufferView const * bv) const;
121         ///
122         void deleteLyXText(BufferView *, bool recursive = true) const;
123         ///
124         bool showInsetDialog(BufferView *) const;
125         /// Appends \c list with all labels found within this inset.
126         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
127         ///
128         int scroll(bool recursive = true) const;
129         ///
130         void scroll(BufferView * bv, float sx) const {
131                 UpdatableInset::scroll(bv, sx);
132         }
133         ///
134         void scroll(BufferView * bv, int offset) const {
135                 UpdatableInset::scroll(bv, offset);
136         }
137         ///
138         void clearSelection(BufferView * bv);
139         ///
140         ParagraphList * getParagraphs(int) const;
141         ///
142         LyXText * getText(int) const;
143
144         /// mark as erased for change tracking
145         void markErased() { clear(true); };
146         /**
147          * Mark as new. Used when pasting in tabular, and adding rows
148          * or columns. Note that pasting will ensure that tracking already
149          * happens, and this just resets the changes for the copied text,
150          * whereas for row/col add, we need to start tracking changes
151          * for the (empty) paragraph contained.
152          */
153         void markNew(bool track_changes = false);
154
155         ///
156         bool checkInsertChar(LyXFont &);
157         ///
158         void getDrawFont(LyXFont &) const;
159         /// append text onto the existing text
160         void appendParagraphs(Buffer * bp, ParagraphList &);
161
162         ///
163         void addPreview(lyx::graphics::PreviewLoader &) const;
164
165         ///
166         void edit(BufferView *, bool);
167         ///
168         void edit(BufferView *, int, int);
169
170         ///
171         int numParagraphs() const { return 1; }
172         ///
173         mutable ParagraphList paragraphs;
174 protected:
175         ///
176         DispatchResult
177         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
178         ///
179         void updateLocal(BufferView *, bool mark_dirty);
180
181 private:
182         ///
183         void init();
184         ///
185         void lfunMousePress(FuncRequest const &);
186         ///
187         void lfunMouseMotion(FuncRequest const &);
188         ///
189         void lfunMouseRelease(FuncRequest const &);
190         // If the inset is empty set the language of the current font to the
191         // language to the surronding text (if different).
192         void sanitizeEmptyText(BufferView *);
193
194         ///
195         DispatchResult moveRight(BufferView *);
196         ///
197         DispatchResult moveLeft(BufferView *);
198         ///
199         DispatchResult moveRightIntern(BufferView *, bool front,
200                                                bool activate_inset = true,
201                                                bool selecting = false);
202         ///
203         DispatchResult moveLeftIntern(BufferView *, bool front,
204                                               bool activate_inset = true,
205                                               bool selecting = false);
206
207         ///
208         DispatchResult moveUp(BufferView *);
209         ///
210         DispatchResult moveDown(BufferView *);
211         ///
212         void setCharFont(Buffer const &, int pos, LyXFont const & font);
213         ///
214         bool checkAndActivateInset(BufferView * bv, bool front);
215         ///
216         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0);
217         ///
218         void removeNewlines();
219         ///
220         int cx() const;
221         ///
222         int cy() const;
223         ///
224         lyx::pos_type cpos() const;
225         ///
226         ParagraphList::iterator cpar() const;
227         ///
228         RowList::iterator crow() const;
229         ///
230         void drawFrame(Painter &, int x) const;
231         ///
232         void clearInset(BufferView *, int start_x, int baseline) const;
233         ///
234         void collapseParagraphs(BufferView *);
235
236         /* Private structures and variables */
237         ///
238         bool autoBreakRows_;
239         ///
240         DrawFrame drawFrame_;
241         /** We store the LColor::color value as an int to get LColor.h out
242          *  of the header file.
243          */
244         int frame_color_;
245         ///
246         bool no_selection;
247         ///
248         mutable lyx::paroffset_type old_par;
249
250         ///
251         // to remember old painted frame dimensions to clear it on the right spot!
252         ///
253         mutable bool in_insetAllowed;
254         ///
255         // these are used to check for mouse movement in Motion selection code
256         ///
257         int mouse_x;
258         int mouse_y;
259 public:
260         ///
261         mutable LyXText text_;
262         ///
263         mutable int textwidth_;
264 };
265 #endif