]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
some using changes small changes in lyxfont and some other things, read the Changelog
[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     LyXParagraph * par;
106
107 protected:
108     ///
109     void UpdateLocal(BufferView *, bool);
110     ///
111     void WriteParagraphData(ostream &) const;
112     ///
113     void resetPos(BufferView *);
114     ///
115     void drawSelection(Painter &, int pos, int baseline, float x);
116     ///
117     void SingleHeight(Painter &, LyXParagraph * par,int pos,
118                       int & asc, int & desc) const;
119     ///
120     int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
121     ///
122     LyXFont GetFont(LyXParagraph * par, int pos) const;
123
124     Buffer * buffer;
125     ///
126     LyXFont current_font;
127     ///
128     LyXFont real_current_font;
129     ///
130     mutable int maxWidth;
131     ///
132     mutable int maxAscent;
133     ///
134     mutable int maxDescent;
135     ///
136     mutable int insetWidth;
137     ///
138     int widthOffset;
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 &, float x = 0.0) 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     bool cutSelection();
168     bool copySelection();
169     bool pasteSelection();
170     ///
171     bool hasSelection() const { return selection_start != selection_end; }
172     ///
173     void SetCharFont(int pos, LyXFont const & font);
174     ///
175     string getText(int);
176         
177     /* Private structures and variables */
178     ///
179     int inset_pos;
180     ///
181     int inset_x;
182     ///
183     int inset_y;
184     ///
185     int interline_space;
186     ///
187     int selection_start;
188     ///
189     int selection_end;
190     ///
191     int old_x;
192     ///
193     int cx;
194     ///
195     int cy;
196     ///
197     int actpos;
198     ///
199     int actrow;
200     ///
201     bool no_selection;
202     ///
203     mutable float xpos;
204     ///
205     mutable bool init_inset;
206     ///
207     UpdatableInset * the_locking_inset;
208     ///
209     struct row_struct {
210         ///
211         int asc;
212         ///
213         int desc;
214         ///
215         int pos;
216         ///
217         int baseline;
218     };
219     ///
220     typedef vector<row_struct> RowList;
221     ///
222     mutable RowList rows;
223     InsetText & operator = (InsetText const & it) {
224         par = it.par;
225         buffer = it.buffer; // suspect
226         current_font = it.current_font;
227         real_current_font = it.real_current_font;
228         maxWidth = it.maxWidth;
229         maxAscent = it.maxAscent;
230         maxDescent = it.maxDescent;
231         insetWidth = it.insetWidth;
232         inset_pos = it.inset_pos;
233         inset_x = it.inset_x;
234         inset_y = it.inset_y;
235         interline_space = it.interline_space;
236         selection_start = it.selection_start;
237         selection_end = it.selection_end;
238         old_x = it.old_x;
239         cx = it.cx;
240         cy = it.cy;
241         actpos = it.actpos;
242         actrow = it.actrow;
243         no_selection = it.no_selection;
244         the_locking_inset = it.the_locking_inset; // suspect
245         rows = it.rows;
246         return * this;
247     }
248 };
249 #endif