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 {
74 InsetText(InsetText const &);
78 Inset * Clone(Buffer const &) const;
80 InsetText & operator=(InsetText const & it);
84 void Read(Buffer const *, LyXLex &);
86 void Write(Buffer const *, std::ostream &) const;
88 int ascent(BufferView *, LyXFont const &) const;
90 int descent(BufferView *, LyXFont const &) const;
92 int width(BufferView *, LyXFont const & f) const;
94 int textWidth(Painter &) const;
96 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
98 void update(BufferView *, LyXFont const &, bool =false);
100 string const EditMessage() const;
102 void Edit(BufferView *, int, int, unsigned int);
104 bool IsTextInset() const { return true; }
106 bool doClearArea() const { return !locked; }
108 void InsetUnlock(BufferView *);
110 bool LockInsetInInset(BufferView *, UpdatableInset *);
112 bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
114 bool UpdateInsetInInset(BufferView *, Inset *);
116 void InsetButtonRelease(BufferView *, int, int, int);
118 void InsetButtonPress(BufferView *, int, int, int);
120 void InsetMotionNotify(BufferView *, int, int, int);
122 void InsetKeyPress(XKeyEvent *);
124 UpdatableInset::RESULT LocalDispatch(BufferView *, int, string const &);
126 int Latex(Buffer const *, std::ostream &,
127 bool fragile, bool free_spc) const;
129 int Ascii(Buffer const *, std::ostream &, int linelen) const;
131 int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
133 int DocBook(Buffer const *, std::ostream &) const ;
135 void Validate(LaTeXFeatures & features) const;
137 Inset::Code LyxCode() const { return Inset::TEXT_CODE; }
139 void GetCursorPos(BufferView *, int & x, int & y) const;
141 unsigned int InsetInInsetY();
143 void ToggleInsetCursor(BufferView *);
145 bool InsertInset(BufferView *, Inset *);
147 UpdatableInset * GetLockingInset();
149 UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
151 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
153 int getMaxWidth(Painter &, UpdatableInset const *) const;
155 void init(InsetText const * ins = 0);
157 void WriteParagraphData(Buffer const *, std::ostream &) const;
159 void SetParagraphData(LyXParagraph *);
161 void SetText(string const &);
163 void SetAutoBreakRows(bool);
165 void SetDrawFrame(BufferView *, DrawFrame);
167 void SetFrameColor(BufferView *, LColor::color);
169 LyXText * getLyXText(BufferView const *) const;
171 void deleteLyXText(BufferView *, bool recursive=true) const;
173 void resizeLyXText(BufferView *) const;
177 mutable UpdateCodes need_update;
181 void UpdateLocal(BufferView *, UpdateCodes, bool mark_dirty);
183 mutable int drawTextXOffset;
185 mutable int drawTextYOffset;
191 LColor::color frame_color;
195 typedef std::map<BufferView *, LyXText *> Cache;
197 typedef Cache::value_type value_type;
199 int BeginningOfMainBody(Buffer const *, LyXParagraph * par) const;
201 void ShowInsetCursor(BufferView *, bool show=true);
203 void HideInsetCursor(BufferView *);
205 UpdatableInset::RESULT moveRight(BufferView *, bool activate_inset = true,
206 bool selecting = false);
208 UpdatableInset::RESULT moveLeft(BufferView *, bool activate_inset = true,
209 bool selecting = false);
211 UpdatableInset::RESULT moveUp(BufferView *);
213 UpdatableInset::RESULT moveDown(BufferView *);
215 void SetCharFont(Buffer const *, int pos, LyXFont const & font);
217 string const getText(int);
219 bool checkAndActivateInset(BufferView * bv, bool behind);
221 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
223 void removeNewlines();
226 int cx(BufferView *) const;
228 int cy(BufferView *) const;
230 LyXParagraph::size_type cpos(BufferView *) const;
232 LyXParagraph * cpar(BufferView *) const;
234 bool cboundary(BufferView *) const;
236 Row * crow(BufferView *) const;
238 /// This instead of a macro
239 LyXText * TEXT(BufferView * bv) const {
240 return getLyXText(bv);
243 /* Private structures and variables */
247 mutable int insetAscent;
249 mutable int insetDescent;
251 mutable int insetWidth;
253 mutable int last_width;
255 mutable int last_height;
259 LyXParagraph * inset_par;
261 LyXParagraph::size_type inset_pos;
275 UpdatableInset * the_locking_inset;
277 LyXParagraph * old_par;