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