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"
16 #include "textcursor.h"
19 #include "ParagraphList.h"
21 #include "dimension.h"
24 #include "support/types.h"
26 #include "frontends/mouse_state.h"
28 #include <boost/shared_ptr.hpp>
40 A text inset is like a TeX box to write full text
41 (including styles and other insets) in a given space.
44 class InsetText : public UpdatableInset {
47 /// numbers need because of test if codeA < codeB
75 InsetText(BufferParams const &);
77 explicit InsetText(InsetText const &);
79 virtual std::auto_ptr<InsetBase> clone() 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 metrics(MetricsInfo &, Dimension &) const;
91 int textWidth() const;
93 void draw(PainterInfo & pi, int x, int y) const;
95 void setUpdateStatus(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 *, InsetOld *);
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 ;
119 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
121 void validate(LaTeXFeatures & features) const;
123 InsetOld::Code lyxCode() const { return InsetOld::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 *, InsetOld *);
135 bool insetAllowed(InsetOld::Code) const;
137 UpdatableInset * getLockingInset() const;
139 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
141 void setFont(BufferView *, LyXFont const &,
142 bool toggleall = false,
143 bool selectall = false);
145 void init(InsetText const * ins);
147 void writeParagraphData(Buffer const *, std::ostream &) const;
149 void setParagraphData(ParagraphList const &);
151 void setText(string const &, LyXFont const &);
153 void setAutoBreakRows(bool);
155 bool getAutoBreakRows() const { return autoBreakRows; }
157 void setDrawFrame(BufferView *, DrawFrame);
159 void setFrameColor(BufferView *, LColor::color);
161 LyXText * getLyXText(BufferView const *,
162 bool const recursive = false) const;
164 void setViewCache(BufferView const * bv) 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 clearSelection(BufferView * bv);
188 InsetOld * getInsetFromID(int id) const;
190 ParagraphList * getParagraphs(int) const;
192 LyXCursor const & cursor(BufferView *) const;
194 bool allowSpellcheck() const { return true; }
197 selectNextWordToSpellcheck(BufferView *, float & value) const;
199 void selectSelectedWord(BufferView *);
201 /// mark as erased for change tracking
202 void markErased() { clear(true); };
204 * Mark as new. Used when pasting in tabular, and adding rows
205 * or columns. Note that pasting will ensure that tracking already
206 * happens, and this just resets the changes for the copied text,
207 * whereas for row/col add, we need to start tracking changes
208 * for the (empty) paragraph contained.
210 void markNew(bool track_changes = false);
212 bool nextChange(BufferView *, lyx::pos_type & length);
215 bool searchForward(BufferView *, string const &,
216 bool = true, bool = false);
218 bool searchBackward(BufferView *, string const &,
219 bool = true, bool = false);
221 bool checkInsertChar(LyXFont &);
223 void getDrawFont(LyXFont &) const;
224 /// append text onto the existing text
225 void appendParagraphs(Buffer * bp, ParagraphList &);
228 void addPreview(lyx::graphics::PreviewLoader &) const;
231 // Public structures and variables
233 mutable int need_update;
235 bool haveParagraphs() const {
239 ParagraphList paragraphs;
242 void updateLocal(BufferView *, int what, bool mark_dirty);
243 /// set parameters for an initial lock of this inset
244 void lockInset(BufferView *);
245 /// lock an inset inside this one
246 void lockInset(BufferView *, UpdatableInset *);
248 mutable int drawTextXOffset;
250 mutable int drawTextYOffset;
254 DrawFrame drawFrame_;
256 LColor::color frame_color;
260 void lfunMousePress(FuncRequest const &);
262 bool lfunMouseRelease(FuncRequest const &);
264 void lfunMouseMotion(FuncRequest const &);
267 RESULT moveRight(BufferView *,
268 bool activate_inset = true,
269 bool selecting = false);
271 RESULT moveLeft(BufferView *,
272 bool activate_inset = true,
273 bool selecting = false);
275 RESULT moveRightIntern(BufferView *, bool front,
276 bool activate_inset = true,
277 bool selecting = false);
279 RESULT moveLeftIntern(BufferView *, bool front,
280 bool activate_inset = true,
281 bool selecting = false);
284 RESULT moveUp(BufferView *);
286 RESULT moveDown(BufferView *);
288 void setCharFont(Buffer const *, int pos, LyXFont const & font);
290 bool checkAndActivateInset(BufferView * bv, bool front);
292 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
293 mouse_button::state button = mouse_button::none);
295 void removeNewlines();
305 lyx::pos_type cpos() const;
307 ParagraphList::iterator cpar() const;
309 bool cboundary() const;
311 RowList::iterator crow() const;
313 void drawFrame(Painter &, int x) const;
315 void clearInset(BufferView *, int start_x, int baseline) const;
317 void saveLyXTextState() const;
319 void restoreLyXTextState() const;
321 void collapseParagraphs(BufferView *);
323 /* Private structures and variables */
329 ParagraphList::iterator inset_par;
331 lyx::pos_type inset_pos;
341 UpdatableInset * the_locking_inset;
343 mutable ParagraphList::iterator old_par;
345 mutable int last_drawn_width;
347 /// some funny 'temporarily saved state'
348 mutable TextCursor sstate;
351 // to remember old painted frame dimensions to clear it on the right spot!
357 mutable bool in_insetAllowed;
359 // these are used to check for mouse movement in Motion selection code
365 void reinitLyXText() const;
367 mutable LyXText text_;
369 mutable int textwidth_;