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