4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS
22 #include "ParagraphList.h"
24 #include "support/types.h"
26 #include <boost/shared_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
75 InsetText(BufferParams const &);
78 InsetText(InsetText const &, bool same_id = false);
82 Inset * clone(Buffer const &, bool same_id = false) const;
84 InsetText & operator=(InsetText const & it);
85 /// empty inset to empty par, or just mark as erased
86 void clear(bool just_mark_erased);
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, mouse_button::state);
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 RESULT localDispatch(FuncRequest const &);
127 int latex(Buffer const *, std::ostream &,
128 bool fragile, bool free_spc) const;
130 int ascii(Buffer const *, std::ostream &, int linelen) const;
132 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
134 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
136 void validate(LaTeXFeatures & features) const;
138 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
140 void getCursorPos(BufferView *, int & x, int & y) const;
142 int insetInInsetY() const;
144 void toggleInsetCursor(BufferView *);
146 void showInsetCursor(BufferView *, bool show = true);
148 void hideInsetCursor(BufferView *);
150 void fitInsetCursor(BufferView *) const;
152 bool insertInset(BufferView *, Inset *);
154 bool insetAllowed(Inset::Code) const;
156 UpdatableInset * getLockingInset() const;
158 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
160 void setFont(BufferView *, LyXFont const &,
161 bool toggleall = false,
162 bool selectall = false);
164 int getMaxWidth(BufferView *, UpdatableInset const *) const;
166 void init(InsetText const * ins = 0, bool same_id = false);
168 void writeParagraphData(Buffer const *, std::ostream &) const;
170 void setParagraphData(Paragraph *, bool same_id = false);
172 void setText(string const &, LyXFont const &);
174 void setAutoBreakRows(bool);
176 bool getAutoBreakRows() const { return autoBreakRows; }
178 void setDrawFrame(BufferView *, DrawFrame);
180 void setFrameColor(BufferView *, LColor::color);
182 LyXText * getLyXText(BufferView const *,
183 bool const recursive = false) const;
185 void deleteLyXText(BufferView *, bool recursive = true) const;
187 void resizeLyXText(BufferView *, bool force = false) const;
189 bool showInsetDialog(BufferView *) const;
191 std::vector<string> const getLabelList() const;
195 int scroll(bool recursive = true) const;
197 void scroll(BufferView * bv, float sx) const {
198 UpdatableInset::scroll(bv, sx);
201 void scroll(BufferView * bv, int offset) const {
202 UpdatableInset::scroll(bv, offset);
205 void selectAll(BufferView * bv);
207 void clearSelection(BufferView * bv);
209 Paragraph * getParFromID(int id) const;
211 Inset * getInsetFromID(int id) const;
213 Paragraph * firstParagraph() const;
215 Paragraph * getFirstParagraph(int) const;
217 LyXCursor const & cursor(BufferView *) const;
219 Paragraph * paragraph() const;
221 void paragraph(Paragraph *);
223 bool allowSpellcheck() const { return true; }
226 selectNextWordToSpellcheck(BufferView *, float & value) const;
228 void selectSelectedWord(BufferView *);
230 void toggleSelection(BufferView *, bool kill_selection);
232 /// mark as erased for change tracking
233 void markErased() { clear(true); };
235 * Mark as new. Used when pasting in tabular, and adding rows
236 * or columns. Note that pasting will ensure that tracking already
237 * happens, and this just resets the changes for the copied text,
238 * whereas for row/col add, we need to start tracking changes
239 * for the (empty) paragraph contained.
241 void markNew(bool track_changes = false);
243 bool nextChange(BufferView *, lyx::pos_type & length);
246 bool searchForward(BufferView *, string const &,
247 bool = true, bool = false);
249 bool searchBackward(BufferView *, string const &,
250 bool = true, bool = false);
252 bool checkInsertChar(LyXFont &);
254 void getDrawFont(LyXFont &) const;
255 /// append text onto the existing text
256 void appendParagraphs(BufferParams const & bp, Paragraph *);
259 void addPreview(grfx::PreviewLoader &) const;
262 // Public structures and variables
264 mutable int need_update;
268 void updateLocal(BufferView *, int what, bool mark_dirty) const;
269 /// set parameters for an initial lock of this inset
270 void lockInset(BufferView *);
271 /// lock an inset inside this one
272 void lockInset(BufferView *, UpdatableInset *);
274 mutable int drawTextXOffset;
276 mutable int drawTextYOffset;
280 DrawFrame drawFrame_;
282 LColor::color frame_color;
286 void lfunMousePress(FuncRequest const &);
288 bool lfunMouseRelease(FuncRequest const &);
290 void lfunMouseMotion(FuncRequest const &);
295 InnerCache(boost::shared_ptr<LyXText>);
297 boost::shared_ptr<LyXText> text;
302 typedef std::map<BufferView *, InnerCache> Cache;
304 typedef Cache::value_type value_type;
306 int beginningOfMainBody(Paragraph * par) const;
308 RESULT moveRight(BufferView *,
309 bool activate_inset = true,
310 bool selecting = false);
312 RESULT moveLeft(BufferView *,
313 bool activate_inset = true,
314 bool selecting = false);
316 RESULT moveRightIntern(BufferView *, bool front,
317 bool activate_inset = true,
318 bool selecting = false);
320 RESULT moveLeftIntern(BufferView *, bool front,
321 bool activate_inset = true,
322 bool selecting = false);
325 RESULT moveUp(BufferView *);
327 RESULT moveDown(BufferView *);
329 void setCharFont(Buffer const *, int pos, LyXFont const & font);
331 bool checkAndActivateInset(BufferView * bv, bool front);
333 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
334 mouse_button::state button = mouse_button::none);
336 void removeNewlines();
338 int cx(BufferView *) const;
340 int cix(BufferView *) const;
342 int cy(BufferView *) const;
344 int ciy(BufferView *) const;
346 lyx::pos_type cpos(BufferView *) const;
348 Paragraph * cpar(BufferView *) const;
350 bool cboundary(BufferView *) const;
352 Row * crow(BufferView *) const;
354 void drawFrame(Painter &, bool cleared) const;
356 void clearFrame(Painter &, bool cleared) const;
358 void clearInset(BufferView *, int baseline, bool & cleared) const;
360 void saveLyXTextState(LyXText *) const;
362 void restoreLyXTextState(BufferView *, LyXText *) const;
364 void reinitLyXText() const;
366 void collapseParagraphs(BufferView *) const;
368 /* Private structures and variables */
370 ParagraphList paragraphs;
374 mutable int insetAscent;
376 mutable int insetDescent;
378 mutable int insetWidth;
382 Paragraph * inset_par;
384 lyx::pos_type inset_pos;
392 mutable int old_max_width;
396 UpdatableInset * the_locking_inset;
398 mutable Paragraph * old_par;
402 mutable int last_drawn_width;
404 mutable bool frame_is_visible;
406 mutable BufferView * cached_bview;
408 mutable boost::shared_ptr<LyXText> cached_text;
412 Paragraph * selstartpar;
413 Paragraph * selendpar;
415 lyx::pos_type selstartpos;
416 lyx::pos_type selendpos;
418 bool selstartboundary;
425 mutable save_state sstate;
428 // this is needed globally so we know that we're using it actually and
429 // so the LyXText-Cache is not erased until used!
430 mutable LyXText * lt;
432 // to remember old painted frame dimensions to clear it on the right spot!
439 bool in_update; /* as update is not reentrant! */
440 mutable BufferView * do_resize;
441 mutable bool do_reinit;
442 mutable bool in_insetAllowed;
444 // these are used to check for mouse movement in Motion selection code