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(Paragraph *, 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, Paragraph *);
249 void addPreview(grfx::PreviewLoader &) const;
252 // Public structures and variables
254 mutable int need_update;
257 ParagraphList paragraphs;
260 void updateLocal(BufferView *, int what, bool mark_dirty);
261 /// set parameters for an initial lock of this inset
262 void lockInset(BufferView *);
263 /// lock an inset inside this one
264 void lockInset(BufferView *, UpdatableInset *);
266 mutable int drawTextXOffset;
268 mutable int drawTextYOffset;
272 DrawFrame drawFrame_;
274 LColor::color frame_color;
278 void lfunMousePress(FuncRequest const &);
280 bool lfunMouseRelease(FuncRequest const &);
282 void lfunMouseMotion(FuncRequest const &);
287 InnerCache(boost::shared_ptr<LyXText>);
289 boost::shared_ptr<LyXText> text;
294 typedef std::map<BufferView *, InnerCache> Cache;
296 typedef Cache::value_type value_type;
298 RESULT moveRight(BufferView *,
299 bool activate_inset = true,
300 bool selecting = false);
302 RESULT moveLeft(BufferView *,
303 bool activate_inset = true,
304 bool selecting = false);
306 RESULT moveRightIntern(BufferView *, bool front,
307 bool activate_inset = true,
308 bool selecting = false);
310 RESULT moveLeftIntern(BufferView *, bool front,
311 bool activate_inset = true,
312 bool selecting = false);
315 RESULT moveUp(BufferView *);
317 RESULT moveDown(BufferView *);
319 void setCharFont(Buffer const *, int pos, LyXFont const & font);
321 bool checkAndActivateInset(BufferView * bv, bool front);
323 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
324 mouse_button::state button = mouse_button::none);
326 void removeNewlines();
328 int cx(BufferView *) const;
330 int cix(BufferView *) const;
332 int cy(BufferView *) const;
334 int ciy(BufferView *) const;
336 lyx::pos_type cpos(BufferView *) const;
338 Paragraph * cpar(BufferView *) const;
340 bool cboundary(BufferView *) const;
342 RowList::iterator crow(BufferView *) const;
344 void drawFrame(Painter &, int x) const;
346 void clearInset(BufferView *, int start_x, int baseline) const;
348 void saveLyXTextState(LyXText *) const;
350 void restoreLyXTextState(LyXText *) const;
352 void reinitLyXText() const;
354 void collapseParagraphs(BufferView *);
356 /* Private structures and variables */
360 mutable int insetAscent;
362 mutable int insetDescent;
364 mutable int insetWidth;
368 Paragraph * inset_par;
370 lyx::pos_type inset_pos;
378 mutable int old_max_width;
382 UpdatableInset * the_locking_inset;
384 mutable Paragraph * old_par;
388 mutable int last_drawn_width;
390 mutable BufferView * cached_bview;
392 mutable boost::shared_ptr<LyXText> cached_text;
396 Paragraph * selstartpar;
397 Paragraph * selendpar;
399 lyx::pos_type selstartpos;
400 lyx::pos_type selendpos;
402 bool selstartboundary;
408 mutable save_state sstate;
411 // this is needed globally so we know that we're using it actually and
412 // so the LyXText-Cache is not erased until used!
413 mutable LyXText * lt;
415 // to remember old painted frame dimensions to clear it on the right spot!
422 bool in_update; /* as update is not reentrant! */
423 mutable BufferView * do_resize;
424 mutable bool do_reinit;
425 mutable bool in_insetAllowed;
427 // these are used to check for mouse movement in Motion selection code