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 &);
75 explicit InsetText(InsetText const &);
77 InsetBase * clone() 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 void metrics(MetricsInfo &, Dimension &) const;
89 int textWidth(BufferView *, bool fordraw = false) const;
91 void draw(PainterInfo & pi, int x, int y) const;
93 void update(BufferView *, bool = false);
95 void setUpdateStatus(BufferView *, int what) const;
97 string const editMessage() const;
99 bool isTextInset() const { return true; }
101 void insetUnlock(BufferView *);
103 bool lockInsetInInset(BufferView *, UpdatableInset *);
105 bool unlockInsetInInset(BufferView *,
106 UpdatableInset *, bool lr = false);
108 bool updateInsetInInset(BufferView *, Inset *);
110 RESULT localDispatch(FuncRequest const &);
112 int latex(Buffer const *, std::ostream &,
113 LatexRunParams const &) const;
115 int ascii(Buffer const *, std::ostream &, int linelen) const;
117 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
119 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
121 void validate(LaTeXFeatures & features) const;
123 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
125 void getCursorPos(BufferView *, int & x, int & y) const;
126 /// Get the absolute document x,y of the cursor
127 virtual void getCursor(BufferView &, int &, int &) const;
129 int insetInInsetY() const;
131 void fitInsetCursor(BufferView *) const;
133 bool insertInset(BufferView *, Inset *);
135 bool insetAllowed(Inset::Code) const;
137 UpdatableInset * getLockingInset() const;
139 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
141 void setFont(BufferView *, LyXFont const &,
142 bool toggleall = false,
143 bool selectall = false);
145 int getMaxWidth(BufferView *, UpdatableInset const *) const;
147 void init(InsetText const * ins);
149 void writeParagraphData(Buffer const *, std::ostream &) const;
151 void setParagraphData(ParagraphList const &);
153 void setText(string const &, LyXFont const &);
155 void setAutoBreakRows(bool);
157 bool getAutoBreakRows() const { return autoBreakRows; }
159 void setDrawFrame(BufferView *, DrawFrame);
161 void setFrameColor(BufferView *, LColor::color);
163 LyXText * getLyXText(BufferView const *,
164 bool const recursive = false) const;
166 void deleteLyXText(BufferView *, bool recursive = true) const;
168 void resizeLyXText(BufferView *, bool force = false) const;
170 bool showInsetDialog(BufferView *) const;
172 void getLabelList(std::vector<string> &) const;
176 int scroll(bool recursive = true) const;
178 void scroll(BufferView * bv, float sx) const {
179 UpdatableInset::scroll(bv, sx);
182 void scroll(BufferView * bv, int offset) const {
183 UpdatableInset::scroll(bv, offset);
186 void selectAll(BufferView * bv);
188 void clearSelection(BufferView * bv);
190 Inset * getInsetFromID(int id) const;
192 ParagraphList * getParagraphs(int) const;
194 LyXCursor const & cursor(BufferView *) const;
196 bool allowSpellcheck() const { return true; }
199 selectNextWordToSpellcheck(BufferView *, float & value) const;
201 void selectSelectedWord(BufferView *);
203 void toggleSelection(BufferView *, bool kill_selection);
205 /// mark as erased for change tracking
206 void markErased() { clear(true); };
208 * Mark as new. Used when pasting in tabular, and adding rows
209 * or columns. Note that pasting will ensure that tracking already
210 * happens, and this just resets the changes for the copied text,
211 * whereas for row/col add, we need to start tracking changes
212 * for the (empty) paragraph contained.
214 void markNew(bool track_changes = false);
216 bool nextChange(BufferView *, lyx::pos_type & length);
219 bool searchForward(BufferView *, string const &,
220 bool = true, bool = false);
222 bool searchBackward(BufferView *, string const &,
223 bool = true, bool = false);
225 bool checkInsertChar(LyXFont &);
227 void getDrawFont(LyXFont &) const;
228 /// append text onto the existing text
229 void appendParagraphs(Buffer * bp, ParagraphList &);
232 void addPreview(grfx::PreviewLoader &) const;
235 // Public structures and variables
237 mutable int need_update;
239 bool haveParagraphs() const {
243 ParagraphList paragraphs;
246 void updateLocal(BufferView *, int what, bool mark_dirty);
247 /// set parameters for an initial lock of this inset
248 void lockInset(BufferView *);
249 /// lock an inset inside this one
250 void lockInset(BufferView *, UpdatableInset *);
252 mutable int drawTextXOffset;
254 mutable int drawTextYOffset;
258 DrawFrame drawFrame_;
260 LColor::color frame_color;
264 void lfunMousePress(FuncRequest const &);
266 bool lfunMouseRelease(FuncRequest const &);
268 void lfunMouseMotion(FuncRequest const &);
273 InnerCache(boost::shared_ptr<LyXText>);
275 boost::shared_ptr<LyXText> text;
280 typedef std::map<BufferView *, InnerCache> Cache;
282 typedef Cache::value_type value_type;
284 RESULT moveRight(BufferView *,
285 bool activate_inset = true,
286 bool selecting = false);
288 RESULT moveLeft(BufferView *,
289 bool activate_inset = true,
290 bool selecting = false);
292 RESULT moveRightIntern(BufferView *, bool front,
293 bool activate_inset = true,
294 bool selecting = false);
296 RESULT moveLeftIntern(BufferView *, bool front,
297 bool activate_inset = true,
298 bool selecting = false);
301 RESULT moveUp(BufferView *);
303 RESULT moveDown(BufferView *);
305 void setCharFont(Buffer const *, int pos, LyXFont const & font);
307 bool checkAndActivateInset(BufferView * bv, bool front);
309 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
310 mouse_button::state button = mouse_button::none);
312 void removeNewlines();
314 int cx(BufferView *) const;
316 int cix(BufferView *) const;
318 int cy(BufferView *) const;
320 int ciy(BufferView *) const;
322 lyx::pos_type cpos(BufferView *) const;
324 ParagraphList::iterator cpar(BufferView *) const;
326 bool cboundary(BufferView *) const;
328 RowList::iterator crow(BufferView *) const;
330 void drawFrame(Painter &, int x) const;
332 void clearInset(BufferView *, int start_x, int baseline) const;
334 void saveLyXTextState(LyXText *) const;
336 void restoreLyXTextState(LyXText *) const;
338 void reinitLyXText() const;
340 void collapseParagraphs(BufferView *);
342 /* Private structures and variables */
346 mutable Dimension dim_;
350 ParagraphList::iterator inset_par;
352 lyx::pos_type inset_pos;
360 mutable int old_max_width;
364 UpdatableInset * the_locking_inset;
366 mutable ParagraphList::iterator old_par;
370 mutable int last_drawn_width;
372 mutable BufferView * cached_bview;
374 mutable boost::shared_ptr<LyXText> cached_text;
377 ParagraphList::iterator lpar;
378 ParagraphList::iterator selstartpar;
379 ParagraphList::iterator selendpar;
381 lyx::pos_type selstartpos;
382 lyx::pos_type selendpos;
384 bool selstartboundary;
390 mutable save_state sstate;
393 // this is needed globally so we know that we're using it actually and
394 // so the LyXText-Cache is not erased until used!
395 mutable LyXText * lt;
397 // to remember old painted frame dimensions to clear it on the right spot!
404 bool in_update; /* as update is not reentrant! */
405 mutable BufferView * do_resize;
406 mutable bool do_reinit;
407 mutable bool in_insetAllowed;
409 // these are used to check for mouse movement in Motion selection code