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