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"
36 A text inset is like a TeX box to write full text
37 (including styles and other insets) in a given space.
40 class InsetText : public UpdatableInset {
52 explicit InsetText(BufferParams const &);
54 InsetText(InsetText const &);
56 virtual std::auto_ptr<InsetBase> clone() const;
58 void operator=(InsetText const & it);
59 /// empty inset to empty par, or just mark as erased
60 void clear(bool just_mark_erased);
62 void read(Buffer const &, LyXLex &);
64 void write(Buffer const &, std::ostream &) const;
66 void metrics(MetricsInfo &, Dimension &) const;
68 int textWidth() const;
70 void draw(PainterInfo & pi, int x, int y) const;
72 std::string const editMessage() const;
74 bool isTextInset() const { return true; }
76 void insetUnlock(BufferView *);
78 bool lockInsetInInset(BufferView *, UpdatableInset *);
80 bool unlockInsetInInset(BufferView *,
81 UpdatableInset *, bool lr = false);
83 dispatch_result localDispatch(FuncRequest const &);
85 int latex(Buffer const &, std::ostream &,
86 LatexRunParams const &) const;
88 int ascii(Buffer const &, std::ostream &, int linelen) const;
90 int linuxdoc(Buffer const &, std::ostream &) const ;
92 int docbook(Buffer const &, std::ostream &, bool mixcont) const ;
94 void validate(LaTeXFeatures & features) const;
96 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
98 void getCursorPos(BufferView *, int & x, int & y) const;
99 /// Get the absolute document x,y of the cursor
100 virtual void getCursor(BufferView &, int &, int &) const;
102 int insetInInsetY() const;
104 void fitInsetCursor(BufferView *) const;
106 bool insertInset(BufferView *, InsetOld *);
108 bool insetAllowed(InsetOld::Code) const;
110 UpdatableInset * getLockingInset() const;
112 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
114 void setFont(BufferView *, LyXFont const &,
115 bool toggleall = false,
116 bool selectall = false);
118 void writeParagraphData(Buffer const &, std::ostream &) const;
120 void setText(std::string const &, LyXFont const &);
122 void setAutoBreakRows(bool);
124 bool getAutoBreakRows() const { return autoBreakRows_; }
126 void setDrawFrame(DrawFrame);
128 LColor_color frameColor() const;
129 void setFrameColor(LColor_color);
131 LyXText * getLyXText(BufferView const *,
132 bool const recursive = false) const;
134 void setViewCache(BufferView const * bv) const;
136 void deleteLyXText(BufferView *, bool recursive = true) const;
138 bool showInsetDialog(BufferView *) const;
139 /// Appends \c list with all labels found within this inset.
140 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
142 int scroll(bool recursive = true) const;
144 void scroll(BufferView * bv, float sx) const {
145 UpdatableInset::scroll(bv, sx);
148 void scroll(BufferView * bv, int offset) const {
149 UpdatableInset::scroll(bv, offset);
152 void clearSelection(BufferView * bv);
154 InsetOld * getInsetFromID(int id) const;
156 ParagraphList * getParagraphs(int) const;
158 LyXText * getText(int) const;
160 LyXCursor const & cursor(BufferView *) const;
162 bool allowSpellcheck() const { return true; }
165 selectNextWordToSpellcheck(BufferView *, float & value) const;
167 void selectSelectedWord(BufferView *);
169 /// mark as erased for change tracking
170 void markErased() { clear(true); };
172 * Mark as new. Used when pasting in tabular, and adding rows
173 * or columns. Note that pasting will ensure that tracking already
174 * happens, and this just resets the changes for the copied text,
175 * whereas for row/col add, we need to start tracking changes
176 * for the (empty) paragraph contained.
178 void markNew(bool track_changes = false);
180 bool nextChange(BufferView *, lyx::pos_type & length);
183 bool searchForward(BufferView *, std::string const &,
184 bool = true, bool = false);
186 bool searchBackward(BufferView *, std::string const &,
187 bool = true, bool = false);
189 bool checkInsertChar(LyXFont &);
191 void getDrawFont(LyXFont &) const;
192 /// append text onto the existing text
193 void appendParagraphs(Buffer * bp, ParagraphList &);
196 void addPreview(lyx::graphics::PreviewLoader &) const;
199 bool haveParagraphs() const {
203 mutable ParagraphList paragraphs;
206 void updateLocal(BufferView *, bool mark_dirty);
207 /// set parameters for an initial lock of this inset
208 void lockInset(BufferView *);
209 /// lock an inset inside this one
210 void lockInset(BufferView *, UpdatableInset *);
216 void lfunMousePress(FuncRequest const &);
218 bool lfunMouseRelease(FuncRequest const &);
220 void lfunMouseMotion(FuncRequest const &);
223 dispatch_result moveRight(BufferView *);
225 dispatch_result moveLeft(BufferView *);
227 dispatch_result moveRightIntern(BufferView *, bool front,
228 bool activate_inset = true,
229 bool selecting = false);
231 dispatch_result moveLeftIntern(BufferView *, bool front,
232 bool activate_inset = true,
233 bool selecting = false);
236 dispatch_result moveUp(BufferView *);
238 dispatch_result moveDown(BufferView *);
240 void setCharFont(Buffer const &, int pos, LyXFont const & font);
242 bool checkAndActivateInset(BufferView * bv, bool front);
244 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
245 mouse_button::state button = mouse_button::none);
247 void removeNewlines();
253 lyx::pos_type cpos() const;
255 ParagraphList::iterator cpar() const;
257 bool cboundary() const;
259 RowList::iterator crow() const;
261 void drawFrame(Painter &, int x) const;
263 void clearInset(BufferView *, int start_x, int baseline) const;
265 void collapseParagraphs(BufferView *);
267 /* Private structures and variables */
271 DrawFrame drawFrame_;
272 /** We store the LColor::color value as an int to get LColor.h out
273 * of the header file.
281 lyx::paroffset_type inset_par;
283 lyx::pos_type inset_pos;
293 UpdatableInset * the_locking_inset;
295 mutable lyx::paroffset_type old_par;
298 // to remember old painted frame dimensions to clear it on the right spot!
300 mutable bool in_insetAllowed;
302 // these are used to check for mouse movement in Motion selection code
308 mutable LyXText text_;
310 mutable int textwidth_;