]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
Fixed the display bug for text-insets we still had and now ERT-insets do
[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 "lyxparagraph.h"
23 #include "LString.h"
24 #include "buffer.h"
25
26 class Painter;
27 class BufferView;
28
29 /** A text inset is like a TeX box
30   
31   To write full text (including styles and other insets) in a given
32   space. 
33 */
34 class InsetText : public UpdatableInset {
35 public:
36         ///
37         enum { TEXT_TO_INSET_OFFSET = 1 };
38     ///
39     InsetText(Buffer *);
40     ///
41     InsetText(InsetText const &, Buffer *);
42     ///
43     ~InsetText();
44     ///
45     Inset * Clone() const;
46     ///
47     void Read(LyXLex &);
48     ///
49     void Write(ostream &) const;
50     ///
51     int ascent(Painter &, LyXFont const &) const;
52     ///
53     int descent(Painter &, LyXFont const &) const;
54     ///
55     int width(Painter &, LyXFont const & f) const;
56     ///
57     int getMaxWidth(UpdatableInset *) const;
58     ///
59     void draw(Painter & pain, LyXFont const &, int , float &) const;
60     ///
61     char const * EditMessage() const;
62     ///
63     void Edit(BufferView *, int, int, unsigned int);
64     ///
65     void InsetUnlock(BufferView *);
66     ///
67     bool UnlockInsetInInset(BufferView *, Inset *, bool lr = false);
68     ///
69     //void UpdateLocal(bool flag=true);
70     ///
71     bool UpdateInsetInInset(BufferView *, Inset *);
72     ///
73     void InsetButtonRelease(BufferView *, int, int, int);
74     ///
75     void InsetButtonPress(BufferView *, int, int, int);
76     ///
77     void InsetMotionNotify(BufferView *, int, int, int);
78     ///
79     void InsetKeyPress(XKeyEvent *);
80     ///
81     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
82     ///
83     int Latex(ostream &, signed char) const;
84 #ifndef USE_OSTREAM_ONLY
85     ///
86     int Latex(string &, signed char) const;
87 #endif
88     ///
89     int Linuxdoc(string &) const { return 0; }
90     ///
91     int DocBook(string &) const { return 0; }
92     ///
93     void Validate(LaTeXFeatures & features) const;
94     ///
95     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
96     ///
97     void GetCursorPos(int & x, int & y) const;
98     ///
99     int InsetInInsetY();
100     ///
101     void ToggleInsetCursor(BufferView *);
102     ///
103     bool InsertInset(BufferView *, Inset *);
104     ///
105     UpdatableInset * GetLockingInset();
106     ///
107     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
108
109     LyXParagraph * par;
110
111 protected:
112     ///
113     void WriteParagraphData(ostream &) const;
114     ///
115     void resetPos(BufferView *);
116     ///
117     void drawSelection(Painter &, int pos, int baseline, float x);
118     ///
119     void SingleHeight(Painter &, LyXParagraph * par,int pos,
120                       int & asc, int & desc) const;
121     ///
122     int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
123     ///
124     LyXFont GetFont(LyXParagraph * par, int pos) const;
125     ///
126     Buffer * buffer;
127     ///
128     LyXFont current_font;
129     ///
130     LyXFont real_current_font;
131     ///
132     mutable int maxWidth;
133     ///
134     mutable int maxAscent;
135     ///
136     mutable int maxDescent;
137     ///
138     mutable int insetWidth;
139     ///
140     bool autoBreakRows;
141
142 private:
143     ///
144     void drawRowSelection(Painter &, int startpos, int endpos, int row,
145                           int baseline, float x) const;
146     ///
147     void drawRowText(Painter &, int startpos, int endpos, int baseline,
148                      float x) const;
149     ///
150     void computeTextRows(Painter &) const;
151     ///
152     void computeBaselines(int) const;
153     ///
154     int BeginningOfMainBody(LyXParagraph * par) const;
155     ///
156     void ShowInsetCursor(BufferView *);
157     ///
158     void HideInsetCursor(BufferView *);
159     ///
160     void setPos(BufferView *, int x, int y, bool activate_inset = true);
161     ///
162     bool moveRight(BufferView *, bool activate_inset = true);
163     bool moveLeft(BufferView *, bool activate_inset = true);
164     bool moveUp(BufferView *, bool activate_inset = true);
165     bool moveDown(BufferView *, bool activate_inset = true);
166     bool Delete();
167     ///
168     bool hasSelection() const { return selection_start != selection_end; }
169     ///
170     void SetCharFont(int pos, LyXFont const & font);
171     ///
172     string getText(int);
173         
174     /* Private structures and variables */
175     ///
176     int inset_pos;
177     ///
178     int inset_x;
179     ///
180     int inset_y;
181     ///
182     int interline_space;
183     ///
184     int selection_start;
185     ///
186     int selection_end;
187     ///
188     int old_x;
189     ///
190     int cx;
191     ///
192     int cy;
193     ///
194     int actpos;
195     ///
196     int actrow;
197     ///
198     bool no_selection;
199     ///
200     mutable bool init_inset;
201     ///
202     UpdatableInset * the_locking_inset;
203     ///
204     struct row_struct {
205         ///
206         int asc;
207         ///
208         int desc;
209         ///
210         int pos;
211         ///
212         int baseline;
213     };
214     ///
215     typedef vector<row_struct> RowList;
216     ///
217     mutable RowList rows;
218     InsetText & operator = (InsetText const & it) {
219         par = it.par;
220         buffer = it.buffer; // suspect
221         current_font = it.current_font;
222         real_current_font = it.real_current_font;
223         maxWidth = it.maxWidth;
224         maxAscent = it.maxAscent;
225         maxDescent = it.maxDescent;
226         insetWidth = it.insetWidth;
227         inset_pos = it.inset_pos;
228         inset_x = it.inset_x;
229         inset_y = it.inset_y;
230         interline_space = it.interline_space;
231         selection_start = it.selection_start;
232         selection_end = it.selection_end;
233         old_x = it.old_x;
234         cx = it.cx;
235         cy = it.cy;
236         actpos = it.actpos;
237         actrow = it.actrow;
238         no_selection = it.no_selection;
239         the_locking_inset = it.the_locking_inset; // suspect
240         rows = it.rows;
241         return * this;
242     }
243 };
244 #endif