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"
18 #include "ParagraphList.h"
20 #include "dimension.h"
23 #include "support/types.h"
25 #include "frontends/mouse_state.h"
27 #include <boost/shared_ptr.hpp>
39 A text inset is like a TeX box to write full text
40 (including styles and other insets) in a given space.
43 class InsetText : public UpdatableInset {
55 InsetText(BufferParams const &);
57 explicit InsetText(InsetText const &);
59 virtual std::auto_ptr<InsetBase> clone() const;
61 InsetText & operator=(InsetText const & it);
62 /// empty inset to empty par, or just mark as erased
63 void clear(bool just_mark_erased);
65 void read(Buffer const *, LyXLex &);
67 void write(Buffer const *, std::ostream &) const;
69 void metrics(MetricsInfo &, Dimension &) const;
71 int textWidth() const;
73 void draw(PainterInfo & pi, int x, int y) const;
75 string const editMessage() const;
77 bool isTextInset() const { return true; }
79 void insetUnlock(BufferView *);
81 bool lockInsetInInset(BufferView *, UpdatableInset *);
83 bool unlockInsetInInset(BufferView *,
84 UpdatableInset *, bool lr = false);
86 RESULT localDispatch(FuncRequest const &);
88 int latex(Buffer const *, std::ostream &,
89 LatexRunParams const &) const;
91 int ascii(Buffer const *, std::ostream &, int linelen) const;
93 int linuxdoc(Buffer const *, std::ostream &) const ;
95 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
97 void validate(LaTeXFeatures & features) const;
99 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
101 void getCursorPos(BufferView *, int & x, int & y) const;
102 /// Get the absolute document x,y of the cursor
103 virtual void getCursor(BufferView &, int &, int &) const;
105 int insetInInsetY() const;
107 void fitInsetCursor(BufferView *) const;
109 bool insertInset(BufferView *, InsetOld *);
111 bool insetAllowed(InsetOld::Code) const;
113 UpdatableInset * getLockingInset() const;
115 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
117 void setFont(BufferView *, LyXFont const &,
118 bool toggleall = false,
119 bool selectall = false);
121 void init(InsetText const * ins);
123 void writeParagraphData(Buffer const *, std::ostream &) const;
125 void setText(string const &, LyXFont const &);
127 void setAutoBreakRows(bool);
129 bool getAutoBreakRows() const { return autoBreakRows; }
131 void setDrawFrame(DrawFrame);
133 void setFrameColor(LColor::color);
135 LyXText * getLyXText(BufferView const *,
136 bool const recursive = false) const;
138 void setViewCache(BufferView const * bv) const;
140 void deleteLyXText(BufferView *, bool recursive = true) const;
142 bool showInsetDialog(BufferView *) const;
144 void getLabelList(std::vector<string> &) const;
146 int scroll(bool recursive = true) const;
148 void scroll(BufferView * bv, float sx) const {
149 UpdatableInset::scroll(bv, sx);
152 void scroll(BufferView * bv, int offset) const {
153 UpdatableInset::scroll(bv, offset);
156 void clearSelection(BufferView * bv);
158 InsetOld * getInsetFromID(int id) const;
160 ParagraphList * getParagraphs(int) const;
162 LyXCursor const & cursor(BufferView *) const;
164 bool allowSpellcheck() const { return true; }
167 selectNextWordToSpellcheck(BufferView *, float & value) const;
169 void selectSelectedWord(BufferView *);
171 /// mark as erased for change tracking
172 void markErased() { clear(true); };
174 * Mark as new. Used when pasting in tabular, and adding rows
175 * or columns. Note that pasting will ensure that tracking already
176 * happens, and this just resets the changes for the copied text,
177 * whereas for row/col add, we need to start tracking changes
178 * for the (empty) paragraph contained.
180 void markNew(bool track_changes = false);
182 bool nextChange(BufferView *, lyx::pos_type & length);
185 bool searchForward(BufferView *, string const &,
186 bool = true, bool = false);
188 bool searchBackward(BufferView *, string const &,
189 bool = true, bool = false);
191 bool checkInsertChar(LyXFont &);
193 void getDrawFont(LyXFont &) const;
194 /// append text onto the existing text
195 void appendParagraphs(Buffer * bp, ParagraphList &);
198 void addPreview(lyx::graphics::PreviewLoader &) const;
201 bool haveParagraphs() const {
205 mutable ParagraphList paragraphs;
208 void updateLocal(BufferView *, bool mark_dirty);
209 /// set parameters for an initial lock of this inset
210 void lockInset(BufferView *);
211 /// lock an inset inside this one
212 void lockInset(BufferView *, UpdatableInset *);
214 mutable int drawTextXOffset;
216 mutable int drawTextYOffset;
220 DrawFrame drawFrame_;
222 LColor::color frame_color;
226 void lfunMousePress(FuncRequest const &);
228 bool lfunMouseRelease(FuncRequest const &);
230 void lfunMouseMotion(FuncRequest const &);
233 RESULT moveRight(BufferView *);
235 RESULT moveLeft(BufferView *);
237 RESULT moveRightIntern(BufferView *, bool front,
238 bool activate_inset = true,
239 bool selecting = false);
241 RESULT moveLeftIntern(BufferView *, bool front,
242 bool activate_inset = true,
243 bool selecting = false);
246 RESULT moveUp(BufferView *);
248 RESULT moveDown(BufferView *);
250 void setCharFont(Buffer const *, int pos, LyXFont const & font);
252 bool checkAndActivateInset(BufferView * bv, bool front);
254 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
255 mouse_button::state button = mouse_button::none);
257 void removeNewlines();
267 lyx::pos_type cpos() const;
269 ParagraphList::iterator cpar() const;
271 bool cboundary() const;
273 RowList::iterator crow() const;
275 void drawFrame(Painter &, int x) const;
277 void clearInset(BufferView *, int start_x, int baseline) const;
279 void collapseParagraphs(BufferView *);
281 /* Private structures and variables */
287 ParagraphList::iterator inset_par;
289 lyx::pos_type inset_pos;
299 UpdatableInset * the_locking_inset;
301 mutable ParagraphList::iterator old_par;
304 // to remember old painted frame dimensions to clear it on the right spot!
306 mutable bool in_insetAllowed;
308 // these are used to check for mouse movement in Motion selection code
314 mutable LyXText text_;
316 mutable int textwidth_;