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