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 ParagraphList * getParagraphs(int) const;
203 LyXCursor const & cursor(BufferView *) const;
205 void paragraph(Paragraph *);
207 bool allowSpellcheck() const { return true; }
210 selectNextWordToSpellcheck(BufferView *, float & value) const;
212 void selectSelectedWord(BufferView *);
214 void toggleSelection(BufferView *, bool kill_selection);
216 /// mark as erased for change tracking
217 void markErased() { clear(true); };
219 * Mark as new. Used when pasting in tabular, and adding rows
220 * or columns. Note that pasting will ensure that tracking already
221 * happens, and this just resets the changes for the copied text,
222 * whereas for row/col add, we need to start tracking changes
223 * for the (empty) paragraph contained.
225 void markNew(bool track_changes = false);
227 bool nextChange(BufferView *, lyx::pos_type & length);
230 bool searchForward(BufferView *, string const &,
231 bool = true, bool = false);
233 bool searchBackward(BufferView *, string const &,
234 bool = true, bool = false);
236 bool checkInsertChar(LyXFont &);
238 void getDrawFont(LyXFont &) const;
239 /// append text onto the existing text
240 void appendParagraphs(Buffer * bp, ParagraphList &);
243 void addPreview(grfx::PreviewLoader &) const;
246 // Public structures and variables
248 mutable int need_update;
250 bool haveParagraphs() const {
254 ParagraphList paragraphs;
257 void updateLocal(BufferView *, int what, bool mark_dirty);
258 /// set parameters for an initial lock of this inset
259 void lockInset(BufferView *);
260 /// lock an inset inside this one
261 void lockInset(BufferView *, UpdatableInset *);
263 mutable int drawTextXOffset;
265 mutable int drawTextYOffset;
269 DrawFrame drawFrame_;
271 LColor::color frame_color;
275 void lfunMousePress(FuncRequest const &);
277 bool lfunMouseRelease(FuncRequest const &);
279 void lfunMouseMotion(FuncRequest const &);
284 InnerCache(boost::shared_ptr<LyXText>);
286 boost::shared_ptr<LyXText> text;
291 typedef std::map<BufferView *, InnerCache> Cache;
293 typedef Cache::value_type value_type;
295 RESULT moveRight(BufferView *,
296 bool activate_inset = true,
297 bool selecting = false);
299 RESULT moveLeft(BufferView *,
300 bool activate_inset = true,
301 bool selecting = false);
303 RESULT moveRightIntern(BufferView *, bool front,
304 bool activate_inset = true,
305 bool selecting = false);
307 RESULT moveLeftIntern(BufferView *, bool front,
308 bool activate_inset = true,
309 bool selecting = false);
312 RESULT moveUp(BufferView *);
314 RESULT moveDown(BufferView *);
316 void setCharFont(Buffer const *, int pos, LyXFont const & font);
318 bool checkAndActivateInset(BufferView * bv, bool front);
320 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
321 mouse_button::state button = mouse_button::none);
323 void removeNewlines();
325 int cx(BufferView *) const;
327 int cix(BufferView *) const;
329 int cy(BufferView *) const;
331 int ciy(BufferView *) const;
333 lyx::pos_type cpos(BufferView *) const;
335 ParagraphList::iterator cpar(BufferView *) const;
337 bool cboundary(BufferView *) const;
339 RowList::iterator crow(BufferView *) const;
341 void drawFrame(Painter &, int x) const;
343 void clearInset(BufferView *, int start_x, int baseline) const;
345 void saveLyXTextState(LyXText *) const;
347 void restoreLyXTextState(LyXText *) const;
349 void reinitLyXText() const;
351 void collapseParagraphs(BufferView *);
353 /* Private structures and variables */
357 mutable int insetAscent;
359 mutable int insetDescent;
361 mutable int insetWidth;
365 ParagraphList::iterator inset_par;
367 lyx::pos_type inset_pos;
375 mutable int old_max_width;
379 UpdatableInset * the_locking_inset;
381 mutable ParagraphList::iterator old_par;
385 mutable int last_drawn_width;
387 mutable BufferView * cached_bview;
389 mutable boost::shared_ptr<LyXText> cached_text;
393 Paragraph * selstartpar;
394 Paragraph * selendpar;
396 lyx::pos_type selstartpos;
397 lyx::pos_type selendpos;
399 bool selstartboundary;
405 mutable save_state sstate;
408 // this is needed globally so we know that we're using it actually and
409 // so the LyXText-Cache is not erased until used!
410 mutable LyXText * lt;
412 // to remember old painted frame dimensions to clear it on the right spot!
419 bool in_update; /* as update is not reentrant! */
420 mutable BufferView * do_resize;
421 mutable bool do_reinit;
422 mutable bool in_insetAllowed;
424 // these are used to check for mouse movement in Motion selection code