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