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