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