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
19 #include "ParagraphList.h"
21 #include "support/types.h"
23 #include <boost/shared_ptr.hpp>
35 A text inset is like a TeX box to write full text
36 (including styles and other insets) in a given space.
39 class InsetText : public UpdatableInset {
42 /// numbers need because of test if codeA < codeB
72 InsetText(BufferParams const &);
75 InsetText(InsetText const &, bool same_id = false);
79 Inset * clone(Buffer const &, bool same_id = false) const;
81 InsetText & operator=(InsetText const & it);
82 /// empty inset to empty par, or just mark as erased
83 void clear(bool just_mark_erased);
85 void read(Buffer const *, LyXLex &);
87 void write(Buffer const *, std::ostream &) const;
89 int ascent(BufferView *, LyXFont const &) const;
91 int descent(BufferView *, LyXFont const &) const;
93 int width(BufferView *, LyXFont const & f) const;
95 int textWidth(BufferView *, bool fordraw = false) const;
97 void draw(BufferView *, LyXFont const &, int , float &, bool) const;
99 void update(BufferView *, LyXFont const &, bool = false);
101 void setUpdateStatus(BufferView *, int what) const;
103 string const editMessage() const;
105 void edit(BufferView *, int, int, mouse_button::state);
107 void edit(BufferView *, bool front = true);
109 bool isTextInset() const { return true; }
111 bool doClearArea() const;
113 void insetUnlock(BufferView *);
115 bool lockInsetInInset(BufferView *, UpdatableInset *);
117 bool unlockInsetInInset(BufferView *,
118 UpdatableInset *, bool lr = false);
120 bool updateInsetInInset(BufferView *, Inset *);
122 RESULT localDispatch(FuncRequest const &);
124 int latex(Buffer const *, std::ostream &,
125 bool fragile, bool free_spc) const;
127 int ascii(Buffer const *, std::ostream &, int linelen) const;
129 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
131 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
133 void validate(LaTeXFeatures & features) const;
135 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
137 void getCursorPos(BufferView *, int & x, int & y) const;
139 int insetInInsetY() const;
141 void toggleInsetCursor(BufferView *);
143 void showInsetCursor(BufferView *, bool show = true);
145 void hideInsetCursor(BufferView *);
147 void fitInsetCursor(BufferView *) const;
149 bool insertInset(BufferView *, Inset *);
151 bool insetAllowed(Inset::Code) const;
153 UpdatableInset * getLockingInset() const;
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, bool same_id = false);
165 void writeParagraphData(Buffer const *, std::ostream &) const;
167 void setParagraphData(Paragraph *, bool same_id = false);
169 void setText(string const &, LyXFont const &);
171 void setAutoBreakRows(bool);
173 bool getAutoBreakRows() const { return autoBreakRows; }
175 void setDrawFrame(BufferView *, DrawFrame);
177 void setFrameColor(BufferView *, LColor::color);
179 LyXText * getLyXText(BufferView const *,
180 bool const recursive = false) const;
182 void deleteLyXText(BufferView *, bool recursive = true) const;
184 void resizeLyXText(BufferView *, bool force = false) const;
186 bool showInsetDialog(BufferView *) const;
188 std::vector<string> const getLabelList() const;
192 int scroll(bool recursive = true) const;
194 void scroll(BufferView * bv, float sx) const {
195 UpdatableInset::scroll(bv, sx);
198 void scroll(BufferView * bv, int offset) const {
199 UpdatableInset::scroll(bv, offset);
202 void selectAll(BufferView * bv);
204 void clearSelection(BufferView * bv);
206 Paragraph * getParFromID(int id) const;
208 Inset * getInsetFromID(int id) const;
210 Paragraph * firstParagraph() const;
212 Paragraph * getFirstParagraph(int) const;
214 LyXCursor const & cursor(BufferView *) const;
216 Paragraph * paragraph() const;
218 void paragraph(Paragraph *);
220 bool allowSpellcheck() const { return true; }
223 selectNextWordToSpellcheck(BufferView *, float & value) const;
225 void selectSelectedWord(BufferView *);
227 void toggleSelection(BufferView *, bool kill_selection);
229 /// mark as erased for change tracking
230 void markErased() { clear(true); };
232 * Mark as new. Used when pasting in tabular, and adding rows
233 * or columns. Note that pasting will ensure that tracking already
234 * happens, and this just resets the changes for the copied text,
235 * whereas for row/col add, we need to start tracking changes
236 * for the (empty) paragraph contained.
238 void markNew(bool track_changes = false);
240 bool nextChange(BufferView *, lyx::pos_type & length);
243 bool searchForward(BufferView *, string const &,
244 bool = true, bool = false);
246 bool searchBackward(BufferView *, string const &,
247 bool = true, bool = false);
249 bool checkInsertChar(LyXFont &);
251 void getDrawFont(LyXFont &) const;
252 /// append text onto the existing text
253 void appendParagraphs(BufferParams const & bp, Paragraph *);
256 void addPreview(grfx::PreviewLoader &) const;
259 // Public structures and variables
261 mutable int need_update;
265 void updateLocal(BufferView *, int what, bool mark_dirty) const;
266 /// set parameters for an initial lock of this inset
267 void lockInset(BufferView *);
268 /// lock an inset inside this one
269 void lockInset(BufferView *, UpdatableInset *);
271 mutable int drawTextXOffset;
273 mutable int drawTextYOffset;
277 DrawFrame drawFrame_;
279 LColor::color frame_color;
283 void lfunMousePress(FuncRequest const &);
285 bool lfunMouseRelease(FuncRequest const &);
287 void lfunMouseMotion(FuncRequest const &);
292 InnerCache(boost::shared_ptr<LyXText>);
294 boost::shared_ptr<LyXText> text;
299 typedef std::map<BufferView *, InnerCache> Cache;
301 typedef Cache::value_type value_type;
303 RESULT moveRight(BufferView *,
304 bool activate_inset = true,
305 bool selecting = false);
307 RESULT moveLeft(BufferView *,
308 bool activate_inset = true,
309 bool selecting = false);
311 RESULT moveRightIntern(BufferView *, bool front,
312 bool activate_inset = true,
313 bool selecting = false);
315 RESULT moveLeftIntern(BufferView *, bool front,
316 bool activate_inset = true,
317 bool selecting = false);
320 RESULT moveUp(BufferView *);
322 RESULT moveDown(BufferView *);
324 void setCharFont(Buffer const *, int pos, LyXFont const & font);
326 bool checkAndActivateInset(BufferView * bv, bool front);
328 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
329 mouse_button::state button = mouse_button::none);
331 void removeNewlines();
333 int cx(BufferView *) const;
335 int cix(BufferView *) const;
337 int cy(BufferView *) const;
339 int ciy(BufferView *) const;
341 lyx::pos_type cpos(BufferView *) const;
343 Paragraph * cpar(BufferView *) const;
345 bool cboundary(BufferView *) const;
347 Row * crow(BufferView *) const;
349 void drawFrame(Painter &, bool cleared) const;
351 void clearFrame(Painter &, bool cleared) const;
353 void clearInset(BufferView *, int baseline, bool & cleared) const;
355 void saveLyXTextState(LyXText *) const;
357 void restoreLyXTextState(BufferView *, LyXText *) const;
359 void reinitLyXText() const;
361 void collapseParagraphs(BufferView *) const;
363 /* Private structures and variables */
365 ParagraphList paragraphs;
369 mutable int insetAscent;
371 mutable int insetDescent;
373 mutable int insetWidth;
377 Paragraph * inset_par;
379 lyx::pos_type inset_pos;
387 mutable int old_max_width;
391 UpdatableInset * the_locking_inset;
393 mutable Paragraph * old_par;
397 mutable int last_drawn_width;
399 mutable bool frame_is_visible;
401 mutable BufferView * cached_bview;
403 mutable boost::shared_ptr<LyXText> cached_text;
407 Paragraph * selstartpar;
408 Paragraph * selendpar;
410 lyx::pos_type selstartpos;
411 lyx::pos_type selendpos;
413 bool selstartboundary;
420 mutable save_state sstate;
423 // this is needed globally so we know that we're using it actually and
424 // so the LyXText-Cache is not erased until used!
425 mutable LyXText * lt;
427 // to remember old painted frame dimensions to clear it on the right spot!
434 bool in_update; /* as update is not reentrant! */
435 mutable BufferView * do_resize;
436 mutable bool do_reinit;
437 mutable bool in_insetAllowed;
439 // these are used to check for mouse movement in Motion selection code