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