]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
Make it compile when USE_BOOST_FORMAT is unset
[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 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "inset.h"
20 #include "LString.h"
21 #include "LColor.h"
22 #include "ParagraphList.h"
23
24 #include "support/types.h"
25
26 #include <boost/shared_ptr.hpp>
27
28 class Painter;
29 class BufferView;
30 class Buffer;
31 class BufferParams;
32 class LyXCursor;
33 class LyXText;
34 class Row;
35 class Paragraph;
36
37 /**
38  A text inset is like a TeX box to write full text
39  (including styles and other insets) in a given space.
40  @author: Jürgen Vigna
41  */
42 class InsetText : public UpdatableInset {
43 public:
44         ///
45         /// numbers need because of test if codeA < codeB
46         ///
47         enum UpdateCodes {
48                 ///
49                 NONE = 0,
50                 ///
51                 CURSOR = 1,
52                 ///
53                 CLEAR_FRAME = 2,
54                 ///
55                 DRAW_FRAME = 4,
56                 ///
57                 SELECTION = 8,
58                 ///
59                 CURSOR_PAR = 16,
60                 ///
61                 FULL = 32,
62                 ///
63                 INIT = 64
64         };
65         ///
66         enum DrawFrame {
67                 ///
68                 NEVER = 0,
69                 ///
70                 LOCKED,
71                 ///
72                 ALWAYS
73         };
74         ///
75         InsetText(BufferParams const &);
76         ///
77         explicit
78         InsetText(InsetText const &, bool same_id = false);
79         ///
80         ~InsetText();
81         ///
82         Inset * clone(Buffer const &, bool same_id = false) const;
83         ///
84         InsetText & operator=(InsetText const & it);
85         ///
86         void clear();
87         ///
88         void read(Buffer const *, LyXLex &);
89         ///
90         void write(Buffer const *, std::ostream &) const;
91         ///
92         int ascent(BufferView *, LyXFont const &) const;
93         ///
94         int descent(BufferView *, LyXFont const &) const;
95         ///
96         int width(BufferView *, LyXFont const & f) const;
97         ///
98         int textWidth(BufferView *, bool fordraw = false) const;
99         ///
100         void draw(BufferView *, LyXFont const &, int , float &, bool) const;
101         ///
102         void update(BufferView *, LyXFont const &, bool = false);
103         ///
104         void setUpdateStatus(BufferView *, int what) const;
105         ///
106         string const editMessage() const;
107         ///
108         void edit(BufferView *, int, int, mouse_button::state);
109         ///
110         void edit(BufferView *, bool front = true);
111         ///
112         bool isTextInset() const { return true; }
113         ///
114         bool doClearArea() const;
115         ///
116         void insetUnlock(BufferView *);
117         ///
118         bool lockInsetInInset(BufferView *, UpdatableInset *);
119         ///
120         bool unlockInsetInInset(BufferView *,
121                                 UpdatableInset *, bool lr = false);
122         ///
123         bool updateInsetInInset(BufferView *, Inset *);
124         ///
125         RESULT localDispatch(FuncRequest const &);
126         ///
127         int latex(Buffer const *, std::ostream &,
128                   bool fragile, bool free_spc) const;
129         ///
130         int ascii(Buffer const *, std::ostream &, int linelen) const;
131         ///
132         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
133         ///
134         int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
135         ///
136         void validate(LaTeXFeatures & features) const;
137         ///
138         Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
139         ///
140         void getCursorPos(BufferView *, int & x, int & y) const;
141         ///
142         int insetInInsetY() const;
143         ///
144         void toggleInsetCursor(BufferView *);
145         ///
146         void showInsetCursor(BufferView *, bool show = true);
147         ///
148         void hideInsetCursor(BufferView *);
149         ///
150         void fitInsetCursor(BufferView *) const;
151         ///
152         bool insertInset(BufferView *, Inset *);
153         ///
154         bool insetAllowed(Inset::Code) const;
155         ///
156         UpdatableInset * getLockingInset() const;
157         ///
158         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
159         ///
160         void setFont(BufferView *, LyXFont const &,
161                      bool toggleall = false,
162                      bool selectall = false);
163         ///
164         int getMaxWidth(BufferView *, UpdatableInset const *) const;
165         ///
166         void init(InsetText const * ins = 0, bool same_id = false);
167         ///
168         void writeParagraphData(Buffer const *, std::ostream &) const;
169         ///
170         void setParagraphData(Paragraph *, bool same_id = false);
171         ///
172         void setText(string const &, LyXFont const &);
173         ///
174         void setAutoBreakRows(bool);
175         ///
176         bool getAutoBreakRows() const { return autoBreakRows; }
177         ///
178         void setDrawFrame(BufferView *, DrawFrame);
179         ///
180         void setFrameColor(BufferView *, LColor::color);
181         ///
182         LyXText * getLyXText(BufferView const *,
183                              bool const recursive = false) const;
184         ///
185         void deleteLyXText(BufferView *, bool recursive = true) const;
186         ///
187         void resizeLyXText(BufferView *, bool force = false) const;
188         ///
189         bool showInsetDialog(BufferView *) const;
190         ///
191         std::vector<string> const getLabelList() const;
192         ///
193         bool nodraw() const;
194         ///
195         int scroll(bool recursive = true) const;
196         ///
197         void scroll(BufferView * bv, float sx) const {
198                 UpdatableInset::scroll(bv, sx);
199         }
200         ///
201         void scroll(BufferView * bv, int offset) const {
202                 UpdatableInset::scroll(bv, offset);
203         }
204         ///
205         void selectAll(BufferView * bv);
206         ///
207         void clearSelection(BufferView * bv);
208         ///
209         Paragraph * getParFromID(int id) const;
210         ///
211         Inset * getInsetFromID(int id) const;
212         ///
213         Paragraph * firstParagraph() const;
214         ///
215         Paragraph * getFirstParagraph(int) const;
216         ///
217         LyXCursor const & cursor(BufferView *) const;
218         ///
219         Paragraph * paragraph() const;
220         ///
221         void paragraph(Paragraph *);
222         ///
223         bool allowSpellcheck() { return true; }
224         ///
225         WordLangTuple const
226         selectNextWordToSpellcheck(BufferView *, float & value) const;
227         ///
228         void selectSelectedWord(BufferView *);
229         ///
230         void toggleSelection(BufferView *, bool kill_selection);
231         ///
232         bool searchForward(BufferView *, string const &,
233                            bool = true, bool = false);
234         ///
235         bool searchBackward(BufferView *, string const &,
236                             bool = true, bool = false);
237         ///
238         bool checkInsertChar(LyXFont &);
239         ///
240         void getDrawFont(LyXFont &) const;
241         ///
242         void appendParagraphs(BufferParams const & bparams, Paragraph *);
243         ///
244         void addPreview(grfx::PreviewLoader &) const;
245
246         //
247         // Public structures and variables
248         ///
249         mutable int need_update;
250
251 protected:
252         ///
253         void updateLocal(BufferView *, int what, bool mark_dirty) const;
254         /// set parameters for an initial lock of this inset
255         void lockInset(BufferView *);
256         /// lock an inset inside this one
257         void lockInset(BufferView *, UpdatableInset *);
258         ///
259         mutable int drawTextXOffset;
260         ///
261         mutable int drawTextYOffset;
262         ///
263         bool autoBreakRows;
264         ///
265         DrawFrame drawFrame_;
266         ///
267         LColor::color frame_color;
268
269 private:
270         ///
271         void lfunMousePress(FuncRequest const &);
272         ///
273         bool lfunMouseRelease(FuncRequest const &);
274         ///
275         void lfunMouseMotion(FuncRequest const &);
276
277         ///
278         struct InnerCache {
279                 ///
280                 InnerCache(boost::shared_ptr<LyXText>);
281                 ///
282                 boost::shared_ptr<LyXText> text;
283                 ///
284                 bool remove;
285         };
286         ///
287         typedef std::map<BufferView *, InnerCache> Cache;
288         ///
289         typedef Cache::value_type value_type;
290         ///
291         int beginningOfMainBody(Paragraph * par) const;
292         ///
293         RESULT moveRight(BufferView *,
294                                          bool activate_inset = true,
295                                          bool selecting = false);
296         ///
297         RESULT moveLeft(BufferView *,
298                                         bool activate_inset = true,
299                                         bool selecting = false);
300         ///
301         RESULT moveRightIntern(BufferView *, bool front,
302                                                bool activate_inset = true,
303                                                bool selecting = false);
304         ///
305         RESULT moveLeftIntern(BufferView *, bool front,
306                                               bool activate_inset = true,
307                                               bool selecting = false);
308
309         ///
310         RESULT moveUp(BufferView *);
311         ///
312         RESULT moveDown(BufferView *);
313         ///
314         void setCharFont(Buffer const *, int pos, LyXFont const & font);
315         ///
316         bool checkAndActivateInset(BufferView * bv, bool front);
317         ///
318         bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
319                                    mouse_button::state button = mouse_button::none);
320         ///
321         void removeNewlines();
322         ///
323         int cx(BufferView *) const;
324         ///
325         int cix(BufferView *) const;
326         ///
327         int cy(BufferView *) const;
328         ///
329         int ciy(BufferView *) const;
330         ///
331         lyx::pos_type cpos(BufferView *) const;
332         ///
333         Paragraph * cpar(BufferView *) const;
334         ///
335         bool cboundary(BufferView *) const;
336         ///
337         Row * crow(BufferView *) const;
338         ///
339         void drawFrame(Painter &, bool cleared) const;
340         ///
341         void clearFrame(Painter &, bool cleared) const;
342         ///
343         void clearInset(BufferView *, int baseline, bool & cleared) const;
344         ///
345         void saveLyXTextState(LyXText *) const;
346         ///
347         void restoreLyXTextState(BufferView *, LyXText *) const;
348         ///
349         void reinitLyXText() const;
350         ///
351         void collapseParagraphs(BufferView *) const;
352
353         /* Private structures and variables */
354         ///
355         ParagraphList paragraphs;
356         ///
357         mutable bool locked;
358         ///
359         mutable int insetAscent;
360         ///
361         mutable int insetDescent;
362         ///
363         mutable int insetWidth;
364         ///
365         mutable int top_y;
366         ///
367         Paragraph * inset_par;
368         ///
369         lyx::pos_type inset_pos;
370         ///
371         bool inset_boundary;
372         ///
373         mutable int inset_x;
374         ///
375         mutable int inset_y;
376         ///
377         mutable int old_max_width;
378         ///
379         bool no_selection;
380         ///
381         UpdatableInset * the_locking_inset;
382         ///
383         mutable Paragraph * old_par;
384         /// The cache.
385         mutable Cache cache;
386         ///
387         mutable int last_drawn_width;
388         ///
389         mutable bool frame_is_visible;
390         ///
391         mutable BufferView * cached_bview;
392         ///
393         mutable boost::shared_ptr<LyXText> cached_text;
394         ///
395         struct save_state {
396                 Paragraph * lpar;
397                 Paragraph * selstartpar;
398                 Paragraph * selendpar;
399                 lyx::pos_type pos;
400                 lyx::pos_type selstartpos;
401                 lyx::pos_type selendpos;
402                 bool boundary;
403                 bool selstartboundary;
404                 bool selendboundary;
405                 bool selection;
406                 bool mark_set;
407                 bool refresh;
408         };
409         ///
410         mutable save_state sstate;
411
412         ///
413         // this is needed globally so we know that we're using it actually and
414         // so the LyXText-Cache is not erased until used!
415         mutable LyXText * lt;
416         ///
417         // to remember old painted frame dimensions to clear it on the right spot!
418         ///
419         mutable int frame_x;
420         mutable int frame_y;
421         mutable int frame_w;
422         mutable int frame_h;
423         ///
424         bool in_update; /* as update is not reentrant! */
425         mutable BufferView * do_resize;
426         mutable bool do_reinit;
427         mutable bool in_insetAllowed;
428         ///
429         // these are used to check for mouse movement in Motion selection code
430         ///
431         int mouse_x;
432         int mouse_y;
433 };
434 #endif