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
15 #include "updatableinset.h"
18 #include "ParagraphList.h"
20 #include "frontends/mouse_state.h"
22 #include "support/types.h"
24 #include <boost/shared_ptr.hpp>
37 A text inset is like a TeX box to write full text
38 (including styles and other insets) in a given space.
41 class InsetText : public UpdatableInset {
44 /// 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 &) const;
99 void update(BufferView *, bool = false);
101 void setUpdateStatus(BufferView *, int what) const;
103 string const editMessage() const;
105 bool isTextInset() const { return true; }
107 void insetUnlock(BufferView *);
109 bool lockInsetInInset(BufferView *, UpdatableInset *);
111 bool unlockInsetInInset(BufferView *,
112 UpdatableInset *, bool lr = false);
114 bool updateInsetInInset(BufferView *, Inset *);
116 RESULT localDispatch(FuncRequest const &);
118 int latex(Buffer const *, std::ostream &,
119 bool fragile, bool free_spc) const;
121 int ascii(Buffer const *, std::ostream &, int linelen) const;
123 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
125 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
127 void validate(LaTeXFeatures & features) const;
129 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
131 void getCursorPos(BufferView *, int & x, int & y) const;
132 /// Get the absolute document x,y of the cursor
133 virtual void getCursor(BufferView &, int &, int &) const;
135 int insetInInsetY() const;
137 void fitInsetCursor(BufferView *) const;
139 bool insertInset(BufferView *, Inset *);
141 bool insetAllowed(Inset::Code) const;
143 UpdatableInset * getLockingInset() const;
145 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
147 void setFont(BufferView *, LyXFont const &,
148 bool toggleall = false,
149 bool selectall = false);
151 int getMaxWidth(BufferView *, UpdatableInset const *) const;
153 void init(InsetText const * ins = 0, bool same_id = false);
155 void writeParagraphData(Buffer const *, std::ostream &) const;
157 void setParagraphData(ParagraphList const &, bool same_id = false);
159 void setText(string const &, LyXFont const &);
161 void setAutoBreakRows(bool);
163 bool getAutoBreakRows() const { return autoBreakRows; }
165 void setDrawFrame(BufferView *, DrawFrame);
167 void setFrameColor(BufferView *, LColor::color);
169 LyXText * getLyXText(BufferView const *,
170 bool const recursive = false) const;
172 void deleteLyXText(BufferView *, bool recursive = true) const;
174 void resizeLyXText(BufferView *, bool force = false) const;
176 bool showInsetDialog(BufferView *) const;
178 std::vector<string> const getLabelList() const;
182 int scroll(bool recursive = true) const;
184 void scroll(BufferView * bv, float sx) const {
185 UpdatableInset::scroll(bv, sx);
188 void scroll(BufferView * bv, int offset) const {
189 UpdatableInset::scroll(bv, offset);
192 void selectAll(BufferView * bv);
194 void clearSelection(BufferView * bv);
196 Inset * getInsetFromID(int id) const;
198 ParagraphList * getParagraphs(int) const;
200 LyXCursor const & cursor(BufferView *) const;
202 void paragraph(Paragraph *);
204 bool allowSpellcheck() const { return true; }
207 selectNextWordToSpellcheck(BufferView *, float & value) const;
209 void selectSelectedWord(BufferView *);
211 void toggleSelection(BufferView *, bool kill_selection);
213 /// mark as erased for change tracking
214 void markErased() { clear(true); };
216 * Mark as new. Used when pasting in tabular, and adding rows
217 * or columns. Note that pasting will ensure that tracking already
218 * happens, and this just resets the changes for the copied text,
219 * whereas for row/col add, we need to start tracking changes
220 * for the (empty) paragraph contained.
222 void markNew(bool track_changes = false);
224 bool nextChange(BufferView *, lyx::pos_type & length);
227 bool searchForward(BufferView *, string const &,
228 bool = true, bool = false);
230 bool searchBackward(BufferView *, string const &,
231 bool = true, bool = false);
233 bool checkInsertChar(LyXFont &);
235 void getDrawFont(LyXFont &) const;
236 /// append text onto the existing text
237 void appendParagraphs(Buffer * bp, ParagraphList &);
240 void addPreview(grfx::PreviewLoader &) const;
243 // Public structures and variables
245 mutable int need_update;
247 bool haveParagraphs() const {
251 ParagraphList paragraphs;
254 void updateLocal(BufferView *, int what, bool mark_dirty);
255 /// set parameters for an initial lock of this inset
256 void lockInset(BufferView *);
257 /// lock an inset inside this one
258 void lockInset(BufferView *, UpdatableInset *);
260 mutable int drawTextXOffset;
262 mutable int drawTextYOffset;
266 DrawFrame drawFrame_;
268 LColor::color frame_color;
272 void lfunMousePress(FuncRequest const &);
274 bool lfunMouseRelease(FuncRequest const &);
276 void lfunMouseMotion(FuncRequest const &);
281 InnerCache(boost::shared_ptr<LyXText>);
283 boost::shared_ptr<LyXText> text;
288 typedef std::map<BufferView *, InnerCache> Cache;
290 typedef Cache::value_type value_type;
292 RESULT moveRight(BufferView *,
293 bool activate_inset = true,
294 bool selecting = false);
296 RESULT moveLeft(BufferView *,
297 bool activate_inset = true,
298 bool selecting = false);
300 RESULT moveRightIntern(BufferView *, bool front,
301 bool activate_inset = true,
302 bool selecting = false);
304 RESULT moveLeftIntern(BufferView *, bool front,
305 bool activate_inset = true,
306 bool selecting = false);
309 RESULT moveUp(BufferView *);
311 RESULT moveDown(BufferView *);
313 void setCharFont(Buffer const *, int pos, LyXFont const & font);
315 bool checkAndActivateInset(BufferView * bv, bool front);
317 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
318 mouse_button::state button = mouse_button::none);
320 void removeNewlines();
322 int cx(BufferView *) const;
324 int cix(BufferView *) const;
326 int cy(BufferView *) const;
328 int ciy(BufferView *) const;
330 lyx::pos_type cpos(BufferView *) const;
332 ParagraphList::iterator cpar(BufferView *) const;
334 bool cboundary(BufferView *) const;
336 RowList::iterator crow(BufferView *) const;
338 void drawFrame(Painter &, int x) const;
340 void clearInset(BufferView *, int start_x, int baseline) const;
342 void saveLyXTextState(LyXText *) const;
344 void restoreLyXTextState(LyXText *) const;
346 void reinitLyXText() const;
348 void collapseParagraphs(BufferView *);
350 /* Private structures and variables */
354 mutable int insetAscent;
356 mutable int insetDescent;
358 mutable int insetWidth;
362 ParagraphList::iterator inset_par;
364 lyx::pos_type inset_pos;
372 mutable int old_max_width;
376 UpdatableInset * the_locking_inset;
378 mutable ParagraphList::iterator old_par;
382 mutable int last_drawn_width;
384 mutable BufferView * cached_bview;
386 mutable boost::shared_ptr<LyXText> cached_text;
390 Paragraph * selstartpar;
391 Paragraph * selendpar;
393 lyx::pos_type selstartpos;
394 lyx::pos_type selendpos;
396 bool selstartboundary;
402 mutable save_state sstate;
405 // this is needed globally so we know that we're using it actually and
406 // so the LyXText-Cache is not erased until used!
407 mutable LyXText * lt;
409 // to remember old painted frame dimensions to clear it on the right spot!
416 bool in_update; /* as update is not reentrant! */
417 mutable BufferView * do_resize;
418 mutable bool do_reinit;
419 mutable bool in_insetAllowed;
421 // these are used to check for mouse movement in Motion selection code