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;
135 /// Get the absolute document x,y of the cursor
136 virtual void getCursor(BufferView &, int &, int &) const;
138 int insetInInsetY() const;
140 void fitInsetCursor(BufferView *) const;
142 bool insertInset(BufferView *, Inset *);
144 bool insetAllowed(Inset::Code) const;
146 UpdatableInset * getLockingInset() const;
148 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
150 void setFont(BufferView *, LyXFont const &,
151 bool toggleall = false,
152 bool selectall = false);
154 int getMaxWidth(BufferView *, UpdatableInset const *) const;
156 void init(InsetText const * ins = 0, bool same_id = false);
158 void writeParagraphData(Buffer const *, std::ostream &) const;
160 void setParagraphData(ParagraphList const &, bool same_id = false);
162 void setText(string const &, LyXFont const &);
164 void setAutoBreakRows(bool);
166 bool getAutoBreakRows() const { return autoBreakRows; }
168 void setDrawFrame(BufferView *, DrawFrame);
170 void setFrameColor(BufferView *, LColor::color);
172 LyXText * getLyXText(BufferView const *,
173 bool const recursive = false) const;
175 void deleteLyXText(BufferView *, bool recursive = true) const;
177 void resizeLyXText(BufferView *, bool force = false) const;
179 bool showInsetDialog(BufferView *) const;
181 std::vector<string> const getLabelList() const;
185 int scroll(bool recursive = true) const;
187 void scroll(BufferView * bv, float sx) const {
188 UpdatableInset::scroll(bv, sx);
191 void scroll(BufferView * bv, int offset) const {
192 UpdatableInset::scroll(bv, offset);
195 void selectAll(BufferView * bv);
197 void clearSelection(BufferView * bv);
199 Inset * getInsetFromID(int id) const;
201 Paragraph * firstParagraph() const;
203 Paragraph * getFirstParagraph(int) const;
205 LyXCursor const & cursor(BufferView *) const;
207 void paragraph(Paragraph *);
209 bool allowSpellcheck() const { return true; }
212 selectNextWordToSpellcheck(BufferView *, float & value) const;
214 void selectSelectedWord(BufferView *);
216 void toggleSelection(BufferView *, bool kill_selection);
218 /// mark as erased for change tracking
219 void markErased() { clear(true); };
221 * Mark as new. Used when pasting in tabular, and adding rows
222 * or columns. Note that pasting will ensure that tracking already
223 * happens, and this just resets the changes for the copied text,
224 * whereas for row/col add, we need to start tracking changes
225 * for the (empty) paragraph contained.
227 void markNew(bool track_changes = false);
229 bool nextChange(BufferView *, lyx::pos_type & length);
232 bool searchForward(BufferView *, string const &,
233 bool = true, bool = false);
235 bool searchBackward(BufferView *, string const &,
236 bool = true, bool = false);
238 bool checkInsertChar(LyXFont &);
240 void getDrawFont(LyXFont &) const;
241 /// append text onto the existing text
242 void appendParagraphs(Buffer * bp, ParagraphList &);
245 void addPreview(grfx::PreviewLoader &) const;
248 // Public structures and variables
250 mutable int need_update;
252 bool haveParagraphs() const {
256 ParagraphList paragraphs;
259 void updateLocal(BufferView *, int what, bool mark_dirty);
260 /// set parameters for an initial lock of this inset
261 void lockInset(BufferView *);
262 /// lock an inset inside this one
263 void lockInset(BufferView *, UpdatableInset *);
265 mutable int drawTextXOffset;
267 mutable int drawTextYOffset;
271 DrawFrame drawFrame_;
273 LColor::color frame_color;
277 void lfunMousePress(FuncRequest const &);
279 bool lfunMouseRelease(FuncRequest const &);
281 void lfunMouseMotion(FuncRequest const &);
286 InnerCache(boost::shared_ptr<LyXText>);
288 boost::shared_ptr<LyXText> text;
293 typedef std::map<BufferView *, InnerCache> Cache;
295 typedef Cache::value_type value_type;
297 RESULT moveRight(BufferView *,
298 bool activate_inset = true,
299 bool selecting = false);
301 RESULT moveLeft(BufferView *,
302 bool activate_inset = true,
303 bool selecting = false);
305 RESULT moveRightIntern(BufferView *, bool front,
306 bool activate_inset = true,
307 bool selecting = false);
309 RESULT moveLeftIntern(BufferView *, bool front,
310 bool activate_inset = true,
311 bool selecting = false);
314 RESULT moveUp(BufferView *);
316 RESULT moveDown(BufferView *);
318 void setCharFont(Buffer const *, int pos, LyXFont const & font);
320 bool checkAndActivateInset(BufferView * bv, bool front);
322 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
323 mouse_button::state button = mouse_button::none);
325 void removeNewlines();
327 int cx(BufferView *) const;
329 int cix(BufferView *) const;
331 int cy(BufferView *) const;
333 int ciy(BufferView *) const;
335 lyx::pos_type cpos(BufferView *) const;
337 ParagraphList::iterator cpar(BufferView *) const;
339 bool cboundary(BufferView *) const;
341 RowList::iterator crow(BufferView *) const;
343 void drawFrame(Painter &, int x) const;
345 void clearInset(BufferView *, int start_x, int baseline) const;
347 void saveLyXTextState(LyXText *) const;
349 void restoreLyXTextState(LyXText *) const;
351 void reinitLyXText() const;
353 void collapseParagraphs(BufferView *);
355 /* Private structures and variables */
359 mutable int insetAscent;
361 mutable int insetDescent;
363 mutable int insetWidth;
367 ParagraphList::iterator inset_par;
369 lyx::pos_type inset_pos;
377 mutable int old_max_width;
381 UpdatableInset * the_locking_inset;
383 mutable ParagraphList::iterator old_par;
387 mutable int last_drawn_width;
389 mutable BufferView * cached_bview;
391 mutable boost::shared_ptr<LyXText> cached_text;
395 Paragraph * selstartpar;
396 Paragraph * selendpar;
398 lyx::pos_type selstartpos;
399 lyx::pos_type selendpos;
401 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