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"
17 #include "ParagraphList_fwd.h"
18 #include "RowList_fwd.h"
21 #include "support/types.h"
23 #include "frontends/mouse_state.h"
25 #include "support/std_string.h"
38 A text inset is like a TeX box to write full text
39 (including styles and other insets) in a given space.
42 class InsetText : public UpdatableInset {
54 InsetText(BufferParams const &);
56 explicit InsetText(InsetText const &);
58 virtual std::auto_ptr<InsetBase> clone() const;
60 InsetText & operator=(InsetText const & it);
61 /// empty inset to empty par, or just mark as erased
62 void clear(bool just_mark_erased);
64 void read(Buffer const &, LyXLex &);
66 void write(Buffer const &, std::ostream &) const;
68 void metrics(MetricsInfo &, Dimension &) const;
70 int textWidth() const;
72 void draw(PainterInfo & pi, int x, int y) const;
74 string const editMessage() const;
76 bool isTextInset() const { return true; }
78 void insetUnlock(BufferView *);
80 bool lockInsetInInset(BufferView *, UpdatableInset *);
82 bool unlockInsetInInset(BufferView *,
83 UpdatableInset *, bool lr = false);
85 RESULT localDispatch(FuncRequest const &);
87 int latex(Buffer const &, std::ostream &,
88 LatexRunParams const &) const;
90 int ascii(Buffer const &, std::ostream &, int linelen) const;
92 int linuxdoc(Buffer const &, std::ostream &) const ;
94 int docbook(Buffer const &, std::ostream &, bool mixcont) const ;
96 void validate(LaTeXFeatures & features) const;
98 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
100 void getCursorPos(BufferView *, int & x, int & y) const;
101 /// Get the absolute document x,y of the cursor
102 virtual void getCursor(BufferView &, int &, int &) const;
104 int insetInInsetY() const;
106 void fitInsetCursor(BufferView *) const;
108 bool insertInset(BufferView *, InsetOld *);
110 bool insetAllowed(InsetOld::Code) const;
112 UpdatableInset * getLockingInset() const;
114 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
116 void setFont(BufferView *, LyXFont const &,
117 bool toggleall = false,
118 bool selectall = false);
120 void init(InsetText const * ins);
122 void writeParagraphData(Buffer const &, std::ostream &) const;
124 void setText(string const &, LyXFont const &);
126 void setAutoBreakRows(bool);
128 bool getAutoBreakRows() const { return autoBreakRows; }
130 void setDrawFrame(DrawFrame);
132 void setFrameColor(EnumLColor);
134 LyXText * getLyXText(BufferView const *,
135 bool const recursive = false) const;
137 void setViewCache(BufferView const * bv) const;
139 void deleteLyXText(BufferView *, bool recursive = true) const;
141 bool showInsetDialog(BufferView *) const;
143 void getLabelList(std::vector<string> &) const;
145 int scroll(bool recursive = true) const;
147 void scroll(BufferView * bv, float sx) const {
148 UpdatableInset::scroll(bv, sx);
151 void scroll(BufferView * bv, int offset) const {
152 UpdatableInset::scroll(bv, offset);
155 void clearSelection(BufferView * bv);
157 InsetOld * getInsetFromID(int id) const;
159 ParagraphList * getParagraphs(int) const;
161 LyXCursor const & cursor(BufferView *) const;
163 bool allowSpellcheck() const { return true; }
166 selectNextWordToSpellcheck(BufferView *, float & value) const;
168 void selectSelectedWord(BufferView *);
170 /// mark as erased for change tracking
171 void markErased() { clear(true); };
173 * Mark as new. Used when pasting in tabular, and adding rows
174 * or columns. Note that pasting will ensure that tracking already
175 * happens, and this just resets the changes for the copied text,
176 * whereas for row/col add, we need to start tracking changes
177 * for the (empty) paragraph contained.
179 void markNew(bool track_changes = false);
181 bool nextChange(BufferView *, lyx::pos_type & length);
184 bool searchForward(BufferView *, string const &,
185 bool = true, bool = false);
187 bool searchBackward(BufferView *, string const &,
188 bool = true, bool = false);
190 bool checkInsertChar(LyXFont &);
192 void getDrawFont(LyXFont &) const;
193 /// append text onto the existing text
194 void appendParagraphs(Buffer * bp, ParagraphList &);
197 void addPreview(lyx::graphics::PreviewLoader &) const;
200 bool haveParagraphs() const {
204 mutable ParagraphList paragraphs;
207 void updateLocal(BufferView *, bool mark_dirty);
208 /// set parameters for an initial lock of this inset
209 void lockInset(BufferView *);
210 /// lock an inset inside this one
211 void lockInset(BufferView *, UpdatableInset *);
215 DrawFrame drawFrame_;
217 LColor::color frame_color;
221 void lfunMousePress(FuncRequest const &);
223 bool lfunMouseRelease(FuncRequest const &);
225 void lfunMouseMotion(FuncRequest const &);
228 RESULT moveRight(BufferView *);
230 RESULT moveLeft(BufferView *);
232 RESULT moveRightIntern(BufferView *, bool front,
233 bool activate_inset = true,
234 bool selecting = false);
236 RESULT moveLeftIntern(BufferView *, bool front,
237 bool activate_inset = true,
238 bool selecting = false);
241 RESULT moveUp(BufferView *);
243 RESULT moveDown(BufferView *);
245 void setCharFont(Buffer const &, int pos, LyXFont const & font);
247 bool checkAndActivateInset(BufferView * bv, bool front);
249 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
250 mouse_button::state button = mouse_button::none);
252 void removeNewlines();
258 lyx::pos_type cpos() const;
260 ParagraphList::iterator cpar() const;
262 bool cboundary() const;
264 RowList::iterator crow() const;
266 void drawFrame(Painter &, int x) const;
268 void clearInset(BufferView *, int start_x, int baseline) const;
270 void collapseParagraphs(BufferView *);
272 /* Private structures and variables */
278 ParagraphList::iterator inset_par;
280 lyx::pos_type inset_pos;
290 UpdatableInset * the_locking_inset;
292 mutable ParagraphList::iterator old_par;
295 // to remember old painted frame dimensions to clear it on the right spot!
297 mutable bool in_insetAllowed;
299 // these are used to check for mouse movement in Motion selection code
305 mutable LyXText text_;
307 mutable int textwidth_;