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