]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
0dd6361172fc4c18815b84cd43130779c5241ffe
[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(std::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(std::ostream &, signed char, bool free_spc) const;
81     ///
82     int Linuxdoc(std::ostream &) const { return 0; }
83     ///
84     int DocBook(std::ostream &) const { return 0; }
85     ///
86     void Validate(LaTeXFeatures & features) const;
87     ///
88     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
89     ///
90     void GetCursorPos(int & x, int & y) const;
91     ///
92     int InsetInInsetY();
93     ///
94     void ToggleInsetCursor(BufferView *);
95     ///
96     bool InsertInset(BufferView *, Inset *);
97     ///
98     UpdatableInset * GetLockingInset();
99     ///
100     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
101     ///
102     void init(Buffer *, LyXParagraph * p = 0);
103
104     LyXParagraph * par;
105
106 protected:
107     ///
108     void UpdateLocal(BufferView *, bool);
109     ///
110     void WriteParagraphData(std::ostream &) const;
111     ///
112     void resetPos(BufferView *);
113     ///
114     void drawSelection(Painter &, int pos, int baseline, float x);
115     ///
116     void SingleHeight(Painter &, LyXParagraph * par,int pos,
117                       int & asc, int & desc) const;
118     ///
119     int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
120     ///
121     LyXFont GetFont(LyXParagraph * par, int pos) const;
122
123     Buffer * buffer;
124     ///
125     LyXFont current_font;
126     ///
127     LyXFont real_current_font;
128     ///
129     mutable int maxWidth;
130     ///
131     mutable int maxAscent;
132     ///
133     mutable int maxDescent;
134     ///
135     mutable int insetWidth;
136     ///
137     int widthOffset;
138     ///
139     bool autoBreakRows;
140
141 private:
142     ///
143     void drawRowSelection(Painter &, int startpos, int endpos, int row,
144                           int baseline, float x) const;
145     ///
146     void drawRowText(Painter &, int startpos, int endpos, int baseline,
147                      float x) const;
148     ///
149     void computeTextRows(Painter &, float x = 0.0) const;
150     ///
151     void computeBaselines(int) const;
152     ///
153     int BeginningOfMainBody(LyXParagraph * par) const;
154     ///
155     void ShowInsetCursor(BufferView *);
156     ///
157     void HideInsetCursor(BufferView *);
158     ///
159     void setPos(BufferView *, int x, int y, bool activate_inset = true);
160     ///
161     bool moveRight(BufferView *, bool activate_inset = true);
162     bool moveLeft(BufferView *, bool activate_inset = true);
163     bool moveUp(BufferView *, bool activate_inset = true);
164     bool moveDown(BufferView *, bool activate_inset = true);
165     bool Delete();
166     bool cutSelection();
167     bool copySelection();
168     bool pasteSelection();
169     ///
170     bool hasSelection() const { return selection_start != selection_end; }
171     ///
172     void SetCharFont(int pos, LyXFont const & font);
173     ///
174     string getText(int);
175         
176     /* Private structures and variables */
177     ///
178     int inset_pos;
179     ///
180     int inset_x;
181     ///
182     int inset_y;
183     ///
184     int interline_space;
185     ///
186     int selection_start;
187     ///
188     int selection_end;
189     ///
190     int old_x;
191     ///
192     int cx;
193     ///
194     int cy;
195     ///
196     int actpos;
197     ///
198     int actrow;
199     ///
200     bool no_selection;
201     ///
202     mutable float xpos;
203     ///
204     mutable bool init_inset;
205     ///
206     UpdatableInset * the_locking_inset;
207     ///
208     struct row_struct {
209         ///
210         int asc;
211         ///
212         int desc;
213         ///
214         int pos;
215         ///
216         int baseline;
217     };
218     ///
219     typedef std::vector<row_struct> RowList;
220     ///
221     mutable RowList rows;
222     InsetText & operator = (InsetText const & it) {
223         par = it.par;
224         buffer = it.buffer; // suspect
225         current_font = it.current_font;
226         real_current_font = it.real_current_font;
227         maxWidth = it.maxWidth;
228         maxAscent = it.maxAscent;
229         maxDescent = it.maxDescent;
230         insetWidth = it.insetWidth;
231         inset_pos = it.inset_pos;
232         inset_x = it.inset_x;
233         inset_y = it.inset_y;
234         interline_space = it.interline_space;
235         selection_start = it.selection_start;
236         selection_end = it.selection_end;
237         old_x = it.old_x;
238         cx = it.cx;
239         cy = it.cy;
240         actpos = it.actpos;
241         actrow = it.actrow;
242         no_selection = it.no_selection;
243         the_locking_inset = it.the_locking_inset; // suspect
244         rows = it.rows;
245         return * this;
246     }
247 };
248 #endif