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;
174 int scroll(bool recursive = true) const;
176 void scroll(BufferView * bv, float sx) const {
177 UpdatableInset::scroll(bv, sx);
180 void scroll(BufferView * bv, int offset) const {
181 UpdatableInset::scroll(bv, offset);
184 void clearSelection(BufferView * bv);
186 InsetOld * getInsetFromID(int id) const;
188 ParagraphList * getParagraphs(int) const;
190 LyXCursor const & cursor(BufferView *) const;
192 bool allowSpellcheck() const { return true; }
195 selectNextWordToSpellcheck(BufferView *, float & value) const;
197 void selectSelectedWord(BufferView *);
199 /// mark as erased for change tracking
200 void markErased() { clear(true); };
202 * Mark as new. Used when pasting in tabular, and adding rows
203 * or columns. Note that pasting will ensure that tracking already
204 * happens, and this just resets the changes for the copied text,
205 * whereas for row/col add, we need to start tracking changes
206 * for the (empty) paragraph contained.
208 void markNew(bool track_changes = false);
210 bool nextChange(BufferView *, lyx::pos_type & length);
213 bool searchForward(BufferView *, string const &,
214 bool = true, bool = false);
216 bool searchBackward(BufferView *, string const &,
217 bool = true, bool = false);
219 bool checkInsertChar(LyXFont &);
221 void getDrawFont(LyXFont &) const;
222 /// append text onto the existing text
223 void appendParagraphs(Buffer * bp, ParagraphList &);
226 void addPreview(lyx::graphics::PreviewLoader &) const;
229 // Public structures and variables
231 mutable int need_update;
233 bool haveParagraphs() const {
237 ParagraphList paragraphs;
240 void updateLocal(BufferView *, int what, bool mark_dirty);
241 /// set parameters for an initial lock of this inset
242 void lockInset(BufferView *);
243 /// lock an inset inside this one
244 void lockInset(BufferView *, UpdatableInset *);
246 mutable int drawTextXOffset;
248 mutable int drawTextYOffset;
252 DrawFrame drawFrame_;
254 LColor::color frame_color;
258 void lfunMousePress(FuncRequest const &);
260 bool lfunMouseRelease(FuncRequest const &);
262 void lfunMouseMotion(FuncRequest const &);
265 RESULT moveRight(BufferView *,
266 bool activate_inset = true,
267 bool selecting = false);
269 RESULT moveLeft(BufferView *,
270 bool activate_inset = true,
271 bool selecting = false);
273 RESULT moveRightIntern(BufferView *, bool front,
274 bool activate_inset = true,
275 bool selecting = false);
277 RESULT moveLeftIntern(BufferView *, bool front,
278 bool activate_inset = true,
279 bool selecting = false);
282 RESULT moveUp(BufferView *);
284 RESULT moveDown(BufferView *);
286 void setCharFont(Buffer const *, int pos, LyXFont const & font);
288 bool checkAndActivateInset(BufferView * bv, bool front);
290 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
291 mouse_button::state button = mouse_button::none);
293 void removeNewlines();
303 lyx::pos_type cpos() const;
305 ParagraphList::iterator cpar() const;
307 bool cboundary() const;
309 RowList::iterator crow() const;
311 void drawFrame(Painter &, int x) const;
313 void clearInset(BufferView *, int start_x, int baseline) const;
315 void saveLyXTextState() const;
317 void restoreLyXTextState() const;
319 void collapseParagraphs(BufferView *);
321 /* Private structures and variables */
327 ParagraphList::iterator inset_par;
329 lyx::pos_type inset_pos;
339 UpdatableInset * the_locking_inset;
341 mutable ParagraphList::iterator old_par;
343 mutable int last_drawn_width;
345 /// some funny 'temporarily saved state'
346 mutable TextCursor sstate;
349 // to remember old painted frame dimensions to clear it on the right spot!
355 mutable bool in_insetAllowed;
357 // these are used to check for mouse movement in Motion selection code
363 void reinitLyXText() const;
365 mutable LyXText text_;
367 mutable int textwidth_;