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 Inset * getInsetFromID(int id) const;
208 Paragraph * firstParagraph() const;
210 Paragraph * getFirstParagraph(int) const;
212 LyXCursor const & cursor(BufferView *) const;
214 Paragraph * paragraph() const;
216 void paragraph(Paragraph *);
218 bool allowSpellcheck() const { return true; }
221 selectNextWordToSpellcheck(BufferView *, float & value) const;
223 void selectSelectedWord(BufferView *);
225 void toggleSelection(BufferView *, bool kill_selection);
227 /// mark as erased for change tracking
228 void markErased() { clear(true); };
230 * Mark as new. Used when pasting in tabular, and adding rows
231 * or columns. Note that pasting will ensure that tracking already
232 * happens, and this just resets the changes for the copied text,
233 * whereas for row/col add, we need to start tracking changes
234 * for the (empty) paragraph contained.
236 void markNew(bool track_changes = false);
238 bool nextChange(BufferView *, lyx::pos_type & length);
241 bool searchForward(BufferView *, string const &,
242 bool = true, bool = false);
244 bool searchBackward(BufferView *, string const &,
245 bool = true, bool = false);
247 bool checkInsertChar(LyXFont &);
249 void getDrawFont(LyXFont &) const;
250 /// append text onto the existing text
251 void appendParagraphs(BufferParams const & bp, Paragraph *);
254 void addPreview(grfx::PreviewLoader &) const;
257 // Public structures and variables
259 mutable int need_update;
263 void updateLocal(BufferView *, int what, bool mark_dirty) const;
264 /// set parameters for an initial lock of this inset
265 void lockInset(BufferView *);
266 /// lock an inset inside this one
267 void lockInset(BufferView *, UpdatableInset *);
269 mutable int drawTextXOffset;
271 mutable int drawTextYOffset;
275 DrawFrame drawFrame_;
277 LColor::color frame_color;
281 void lfunMousePress(FuncRequest const &);
283 bool lfunMouseRelease(FuncRequest const &);
285 void lfunMouseMotion(FuncRequest const &);
290 InnerCache(boost::shared_ptr<LyXText>);
292 boost::shared_ptr<LyXText> text;
297 typedef std::map<BufferView *, InnerCache> Cache;
299 typedef Cache::value_type value_type;
301 RESULT moveRight(BufferView *,
302 bool activate_inset = true,
303 bool selecting = false);
305 RESULT moveLeft(BufferView *,
306 bool activate_inset = true,
307 bool selecting = false);
309 RESULT moveRightIntern(BufferView *, bool front,
310 bool activate_inset = true,
311 bool selecting = false);
313 RESULT moveLeftIntern(BufferView *, bool front,
314 bool activate_inset = true,
315 bool selecting = false);
318 RESULT moveUp(BufferView *);
320 RESULT moveDown(BufferView *);
322 void setCharFont(Buffer const *, int pos, LyXFont const & font);
324 bool checkAndActivateInset(BufferView * bv, bool front);
326 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
327 mouse_button::state button = mouse_button::none);
329 void removeNewlines();
331 int cx(BufferView *) const;
333 int cix(BufferView *) const;
335 int cy(BufferView *) const;
337 int ciy(BufferView *) const;
339 lyx::pos_type cpos(BufferView *) const;
341 Paragraph * cpar(BufferView *) const;
343 bool cboundary(BufferView *) const;
345 Row * crow(BufferView *) const;
347 void drawFrame(Painter &, bool cleared) const;
349 void clearFrame(Painter &, bool cleared) const;
351 void clearInset(BufferView *, int baseline, bool & cleared) const;
353 void saveLyXTextState(LyXText *) const;
355 void restoreLyXTextState(BufferView *, LyXText *) const;
357 void reinitLyXText() const;
359 void collapseParagraphs(BufferView *) const;
361 /* Private structures and variables */
363 ParagraphList paragraphs;
367 mutable int insetAscent;
369 mutable int insetDescent;
371 mutable int insetWidth;
375 Paragraph * inset_par;
377 lyx::pos_type inset_pos;
385 mutable int old_max_width;
389 UpdatableInset * the_locking_inset;
391 mutable Paragraph * old_par;
395 mutable int last_drawn_width;
397 mutable bool frame_is_visible;
399 mutable BufferView * cached_bview;
401 mutable boost::shared_ptr<LyXText> cached_text;
405 Paragraph * selstartpar;
406 Paragraph * selendpar;
408 lyx::pos_type selstartpos;
409 lyx::pos_type selendpos;
411 bool selstartboundary;
418 mutable save_state sstate;
421 // this is needed globally so we know that we're using it actually and
422 // so the LyXText-Cache is not erased until used!
423 mutable LyXText * lt;
425 // to remember old painted frame dimensions to clear it on the right spot!
432 bool in_update; /* as update is not reentrant! */
433 mutable BufferView * do_resize;
434 mutable bool do_reinit;
435 mutable bool in_insetAllowed;
437 // these are used to check for mouse movement in Motion selection code