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