]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
f3e88c38dadfa72989d1eab7dae9067e13dfd683
[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         explicit
41     InsetText(Buffer *);
42     ///
43     InsetText(InsetText const &, Buffer *);
44     ///
45     ~InsetText();
46     ///
47     Inset * Clone() const;
48     ///
49     void Read(LyXLex &);
50     ///
51     void Write(std::ostream &) const;
52     ///
53     int ascent(Painter &, LyXFont const &) const;
54     ///
55     int descent(Painter &, LyXFont const &) const;
56     ///
57     int width(Painter &, LyXFont const & f) const;
58     ///
59     void draw(Painter & pain, LyXFont const &, int , float &) const;
60     ///
61     char const * 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     bool UpdateInsetInInset(BufferView *, Inset *);
70     ///
71     void InsetButtonRelease(BufferView *, int, int, int);
72     ///
73     void InsetButtonPress(BufferView *, int, int, int);
74     ///
75     void InsetMotionNotify(BufferView *, int, int, int);
76     ///
77     void InsetKeyPress(XKeyEvent *);
78     ///
79     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
80     ///
81     int Latex(std::ostream &, bool fragile, bool free_spc) const;
82     ///
83     int Linuxdoc(std::ostream &) const { return 0; }
84     ///
85     int DocBook(std::ostream &) const { return 0; }
86     ///
87     void Validate(LaTeXFeatures & features) const;
88     ///
89     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
90     ///
91     void GetCursorPos(int & x, int & y) const;
92     ///
93     int InsetInInsetY();
94     ///
95     void ToggleInsetCursor(BufferView *);
96     ///
97     bool InsertInset(BufferView *, Inset *);
98     ///
99     UpdatableInset * GetLockingInset();
100     ///
101     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
102     ///
103     void init(Buffer *, InsetText const * ins = 0);
104
105     LyXParagraph * par;
106
107 protected:
108     ///
109     void UpdateLocal(BufferView *, bool);
110     ///
111     void WriteParagraphData(std::ostream &) const;
112     ///
113     void resetPos(BufferView *, bool setfont=false);
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     virtual LyXFont GetDrawFont(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 std::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