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
25 #include "paragraph.h"
26 #include "lyxcursor.h"
27 #include <boost/smart_ptr.hpp>
38 A text inset is like a TeX box to write full text
39 (including styles and other insets) in a given space.
42 class InsetText : public UpdatableInset {
45 /// numbers need because of test if codeA < codeB
78 InsetText(InsetText const &, bool same_id = false);
82 Inset * clone(Buffer const &, bool same_id = false) const;
84 InsetText & operator=(InsetText const & it);
88 void read(Buffer const *, LyXLex &);
90 void write(Buffer const *, std::ostream &) const;
92 int ascent(BufferView *, LyXFont const &) const;
94 int descent(BufferView *, LyXFont const &) const;
96 int width(BufferView *, LyXFont const & f) const;
98 int textWidth(BufferView *, bool fordraw = false) const;
100 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
102 void update(BufferView *, LyXFont const &, bool =false);
104 void setUpdateStatus(BufferView *, int what) const;
106 string const editMessage() const;
108 void edit(BufferView *, int, int, unsigned int);
110 void edit(BufferView *, bool front = true);
112 bool isTextInset() const { return true; }
114 bool doClearArea() const;
116 void insetUnlock(BufferView *);
118 bool lockInsetInInset(BufferView *, UpdatableInset *);
120 bool unlockInsetInInset(BufferView *,
121 UpdatableInset *, bool lr = false);
123 bool updateInsetInInset(BufferView *, Inset *);
125 bool insetButtonRelease(BufferView *, int, int, int);
127 void insetButtonPress(BufferView *, int, int, int);
129 void insetMotionNotify(BufferView *, int, int, int);
131 void insetKeyPress(XKeyEvent *);
133 UpdatableInset::RESULT localDispatch(BufferView *,
134 kb_action, string const &);
136 int latex(Buffer const *, std::ostream &,
137 bool fragile, bool free_spc) const;
139 int ascii(Buffer const *, std::ostream &, int linelen) const;
141 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
143 int docbook(Buffer const *, std::ostream &) const ;
145 void validate(LaTeXFeatures & features) const;
147 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
149 void getCursorPos(BufferView *, int & x, int & y) const;
151 unsigned int insetInInsetY();
153 void toggleInsetCursor(BufferView *);
155 void showInsetCursor(BufferView *, bool show=true);
157 void hideInsetCursor(BufferView *);
159 void fitInsetCursor(BufferView *) const;
161 bool insertInset(BufferView *, Inset *);
163 bool insetAllowed(Inset::Code) const;
165 UpdatableInset * getLockingInset() const;
167 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
169 void setFont(BufferView *, LyXFont const &,
170 bool toggleall = false,
171 bool selectall = false);
173 int getMaxWidth(BufferView *, UpdatableInset const *) const;
175 void init(InsetText const * ins = 0, bool same_id = false);
177 void writeParagraphData(Buffer const *, std::ostream &) const;
179 void setParagraphData(Paragraph *, bool same_id = false);
181 void setText(string const &);
183 void setAutoBreakRows(bool);
185 bool getAutoBreakRows() const { return autoBreakRows; }
187 void setDrawFrame(BufferView *, DrawFrame);
189 void setFrameColor(BufferView *, LColor::color);
191 LyXText * getLyXText(BufferView const *,
192 bool const recursive = false) const;
194 void deleteLyXText(BufferView *, bool recursive = true) const;
196 void resizeLyXText(BufferView *, bool force = false) const;
198 bool showInsetDialog(BufferView *) const;
200 std::vector<string> const getLabelList() const;
204 int scroll(bool recursive=true) const;
206 void scroll(BufferView *bv, float sx) const {
207 UpdatableInset::scroll(bv, sx);
210 void scroll(BufferView *bv, int offset) const {
211 UpdatableInset::scroll(bv, offset);
214 void selectAll(BufferView *bv);
216 void clearSelection(BufferView *bv);
218 Paragraph * getParFromID(int id) const;
220 Inset * getInsetFromID(int id) const;
222 Paragraph * firstParagraph() const;
224 Paragraph * getFirstParagraph(int) const;
226 LyXCursor const & cursor(BufferView *) const;
228 Paragraph * paragraph() const;
230 void paragraph(Paragraph *);
232 bool allowSpellcheck() { return true; }
233 string const selectNextWordToSpellcheck(BufferView *, float & value) const;
234 void selectSelectedWord(BufferView *);
235 void toggleSelection(BufferView *, bool kill_selection);
237 bool searchForward(BufferView *, string const &,
238 bool const & = true, bool const & = false);
239 bool searchBackward(BufferView *, string const &,
240 bool const & = true, bool const & = false);
242 bool checkInsertChar(LyXFont &);
245 // Public structures and variables
247 mutable int need_update;
251 void updateLocal(BufferView *, int what, bool mark_dirty) const;
253 void lockInset(BufferView *, UpdatableInset *);
255 mutable int drawTextXOffset;
257 mutable int drawTextYOffset;
261 DrawFrame drawFrame_;
263 LColor::color frame_color;
267 InnerCache(boost::shared_ptr<LyXText>);
269 boost::shared_ptr<LyXText> text;
273 typedef std::map<BufferView *, struct InnerCache > Cache;
275 typedef Cache::value_type value_type;
277 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
279 UpdatableInset::RESULT moveRight(BufferView *,
280 bool activate_inset = true,
281 bool selecting = false);
283 UpdatableInset::RESULT moveLeft(BufferView *,
284 bool activate_inset = true,
285 bool selecting = false);
287 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
288 bool activate_inset = true,
289 bool selecting = false);
291 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
292 bool activate_inset = true,
293 bool selecting = false);
296 UpdatableInset::RESULT moveUp(BufferView *);
298 UpdatableInset::RESULT moveDown(BufferView *);
300 void setCharFont(Buffer const *, int pos, LyXFont const & font);
302 bool checkAndActivateInset(BufferView * bv, bool behind);
304 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
307 void removeNewlines();
309 int cx(BufferView *) const;
311 int cy(BufferView *) const;
313 lyx::pos_type cpos(BufferView *) const;
315 Paragraph * cpar(BufferView *) const;
317 bool cboundary(BufferView *) const;
319 Row * crow(BufferView *) const;
321 void drawFrame(Painter &, bool cleared) const;
323 void clearFrame(Painter &, bool cleared) const;
325 void clearInset(BufferView *, int baseline, bool & cleared) const;
327 void saveLyXTextState(LyXText *) const;
328 void restoreLyXTextState(BufferView *, LyXText *) const;
330 void reinitLyXText() const;
332 /* Private structures and variables */
338 mutable int insetAscent;
340 mutable int insetDescent;
342 mutable int insetWidth;
346 Paragraph * inset_par;
348 lyx::pos_type inset_pos;
356 mutable int old_max_width;
362 UpdatableInset * the_locking_inset;
364 mutable Paragraph * old_par;
368 mutable int last_drawn_width;
370 mutable bool frame_is_visible;
372 mutable BufferView * cached_bview;
374 mutable boost::shared_ptr<LyXText> cached_text;
376 mutable struct save_state {
378 Paragraph * selstartpar;
379 Paragraph * selendpar;
381 lyx::pos_type selstartpos;
382 lyx::pos_type selendpos;
384 bool selstartboundary;
391 // this is needed globally so we know that we're using it actually and
392 // so the LyXText-Cache is not erased until used!
393 mutable LyXText * lt;
395 // to remember old painted frame dimensions to clear it on the right spot!
402 bool in_update; /* as update is not reentrant! */
403 mutable BufferView * do_resize;
404 mutable bool do_reinit;
405 mutable bool in_insetAllowed;