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