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 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(BufferView *, bool fordraw = false) const;
93 void draw(PainterInfo & pi, int x, int y) const;
95 void update(BufferView *, bool = false);
97 void setUpdateStatus(int what) const;
99 string const editMessage() const;
101 bool isTextInset() const { return true; }
103 void insetUnlock(BufferView *);
105 bool lockInsetInInset(BufferView *, UpdatableInset *);
107 bool unlockInsetInInset(BufferView *,
108 UpdatableInset *, bool lr = false);
110 bool updateInsetInInset(BufferView *, Inset *);
112 RESULT localDispatch(FuncRequest const &);
114 int latex(Buffer const *, std::ostream &,
115 LatexRunParams const &) const;
117 int ascii(Buffer const *, std::ostream &, int linelen) const;
119 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
121 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
123 void validate(LaTeXFeatures & features) const;
125 Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
127 void getCursorPos(BufferView *, int & x, int & y) const;
128 /// Get the absolute document x,y of the cursor
129 virtual void getCursor(BufferView &, int &, int &) const;
131 int insetInInsetY() const;
133 void fitInsetCursor(BufferView *) const;
135 bool insertInset(BufferView *, Inset *);
137 bool insetAllowed(Inset::Code) const;
139 UpdatableInset * getLockingInset() const;
141 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
143 void setFont(BufferView *, LyXFont const &,
144 bool toggleall = false,
145 bool selectall = false);
147 int getMaxWidth(BufferView *, UpdatableInset const *) const;
149 void init(InsetText const * ins);
151 void writeParagraphData(Buffer const *, std::ostream &) const;
153 void setParagraphData(ParagraphList const &);
155 void setText(string const &, LyXFont const &);
157 void setAutoBreakRows(bool);
159 bool getAutoBreakRows() const { return autoBreakRows; }
161 void setDrawFrame(BufferView *, DrawFrame);
163 void setFrameColor(BufferView *, LColor::color);
165 LyXText * getLyXText(BufferView const *,
166 bool const recursive = false) const;
168 void setViewCache(BufferView const * bv) const;
170 void deleteLyXText(BufferView *, bool recursive = true) const;
172 void resizeLyXText(BufferView *, bool force = false) const;
174 bool showInsetDialog(BufferView *) const;
176 void getLabelList(std::vector<string> &) const;
180 int scroll(bool recursive = true) const;
182 void scroll(BufferView * bv, float sx) const {
183 UpdatableInset::scroll(bv, sx);
186 void scroll(BufferView * bv, int offset) const {
187 UpdatableInset::scroll(bv, offset);
190 void clearSelection(BufferView * bv);
192 Inset * getInsetFromID(int id) const;
194 ParagraphList * getParagraphs(int) const;
196 LyXCursor const & cursor(BufferView *) const;
198 bool allowSpellcheck() const { return true; }
201 selectNextWordToSpellcheck(BufferView *, float & value) const;
203 void selectSelectedWord(BufferView *);
205 void toggleSelection(BufferView *, bool kill_selection);
207 /// mark as erased for change tracking
208 void markErased() { clear(true); };
210 * Mark as new. Used when pasting in tabular, and adding rows
211 * or columns. Note that pasting will ensure that tracking already
212 * happens, and this just resets the changes for the copied text,
213 * whereas for row/col add, we need to start tracking changes
214 * for the (empty) paragraph contained.
216 void markNew(bool track_changes = false);
218 bool nextChange(BufferView *, lyx::pos_type & length);
221 bool searchForward(BufferView *, string const &,
222 bool = true, bool = false);
224 bool searchBackward(BufferView *, string const &,
225 bool = true, bool = false);
227 bool checkInsertChar(LyXFont &);
229 void getDrawFont(LyXFont &) const;
230 /// append text onto the existing text
231 void appendParagraphs(Buffer * bp, ParagraphList &);
234 void addPreview(lyx::graphics::PreviewLoader &) const;
237 // Public structures and variables
239 mutable int need_update;
241 bool haveParagraphs() const {
245 ParagraphList paragraphs;
248 void updateLocal(BufferView *, int what, bool mark_dirty);
249 /// set parameters for an initial lock of this inset
250 void lockInset(BufferView *);
251 /// lock an inset inside this one
252 void lockInset(BufferView *, UpdatableInset *);
254 mutable int drawTextXOffset;
256 mutable int drawTextYOffset;
260 DrawFrame drawFrame_;
262 LColor::color frame_color;
266 void lfunMousePress(FuncRequest const &);
268 bool lfunMouseRelease(FuncRequest const &);
270 void lfunMouseMotion(FuncRequest const &);
273 RESULT moveRight(BufferView *,
274 bool activate_inset = true,
275 bool selecting = false);
277 RESULT moveLeft(BufferView *,
278 bool activate_inset = true,
279 bool selecting = false);
281 RESULT moveRightIntern(BufferView *, bool front,
282 bool activate_inset = true,
283 bool selecting = false);
285 RESULT moveLeftIntern(BufferView *, bool front,
286 bool activate_inset = true,
287 bool selecting = false);
290 RESULT moveUp(BufferView *);
292 RESULT moveDown(BufferView *);
294 void setCharFont(Buffer const *, int pos, LyXFont const & font);
296 bool checkAndActivateInset(BufferView * bv, bool front);
298 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
299 mouse_button::state button = mouse_button::none);
301 void removeNewlines();
303 int cx(BufferView *) const;
305 int cix(BufferView *) const;
311 lyx::pos_type cpos() const;
313 ParagraphList::iterator cpar() const;
315 bool cboundary() const;
317 RowList::iterator crow() const;
319 void drawFrame(Painter &, int x) const;
321 void clearInset(BufferView *, int start_x, int baseline) const;
323 void saveLyXTextState() const;
325 void restoreLyXTextState() const;
327 void collapseParagraphs(BufferView *);
329 /* Private structures and variables */
333 mutable Dimension dim_;
337 ParagraphList::iterator inset_par;
339 lyx::pos_type inset_pos;
347 mutable int old_max_width;
351 UpdatableInset * the_locking_inset;
353 mutable ParagraphList::iterator old_par;
355 mutable int last_drawn_width;
357 /// some funny 'temporarily saved state'
358 mutable TextCursor sstate;
361 // to remember old painted frame dimensions to clear it on the right spot!
368 bool in_update; /* as update is not reentrant! */
369 mutable bool in_insetAllowed;
371 // these are used to check for mouse movement in Motion selection code
377 void reinitLyXText() const;
379 mutable LyXText text_;