]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
f6382fe61ab107ea7c980f4b0008ea377d4fae56
[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 // The pristine updatable inset: Text
12
13
14 #ifndef INSETTEXT_H
15 #define INSETTEXT_H
16
17 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "lyxinset.h"
22 #include "LString.h"
23 #include "lyxcursor.h"
24
25 class Painter;
26 class BufferView;
27 class Buffer;
28 class LyXCursor;
29 class LyXParagraph;
30 class LColor;
31 class LyXText;
32 class LyXScreen;
33
34 /**
35  * A text inset is like a TeX box to write full text
36  * (including styles and other insets) in a given space. 
37  */
38 class InsetText : public UpdatableInset {
39 public:
40     ///
41     enum UpdateCodes {
42         NONE = 0,
43         INIT,
44         FULL,
45         CURSOR_PAR,
46         CURSOR,
47         SELECTION,
48         FRAME
49     };
50     ///
51     enum DrawFrame {
52         NEVER = 0,
53         LOCKED,
54         ALWAYS
55     };
56     ///
57     explicit
58     InsetText();
59     ///
60     InsetText(InsetText const &);
61     ///
62     ~InsetText();
63     ///
64     Inset * Clone() const;
65     ///
66     InsetText & operator= (InsetText const & it);
67     ///
68     void clear() const { par->clearContents(); }
69     ///
70     void Read(Buffer const *, LyXLex &);
71     ///
72     void Write(Buffer const *, std::ostream &) const;
73     ///
74     int ascent(Painter &, LyXFont const &) const;
75     ///
76     int descent(Painter &, LyXFont const &) const;
77     ///
78     int width(Painter &, LyXFont const & f) const;
79     ///
80     int textWidth(Painter &) const;
81     ///
82     void draw(BufferView *, LyXFont const &, int , float &, bool) const;
83     ///
84     void update(BufferView *, LyXFont const &, bool =false);
85     ///
86     char const * EditMessage() const;
87     ///
88     void Edit(BufferView *, int, int, unsigned int);
89     ///
90     bool IsTextInset() const { return true; }
91     ///
92     bool doClearArea() const { return !locked; }
93     ///
94     void InsetUnlock(BufferView *);
95     ///
96     bool LockInsetInInset(BufferView *, UpdatableInset *);
97     ///
98     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
99     ///
100     bool UpdateInsetInInset(BufferView *, Inset *);
101     ///
102     void InsetButtonRelease(BufferView *, int, int, int);
103     ///
104     void InsetButtonPress(BufferView *, int, int, int);
105     ///
106     void InsetMotionNotify(BufferView *, int, int, int);
107     ///
108     void InsetKeyPress(XKeyEvent *);
109     ///
110     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
111     ///
112     int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
113     ///
114     int Ascii(Buffer const *, std::ostream &) const { return 0; }
115     ///
116     int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
117     ///
118     int DocBook(Buffer const *, std::ostream &) const { return 0; }
119     ///
120     void Validate(LaTeXFeatures & features) const;
121     ///
122     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
123     ///
124     void GetCursorPos(BufferView *, int & x, int & y) const;
125     ///
126     int InsetInInsetY();
127     ///
128     void ToggleInsetCursor(BufferView *);
129     ///
130     bool InsertInset(BufferView *, Inset *);
131     ///
132     UpdatableInset * GetLockingInset();
133     ///
134     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
135     ///
136     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
137     ///
138     void init(InsetText const * ins = 0);
139     ///
140     void WriteParagraphData(Buffer const *, std::ostream &) const;
141     ///
142     void SetParagraphData(LyXParagraph *);
143     ///
144     void SetAutoBreakRows(bool);
145     ///
146     void SetDrawFrame(BufferView *, DrawFrame);
147     ///
148     void SetFrameColor(BufferView *, LColor::color);
149     ///
150 //    LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
151     ///
152     LyXText * getLyXText(BufferView *) const;
153     void deleteLyXText(BufferView *);
154
155     LyXParagraph * par;
156
157 protected:
158     ///
159     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
160     ///
161     virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
162
163     mutable int drawTextXOffset;
164     mutable int drawTextYOffset;
165     ///
166     bool autoBreakRows;
167     DrawFrame drawFrame;
168     ///
169     LColor::color frame_color;
170     ///
171     mutable UpdateCodes need_update;
172
173 private:
174     ///
175     typedef std::map<BufferView *, LyXText *> Cache;
176     ///
177     typedef Cache::value_type value_type;
178     ///
179     int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
180     ///
181     void ShowInsetCursor(BufferView *);
182     ///
183     void HideInsetCursor(BufferView *);
184     ///
185     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
186     ///
187     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
188     ///
189     UpdatableInset::RESULT moveUp(BufferView *);
190     ///
191     UpdatableInset::RESULT moveDown(BufferView *);
192     ///
193     void SetCharFont(Buffer const *, int pos, LyXFont const & font);
194     ///
195     string getText(int);
196     ///
197     bool checkAndActivateInset(BufferView * bv, bool behind);
198     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
199                                int button = 0);
200     ///
201     int cx(BufferView *) const;
202     int cy(BufferView *) const;
203     int cpos(BufferView *) const;
204     LyXParagraph * cpar(BufferView *) const;
205     Row * crow(BufferView *) const;
206
207     /// This instead of a macro
208     LyXText * TEXT(BufferView * bv) const {
209         return getLyXText(bv);
210     }
211         
212     /* Private structures and variables */
213     ///
214     mutable bool locked;
215     ///
216     int insetAscent;
217     int insetDescent;
218     int insetWidth;
219     mutable int last_width;
220     mutable int last_height;
221     mutable int top_y;
222     ///
223     LyXParagraph * inset_par;
224     ///
225     int inset_pos;
226     ///
227     mutable int inset_x;
228     ///
229     mutable int inset_y;
230     ///
231     int interline_space;
232     ///
233     bool no_selection;
234     ///
235     mutable float xpos;
236     ///
237     UpdatableInset * the_locking_inset;
238     ///
239     LyXParagraph * old_par;
240     /// The cache.
241     mutable Cache cache;
242 };
243 #endif