]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
b4b76b8790004c2c4e7a26dee7a14b97977d17ba
[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 &, bool fragile, bool free_spc) const;
114     ///
115     int Ascii(Buffer const *, std::ostream &) const { return 0; }
116     ///
117     int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
118     ///
119     int DocBook(Buffer const *, std::ostream &) const { return 0; }
120     ///
121     void Validate(LaTeXFeatures & features) const;
122     ///
123     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
124     ///
125     void GetCursorPos(BufferView *, int & x, int & y) const;
126     ///
127     int InsetInInsetY();
128     ///
129     void ToggleInsetCursor(BufferView *);
130     ///
131     bool InsertInset(BufferView *, Inset *);
132     ///
133     UpdatableInset * GetLockingInset();
134     ///
135     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
136     ///
137     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
138     ///
139     int getMaxWidth(Painter &, UpdatableInset const *) const;
140     ///
141     void init(InsetText const * ins = 0);
142     ///
143     void WriteParagraphData(Buffer const *, std::ostream &) const;
144     ///
145     void SetParagraphData(LyXParagraph *);
146     ///
147     void SetAutoBreakRows(bool);
148     ///
149     void SetDrawFrame(BufferView *, DrawFrame);
150     ///
151     void SetFrameColor(BufferView *, LColor::color);
152     ///
153 //    LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
154     ///
155     LyXText * getLyXText(BufferView *) const;
156     void deleteLyXText(BufferView *, bool recursive=true) const;
157     void resizeLyXText(BufferView *) const;
158
159     LyXParagraph * par;
160     ///
161     mutable UpdateCodes need_update;
162
163 protected:
164     ///
165     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
166
167     mutable int drawTextXOffset;
168     mutable int drawTextYOffset;
169     ///
170     bool autoBreakRows;
171     DrawFrame drawFrame;
172     ///
173     LColor::color frame_color;
174
175 private:
176     ///
177     typedef std::map<BufferView *, LyXText *> Cache;
178     ///
179     typedef Cache::value_type value_type;
180     ///
181     int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
182     ///
183     void ShowInsetCursor(BufferView *);
184     ///
185     void HideInsetCursor(BufferView *);
186     ///
187     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
188     ///
189     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
190     ///
191     UpdatableInset::RESULT moveUp(BufferView *);
192     ///
193     UpdatableInset::RESULT moveDown(BufferView *);
194     ///
195     void SetCharFont(Buffer const *, int pos, LyXFont const & font);
196     ///
197     string getText(int);
198     ///
199     bool checkAndActivateInset(BufferView * bv, bool behind);
200     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
201                                int button = 0);
202     ///
203     int cx(BufferView *) const;
204     int cy(BufferView *) const;
205     int cpos(BufferView *) const;
206     LyXParagraph * cpar(BufferView *) const;
207     Row * crow(BufferView *) const;
208
209     /// This instead of a macro
210     LyXText * TEXT(BufferView * bv) const {
211         return getLyXText(bv);
212     }
213         
214     /* Private structures and variables */
215     ///
216     mutable bool locked;
217     ///
218     mutable int insetAscent;
219     mutable int insetDescent;
220     mutable int insetWidth;
221     mutable int last_width;
222     mutable int last_height;
223     mutable int top_y;
224     ///
225     LyXParagraph * inset_par;
226     ///
227     int inset_pos;
228     ///
229     mutable int inset_x;
230     ///
231     mutable int inset_y;
232     ///
233     int interline_space;
234     ///
235     bool no_selection;
236     ///
237     mutable float xpos;
238     ///
239     UpdatableInset * the_locking_inset;
240     ///
241     LyXParagraph * old_par;
242     /// The cache.
243     mutable Cache cache;
244 };
245 #endif