]> git.lyx.org Git - lyx.git/blob - src/insets/insettext.h
c61fffd0a493b5d80beb6f00e41b835f0819ee25
[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 class LyXScreen;
33
34 /**
35  * A text inset is like a TeX box to write full text
36  * (including styles and other insets) in a given space. 
37  */
38 class InsetText : public UpdatableInset {
39 public:
40     ///
41     enum { TEXT_TO_INSET_OFFSET = 2 };
42     ///
43     enum UpdateCodes {
44         NONE = 0,
45         INIT,
46         FULL,
47         CURSOR_PAR,
48         SELECTION
49     };
50     ///
51     explicit
52     InsetText();
53     ///
54     InsetText(InsetText const &);
55     ///
56     ~InsetText();
57     ///
58     Inset * Clone() const;
59     ///
60     InsetText & operator= (InsetText const & it);
61     ///
62     void clear() const { par->clearContents(); }
63     ///
64     void Read(Buffer const *, LyXLex &);
65     ///
66     void Write(Buffer const *, std::ostream &) const;
67     ///
68     int ascent(Painter &, LyXFont const &) const;
69     ///
70     int descent(Painter &, LyXFont const &) const;
71     ///
72     int width(Painter &, LyXFont const & f) const;
73     ///
74     void draw(BufferView *, LyXFont const &, int , float &) const;
75     ///
76     void update(BufferView *, LyXFont const &, bool =false);
77     ///
78     char const * EditMessage() const;
79     ///
80     void Edit(BufferView *, int, int, unsigned int);
81     ///
82     bool IsTextInset() const { return true; }
83     ///
84     bool doClearArea() const { return !locked; }
85     ///
86     void InsetUnlock(BufferView *);
87     ///
88     bool LockInsetInInset(BufferView *, UpdatableInset *);
89     ///
90     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
91     ///
92     bool UpdateInsetInInset(BufferView *, Inset *);
93     ///
94     void InsetButtonRelease(BufferView *, int, int, int);
95     ///
96     void InsetButtonPress(BufferView *, int, int, int);
97     ///
98     void InsetMotionNotify(BufferView *, int, int, int);
99     ///
100     void InsetKeyPress(XKeyEvent *);
101     ///
102     UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
103     ///
104     int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
105     ///
106     int Ascii(Buffer const *, std::ostream &) const { return 0; }
107     ///
108     int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
109     ///
110     int DocBook(Buffer const *, std::ostream &) const { return 0; }
111     ///
112     void Validate(LaTeXFeatures & features) const;
113     ///
114     Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
115     ///
116     void GetCursorPos(BufferView *, int & x, int & y) const;
117     ///
118     int InsetInInsetY();
119     ///
120     void ToggleInsetCursor(BufferView *);
121     ///
122     bool InsertInset(BufferView *, Inset *);
123     ///
124     UpdatableInset * GetLockingInset();
125     ///
126     UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
127     ///
128     void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
129     ///
130     void init(InsetText const * ins = 0);
131     ///
132     void SetParagraphData(LyXParagraph *);
133     ///
134     void SetAutoBreakRows(bool);
135     ///
136     void SetDrawLockedFrame(bool);
137     ///
138     void SetFrameColor(LColor::color);
139     ///
140     LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
141     ///
142     LyXText * getLyXText(BufferView *) const;
143     void deleteLyXText(BufferView *);
144
145     LyXParagraph * par;
146
147 protected:
148     ///
149     void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
150     ///
151     void WriteParagraphData(Buffer const *, std::ostream &) const;
152     ///
153     virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
154
155     mutable int drawTextXOffset;
156     mutable int drawTextYOffset;
157     ///
158     bool autoBreakRows;
159     bool drawLockedFrame;
160     ///
161     LColor::color frame_color;
162
163 private:
164     ///
165     typedef std::map<BufferView *, LyXText *> Cache;
166     ///
167     typedef Cache::value_type value_type;
168     ///
169     int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
170     ///
171     void ShowInsetCursor(BufferView *);
172     ///
173     void HideInsetCursor(BufferView *);
174     ///
175     UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
176     ///
177     UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
178     ///
179     UpdatableInset::RESULT moveUp(BufferView *);
180     ///
181     UpdatableInset::RESULT moveDown(BufferView *);
182     ///
183     void SetCharFont(Buffer const *, int pos, LyXFont const & font);
184     ///
185     string getText(int);
186     ///
187     bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
188                                int button = 0);
189     ///
190     int cx(BufferView *) const;
191     int cy(BufferView *) const;
192     int cpos(BufferView *) const;
193     LyXParagraph * cpar(BufferView *) const;
194     Row * crow(BufferView *) const;
195         
196     /* Private structures and variables */
197     ///
198     mutable bool locked;
199     ///
200     int insetAscent;
201     int insetDescent;
202     int insetWidth;
203     ///
204     int inset_pos;
205     ///
206     mutable int inset_x;
207     ///
208     mutable int inset_y;
209     ///
210     int interline_space;
211     ///
212     bool no_selection;
213     ///
214     mutable float xpos;
215     ///
216     mutable UpdateCodes need_update;
217     ///
218     UpdatableInset * the_locking_inset;
219     ///
220     LyXParagraph * old_par;
221     /// The cache.
222     mutable Cache cache;
223 };
224 #endif