2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
9 *======================================================
11 // The pristine updatable inset: Text
23 #include "lyxcursor.h"
35 * A text inset is like a TeX box to write full text
36 * (including styles and other insets) in a given space.
38 class InsetText : public UpdatableInset {
60 InsetText(InsetText const &);
64 Inset * Clone() const;
66 InsetText & operator= (InsetText const & it);
68 void clear() const { par->clearContents(); }
70 void Read(Buffer const *, LyXLex &);
72 void Write(Buffer const *, std::ostream &) const;
74 int ascent(Painter &, LyXFont const &) const;
76 int descent(Painter &, LyXFont const &) const;
78 int width(Painter &, LyXFont const & f) const;
80 int textWidth(Painter &) const;
82 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
84 void update(BufferView *, LyXFont const &, bool =false);
86 char const * EditMessage() const;
88 void Edit(BufferView *, int, int, unsigned int);
90 bool IsTextInset() const { return true; }
92 bool doClearArea() const { return !locked; }
94 void InsetUnlock(BufferView *);
96 bool LockInsetInInset(BufferView *, UpdatableInset *);
98 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
100 bool UpdateInsetInInset(BufferView *, Inset *);
102 void InsetButtonRelease(BufferView *, int, int, int);
104 void InsetButtonPress(BufferView *, int, int, int);
106 void InsetMotionNotify(BufferView *, int, int, int);
108 void InsetKeyPress(XKeyEvent *);
110 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
112 int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
114 int Ascii(Buffer const *, std::ostream &) const { return 0; }
116 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
118 int DocBook(Buffer const *, std::ostream &) const { return 0; }
120 void Validate(LaTeXFeatures & features) const;
122 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
124 void GetCursorPos(BufferView *, int & x, int & y) const;
128 void ToggleInsetCursor(BufferView *);
130 bool InsertInset(BufferView *, Inset *);
132 UpdatableInset * GetLockingInset();
134 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
136 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
138 void init(InsetText const * ins = 0);
140 void WriteParagraphData(Buffer const *, std::ostream &) const;
142 void SetParagraphData(LyXParagraph *);
144 void SetAutoBreakRows(bool);
146 void SetDrawFrame(BufferView *, DrawFrame);
148 void SetFrameColor(BufferView *, LColor::color);
150 // LyXFont GetDrawFont(BufferView *, LyXParagraph *, int pos) const;
152 LyXText * getLyXText(BufferView *) const;
153 void deleteLyXText(BufferView *);
159 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
161 virtual int getMaxTextWidth(Painter &, UpdatableInset const *) const;
163 mutable int drawTextXOffset;
164 mutable int drawTextYOffset;
169 LColor::color frame_color;
171 mutable UpdateCodes need_update;
175 typedef std::map<BufferView *, LyXText *> Cache;
177 typedef Cache::value_type value_type;
179 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
181 void ShowInsetCursor(BufferView *);
183 void HideInsetCursor(BufferView *);
185 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true);
187 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true);
189 UpdatableInset::RESULT moveUp(BufferView *);
191 UpdatableInset::RESULT moveDown(BufferView *);
193 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
197 bool checkAndActivateInset(BufferView * bv, bool behind);
198 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
201 int cx(BufferView *) const;
202 int cy(BufferView *) const;
203 int cpos(BufferView *) const;
204 LyXParagraph * cpar(BufferView *) const;
205 Row * crow(BufferView *) const;
207 /// This instead of a macro
208 LyXText * TEXT(BufferView * bv) const {
209 return getLyXText(bv);
212 /* Private structures and variables */
219 mutable int last_width;
220 mutable int last_height;
223 LyXParagraph * inset_par;
237 UpdatableInset * the_locking_inset;
239 LyXParagraph * old_par;