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 void dimension(BufferView *, LyXFont const &, Dimension &) const;
91 int textWidth(BufferView *, bool fordraw = false) const;
93 void draw(BufferView *, LyXFont const &, int , float &) const;
95 void update(BufferView *, bool = false);
97 void setUpdateStatus(BufferView *, int what) const;
99 string const editMessage() const;
101 bool isTextInset() const { return true; }
103 void insetUnlock(BufferView *);
105 bool lockInsetInInset(BufferView *, UpdatableInset *);
107 bool unlockInsetInInset(BufferView *,
108 UpdatableInset *, bool lr = false);
110 bool updateInsetInInset(BufferView *, Inset *);
112 RESULT localDispatch(FuncRequest const &);
114 int latex(Buffer const *, std::ostream &,
115 bool fragile, bool free_spc) const;
117 int ascii(Buffer const *, std::ostream &, int linelen) const;
119 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
121 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
123 void validate(LaTeXFeatures & features) const;
125 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
127 void getCursorPos(BufferView *, int & x, int & y) const;
128 /// Get the absolute document x,y of the cursor
129 virtual void getCursor(BufferView &, int &, int &) const;
131 int insetInInsetY() const;
133 void fitInsetCursor(BufferView *) const;
135 bool insertInset(BufferView *, Inset *);
137 bool insetAllowed(Inset::Code) const;
139 UpdatableInset * getLockingInset() const;
141 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
143 void setFont(BufferView *, LyXFont const &,
144 bool toggleall = false,
145 bool selectall = false);
147 int getMaxWidth(BufferView *, UpdatableInset const *) const;
149 void init(InsetText const * ins = 0, bool same_id = false);
151 void writeParagraphData(Buffer const *, std::ostream &) const;
153 void setParagraphData(ParagraphList const &, bool same_id = false);
155 void setText(string const &, LyXFont const &);
157 void setAutoBreakRows(bool);
159 bool getAutoBreakRows() const { return autoBreakRows; }
161 void setDrawFrame(BufferView *, DrawFrame);
163 void setFrameColor(BufferView *, LColor::color);
165 LyXText * getLyXText(BufferView const *,
166 bool const recursive = false) const;
168 void deleteLyXText(BufferView *, bool recursive = true) const;
170 void resizeLyXText(BufferView *, bool force = false) const;
172 bool showInsetDialog(BufferView *) const;
174 std::vector<string> const getLabelList() const;
178 int scroll(bool recursive = true) const;
180 void scroll(BufferView * bv, float sx) const {
181 UpdatableInset::scroll(bv, sx);
184 void scroll(BufferView * bv, int offset) const {
185 UpdatableInset::scroll(bv, offset);
188 void selectAll(BufferView * bv);
190 void clearSelection(BufferView * bv);
192 Inset * getInsetFromID(int id) const;
194 ParagraphList * getParagraphs(int) const;
196 LyXCursor const & cursor(BufferView *) const;
198 void paragraph(Paragraph *);
200 bool allowSpellcheck() const { return true; }
203 selectNextWordToSpellcheck(BufferView *, float & value) const;
205 void selectSelectedWord(BufferView *);
207 void toggleSelection(BufferView *, bool kill_selection);
209 /// mark as erased for change tracking
210 void markErased() { clear(true); };
212 * Mark as new. Used when pasting in tabular, and adding rows
213 * or columns. Note that pasting will ensure that tracking already
214 * happens, and this just resets the changes for the copied text,
215 * whereas for row/col add, we need to start tracking changes
216 * for the (empty) paragraph contained.
218 void markNew(bool track_changes = false);
220 bool nextChange(BufferView *, lyx::pos_type & length);
223 bool searchForward(BufferView *, string const &,
224 bool = true, bool = false);
226 bool searchBackward(BufferView *, string const &,
227 bool = true, bool = false);
229 bool checkInsertChar(LyXFont &);
231 void getDrawFont(LyXFont &) const;
232 /// append text onto the existing text
233 void appendParagraphs(Buffer * bp, ParagraphList &);
236 void addPreview(grfx::PreviewLoader &) const;
239 // Public structures and variables
241 mutable int need_update;
243 bool haveParagraphs() const {
247 ParagraphList paragraphs;
250 void updateLocal(BufferView *, int what, bool mark_dirty);
251 /// set parameters for an initial lock of this inset
252 void lockInset(BufferView *);
253 /// lock an inset inside this one
254 void lockInset(BufferView *, UpdatableInset *);
256 mutable int drawTextXOffset;
258 mutable int drawTextYOffset;
262 DrawFrame drawFrame_;
264 LColor::color frame_color;
268 void lfunMousePress(FuncRequest const &);
270 bool lfunMouseRelease(FuncRequest const &);
272 void lfunMouseMotion(FuncRequest const &);
277 InnerCache(boost::shared_ptr<LyXText>);
279 boost::shared_ptr<LyXText> text;
284 typedef std::map<BufferView *, InnerCache> Cache;
286 typedef Cache::value_type value_type;
288 RESULT moveRight(BufferView *,
289 bool activate_inset = true,
290 bool selecting = false);
292 RESULT moveLeft(BufferView *,
293 bool activate_inset = true,
294 bool selecting = false);
296 RESULT moveRightIntern(BufferView *, bool front,
297 bool activate_inset = true,
298 bool selecting = false);
300 RESULT moveLeftIntern(BufferView *, bool front,
301 bool activate_inset = true,
302 bool selecting = false);
305 RESULT moveUp(BufferView *);
307 RESULT moveDown(BufferView *);
309 void setCharFont(Buffer const *, int pos, LyXFont const & font);
311 bool checkAndActivateInset(BufferView * bv, bool front);
313 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
314 mouse_button::state button = mouse_button::none);
316 void removeNewlines();
318 int cx(BufferView *) const;
320 int cix(BufferView *) const;
322 int cy(BufferView *) const;
324 int ciy(BufferView *) const;
326 lyx::pos_type cpos(BufferView *) const;
328 ParagraphList::iterator cpar(BufferView *) const;
330 bool cboundary(BufferView *) const;
332 RowList::iterator crow(BufferView *) const;
334 void drawFrame(Painter &, int x) const;
336 void clearInset(BufferView *, int start_x, int baseline) const;
338 void saveLyXTextState(LyXText *) const;
340 void restoreLyXTextState(LyXText *) const;
342 void reinitLyXText() const;
344 void collapseParagraphs(BufferView *);
346 /* Private structures and variables */
350 mutable int insetAscent;
352 mutable int insetDescent;
354 mutable int insetWidth;
358 ParagraphList::iterator inset_par;
360 lyx::pos_type inset_pos;
368 mutable int old_max_width;
372 UpdatableInset * the_locking_inset;
374 mutable ParagraphList::iterator old_par;
378 mutable int last_drawn_width;
380 mutable BufferView * cached_bview;
382 mutable boost::shared_ptr<LyXText> cached_text;
386 Paragraph * selstartpar;
387 Paragraph * selendpar;
389 lyx::pos_type selstartpos;
390 lyx::pos_type selendpos;
392 bool selstartboundary;
398 mutable save_state sstate;
401 // this is needed globally so we know that we're using it actually and
402 // so the LyXText-Cache is not erased until used!
403 mutable LyXText * lt;
405 // to remember old painted frame dimensions to clear it on the right spot!
412 bool in_update; /* as update is not reentrant! */
413 mutable BufferView * do_resize;
414 mutable bool do_reinit;
415 mutable bool in_insetAllowed;
417 // these are used to check for mouse movement in Motion selection code