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(BufferView *, 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 selectAll(BufferView * bv);
192 void clearSelection(BufferView * bv);
194 Inset * getInsetFromID(int id) const;
196 ParagraphList * getParagraphs(int) const;
198 LyXCursor const & cursor(BufferView *) const;
200 bool allowSpellcheck() const { return true; }
203 selectNextWordToSpellcheck(BufferView *, float & value) const;
205 void selectSelectedWord(BufferView *);
207 void toggleSelection(BufferView *, bool kill_selection);
209 /// mark as erased for change tracking
210 void markErased() { clear(true); };
212 * Mark as new. Used when pasting in tabular, and adding rows
213 * or columns. Note that pasting will ensure that tracking already
214 * happens, and this just resets the changes for the copied text,
215 * whereas for row/col add, we need to start tracking changes
216 * for the (empty) paragraph contained.
218 void markNew(bool track_changes = false);
220 bool nextChange(BufferView *, lyx::pos_type & length);
223 bool searchForward(BufferView *, string const &,
224 bool = true, bool = false);
226 bool searchBackward(BufferView *, string const &,
227 bool = true, bool = false);
229 bool checkInsertChar(LyXFont &);
231 void getDrawFont(LyXFont &) const;
232 /// append text onto the existing text
233 void appendParagraphs(Buffer * bp, ParagraphList &);
236 void addPreview(lyx::graphics::PreviewLoader &) const;
239 // Public structures and variables
241 mutable int need_update;
243 bool haveParagraphs() const {
247 ParagraphList paragraphs;
250 void updateLocal(BufferView *, int what, bool mark_dirty);
251 /// set parameters for an initial lock of this inset
252 void lockInset(BufferView *);
253 /// lock an inset inside this one
254 void lockInset(BufferView *, UpdatableInset *);
256 mutable int drawTextXOffset;
258 mutable int drawTextYOffset;
262 DrawFrame drawFrame_;
264 LColor::color frame_color;
268 void lfunMousePress(FuncRequest const &);
270 bool lfunMouseRelease(FuncRequest const &);
272 void lfunMouseMotion(FuncRequest const &);
275 RESULT moveRight(BufferView *,
276 bool activate_inset = true,
277 bool selecting = false);
279 RESULT moveLeft(BufferView *,
280 bool activate_inset = true,
281 bool selecting = false);
283 RESULT moveRightIntern(BufferView *, bool front,
284 bool activate_inset = true,
285 bool selecting = false);
287 RESULT moveLeftIntern(BufferView *, bool front,
288 bool activate_inset = true,
289 bool selecting = false);
292 RESULT moveUp(BufferView *);
294 RESULT moveDown(BufferView *);
296 void setCharFont(Buffer const *, int pos, LyXFont const & font);
298 bool checkAndActivateInset(BufferView * bv, bool front);
300 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
301 mouse_button::state button = mouse_button::none);
303 void removeNewlines();
305 int cx(BufferView *) const;
307 int cix(BufferView *) const;
309 int cy(BufferView *) const;
311 int ciy(BufferView *) const;
313 lyx::pos_type cpos() const;
315 ParagraphList::iterator cpar() const;
317 bool cboundary() const;
319 RowList::iterator crow() const;
321 void drawFrame(Painter &, int x) const;
323 void clearInset(BufferView *, int start_x, int baseline) const;
325 void saveLyXTextState(LyXText *) const;
327 void restoreLyXTextState(LyXText *) const;
329 void collapseParagraphs(BufferView *);
331 /* Private structures and variables */
335 mutable Dimension dim_;
339 ParagraphList::iterator inset_par;
341 lyx::pos_type inset_pos;
349 mutable int old_max_width;
353 UpdatableInset * the_locking_inset;
355 mutable ParagraphList::iterator old_par;
357 mutable int last_drawn_width;
359 /// some funny 'temporarily saved state'
360 mutable TextCursor sstate;
363 // to remember old painted frame dimensions to clear it on the right spot!
370 bool in_update; /* as update is not reentrant! */
371 mutable bool in_insetAllowed;
373 // these are used to check for mouse movement in Motion selection code
379 void reinitLyXText() const;
381 mutable LyXText text_;