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