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"
28 #include <boost/smart_ptr.hpp>
40 A text inset is like a TeX box to write full text
41 (including styles and other insets) in a given space.
44 class InsetText : public UpdatableInset {
47 /// numbers need because of test if codeA < codeB
77 InsetText(BufferParams const &);
80 InsetText(InsetText const &, bool same_id = false);
84 Inset * clone(Buffer const &, bool same_id = false) const;
86 InsetText & operator=(InsetText const & it);
90 void read(Buffer const *, LyXLex &);
92 void write(Buffer const *, std::ostream &) const;
94 int ascent(BufferView *, LyXFont const &) const;
96 int descent(BufferView *, LyXFont const &) const;
98 int width(BufferView *, LyXFont const & f) const;
100 int textWidth(BufferView *, bool fordraw = false) const;
102 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
104 void update(BufferView *, LyXFont const &, bool = false);
106 void setUpdateStatus(BufferView *, int what) const;
108 string const editMessage() const;
110 void edit(BufferView *, int, int, unsigned int);
112 void edit(BufferView *, bool front = true);
114 bool isTextInset() const { return true; }
116 bool doClearArea() const;
118 void insetUnlock(BufferView *);
120 bool lockInsetInInset(BufferView *, UpdatableInset *);
122 bool unlockInsetInInset(BufferView *,
123 UpdatableInset *, bool lr = false);
125 bool updateInsetInInset(BufferView *, Inset *);
127 bool insetButtonRelease(BufferView *, int, int, int);
129 void insetButtonPress(BufferView *, int, int, int);
131 void insetMotionNotify(BufferView *, int, int, int);
133 void insetKeyPress(XKeyEvent *);
135 UpdatableInset::RESULT localDispatch(BufferView *,
136 kb_action, string const &);
138 int latex(Buffer const *, std::ostream &,
139 bool fragile, bool free_spc) const;
141 int ascii(Buffer const *, std::ostream &, int linelen) const;
143 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
145 int docbook(Buffer const *, std::ostream &) const ;
147 void validate(LaTeXFeatures & features) const;
149 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
151 void getCursorPos(BufferView *, int & x, int & y) const;
153 unsigned int insetInInsetY();
155 void toggleInsetCursor(BufferView *);
157 void showInsetCursor(BufferView *, bool show = true);
159 void hideInsetCursor(BufferView *);
161 void fitInsetCursor(BufferView *) const;
163 bool insertInset(BufferView *, Inset *);
165 bool insetAllowed(Inset::Code) const;
167 UpdatableInset * getLockingInset() const;
169 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
171 void setFont(BufferView *, LyXFont const &,
172 bool toggleall = false,
173 bool selectall = false);
175 int getMaxWidth(BufferView *, UpdatableInset const *) const;
177 void init(InsetText const * ins = 0, bool same_id = false);
179 void writeParagraphData(Buffer const *, std::ostream &) const;
181 void setParagraphData(Paragraph *, bool same_id = false);
183 void setText(string const &);
185 void setAutoBreakRows(bool);
187 bool getAutoBreakRows() const { return autoBreakRows; }
189 void setDrawFrame(BufferView *, DrawFrame);
191 void setFrameColor(BufferView *, LColor::color);
193 LyXText * getLyXText(BufferView const *,
194 bool const recursive = false) const;
196 void deleteLyXText(BufferView *, bool recursive = true) const;
198 void resizeLyXText(BufferView *, bool force = false) const;
200 bool showInsetDialog(BufferView *) const;
202 std::vector<string> const getLabelList() const;
206 int scroll(bool recursive = true) const;
208 void scroll(BufferView * bv, float sx) const {
209 UpdatableInset::scroll(bv, sx);
212 void scroll(BufferView * bv, int offset) const {
213 UpdatableInset::scroll(bv, offset);
216 void selectAll(BufferView * bv);
218 void clearSelection(BufferView * bv);
220 Paragraph * getParFromID(int id) const;
222 Inset * getInsetFromID(int id) const;
224 Paragraph * firstParagraph() const;
226 Paragraph * getFirstParagraph(int) const;
228 LyXCursor const & cursor(BufferView *) const;
230 Paragraph * paragraph() const;
232 void paragraph(Paragraph *);
234 bool allowSpellcheck() { return true; }
236 string const selectNextWordToSpellcheck(BufferView *,
237 float & value) const;
238 void selectSelectedWord(BufferView *);
240 void toggleSelection(BufferView *, bool kill_selection);
242 bool searchForward(BufferView *, string const &,
243 bool = true, bool = false);
245 bool searchBackward(BufferView *, string const &,
246 bool = true, bool = false);
248 bool checkInsertChar(LyXFont &);
250 void getDrawFont(LyXFont &) const;
252 void appendParagraphs(BufferParams const & bparams, Paragraph *);
255 // Public structures and variables
257 mutable int need_update;
261 void updateLocal(BufferView *, int what, bool mark_dirty) const;
263 void lockInset(BufferView *, UpdatableInset *);
265 mutable int drawTextXOffset;
267 mutable int drawTextYOffset;
271 DrawFrame drawFrame_;
273 LColor::color frame_color;
279 InnerCache(boost::shared_ptr<LyXText>);
281 boost::shared_ptr<LyXText> text;
286 typedef std::map<BufferView *, InnerCache> Cache;
288 typedef Cache::value_type value_type;
290 int beginningOfMainBody(Buffer const *, Paragraph * par) const;
292 UpdatableInset::RESULT moveRight(BufferView *,
293 bool activate_inset = true,
294 bool selecting = false);
296 UpdatableInset::RESULT moveLeft(BufferView *,
297 bool activate_inset = true,
298 bool selecting = false);
300 UpdatableInset::RESULT moveRightIntern(BufferView *, bool behind,
301 bool activate_inset = true,
302 bool selecting = false);
304 UpdatableInset::RESULT moveLeftIntern(BufferView *, bool behind,
305 bool activate_inset = true,
306 bool selecting = false);
309 UpdatableInset::RESULT moveUp(BufferView *);
311 UpdatableInset::RESULT moveDown(BufferView *);
313 void setCharFont(Buffer const *, int pos, LyXFont const & font);
315 bool checkAndActivateInset(BufferView * bv, bool behind);
317 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
320 void removeNewlines();
322 int cx(BufferView *) const;
324 int cy(BufferView *) const;
326 lyx::pos_type cpos(BufferView *) const;
328 Paragraph * cpar(BufferView *) const;
330 bool cboundary(BufferView *) const;
332 Row * crow(BufferView *) const;
334 void drawFrame(Painter &, bool cleared) const;
336 void clearFrame(Painter &, bool cleared) const;
338 void clearInset(BufferView *, int baseline, bool & cleared) const;
340 void saveLyXTextState(LyXText *) const;
342 void restoreLyXTextState(BufferView *, LyXText *) const;
344 void reinitLyXText() const;
346 void collapseParagraphs(BufferParams const & bparams) const;
348 /* Private structures and variables */
354 mutable int insetAscent;
356 mutable int insetDescent;
358 mutable int insetWidth;
362 Paragraph * inset_par;
364 lyx::pos_type inset_pos;
372 mutable int old_max_width;
378 UpdatableInset * the_locking_inset;
380 mutable Paragraph * old_par;
384 mutable int last_drawn_width;
386 mutable bool frame_is_visible;
388 mutable BufferView * cached_bview;
390 mutable boost::shared_ptr<LyXText> cached_text;
394 Paragraph * selstartpar;
395 Paragraph * selendpar;
397 lyx::pos_type selstartpos;
398 lyx::pos_type selendpos;
400 bool selstartboundary;
407 mutable save_state sstate;
410 // this is needed globally so we know that we're using it actually and
411 // so the LyXText-Cache is not erased until used!
412 mutable LyXText * lt;
414 // to remember old painted frame dimensions to clear it on the right spot!
421 bool in_update; /* as update is not reentrant! */
422 mutable BufferView * do_resize;
423 mutable bool do_reinit;
424 mutable bool in_insetAllowed;
426 // these are used to check for mouse movement in Motion selection code