2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1998 The LyX Team.
10 *======================================================
12 // The pristine updatable inset: Text
24 #include "lyxcursor.h"
36 A text inset is like a TeX box to write full text
37 (including styles and other insets) in a given space.
40 class InsetText : public UpdatableInset {
43 /// numbers need because of test if codeA < codeB
76 InsetText(InsetText const &);
80 Inset * Clone(Buffer const &) const;
82 InsetText & operator=(InsetText const & it);
86 void Read(Buffer const *, LyXLex &);
88 void Write(Buffer const *, std::ostream &) const;
90 int ascent(BufferView *, LyXFont const &) const;
92 int descent(BufferView *, LyXFont const &) const;
94 int width(BufferView *, LyXFont const & f) const;
96 int textWidth(Painter &) const;
98 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
100 void update(BufferView *, LyXFont const &, bool =false);
102 void SetUpdateStatus(BufferView *, UpdateCodes);
104 string const EditMessage() const;
106 void Edit(BufferView *, int, int, unsigned int);
108 bool IsTextInset() const { return true; }
110 bool doClearArea() const { return !locked; }
112 void InsetUnlock(BufferView *);
114 bool LockInsetInInset(BufferView *, UpdatableInset *);
116 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
118 bool UpdateInsetInInset(BufferView *, Inset *);
120 void InsetButtonRelease(BufferView *, int, int, int);
122 void InsetButtonPress(BufferView *, int, int, int);
124 void InsetMotionNotify(BufferView *, int, int, int);
126 void InsetKeyPress(XKeyEvent *);
128 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
130 int Latex(Buffer const *, std::ostream &,
131 bool fragile, bool free_spc) const;
133 int Ascii(Buffer const *, std::ostream &, int linelen) const;
135 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
137 int DocBook(Buffer const *, std::ostream &) const ;
139 void Validate(LaTeXFeatures & features) const;
141 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
143 void GetCursorPos(BufferView *, int & x, int & y) const;
145 unsigned int InsetInInsetY();
147 void ToggleInsetCursor(BufferView *);
149 bool InsertInset(BufferView *, Inset *);
151 UpdatableInset * GetLockingInset();
153 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
155 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
157 int getMaxWidth(Painter &, UpdatableInset const *) const;
159 void init(InsetText const * ins = 0);
161 void WriteParagraphData(Buffer const *, std::ostream &) const;
163 void SetParagraphData(LyXParagraph *);
165 void SetText(string const &);
167 void SetAutoBreakRows(bool);
169 void SetDrawFrame(BufferView *, DrawFrame);
171 void SetFrameColor(BufferView *, LColor::color);
173 LyXText * getLyXText(BufferView const *) const;
175 void deleteLyXText(BufferView *, bool recursive=true) const;
177 void resizeLyXText(BufferView *) const;
181 mutable UpdateCodes need_update;
185 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
187 mutable int drawTextXOffset;
189 mutable int drawTextYOffset;
195 LColor::color frame_color;
199 typedef std::map<BufferView *, LyXText *> Cache;
201 typedef Cache::value_type value_type;
203 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
205 void ShowInsetCursor(BufferView *, bool show=true);
207 void HideInsetCursor(BufferView *);
209 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
210 bool selecting = false);
212 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
213 bool selecting = false);
215 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
216 bool activate_inset = true,
217 bool selecting = false);
219 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
220 bool activate_inset = true,
221 bool selecting = false);
224 UpdatableInset::RESULT moveUp(BufferView *);
226 UpdatableInset::RESULT moveDown(BufferView *);
228 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
230 string const getText(int);
232 bool checkAndActivateInset(BufferView * bv, bool behind);
234 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
236 void removeNewlines();
239 int cx(BufferView *) const;
241 int cy(BufferView *) const;
243 LyXParagraph::size_type cpos(BufferView *) const;
245 LyXParagraph * cpar(BufferView *) const;
247 bool cboundary(BufferView *) const;
249 Row * crow(BufferView *) const;
251 /// This instead of a macro
252 LyXText * TEXT(BufferView * bv) const {
253 return getLyXText(bv);
256 /* Private structures and variables */
260 mutable int insetAscent;
262 mutable int insetDescent;
264 mutable int insetWidth;
266 mutable int last_width;
268 mutable int last_height;
272 LyXParagraph * inset_par;
274 LyXParagraph::size_type inset_pos;
288 UpdatableInset * the_locking_inset;
290 LyXParagraph * old_par;