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