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