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 { return 0; }
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 void toggleSelection(BufferView *, bool kill_selection);
203 /// mark as erased for change tracking
204 void markErased() { clear(true); };
206 * Mark as new. Used when pasting in tabular, and adding rows
207 * or columns. Note that pasting will ensure that tracking already
208 * happens, and this just resets the changes for the copied text,
209 * whereas for row/col add, we need to start tracking changes
210 * for the (empty) paragraph contained.
212 void markNew(bool track_changes = false);
214 bool nextChange(BufferView *, lyx::pos_type & length);
217 bool searchForward(BufferView *, string const &,
218 bool = true, bool = false);
220 bool searchBackward(BufferView *, string const &,
221 bool = true, bool = false);
223 bool checkInsertChar(LyXFont &);
225 void getDrawFont(LyXFont &) const;
226 /// append text onto the existing text
227 void appendParagraphs(Buffer * bp, ParagraphList &);
230 void addPreview(lyx::graphics::PreviewLoader &) const;
233 // Public structures and variables
235 mutable int need_update;
237 bool haveParagraphs() const {
241 ParagraphList paragraphs;
244 void updateLocal(BufferView *, int what, bool mark_dirty);
245 /// set parameters for an initial lock of this inset
246 void lockInset(BufferView *);
247 /// lock an inset inside this one
248 void lockInset(BufferView *, UpdatableInset *);
250 mutable int drawTextXOffset;
252 mutable int drawTextYOffset;
256 DrawFrame drawFrame_;
258 LColor::color frame_color;
262 void lfunMousePress(FuncRequest const &);
264 bool lfunMouseRelease(FuncRequest const &);
266 void lfunMouseMotion(FuncRequest const &);
269 RESULT moveRight(BufferView *,
270 bool activate_inset = true,
271 bool selecting = false);
273 RESULT moveLeft(BufferView *,
274 bool activate_inset = true,
275 bool selecting = false);
277 RESULT moveRightIntern(BufferView *, bool front,
278 bool activate_inset = true,
279 bool selecting = false);
281 RESULT moveLeftIntern(BufferView *, bool front,
282 bool activate_inset = true,
283 bool selecting = false);
286 RESULT moveUp(BufferView *);
288 RESULT moveDown(BufferView *);
290 void setCharFont(Buffer const *, int pos, LyXFont const & font);
292 bool checkAndActivateInset(BufferView * bv, bool front);
294 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
295 mouse_button::state button = mouse_button::none);
297 void removeNewlines();
299 int cx(BufferView *) const;
301 int cix(BufferView *) const;
307 lyx::pos_type cpos() const;
309 ParagraphList::iterator cpar() const;
311 bool cboundary() const;
313 RowList::iterator crow() const;
315 void drawFrame(Painter &, int x) const;
317 void clearInset(BufferView *, int start_x, int baseline) const;
319 void saveLyXTextState() const;
321 void restoreLyXTextState() const;
323 void collapseParagraphs(BufferView *);
325 /* Private structures and variables */
331 ParagraphList::iterator inset_par;
333 lyx::pos_type inset_pos;
343 UpdatableInset * the_locking_inset;
345 mutable ParagraphList::iterator old_par;
347 mutable int last_drawn_width;
349 /// some funny 'temporarily saved state'
350 mutable TextCursor sstate;
353 // to remember old painted frame dimensions to clear it on the right spot!
359 mutable bool in_insetAllowed;
361 // these are used to check for mouse movement in Motion selection code
367 void reinitLyXText() const;
369 mutable LyXText text_;
371 mutable int textwidth_;