]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
8107cba39e9413af33a4008dcdfca27da18d0818
[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 "LString.h"
23 #include "lyxcursor.h"
24
25 class Painter;
26 class BufferView;
27 class Buffer;
28 class LyXCursor;
29 class LyXParagraph;
30 class LColor;
31
32 /** A text inset is like a TeX box
33   
34   To write full text (including styles and other insets) in a given
35   space. 
36 */
37 class InsetText : public UpdatableInset {
38 public:
39     ///
40     enum { TEXT_TO_INSET_OFFSET = 2 };
41     ///
42     explicit
43     InsetText(Buffer *);
44     ///
45     InsetText(InsetText const &, Buffer *);
46     ///
47     ~InsetText();
48     ///
49     Inset * Clone() const;
50     ///
51     void clear() const { par->clearContents(); }
52     ///
53     void Read(LyXLex &);
54     ///
55     void Write(std::ostream &) const;
56     ///
57     int ascent(Painter &, LyXFont const &) const;
58     ///
59     int descent(Painter &, LyXFont const &) const;
60     ///
61     int width(Painter &, LyXFont const & f) const;
62     ///
63     void draw(Painter & pain, LyXFont const &, int , float &) const;
64     ///
65     char const * EditMessage() const;
66     ///
67     void Edit(BufferView *, int, int, unsigned int);
68     ///
69     void InsetUnlock(BufferView *);
70     ///
71     bool LockInsetInInset(BufferView *, UpdatableInset *);
72     ///
73     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
74     ///
75     bool UpdateInsetInInset(BufferView *, Inset *);
76     ///
77     void InsetButtonRelease(BufferView *, int, int, int);
78     ///
79     void InsetButtonPress(BufferView *, int, int, int);
80     ///
81     void InsetMotionNotify(BufferView *, int, int, int);
82     ///
83     void InsetKeyPress(XKeyEvent *);
84     ///
85     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
86     ///
87     int Latex(std::ostream &, bool fragile, bool free_spc) const;
88     ///
89     int Ascii(std::ostream &) const { return 0; }
90     ///
91     int Linuxdoc(std::ostream &) const { return 0; }
92     ///
93     int DocBook(std::ostream &) const { return 0; }
94     ///
95     void Validate(LaTeXFeatures & features) const;
96     ///
97     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
98     ///
99     void GetCursorPos(int & x, int & y) const;
100     ///
101     int InsetInInsetY();
102     ///
103     void ToggleInsetCursor(BufferView *);
104     ///
105     bool InsertInset(BufferView *, Inset *);
106     ///
107     UpdatableInset * GetLockingInset();
108     ///
109     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
110     ///
111     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
112     ///
113     void init(Buffer *, InsetText const * ins = 0);
114     ///
115     void SetParagraphData(LyXParagraph *);
116     ///
117     void SetAutoBreakRows(bool);
118     ///
119     void SetDrawLockedFrame(bool);
120     ///
121     void SetFrameColor(LColor::color);
122     ///
123     void computeTextRows(Painter &) const;
124
125     LyXParagraph * par;
126
127 protected:
128     ///
129     void UpdateLocal(BufferView *, bool);
130     ///
131     void WriteParagraphData(std::ostream &) const;
132     ///
133     void resetPos(Painter &) const;
134     ///
135     void drawSelection(Painter &, int pos, int baseline, float x);
136     ///
137     void SingleHeight(Painter &, LyXParagraph * par,int pos,
138                       int & asc, int & desc) const;
139     ///
140     int SingleWidth(Painter &, LyXParagraph * par, int pos) const;
141     ///
142     LyXFont GetFont(LyXParagraph * par, int pos) const;
143     ///
144     virtual LyXFont GetDrawFont(LyXParagraph * par, int pos) const;
145     ///
146     virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
147
148     Buffer * buffer;
149     ///
150     LyXFont current_font;
151     ///
152     LyXFont real_current_font;
153     ///
154     mutable int maxAscent;
155     ///
156     mutable int maxDescent;
157     ///
158     mutable int insetWidth;
159     ///
160     mutable int drawTextXOffset;
161     mutable int drawTextYOffset;
162     ///
163     bool autoBreakRows;
164     bool drawLockedFrame;
165     ///
166     LColor::color frame_color;
167
168 private:
169     ///
170     void drawRowSelection(Painter &, int startpos, int endpos, int row,
171                           int baseline, float x) const;
172     ///
173     void drawRowText(Painter &, int startpos, int endpos, int baseline,
174                      float x) const;
175     ///
176     void computeBaselines(int) const;
177     ///
178     int BeginningOfMainBody(LyXParagraph * par) const;
179     ///
180     void ShowInsetCursor(BufferView *);
181     ///
182     void HideInsetCursor(BufferView *);
183     ///
184     void setPos(Painter &, int x, int y) const;
185     ///
186     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
187         ///
188     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
189         ///
190     UpdatableInset::RESULT moveUp(BufferView *);
191         ///
192     UpdatableInset::RESULT moveDown(BufferView *);
193         ///
194     bool Delete();
195         ///
196     bool cutSelection();
197         ///
198     bool copySelection();
199         ///
200     bool pasteSelection();
201     ///
202     bool hasSelection() const
203                 { return (selection_start_cursor != selection_end_cursor); }
204     ///
205     void SetCharFont(int pos, LyXFont const & font);
206     ///
207     string getText(int);
208     ///
209     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
210                                int button = 0);
211         
212     /* Private structures and variables */
213     ///
214     bool locked;
215     ///
216     int inset_pos;
217     ///
218     mutable int inset_x;
219     ///
220     mutable int inset_y;
221     ///
222     int interline_space;
223     ///
224     LyXCursor selection_start_cursor;
225     ///
226     LyXCursor selection_end_cursor;
227     ///
228     mutable LyXCursor cursor;
229     ///
230     mutable LyXCursor old_cursor;
231     ///
232     mutable int actrow;
233     ///
234     bool no_selection;
235     ///
236     mutable float xpos;
237     ///
238     mutable bool init_inset;
239     ///
240     UpdatableInset * the_locking_inset;
241     ///
242     struct row_struct {
243         ///
244         int asc;
245         ///
246         int desc;
247         ///
248         int pos;
249         ///
250         int baseline;
251     };
252     ///
253     typedef std::vector<row_struct> RowList;
254     ///
255     mutable RowList rows;
256         ///
257     InsetText & operator = (InsetText const & it) {
258         par = it.par;
259         buffer = it.buffer; // suspect
260         current_font = it.current_font;
261         real_current_font = it.real_current_font;
262         maxAscent = it.maxAscent;
263         maxDescent = it.maxDescent;
264         insetWidth = it.insetWidth;
265         inset_pos = it.inset_pos;
266         inset_x = it.inset_x;
267         inset_y = it.inset_y;
268         interline_space = it.interline_space;
269         selection_start_cursor = selection_end_cursor = cursor = it.cursor;
270         actrow = it.actrow;
271         no_selection = it.no_selection;
272         the_locking_inset = it.the_locking_inset; // suspect
273         rows = it.rows;
274         return * this;
275     }
276 };
277 #endif