]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
af481dec57d6900dcfab1bb3ab4dc81a1fb8b86a
[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     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
188     UpdatableInset::RESULT moveUp(BufferView *);
189     UpdatableInset::RESULT moveDown(BufferView *);
190     bool Delete();
191     bool cutSelection();
192     bool copySelection();
193     bool pasteSelection();
194     ///
195     bool hasSelection() const
196                 { return (selection_start_cursor != selection_end_cursor); }
197     ///
198     void SetCharFont(int pos, LyXFont const & font);
199     ///
200     string getText(int);
201     ///
202     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
203                                int button = 0);
204         
205     /* Private structures and variables */
206     ///
207     bool locked;
208     ///
209     int inset_pos;
210     ///
211     mutable int inset_x;
212     ///
213     mutable int inset_y;
214     ///
215     int interline_space;
216     ///
217     LyXCursor selection_start_cursor;
218     ///
219     LyXCursor selection_end_cursor;
220     ///
221     mutable LyXCursor cursor;
222     ///
223     mutable LyXCursor old_cursor;
224     ///
225     mutable int actrow;
226     ///
227     bool no_selection;
228     ///
229     mutable float xpos;
230     ///
231     mutable bool init_inset;
232     ///
233     UpdatableInset * the_locking_inset;
234     ///
235     struct row_struct {
236         ///
237         int asc;
238         ///
239         int desc;
240         ///
241         int pos;
242         ///
243         int baseline;
244     };
245     ///
246     typedef std::vector<row_struct> RowList;
247     ///
248     mutable RowList rows;
249     InsetText & operator = (InsetText const & it) {
250         par = it.par;
251         buffer = it.buffer; // suspect
252         current_font = it.current_font;
253         real_current_font = it.real_current_font;
254         maxAscent = it.maxAscent;
255         maxDescent = it.maxDescent;
256         insetWidth = it.insetWidth;
257         inset_pos = it.inset_pos;
258         inset_x = it.inset_x;
259         inset_y = it.inset_y;
260         interline_space = it.interline_space;
261         selection_start_cursor = selection_end_cursor = cursor = it.cursor;
262         actrow = it.actrow;
263         no_selection = it.no_selection;
264         the_locking_inset = it.the_locking_inset; // suspect
265         rows = it.rows;
266         return * this;
267     }
268 };
269 #endif