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 "ParagraphList_fwd.h"
17 #include "RowList_fwd.h"
20 #include "support/types.h"
22 #include "frontends/mouse_state.h"
24 #include "support/std_string.h"
37 A text inset is like a TeX box to write full text
38 (including styles and other insets) in a given space.
41 class InsetText : public UpdatableInset {
53 InsetText(BufferParams const &);
55 explicit InsetText(InsetText const &);
57 virtual std::auto_ptr<InsetBase> clone() const;
59 InsetText & operator=(InsetText const & it);
60 /// empty inset to empty par, or just mark as erased
61 void clear(bool just_mark_erased);
63 void read(Buffer const &, LyXLex &);
65 void write(Buffer const &, std::ostream &) const;
67 void metrics(MetricsInfo &, Dimension &) const;
69 int textWidth() const;
71 void draw(PainterInfo & pi, int x, int y) const;
73 string const editMessage() const;
75 bool isTextInset() const { return true; }
77 void insetUnlock(BufferView *);
79 bool lockInsetInInset(BufferView *, UpdatableInset *);
81 bool unlockInsetInInset(BufferView *,
82 UpdatableInset *, bool lr = false);
84 RESULT localDispatch(FuncRequest const &);
86 int latex(Buffer const &, std::ostream &,
87 LatexRunParams const &) const;
89 int ascii(Buffer const &, std::ostream &, int linelen) const;
91 int linuxdoc(Buffer const &, std::ostream &) const ;
93 int docbook(Buffer const &, std::ostream &, bool mixcont) const ;
95 void validate(LaTeXFeatures & features) const;
97 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
99 void getCursorPos(BufferView *, int & x, int & y) const;
100 /// Get the absolute document x,y of the cursor
101 virtual void getCursor(BufferView &, int &, int &) const;
103 int insetInInsetY() const;
105 void fitInsetCursor(BufferView *) const;
107 bool insertInset(BufferView *, InsetOld *);
109 bool insetAllowed(InsetOld::Code) const;
111 UpdatableInset * getLockingInset() const;
113 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
115 void setFont(BufferView *, LyXFont const &,
116 bool toggleall = false,
117 bool selectall = false);
119 void init(InsetText const * ins);
121 void writeParagraphData(Buffer const &, std::ostream &) const;
123 void setText(string const &, LyXFont const &);
125 void setAutoBreakRows(bool);
127 bool getAutoBreakRows() const { return autoBreakRows_; }
129 void setDrawFrame(DrawFrame);
131 EnumLColor frameColor() const;
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 void lfunMousePress(FuncRequest const &);
217 bool lfunMouseRelease(FuncRequest const &);
219 void lfunMouseMotion(FuncRequest const &);
222 RESULT moveRight(BufferView *);
224 RESULT moveLeft(BufferView *);
226 RESULT moveRightIntern(BufferView *, bool front,
227 bool activate_inset = true,
228 bool selecting = false);
230 RESULT moveLeftIntern(BufferView *, bool front,
231 bool activate_inset = true,
232 bool selecting = false);
235 RESULT moveUp(BufferView *);
237 RESULT moveDown(BufferView *);
239 void setCharFont(Buffer const &, int pos, LyXFont const & font);
241 bool checkAndActivateInset(BufferView * bv, bool front);
243 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
244 mouse_button::state button = mouse_button::none);
246 void removeNewlines();
252 lyx::pos_type cpos() const;
254 ParagraphList::iterator cpar() const;
256 bool cboundary() const;
258 RowList::iterator crow() const;
260 void drawFrame(Painter &, int x) const;
262 void clearInset(BufferView *, int start_x, int baseline) const;
264 void collapseParagraphs(BufferView *);
266 /* Private structures and variables */
270 DrawFrame drawFrame_;
271 /** We store the LColor::color value as an int to get LColor.h out
272 * of the header file.
280 ParagraphList::iterator inset_par;
282 lyx::pos_type inset_pos;
292 UpdatableInset * the_locking_inset;
294 mutable ParagraphList::iterator old_par;
297 // to remember old painted frame dimensions to clear it on the right spot!
299 mutable bool in_insetAllowed;
301 // these are used to check for mouse movement in Motion selection code
307 mutable LyXText text_;
309 mutable int textwidth_;