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