]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
54efee5a404a4ab115e761d2721aeff008df95bb
[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() const { par->clearContents(); }
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 *) const;
157
158     LyXParagraph * par;
159     ///
160     mutable UpdateCodes need_update;
161
162 protected:
163     ///
164     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
165
166     mutable int drawTextXOffset;
167     mutable int drawTextYOffset;
168     ///
169     bool autoBreakRows;
170     DrawFrame drawFrame;
171     ///
172     LColor::color frame_color;
173
174 private:
175     ///
176     typedef std::map<BufferView *, LyXText *> Cache;
177     ///
178     typedef Cache::value_type value_type;
179     ///
180     int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
181     ///
182     void ShowInsetCursor(BufferView *);
183     ///
184     void HideInsetCursor(BufferView *);
185     ///
186     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
187     ///
188     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
189     ///
190     UpdatableInset::RESULT moveUp(BufferView *);
191     ///
192     UpdatableInset::RESULT moveDown(BufferView *);
193     ///
194     void SetCharFont(Buffer const *, int pos, LyXFont const & font);
195     ///
196     string getText(int);
197     ///
198     bool checkAndActivateInset(BufferView * bv, bool behind);
199     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
200                                int button = 0);
201     ///
202     int cx(BufferView *) const;
203     int cy(BufferView *) const;
204     int cpos(BufferView *) const;
205     LyXParagraph * cpar(BufferView *) const;
206     Row * crow(BufferView *) const;
207
208     /// This instead of a macro
209     LyXText * TEXT(BufferView * bv) const {
210         return getLyXText(bv);
211     }
212         
213     /* Private structures and variables */
214     ///
215     mutable bool locked;
216     ///
217     mutable int insetAscent;
218     mutable int insetDescent;
219     mutable int insetWidth;
220     mutable int last_width;
221     mutable int last_height;
222     mutable int top_y;
223     ///
224     LyXParagraph * inset_par;
225     ///
226     int inset_pos;
227     ///
228     mutable int inset_x;
229     ///
230     mutable int inset_y;
231     ///
232     int interline_space;
233     ///
234     bool no_selection;
235     ///
236     mutable float xpos;
237     ///
238     UpdatableInset * the_locking_inset;
239     ///
240     LyXParagraph * old_par;
241     /// The cache.
242     mutable Cache cache;
243 };
244 #endif