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"
21 #include "support/types.h"
23 #include <boost/shared_ptr.hpp>
35 A text inset is like a TeX box to write full text
36 (including styles and other insets) in a given space.
39 class InsetText : public UpdatableInset {
42 /// numbers need because of test if codeA < codeB
70 InsetText(BufferParams const &);
73 InsetText(InsetText const &, bool same_id = false);
77 Inset * clone(Buffer const &, bool same_id = false) const;
79 InsetText & operator=(InsetText const & it);
80 /// empty inset to empty par, or just mark as erased
81 void clear(bool just_mark_erased);
83 void read(Buffer const *, LyXLex &);
85 void write(Buffer const *, std::ostream &) const;
87 int ascent(BufferView *, LyXFont const &) const;
89 int descent(BufferView *, LyXFont const &) const;
91 int width(BufferView *, LyXFont const & f) const;
93 int textWidth(BufferView *, bool fordraw = false) const;
95 void draw(BufferView *, LyXFont const &, int , float &) const;
97 void update(BufferView *, bool = false);
99 void setUpdateStatus(BufferView *, int what) const;
101 string const editMessage() const;
103 void edit(BufferView *, int, int, mouse_button::state);
105 void edit(BufferView *, bool front = true);
107 bool isTextInset() const { return true; }
109 void insetUnlock(BufferView *);
111 bool lockInsetInInset(BufferView *, UpdatableInset *);
113 bool unlockInsetInInset(BufferView *,
114 UpdatableInset *, bool lr = false);
116 bool updateInsetInInset(BufferView *, Inset *);
118 RESULT localDispatch(FuncRequest const &);
120 int latex(Buffer const *, std::ostream &,
121 bool fragile, bool free_spc) const;
123 int ascii(Buffer const *, std::ostream &, int linelen) const;
125 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
127 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
129 void validate(LaTeXFeatures & features) const;
131 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
133 void getCursorPos(BufferView *, int & x, int & y) const;
135 int insetInInsetY() const;
137 void toggleInsetCursor(BufferView *);
139 void showInsetCursor(BufferView *, bool show = true);
141 void hideInsetCursor(BufferView *);
143 void fitInsetCursor(BufferView *) const;
145 bool insertInset(BufferView *, Inset *);
147 bool insetAllowed(Inset::Code) const;
149 UpdatableInset * getLockingInset() const;
151 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
153 void setFont(BufferView *, LyXFont const &,
154 bool toggleall = false,
155 bool selectall = false);
157 int getMaxWidth(BufferView *, UpdatableInset const *) const;
159 void init(InsetText const * ins = 0, bool same_id = false);
161 void writeParagraphData(Buffer const *, std::ostream &) const;
163 void setParagraphData(Paragraph *, bool same_id = false);
165 void setText(string const &, LyXFont const &);
167 void setAutoBreakRows(bool);
169 bool getAutoBreakRows() const { return autoBreakRows; }
171 void setDrawFrame(BufferView *, DrawFrame);
173 void setFrameColor(BufferView *, LColor::color);
175 LyXText * getLyXText(BufferView const *,
176 bool const recursive = false) const;
178 void deleteLyXText(BufferView *, bool recursive = true) const;
180 void resizeLyXText(BufferView *, bool force = false) const;
182 bool showInsetDialog(BufferView *) const;
184 std::vector<string> const getLabelList() const;
188 int scroll(bool recursive = true) const;
190 void scroll(BufferView * bv, float sx) const {
191 UpdatableInset::scroll(bv, sx);
194 void scroll(BufferView * bv, int offset) const {
195 UpdatableInset::scroll(bv, offset);
198 void selectAll(BufferView * bv);
200 void clearSelection(BufferView * bv);
202 Inset * getInsetFromID(int id) const;
204 Paragraph * firstParagraph() const;
206 Paragraph * getFirstParagraph(int) const;
208 LyXCursor const & cursor(BufferView *) const;
210 Paragraph * paragraph() const;
212 void paragraph(Paragraph *);
214 bool allowSpellcheck() const { return true; }
217 selectNextWordToSpellcheck(BufferView *, float & value) const;
219 void selectSelectedWord(BufferView *);
221 void toggleSelection(BufferView *, bool kill_selection);
223 /// mark as erased for change tracking
224 void markErased() { clear(true); };
226 * Mark as new. Used when pasting in tabular, and adding rows
227 * or columns. Note that pasting will ensure that tracking already
228 * happens, and this just resets the changes for the copied text,
229 * whereas for row/col add, we need to start tracking changes
230 * for the (empty) paragraph contained.
232 void markNew(bool track_changes = false);
234 bool nextChange(BufferView *, lyx::pos_type & length);
237 bool searchForward(BufferView *, string const &,
238 bool = true, bool = false);
240 bool searchBackward(BufferView *, string const &,
241 bool = true, bool = false);
243 bool checkInsertChar(LyXFont &);
245 void getDrawFont(LyXFont &) const;
246 /// append text onto the existing text
247 void appendParagraphs(Buffer * bp, Paragraph *);
250 void addPreview(grfx::PreviewLoader &) const;
253 // Public structures and variables
255 mutable int need_update;
258 ParagraphList paragraphs;
261 void updateLocal(BufferView *, int what, bool mark_dirty);
262 /// set parameters for an initial lock of this inset
263 void lockInset(BufferView *);
264 /// lock an inset inside this one
265 void lockInset(BufferView *, UpdatableInset *);
267 mutable int drawTextXOffset;
269 mutable int drawTextYOffset;
273 DrawFrame drawFrame_;
275 LColor::color frame_color;
279 void lfunMousePress(FuncRequest const &);
281 bool lfunMouseRelease(FuncRequest const &);
283 void lfunMouseMotion(FuncRequest const &);
288 InnerCache(boost::shared_ptr<LyXText>);
290 boost::shared_ptr<LyXText> text;
295 typedef std::map<BufferView *, InnerCache> Cache;
297 typedef Cache::value_type value_type;
299 RESULT moveRight(BufferView *,
300 bool activate_inset = true,
301 bool selecting = false);
303 RESULT moveLeft(BufferView *,
304 bool activate_inset = true,
305 bool selecting = false);
307 RESULT moveRightIntern(BufferView *, bool front,
308 bool activate_inset = true,
309 bool selecting = false);
311 RESULT moveLeftIntern(BufferView *, bool front,
312 bool activate_inset = true,
313 bool selecting = false);
316 RESULT moveUp(BufferView *);
318 RESULT moveDown(BufferView *);
320 void setCharFont(Buffer const *, int pos, LyXFont const & font);
322 bool checkAndActivateInset(BufferView * bv, bool front);
324 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
325 mouse_button::state button = mouse_button::none);
327 void removeNewlines();
329 int cx(BufferView *) const;
331 int cix(BufferView *) const;
333 int cy(BufferView *) const;
335 int ciy(BufferView *) const;
337 lyx::pos_type cpos(BufferView *) const;
339 Paragraph * cpar(BufferView *) const;
341 bool cboundary(BufferView *) const;
343 Row * crow(BufferView *) const;
345 void drawFrame(Painter &, int x) const;
347 void clearInset(BufferView *, int start_x, int baseline) const;
349 void saveLyXTextState(LyXText *) const;
351 void restoreLyXTextState(LyXText *) const;
353 void reinitLyXText() const;
355 void collapseParagraphs(BufferView *);
357 /* Private structures and variables */
361 mutable int insetAscent;
363 mutable int insetDescent;
365 mutable int insetWidth;
369 Paragraph * inset_par;
371 lyx::pos_type inset_pos;
379 mutable int old_max_width;
383 UpdatableInset * the_locking_inset;
385 mutable Paragraph * old_par;
389 mutable int last_drawn_width;
391 mutable BufferView * cached_bview;
393 mutable boost::shared_ptr<LyXText> cached_text;
397 Paragraph * selstartpar;
398 Paragraph * selendpar;
400 lyx::pos_type selstartpos;
401 lyx::pos_type selendpos;
403 bool selstartboundary;
409 mutable save_state sstate;
412 // this is needed globally so we know that we're using it actually and
413 // so the LyXText-Cache is not erased until used!
414 mutable LyXText * lt;
416 // to remember old painted frame dimensions to clear it on the right spot!
423 bool in_update; /* as update is not reentrant! */
424 mutable BufferView * do_resize;
425 mutable bool do_reinit;
426 mutable bool in_insetAllowed;
428 // these are used to check for mouse movement in Motion selection code