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
67 InsetText(BufferParams const &);
69 explicit InsetText(InsetText const &);
71 virtual std::auto_ptr<InsetBase> clone() const;
73 InsetText & operator=(InsetText const & it);
74 /// empty inset to empty par, or just mark as erased
75 void clear(bool just_mark_erased);
77 void read(Buffer const *, LyXLex &);
79 void write(Buffer const *, std::ostream &) const;
81 void metrics(MetricsInfo &, Dimension &) const;
83 int textWidth() const;
85 void draw(PainterInfo & pi, int x, int y) const;
87 void setUpdateStatus(int what) const;
89 string const editMessage() const;
91 bool isTextInset() const { return true; }
93 void insetUnlock(BufferView *);
95 bool lockInsetInInset(BufferView *, UpdatableInset *);
97 bool unlockInsetInInset(BufferView *,
98 UpdatableInset *, bool lr = false);
100 bool updateInsetInInset(BufferView *, InsetOld *);
102 RESULT localDispatch(FuncRequest const &);
104 int latex(Buffer const *, std::ostream &,
105 LatexRunParams const &) const;
107 int ascii(Buffer const *, std::ostream &, int linelen) const;
109 int linuxdoc(Buffer const *, std::ostream &) const ;
111 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
113 void validate(LaTeXFeatures & features) const;
115 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
117 void getCursorPos(BufferView *, int & x, int & y) const;
118 /// Get the absolute document x,y of the cursor
119 virtual void getCursor(BufferView &, int &, int &) const;
121 int insetInInsetY() const;
123 void fitInsetCursor(BufferView *) const;
125 bool insertInset(BufferView *, InsetOld *);
127 bool insetAllowed(InsetOld::Code) const;
129 UpdatableInset * getLockingInset() const;
131 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
133 void setFont(BufferView *, LyXFont const &,
134 bool toggleall = false,
135 bool selectall = false);
137 void init(InsetText const * ins);
139 void writeParagraphData(Buffer const *, std::ostream &) const;
141 void setParagraphData(ParagraphList const &);
143 void setText(string const &, LyXFont const &);
145 void setAutoBreakRows(bool);
147 bool getAutoBreakRows() const { return autoBreakRows; }
149 void setDrawFrame(BufferView *, DrawFrame);
151 void setFrameColor(BufferView *, LColor::color);
153 LyXText * getLyXText(BufferView const *,
154 bool const recursive = false) const;
156 void setViewCache(BufferView const * bv) const;
158 void deleteLyXText(BufferView *, bool recursive = true) const;
160 void resizeLyXText(BufferView *, bool force = false) const;
162 bool showInsetDialog(BufferView *) const;
164 void getLabelList(std::vector<string> &) const;
166 int scroll(bool recursive = true) const;
168 void scroll(BufferView * bv, float sx) const {
169 UpdatableInset::scroll(bv, sx);
172 void scroll(BufferView * bv, int offset) const {
173 UpdatableInset::scroll(bv, offset);
176 void clearSelection(BufferView * bv);
178 InsetOld * getInsetFromID(int id) const;
180 ParagraphList * getParagraphs(int) const;
182 LyXCursor const & cursor(BufferView *) const;
184 bool allowSpellcheck() const { return true; }
187 selectNextWordToSpellcheck(BufferView *, float & value) const;
189 void selectSelectedWord(BufferView *);
191 /// mark as erased for change tracking
192 void markErased() { clear(true); };
194 * Mark as new. Used when pasting in tabular, and adding rows
195 * or columns. Note that pasting will ensure that tracking already
196 * happens, and this just resets the changes for the copied text,
197 * whereas for row/col add, we need to start tracking changes
198 * for the (empty) paragraph contained.
200 void markNew(bool track_changes = false);
202 bool nextChange(BufferView *, lyx::pos_type & length);
205 bool searchForward(BufferView *, string const &,
206 bool = true, bool = false);
208 bool searchBackward(BufferView *, string const &,
209 bool = true, bool = false);
211 bool checkInsertChar(LyXFont &);
213 void getDrawFont(LyXFont &) const;
214 /// append text onto the existing text
215 void appendParagraphs(Buffer * bp, ParagraphList &);
218 void addPreview(lyx::graphics::PreviewLoader &) const;
221 // Public structures and variables
223 mutable int need_update;
225 bool haveParagraphs() const {
229 ParagraphList paragraphs;
232 void updateLocal(BufferView *, bool mark_dirty);
233 /// set parameters for an initial lock of this inset
234 void lockInset(BufferView *);
235 /// lock an inset inside this one
236 void lockInset(BufferView *, UpdatableInset *);
238 mutable int drawTextXOffset;
240 mutable int drawTextYOffset;
244 DrawFrame drawFrame_;
246 LColor::color frame_color;
250 void lfunMousePress(FuncRequest const &);
252 bool lfunMouseRelease(FuncRequest const &);
254 void lfunMouseMotion(FuncRequest const &);
257 RESULT moveRight(BufferView *,
258 bool activate_inset = true,
259 bool selecting = false);
261 RESULT moveLeft(BufferView *,
262 bool activate_inset = true,
263 bool selecting = false);
265 RESULT moveRightIntern(BufferView *, bool front,
266 bool activate_inset = true,
267 bool selecting = false);
269 RESULT moveLeftIntern(BufferView *, bool front,
270 bool activate_inset = true,
271 bool selecting = false);
274 RESULT moveUp(BufferView *);
276 RESULT moveDown(BufferView *);
278 void setCharFont(Buffer const *, int pos, LyXFont const & font);
280 bool checkAndActivateInset(BufferView * bv, bool front);
282 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
283 mouse_button::state button = mouse_button::none);
285 void removeNewlines();
295 lyx::pos_type cpos() const;
297 ParagraphList::iterator cpar() const;
299 bool cboundary() const;
301 RowList::iterator crow() const;
303 void drawFrame(Painter &, int x) const;
305 void clearInset(BufferView *, int start_x, int baseline) const;
307 void saveLyXTextState() const;
309 void restoreLyXTextState() const;
311 void collapseParagraphs(BufferView *);
313 /* Private structures and variables */
319 ParagraphList::iterator inset_par;
321 lyx::pos_type inset_pos;
331 UpdatableInset * the_locking_inset;
333 mutable ParagraphList::iterator old_par;
335 mutable int last_drawn_width;
337 /// some funny 'temporarily saved state'
338 mutable TextCursor sstate;
341 // to remember old painted frame dimensions to clear it on the right spot!
347 mutable bool in_insetAllowed;
349 // these are used to check for mouse movement in Motion selection code
355 void reinitLyXText() const;
357 mutable LyXText text_;
359 mutable int textwidth_;