]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
85067aab78cde83d96704402edbb0dce188489f4
[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 using std::ostream;
27 using std::vector;
28
29 class Painter;
30 class BufferView;
31 class Buffer;
32
33 /** A text inset is like a TeX box
34   
35   To write full text (including styles and other insets) in a given
36   space. 
37 */
38 class InsetText : public UpdatableInset {
39 public:
40         ///
41         enum { TEXT_TO_INSET_OFFSET = 1 };
42     ///
43     InsetText(Buffer *);
44     ///
45     InsetText(InsetText const &, Buffer *);
46     ///
47     ~InsetText();
48     ///
49     Inset * Clone() const;
50     ///
51     void Read(LyXLex &);
52     ///
53     void Write(ostream &) const;
54     ///
55     int ascent(Painter &, LyXFont const &) const;
56     ///
57     int descent(Painter &, LyXFont const &) const;
58     ///
59     int width(Painter &, LyXFont const & f) const;
60     ///
61     void draw(Painter & pain, LyXFont const &, int , float &) const;
62     ///
63     char const * EditMessage() const;
64     ///
65     void Edit(BufferView *, int, int, unsigned int);
66     ///
67     void InsetUnlock(BufferView *);
68     ///
69     bool UnlockInsetInInset(BufferView *, Inset *, bool lr = false);
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, bool free_spc) const;
84     ///
85     int Linuxdoc(ostream &) const { return 0; }
86     ///
87     int DocBook(ostream &) const { return 0; }
88     ///
89     void Validate(LaTeXFeatures & features) const;
90     ///
91     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
92     ///
93     void GetCursorPos(int & x, int & y) const;
94     ///
95     int InsetInInsetY();
96     ///
97     void ToggleInsetCursor(BufferView *);
98     ///
99     bool InsertInset(BufferView *, Inset *);
100     ///
101     UpdatableInset * GetLockingInset();
102     ///
103     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
104     ///
105     void init(Buffer *, LyXParagraph * p = 0);
106
107     LyXParagraph * par;
108
109 protected:
110     ///
111     void UpdateLocal(BufferView *, bool);
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     int widthOffset;
141     ///
142     bool autoBreakRows;
143
144 private:
145     ///
146     void drawRowSelection(Painter &, int startpos, int endpos, int row,
147                           int baseline, float x) const;
148     ///
149     void drawRowText(Painter &, int startpos, int endpos, int baseline,
150                      float x) const;
151     ///
152     void computeTextRows(Painter &, float x = 0.0) const;
153     ///
154     void computeBaselines(int) const;
155     ///
156     int BeginningOfMainBody(LyXParagraph * par) const;
157     ///
158     void ShowInsetCursor(BufferView *);
159     ///
160     void HideInsetCursor(BufferView *);
161     ///
162     void setPos(BufferView *, int x, int y, bool activate_inset = true);
163     ///
164     bool moveRight(BufferView *, bool activate_inset = true);
165     bool moveLeft(BufferView *, bool activate_inset = true);
166     bool moveUp(BufferView *, bool activate_inset = true);
167     bool moveDown(BufferView *, bool activate_inset = true);
168     bool Delete();
169     bool cutSelection();
170     bool copySelection();
171     bool pasteSelection();
172     ///
173     bool hasSelection() const { return selection_start != selection_end; }
174     ///
175     void SetCharFont(int pos, LyXFont const & font);
176     ///
177     string getText(int);
178         
179     /* Private structures and variables */
180     ///
181     int inset_pos;
182     ///
183     int inset_x;
184     ///
185     int inset_y;
186     ///
187     int interline_space;
188     ///
189     int selection_start;
190     ///
191     int selection_end;
192     ///
193     int old_x;
194     ///
195     int cx;
196     ///
197     int cy;
198     ///
199     int actpos;
200     ///
201     int actrow;
202     ///
203     bool no_selection;
204     ///
205     mutable float xpos;
206     ///
207     mutable bool init_inset;
208     ///
209     UpdatableInset * the_locking_inset;
210     ///
211     struct row_struct {
212         ///
213         int asc;
214         ///
215         int desc;
216         ///
217         int pos;
218         ///
219         int baseline;
220     };
221     ///
222     typedef vector<row_struct> RowList;
223     ///
224     mutable RowList rows;
225     InsetText & operator = (InsetText const & it) {
226         par = it.par;
227         buffer = it.buffer; // suspect
228         current_font = it.current_font;
229         real_current_font = it.real_current_font;
230         maxWidth = it.maxWidth;
231         maxAscent = it.maxAscent;
232         maxDescent = it.maxDescent;
233         insetWidth = it.insetWidth;
234         inset_pos = it.inset_pos;
235         inset_x = it.inset_x;
236         inset_y = it.inset_y;
237         interline_space = it.interline_space;
238         selection_start = it.selection_start;
239         selection_end = it.selection_end;
240         old_x = it.old_x;
241         cx = it.cx;
242         cy = it.cy;
243         actpos = it.actpos;
244         actrow = it.actrow;
245         no_selection = it.no_selection;
246         the_locking_inset = it.the_locking_inset; // suspect
247         rows = it.rows;
248         return * this;
249     }
250 };
251 #endif