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