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
16 #include "updatableinset.h"
19 #include "ParagraphList.h"
22 #include "support/types.h"
24 #include <boost/shared_ptr.hpp>
36 A text inset is like a TeX box to write full text
37 (including styles and other insets) in a given space.
40 class InsetText : public UpdatableInset {
43 /// numbers need because of test if codeA < codeB
71 InsetText(BufferParams const &);
74 InsetText(InsetText const &, bool same_id = false);
78 Inset * clone(Buffer const &, bool same_id = false) const;
80 InsetText & operator=(InsetText const & it);
81 /// empty inset to empty par, or just mark as erased
82 void clear(bool just_mark_erased);
84 void read(Buffer const *, LyXLex &);
86 void write(Buffer const *, std::ostream &) const;
88 int ascent(BufferView *, LyXFont const &) const;
90 int descent(BufferView *, LyXFont const &) const;
92 int width(BufferView *, LyXFont const & f) const;
94 int textWidth(BufferView *, bool fordraw = false) const;
96 void draw(BufferView *, LyXFont const &, int , float &) const;
98 void update(BufferView *, bool = false);
100 void setUpdateStatus(BufferView *, int what) const;
102 string const editMessage() const;
104 void edit(BufferView *, int, int, mouse_button::state);
106 void edit(BufferView *, bool front = true);
108 bool isTextInset() const { return true; }
110 void insetUnlock(BufferView *);
112 bool lockInsetInInset(BufferView *, UpdatableInset *);
114 bool unlockInsetInInset(BufferView *,
115 UpdatableInset *, bool lr = false);
117 bool updateInsetInInset(BufferView *, Inset *);
119 RESULT localDispatch(FuncRequest const &);
121 int latex(Buffer const *, std::ostream &,
122 bool fragile, bool free_spc) const;
124 int ascii(Buffer const *, std::ostream &, int linelen) const;
126 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
128 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
130 void validate(LaTeXFeatures & features) const;
132 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
134 void getCursorPos(BufferView *, int & x, int & y) const;
136 int insetInInsetY() const;
138 void toggleInsetCursor(BufferView *);
140 void showInsetCursor(BufferView *, bool show = true);
142 void hideInsetCursor(BufferView *);
144 void fitInsetCursor(BufferView *) const;
146 bool insertInset(BufferView *, Inset *);
148 bool insetAllowed(Inset::Code) const;
150 UpdatableInset * getLockingInset() const;
152 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
154 void setFont(BufferView *, LyXFont const &,
155 bool toggleall = false,
156 bool selectall = false);
158 int getMaxWidth(BufferView *, UpdatableInset const *) const;
160 void init(InsetText const * ins = 0, bool same_id = false);
162 void writeParagraphData(Buffer const *, std::ostream &) const;
164 void setParagraphData(ParagraphList const &, bool same_id = false);
166 void setText(string const &, LyXFont const &);
168 void setAutoBreakRows(bool);
170 bool getAutoBreakRows() const { return autoBreakRows; }
172 void setDrawFrame(BufferView *, DrawFrame);
174 void setFrameColor(BufferView *, LColor::color);
176 LyXText * getLyXText(BufferView const *,
177 bool const recursive = false) const;
179 void deleteLyXText(BufferView *, bool recursive = true) const;
181 void resizeLyXText(BufferView *, bool force = false) const;
183 bool showInsetDialog(BufferView *) const;
185 std::vector<string> const getLabelList() const;
189 int scroll(bool recursive = true) const;
191 void scroll(BufferView * bv, float sx) const {
192 UpdatableInset::scroll(bv, sx);
195 void scroll(BufferView * bv, int offset) const {
196 UpdatableInset::scroll(bv, offset);
199 void selectAll(BufferView * bv);
201 void clearSelection(BufferView * bv);
203 Inset * getInsetFromID(int id) const;
205 Paragraph * firstParagraph() const;
207 Paragraph * getFirstParagraph(int) const;
209 LyXCursor const & cursor(BufferView *) const;
211 void paragraph(Paragraph *);
213 bool allowSpellcheck() const { return true; }
216 selectNextWordToSpellcheck(BufferView *, float & value) const;
218 void selectSelectedWord(BufferView *);
220 void toggleSelection(BufferView *, bool kill_selection);
222 /// mark as erased for change tracking
223 void markErased() { clear(true); };
225 * Mark as new. Used when pasting in tabular, and adding rows
226 * or columns. Note that pasting will ensure that tracking already
227 * happens, and this just resets the changes for the copied text,
228 * whereas for row/col add, we need to start tracking changes
229 * for the (empty) paragraph contained.
231 void markNew(bool track_changes = false);
233 bool nextChange(BufferView *, lyx::pos_type & length);
236 bool searchForward(BufferView *, string const &,
237 bool = true, bool = false);
239 bool searchBackward(BufferView *, string const &,
240 bool = true, bool = false);
242 bool checkInsertChar(LyXFont &);
244 void getDrawFont(LyXFont &) const;
245 /// append text onto the existing text
246 void appendParagraphs(Buffer * bp, ParagraphList &);
249 void addPreview(grfx::PreviewLoader &) const;
252 // Public structures and variables
254 mutable int need_update;
256 bool haveParagraphs() const {
260 ParagraphList paragraphs;
263 void updateLocal(BufferView *, int what, bool mark_dirty);
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 ParagraphList::iterator cpar(BufferView *) const;
343 bool cboundary(BufferView *) const;
345 RowList::iterator crow(BufferView *) const;
347 void drawFrame(Painter &, int x) const;
349 void clearInset(BufferView *, int start_x, int baseline) const;
351 void saveLyXTextState(LyXText *) const;
353 void restoreLyXTextState(LyXText *) const;
355 void reinitLyXText() const;
357 void collapseParagraphs(BufferView *);
359 /* Private structures and variables */
363 mutable int insetAscent;
365 mutable int insetDescent;
367 mutable int insetWidth;
371 ParagraphList::iterator inset_par;
373 lyx::pos_type inset_pos;
381 mutable int old_max_width;
385 UpdatableInset * the_locking_inset;
387 mutable ParagraphList::iterator old_par;
391 mutable int last_drawn_width;
393 mutable BufferView * cached_bview;
395 mutable boost::shared_ptr<LyXText> cached_text;
399 Paragraph * selstartpar;
400 Paragraph * selendpar;
402 lyx::pos_type selstartpos;
403 lyx::pos_type selendpos;
405 bool selstartboundary;
411 mutable save_state sstate;
414 // this is needed globally so we know that we're using it actually and
415 // so the LyXText-Cache is not erased until used!
416 mutable LyXText * lt;
418 // to remember old painted frame dimensions to clear it on the right spot!
425 bool in_update; /* as update is not reentrant! */
426 mutable BufferView * do_resize;
427 mutable bool do_reinit;
428 mutable bool in_insetAllowed;
430 // these are used to check for mouse movement in Motion selection code