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 &, bool same_id = false);
80 Inset * clone(Buffer const &, bool same_id = false) const;
82 InsetText & operator=(InsetText const & it);
83 /// empty inset to empty par, or just mark as erased
84 void clear(bool just_mark_erased);
86 void read(Buffer const *, LyXLex &);
88 void write(Buffer const *, std::ostream &) const;
90 void dimension(BufferView *, LyXFont const &, Dimension &) const;
92 int textWidth(BufferView *, bool fordraw = false) const;
94 void draw(BufferView *, LyXFont const &, int , float &) const;
96 void update(BufferView *, bool = false);
98 void setUpdateStatus(BufferView *, int what) const;
100 string const editMessage() const;
102 bool isTextInset() const { return true; }
104 void insetUnlock(BufferView *);
106 bool lockInsetInInset(BufferView *, UpdatableInset *);
108 bool unlockInsetInInset(BufferView *,
109 UpdatableInset *, bool lr = false);
111 bool updateInsetInInset(BufferView *, Inset *);
113 RESULT localDispatch(FuncRequest const &);
115 int latex(Buffer const *, std::ostream &, LatexRunParams const &,
116 bool fragile, bool free_spc) const;
118 int ascii(Buffer const *, std::ostream &, int linelen) const;
120 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
122 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
124 void validate(LaTeXFeatures & features) const;
126 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
128 void getCursorPos(BufferView *, int & x, int & y) const;
129 /// Get the absolute document x,y of the cursor
130 virtual void getCursor(BufferView &, int &, int &) const;
132 int insetInInsetY() const;
134 void fitInsetCursor(BufferView *) const;
136 bool insertInset(BufferView *, Inset *);
138 bool insetAllowed(Inset::Code) const;
140 UpdatableInset * getLockingInset() const;
142 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
144 void setFont(BufferView *, LyXFont const &,
145 bool toggleall = false,
146 bool selectall = false);
148 int getMaxWidth(BufferView *, UpdatableInset const *) const;
150 void init(InsetText const * ins = 0, bool same_id = false);
152 void writeParagraphData(Buffer const *, std::ostream &) const;
154 void setParagraphData(ParagraphList const &, bool same_id = false);
156 void setText(string const &, LyXFont const &);
158 void setAutoBreakRows(bool);
160 bool getAutoBreakRows() const { return autoBreakRows; }
162 void setDrawFrame(BufferView *, DrawFrame);
164 void setFrameColor(BufferView *, LColor::color);
166 LyXText * getLyXText(BufferView const *,
167 bool const recursive = false) const;
169 void deleteLyXText(BufferView *, bool recursive = true) const;
171 void resizeLyXText(BufferView *, bool force = false) const;
173 bool showInsetDialog(BufferView *) const;
175 std::vector<string> const getLabelList() const;
179 int scroll(bool recursive = true) const;
181 void scroll(BufferView * bv, float sx) const {
182 UpdatableInset::scroll(bv, sx);
185 void scroll(BufferView * bv, int offset) const {
186 UpdatableInset::scroll(bv, offset);
189 void selectAll(BufferView * bv);
191 void clearSelection(BufferView * bv);
193 Inset * getInsetFromID(int id) const;
195 ParagraphList * getParagraphs(int) const;
197 LyXCursor const & cursor(BufferView *) const;
199 bool allowSpellcheck() const { return true; }
202 selectNextWordToSpellcheck(BufferView *, float & value) const;
204 void selectSelectedWord(BufferView *);
206 void toggleSelection(BufferView *, bool kill_selection);
208 /// mark as erased for change tracking
209 void markErased() { clear(true); };
211 * Mark as new. Used when pasting in tabular, and adding rows
212 * or columns. Note that pasting will ensure that tracking already
213 * happens, and this just resets the changes for the copied text,
214 * whereas for row/col add, we need to start tracking changes
215 * for the (empty) paragraph contained.
217 void markNew(bool track_changes = false);
219 bool nextChange(BufferView *, lyx::pos_type & length);
222 bool searchForward(BufferView *, string const &,
223 bool = true, bool = false);
225 bool searchBackward(BufferView *, string const &,
226 bool = true, bool = false);
228 bool checkInsertChar(LyXFont &);
230 void getDrawFont(LyXFont &) const;
231 /// append text onto the existing text
232 void appendParagraphs(Buffer * bp, ParagraphList &);
235 void addPreview(grfx::PreviewLoader &) const;
238 // Public structures and variables
240 mutable int need_update;
242 bool haveParagraphs() const {
246 ParagraphList paragraphs;
249 void updateLocal(BufferView *, int what, bool mark_dirty);
250 /// set parameters for an initial lock of this inset
251 void lockInset(BufferView *);
252 /// lock an inset inside this one
253 void lockInset(BufferView *, UpdatableInset *);
255 mutable int drawTextXOffset;
257 mutable int drawTextYOffset;
261 DrawFrame drawFrame_;
263 LColor::color frame_color;
267 void lfunMousePress(FuncRequest const &);
269 bool lfunMouseRelease(FuncRequest const &);
271 void lfunMouseMotion(FuncRequest const &);
276 InnerCache(boost::shared_ptr<LyXText>);
278 boost::shared_ptr<LyXText> text;
283 typedef std::map<BufferView *, InnerCache> Cache;
285 typedef Cache::value_type value_type;
287 RESULT moveRight(BufferView *,
288 bool activate_inset = true,
289 bool selecting = false);
291 RESULT moveLeft(BufferView *,
292 bool activate_inset = true,
293 bool selecting = false);
295 RESULT moveRightIntern(BufferView *, bool front,
296 bool activate_inset = true,
297 bool selecting = false);
299 RESULT moveLeftIntern(BufferView *, bool front,
300 bool activate_inset = true,
301 bool selecting = false);
304 RESULT moveUp(BufferView *);
306 RESULT moveDown(BufferView *);
308 void setCharFont(Buffer const *, int pos, LyXFont const & font);
310 bool checkAndActivateInset(BufferView * bv, bool front);
312 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
313 mouse_button::state button = mouse_button::none);
315 void removeNewlines();
317 int cx(BufferView *) const;
319 int cix(BufferView *) const;
321 int cy(BufferView *) const;
323 int ciy(BufferView *) const;
325 lyx::pos_type cpos(BufferView *) const;
327 ParagraphList::iterator cpar(BufferView *) const;
329 bool cboundary(BufferView *) const;
331 RowList::iterator crow(BufferView *) const;
333 void drawFrame(Painter &, int x) const;
335 void clearInset(BufferView *, int start_x, int baseline) const;
337 void saveLyXTextState(LyXText *) const;
339 void restoreLyXTextState(LyXText *) const;
341 void reinitLyXText() const;
343 void collapseParagraphs(BufferView *);
345 /* Private structures and variables */
349 mutable Dimension dim_;
353 ParagraphList::iterator inset_par;
355 lyx::pos_type inset_pos;
363 mutable int old_max_width;
367 UpdatableInset * the_locking_inset;
369 mutable ParagraphList::iterator old_par;
373 mutable int last_drawn_width;
375 mutable BufferView * cached_bview;
377 mutable boost::shared_ptr<LyXText> cached_text;
381 Paragraph * selstartpar;
382 Paragraph * selendpar;
384 lyx::pos_type selstartpos;
385 lyx::pos_type selendpos;
387 bool selstartboundary;
393 mutable save_state sstate;
396 // this is needed globally so we know that we're using it actually and
397 // so the LyXText-Cache is not erased until used!
398 mutable LyXText * lt;
400 // to remember old painted frame dimensions to clear it on the right spot!
407 bool in_update; /* as update is not reentrant! */
408 mutable BufferView * do_resize;
409 mutable bool do_reinit;
410 mutable bool in_insetAllowed;
412 // these are used to check for mouse movement in Motion selection code