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