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(BufferView *) const;
98 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
100 void update(BufferView *, LyXFont const &, bool =false);
102 void setUpdateStatus(BufferView *, int what) const;
104 string const editMessage() const;
106 void edit(BufferView *, int, int, unsigned int);
108 bool isTextInset() const { return true; }
110 bool doClearArea() const;
112 void insetUnlock(BufferView *);
114 bool lockInsetInInset(BufferView *, UpdatableInset *);
116 bool unlockInsetInInset(BufferView *,
117 UpdatableInset *, bool lr = false);
119 bool updateInsetInInset(BufferView *, Inset *);
121 void insetButtonRelease(BufferView *, int, int, int);
123 void insetButtonPress(BufferView *, int, int, int);
125 void insetMotionNotify(BufferView *, int, int, int);
127 void insetKeyPress(XKeyEvent *);
129 UpdatableInset::RESULT localDispatch(BufferView *,
130 kb_action, string const &);
132 int latex(Buffer const *, std::ostream &,
133 bool fragile, bool free_spc) const;
135 int ascii(Buffer const *, std::ostream &, int linelen) const;
137 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
139 int docBook(Buffer const *, std::ostream &) const ;
141 void validate(LaTeXFeatures & features) const;
143 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
145 void getCursorPos(BufferView *, int & x, int & y) const;
147 unsigned int insetInInsetY();
149 void toggleInsetCursor(BufferView *);
151 bool insertInset(BufferView *, Inset *);
153 UpdatableInset * getLockingInset();
155 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
157 void setFont(BufferView *, LyXFont const &,
158 bool toggleall = false,
159 bool selectall = false);
161 int getMaxWidth(BufferView *, UpdatableInset const *) const;
163 void init(InsetText const * ins = 0);
165 void writeParagraphData(Buffer const *, std::ostream &) const;
167 void setParagraphData(Paragraph *);
169 void setText(string const &);
171 void setAutoBreakRows(bool);
173 void setDrawFrame(BufferView *, DrawFrame);
175 void setFrameColor(BufferView *, LColor::color);
177 LyXText * getLyXText(BufferView const *,
178 bool const recursive = false) const;
180 void deleteLyXText(BufferView *, bool recursive = true) const;
182 void resizeLyXText(BufferView *, bool force = false) const;
184 bool showInsetDialog(BufferView *) const;
186 std::vector<string> const getLabelList() const;
190 int scroll(bool recursive=true) const;
192 void scroll(BufferView *bv, float sx) const {
193 UpdatableInset::scroll(bv, sx);
196 void scroll(BufferView *bv, int offset) const {
197 UpdatableInset::scroll(bv, offset);
200 void selectAll(BufferView *bv);
202 void clearSelection(BufferView *bv);
206 mutable int need_update;
210 void updateLocal(BufferView *, int what, bool mark_dirty);
212 mutable int drawTextXOffset;
214 mutable int drawTextYOffset;
218 DrawFrame drawFrame_;
220 LColor::color frame_color;
224 typedef std::map<BufferView *, LyXText *> Cache;
226 typedef Cache::value_type value_type;
228 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
230 void showInsetCursor(BufferView *, bool show=true);
232 void hideInsetCursor(BufferView *);
234 UpdatableInset::RESULT moveRight(BufferView *,
235 bool activate_inset = true,
236 bool selecting = false);
238 UpdatableInset::RESULT moveLeft(BufferView *,
239 bool activate_inset = true,
240 bool selecting = false);
242 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
243 bool activate_inset = true,
244 bool selecting = false);
246 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
247 bool activate_inset = true,
248 bool selecting = false);
251 UpdatableInset::RESULT moveUp(BufferView *);
253 UpdatableInset::RESULT moveDown(BufferView *);
255 void setCharFont(Buffer const *, int pos, LyXFont const & font);
257 string const getText(int);
259 bool checkAndActivateInset(BufferView * bv, bool behind);
261 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
264 void removeNewlines();
266 int cx(BufferView *) const;
268 int cy(BufferView *) const;
270 Paragraph::size_type cpos(BufferView *) const;
272 Paragraph * cpar(BufferView *) const;
274 bool cboundary(BufferView *) const;
276 Row * crow(BufferView *) const;
278 void drawFrame(Painter &, bool cleared) const;
280 void clearFrame(Painter &, bool cleared) const;
282 void clearInset(Painter &, int baseline, bool & cleared) const;
284 /* Private structures and variables */
288 mutable int insetAscent;
290 mutable int insetDescent;
292 mutable int insetWidth;
294 mutable int last_width;
296 mutable int last_height;
300 Paragraph * inset_par;
302 Paragraph::size_type inset_pos;
310 mutable unsigned int old_max_width;
316 UpdatableInset * the_locking_inset;
322 mutable int last_drawn_width;
324 mutable bool frame_is_visible;