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 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 LyXCursor const & cursor(BufferView *) const;
160 bool allowSpellcheck() const { return true; }
163 selectNextWordToSpellcheck(BufferView *, float & value) const;
165 void selectSelectedWord(BufferView *);
167 /// mark as erased for change tracking
168 void markErased() { clear(true); };
170 * Mark as new. Used when pasting in tabular, and adding rows
171 * or columns. Note that pasting will ensure that tracking already
172 * happens, and this just resets the changes for the copied text,
173 * whereas for row/col add, we need to start tracking changes
174 * for the (empty) paragraph contained.
176 void markNew(bool track_changes = false);
178 bool nextChange(BufferView *, lyx::pos_type & length);
181 bool searchForward(BufferView *, std::string const &,
182 bool = true, bool = false);
184 bool searchBackward(BufferView *, std::string const &,
185 bool = true, bool = false);
187 bool checkInsertChar(LyXFont &);
189 void getDrawFont(LyXFont &) const;
190 /// append text onto the existing text
191 void appendParagraphs(Buffer * bp, ParagraphList &);
194 void addPreview(lyx::graphics::PreviewLoader &) const;
197 bool haveParagraphs() const {
201 mutable ParagraphList paragraphs;
204 void updateLocal(BufferView *, bool mark_dirty);
205 /// set parameters for an initial lock of this inset
206 void lockInset(BufferView *);
207 /// lock an inset inside this one
208 void lockInset(BufferView *, UpdatableInset *);
214 void lfunMousePress(FuncRequest const &);
216 bool lfunMouseRelease(FuncRequest const &);
218 void lfunMouseMotion(FuncRequest const &);
221 RESULT moveRight(BufferView *);
223 RESULT moveLeft(BufferView *);
225 RESULT moveRightIntern(BufferView *, bool front,
226 bool activate_inset = true,
227 bool selecting = false);
229 RESULT moveLeftIntern(BufferView *, bool front,
230 bool activate_inset = true,
231 bool selecting = false);
234 RESULT moveUp(BufferView *);
236 RESULT moveDown(BufferView *);
238 void setCharFont(Buffer const &, int pos, LyXFont const & font);
240 bool checkAndActivateInset(BufferView * bv, bool front);
242 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
243 mouse_button::state button = mouse_button::none);
245 void removeNewlines();
251 lyx::pos_type cpos() const;
253 ParagraphList::iterator cpar() const;
255 bool cboundary() const;
257 RowList::iterator crow() const;
259 void drawFrame(Painter &, int x) const;
261 void clearInset(BufferView *, int start_x, int baseline) const;
263 void collapseParagraphs(BufferView *);
265 /* Private structures and variables */
269 DrawFrame drawFrame_;
270 /** We store the LColor::color value as an int to get LColor.h out
271 * of the header file.
279 ParagraphList::iterator inset_par;
281 lyx::pos_type inset_pos;
291 UpdatableInset * the_locking_inset;
293 mutable ParagraphList::iterator old_par;
296 // to remember old painted frame dimensions to clear it on the right spot!
298 mutable bool in_insetAllowed;
300 // these are used to check for mouse movement in Motion selection code
306 mutable LyXText text_;
308 mutable int textwidth_;