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