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 "dimension.h"
21 #include "frontends/mouse_state.h"
23 #include "support/types.h"
25 #include <boost/shared_ptr.hpp>
38 A text inset is like a TeX box to write full text
39 (including styles and other insets) in a given space.
42 class InsetText : public UpdatableInset {
45 /// numbers need because of test if codeA < codeB
73 InsetText(BufferParams const &);
76 InsetText(InsetText const &);
79 //InsetText(InsetText const &, bool same_id);
83 Inset * clone(Buffer const &) const;
85 //Inset * clone(Buffer const &, bool same_id) const;
87 InsetText & operator=(InsetText const & it);
88 /// empty inset to empty par, or just mark as erased
89 void clear(bool just_mark_erased);
91 void read(Buffer const *, LyXLex &);
93 void write(Buffer const *, std::ostream &) const;
95 void dimension(BufferView *, LyXFont const &, Dimension &) const;
97 int textWidth(BufferView *, bool fordraw = false) const;
99 void draw(BufferView *, LyXFont const &, int , float &) const;
101 void update(BufferView *, bool = false);
103 void setUpdateStatus(BufferView *, int what) const;
105 string const editMessage() const;
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 LatexRunParams const &) 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;
134 /// Get the absolute document x,y of the cursor
135 virtual void getCursor(BufferView &, int &, int &) const;
137 int insetInInsetY() const;
139 void fitInsetCursor(BufferView *) const;
141 bool insertInset(BufferView *, Inset *);
143 bool insetAllowed(Inset::Code) const;
145 UpdatableInset * getLockingInset() const;
147 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
149 void setFont(BufferView *, LyXFont const &,
150 bool toggleall = false,
151 bool selectall = false);
153 int getMaxWidth(BufferView *, UpdatableInset const *) const;
155 void init(InsetText const * ins);
157 //void init(InsetText const * ins, bool same_id);
159 void writeParagraphData(Buffer const *, std::ostream &) const;
161 void setParagraphData(ParagraphList const &);
163 //void setParagraphData(ParagraphList const &, bool same_id);
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 ParagraphList * getParagraphs(int) const;
206 LyXCursor const & cursor(BufferView *) const;
208 bool allowSpellcheck() const { return true; }
211 selectNextWordToSpellcheck(BufferView *, float & value) const;
213 void selectSelectedWord(BufferView *);
215 void toggleSelection(BufferView *, bool kill_selection);
217 /// mark as erased for change tracking
218 void markErased() { clear(true); };
220 * Mark as new. Used when pasting in tabular, and adding rows
221 * or columns. Note that pasting will ensure that tracking already
222 * happens, and this just resets the changes for the copied text,
223 * whereas for row/col add, we need to start tracking changes
224 * for the (empty) paragraph contained.
226 void markNew(bool track_changes = false);
228 bool nextChange(BufferView *, lyx::pos_type & length);
231 bool searchForward(BufferView *, string const &,
232 bool = true, bool = false);
234 bool searchBackward(BufferView *, string const &,
235 bool = true, bool = false);
237 bool checkInsertChar(LyXFont &);
239 void getDrawFont(LyXFont &) const;
240 /// append text onto the existing text
241 void appendParagraphs(Buffer * bp, ParagraphList &);
244 void addPreview(grfx::PreviewLoader &) const;
247 // Public structures and variables
249 mutable int need_update;
251 bool haveParagraphs() const {
255 ParagraphList paragraphs;
258 void updateLocal(BufferView *, int what, bool mark_dirty);
259 /// set parameters for an initial lock of this inset
260 void lockInset(BufferView *);
261 /// lock an inset inside this one
262 void lockInset(BufferView *, UpdatableInset *);
264 mutable int drawTextXOffset;
266 mutable int drawTextYOffset;
270 DrawFrame drawFrame_;
272 LColor::color frame_color;
276 void lfunMousePress(FuncRequest const &);
278 bool lfunMouseRelease(FuncRequest const &);
280 void lfunMouseMotion(FuncRequest const &);
285 InnerCache(boost::shared_ptr<LyXText>);
287 boost::shared_ptr<LyXText> text;
292 typedef std::map<BufferView *, InnerCache> Cache;
294 typedef Cache::value_type value_type;
296 RESULT moveRight(BufferView *,
297 bool activate_inset = true,
298 bool selecting = false);
300 RESULT moveLeft(BufferView *,
301 bool activate_inset = true,
302 bool selecting = false);
304 RESULT moveRightIntern(BufferView *, bool front,
305 bool activate_inset = true,
306 bool selecting = false);
308 RESULT moveLeftIntern(BufferView *, bool front,
309 bool activate_inset = true,
310 bool selecting = false);
313 RESULT moveUp(BufferView *);
315 RESULT moveDown(BufferView *);
317 void setCharFont(Buffer const *, int pos, LyXFont const & font);
319 bool checkAndActivateInset(BufferView * bv, bool front);
321 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
322 mouse_button::state button = mouse_button::none);
324 void removeNewlines();
326 int cx(BufferView *) const;
328 int cix(BufferView *) const;
330 int cy(BufferView *) const;
332 int ciy(BufferView *) const;
334 lyx::pos_type cpos(BufferView *) const;
336 ParagraphList::iterator cpar(BufferView *) const;
338 bool cboundary(BufferView *) const;
340 RowList::iterator crow(BufferView *) const;
342 void drawFrame(Painter &, int x) const;
344 void clearInset(BufferView *, int start_x, int baseline) const;
346 void saveLyXTextState(LyXText *) const;
348 void restoreLyXTextState(LyXText *) const;
350 void reinitLyXText() const;
352 void collapseParagraphs(BufferView *);
354 /* Private structures and variables */
358 mutable Dimension dim_;
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