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