]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
e6544af41d9f37e00939ac9a689127f0c79c7a5c
[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
32 /** A text inset is like a TeX box
33   
34   To write full text (including styles and other insets) in a given
35   space. 
36 */
37 class InsetText : public UpdatableInset {
38 public:
39     ///
40     enum { TEXT_TO_INSET_OFFSET = 2 };
41     ///
42     explicit
43     InsetText(Buffer *);
44     ///
45     InsetText(InsetText const &, Buffer *);
46     ///
47     ~InsetText();
48     ///
49     Inset * Clone() const;
50     ///
51     void clear() const { par->clearContents(); }
52     ///
53     void Read(LyXLex &);
54     ///
55     void Write(std::ostream &) const;
56     ///
57     int ascent(Painter &, LyXFont const &) const;
58     ///
59     int descent(Painter &, LyXFont const &) const;
60     ///
61     int width(Painter &, LyXFont const & f) const;
62     ///
63     void draw(Painter & pain, LyXFont const &, int , float &) const;
64     ///
65     char const * EditMessage() const;
66     ///
67     void Edit(BufferView *, int, int, unsigned int);
68     ///
69     void InsetUnlock(BufferView *);
70     ///
71     bool LockInsetInInset(BufferView *, UpdatableInset *);
72     ///
73     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
74     ///
75     bool UpdateInsetInInset(BufferView *, Inset *);
76     ///
77     void InsetButtonRelease(BufferView *, int, int, int);
78     ///
79     void InsetButtonPress(BufferView *, int, int, int);
80     ///
81     void InsetMotionNotify(BufferView *, int, int, int);
82     ///
83     void InsetKeyPress(XKeyEvent *);
84     ///
85     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
86     ///
87     int Latex(std::ostream &, bool fragile, bool free_spc) const;
88     ///
89     int Ascii(std::ostream &) const { return 0; }
90     ///
91     int Linuxdoc(std::ostream &) const { return 0; }
92     ///
93     int DocBook(std::ostream &) const { return 0; }
94     ///
95     void Validate(LaTeXFeatures & features) const;
96     ///
97     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
98     ///
99     void GetCursorPos(int & x, int & y) const;
100     ///
101     int InsetInInsetY();
102     ///
103     void ToggleInsetCursor(BufferView *);
104     ///
105     bool InsertInset(BufferView *, Inset *);
106     ///
107     UpdatableInset * GetLockingInset();
108     ///
109     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
110     ///
111     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
112     ///
113     void init(Buffer *, InsetText const * ins = 0);
114     ///
115     void SetParagraphData(LyXParagraph *);
116     ///
117     void SetAutoBreakRows(bool);
118     ///
119     void SetDrawLockedFrame(bool);
120     ///
121     void SetFrameColor(LColor::color);
122     ///
123     void computeTextRows(Painter &) const;
124     ///
125     Buffer * BufferOwner() const { return buffer; }
126
127     LyXParagraph * par;
128
129 protected:
130     ///
131     void UpdateLocal(BufferView *, bool);
132     ///
133     void WriteParagraphData(std::ostream &) const;
134     ///
135     void resetPos(Painter &) const;
136     ///
137     void drawSelection(Painter &, int pos, int baseline, float x);
138     ///
139     void SingleHeight(Painter &, LyXParagraph * par,int pos,
140                       int & asc, int & desc) const;
141     ///
142     int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
143     ///
144     LyXFont GetFont(LyXParagraph * par, int pos) const;
145     ///
146     virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
147     ///
148     virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
149
150     Buffer * buffer;
151     ///
152     LyXFont current_font;
153     ///
154     LyXFont real_current_font;
155     ///
156     mutable int maxAscent;
157     ///
158     mutable int maxDescent;
159     ///
160     mutable int insetWidth;
161     ///
162     mutable int drawTextXOffset;
163     mutable int drawTextYOffset;
164     ///
165     bool autoBreakRows;
166     bool drawLockedFrame;
167     ///
168     LColor::color frame_color;
169
170 private:
171     ///
172     void drawRowSelection(Painter &, int startpos, int endpos, int row,
173                           int baseline, float x) const;
174     ///
175     void drawRowText(Painter &, int startpos, int endpos, int baseline,
176                      float x) const;
177     ///
178     void computeBaselines(int) const;
179     ///
180     int BeginningOfMainBody(LyXParagraph * par) const;
181     ///
182     void ShowInsetCursor(BufferView *);
183     ///
184     void HideInsetCursor(BufferView *);
185     ///
186     void setPos(Painter &, int x, int y) const;
187     ///
188     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
189         ///
190     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
191         ///
192     UpdatableInset::RESULT moveUp(BufferView *);
193         ///
194     UpdatableInset::RESULT moveDown(BufferView *);
195         ///
196     bool Delete();
197         ///
198     bool cutSelection();
199         ///
200     bool copySelection();
201         ///
202     bool pasteSelection();
203     ///
204     bool hasSelection() const
205                 { return (selection_start_cursor != selection_end_cursor); }
206     ///
207     void SetCharFont(int pos, LyXFont const & font);
208     ///
209     string getText(int);
210     ///
211     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
212                                int button = 0);
213         
214     /* Private structures and variables */
215     ///
216     bool locked;
217     ///
218     int inset_pos;
219     ///
220     mutable int inset_x;
221     ///
222     mutable int inset_y;
223     ///
224     int interline_space;
225     ///
226     LyXCursor selection_start_cursor;
227     ///
228     LyXCursor selection_end_cursor;
229     ///
230     mutable LyXCursor cursor;
231     ///
232     mutable LyXCursor old_cursor;
233     ///
234     mutable int actrow;
235     ///
236     bool no_selection;
237     ///
238     mutable float xpos;
239     ///
240     mutable bool init_inset;
241     ///
242     UpdatableInset * the_locking_inset;
243     ///
244     struct row_struct {
245         ///
246         int asc;
247         ///
248         int desc;
249         ///
250         int pos;
251         ///
252         int baseline;
253     };
254     ///
255     typedef std::vector<row_struct> RowList;
256     ///
257     mutable RowList rows;
258         ///
259     InsetText & operator = (InsetText const & it) {
260         par = it.par;
261         buffer = it.buffer; // suspect
262         current_font = it.current_font;
263         real_current_font = it.real_current_font;
264         maxAscent = it.maxAscent;
265         maxDescent = it.maxDescent;
266         insetWidth = it.insetWidth;
267         inset_pos = it.inset_pos;
268         inset_x = it.inset_x;
269         inset_y = it.inset_y;
270         interline_space = it.interline_space;
271         selection_start_cursor = selection_end_cursor = cursor = it.cursor;
272         actrow = it.actrow;
273         no_selection = it.no_selection;
274         the_locking_inset = it.the_locking_inset; // suspect
275         rows = it.rows;
276         return * this;
277     }
278 };
279 #endif