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 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 *, Inset *);
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 Inset::Code lyxCode() const { return Inset::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 *, Inset *);
135 bool insetAllowed(Inset::Code) const;
137 UpdatableInset * getLockingInset() const;
139 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
141 void setFont(BufferView *, LyXFont const &,
142 bool toggleall = false,
143 bool selectall = false);
145 int getMaxWidth(BufferView *, UpdatableInset const *) const;
147 void init(InsetText const * ins);
149 void writeParagraphData(Buffer const *, std::ostream &) const;
151 void setParagraphData(ParagraphList const &);
153 void setText(string const &, LyXFont const &);
155 void setAutoBreakRows(bool);
157 bool getAutoBreakRows() const { return autoBreakRows; }
159 void setDrawFrame(BufferView *, DrawFrame);
161 void setFrameColor(BufferView *, LColor::color);
163 LyXText * getLyXText(BufferView const *,
164 bool const recursive = false) const;
166 void setViewCache(BufferView const * bv) const;
168 void deleteLyXText(BufferView *, bool recursive = true) const;
170 void resizeLyXText(BufferView *, bool force = false) const;
172 bool showInsetDialog(BufferView *) const;
174 void getLabelList(std::vector<string> &) const;
178 int scroll(bool recursive = true) const;
180 void scroll(BufferView * bv, float sx) const {
181 UpdatableInset::scroll(bv, sx);
184 void scroll(BufferView * bv, int offset) const {
185 UpdatableInset::scroll(bv, offset);
188 void clearSelection(BufferView * bv);
190 Inset * getInsetFromID(int id) const;
192 ParagraphList * getParagraphs(int) const;
194 LyXCursor const & cursor(BufferView *) const;
196 bool allowSpellcheck() const { return true; }
199 selectNextWordToSpellcheck(BufferView *, float & value) const;
201 void selectSelectedWord(BufferView *);
203 void toggleSelection(BufferView *, bool kill_selection);
205 /// mark as erased for change tracking
206 void markErased() { clear(true); };
208 * Mark as new. Used when pasting in tabular, and adding rows
209 * or columns. Note that pasting will ensure that tracking already
210 * happens, and this just resets the changes for the copied text,
211 * whereas for row/col add, we need to start tracking changes
212 * for the (empty) paragraph contained.
214 void markNew(bool track_changes = false);
216 bool nextChange(BufferView *, lyx::pos_type & length);
219 bool searchForward(BufferView *, string const &,
220 bool = true, bool = false);
222 bool searchBackward(BufferView *, string const &,
223 bool = true, bool = false);
225 bool checkInsertChar(LyXFont &);
227 void getDrawFont(LyXFont &) const;
228 /// append text onto the existing text
229 void appendParagraphs(Buffer * bp, ParagraphList &);
232 void addPreview(lyx::graphics::PreviewLoader &) const;
235 // Public structures and variables
237 mutable int need_update;
239 bool haveParagraphs() const {
243 ParagraphList paragraphs;
246 void updateLocal(BufferView *, int what, bool mark_dirty);
247 /// set parameters for an initial lock of this inset
248 void lockInset(BufferView *);
249 /// lock an inset inside this one
250 void lockInset(BufferView *, UpdatableInset *);
252 mutable int drawTextXOffset;
254 mutable int drawTextYOffset;
258 DrawFrame drawFrame_;
260 LColor::color frame_color;
264 void lfunMousePress(FuncRequest const &);
266 bool lfunMouseRelease(FuncRequest const &);
268 void lfunMouseMotion(FuncRequest const &);
271 RESULT moveRight(BufferView *,
272 bool activate_inset = true,
273 bool selecting = false);
275 RESULT moveLeft(BufferView *,
276 bool activate_inset = true,
277 bool selecting = false);
279 RESULT moveRightIntern(BufferView *, bool front,
280 bool activate_inset = true,
281 bool selecting = false);
283 RESULT moveLeftIntern(BufferView *, bool front,
284 bool activate_inset = true,
285 bool selecting = false);
288 RESULT moveUp(BufferView *);
290 RESULT moveDown(BufferView *);
292 void setCharFont(Buffer const *, int pos, LyXFont const & font);
294 bool checkAndActivateInset(BufferView * bv, bool front);
296 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
297 mouse_button::state button = mouse_button::none);
299 void removeNewlines();
301 int cx(BufferView *) const;
303 int cix(BufferView *) const;
309 lyx::pos_type cpos() const;
311 ParagraphList::iterator cpar() const;
313 bool cboundary() const;
315 RowList::iterator crow() const;
317 void drawFrame(Painter &, int x) const;
319 void clearInset(BufferView *, int start_x, int baseline) const;
321 void saveLyXTextState() const;
323 void restoreLyXTextState() const;
325 void collapseParagraphs(BufferView *);
327 /* Private structures and variables */
331 mutable Dimension dim_;
335 ParagraphList::iterator inset_par;
337 lyx::pos_type inset_pos;
345 mutable int old_max_width;
349 UpdatableInset * the_locking_inset;
351 mutable ParagraphList::iterator old_par;
353 mutable int last_drawn_width;
355 /// some funny 'temporarily saved state'
356 mutable TextCursor sstate;
359 // to remember old painted frame dimensions to clear it on the right spot!
365 mutable bool in_insetAllowed;
367 // these are used to check for mouse movement in Motion selection code
373 void reinitLyXText() const;
375 mutable LyXText text_;