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 int latex(Buffer const &, std::ostream &,
84 LatexRunParams const &) const;
86 int ascii(Buffer const &, std::ostream &, int linelen) const;
88 int linuxdoc(Buffer const &, std::ostream &) const ;
90 int docbook(Buffer const &, std::ostream &, bool mixcont) const ;
92 void validate(LaTeXFeatures & features) const;
94 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
96 void getCursorPos(BufferView *, int & x, int & y) const;
97 /// Get the absolute document x,y of the cursor
98 virtual void getCursor(BufferView &, int &, int &) const;
100 int insetInInsetY() const;
102 void fitInsetCursor(BufferView *) const;
104 bool insertInset(BufferView *, InsetOld *);
106 bool insetAllowed(InsetOld::Code) const;
108 UpdatableInset * getLockingInset() const;
110 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
112 void setFont(BufferView *, LyXFont const &,
113 bool toggleall = false,
114 bool selectall = false);
116 void writeParagraphData(Buffer const &, std::ostream &) const;
118 void setText(std::string const &, LyXFont const &);
120 void setAutoBreakRows(bool);
122 bool getAutoBreakRows() const { return autoBreakRows_; }
124 void setDrawFrame(DrawFrame);
126 LColor_color frameColor() const;
127 void setFrameColor(LColor_color);
129 LyXText * getLyXText(BufferView const *,
130 bool const recursive = false) const;
132 void setViewCache(BufferView const * bv) const;
134 void deleteLyXText(BufferView *, bool recursive = true) const;
136 bool showInsetDialog(BufferView *) const;
137 /// Appends \c list with all labels found within this inset.
138 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
140 int scroll(bool recursive = true) const;
142 void scroll(BufferView * bv, float sx) const {
143 UpdatableInset::scroll(bv, sx);
146 void scroll(BufferView * bv, int offset) const {
147 UpdatableInset::scroll(bv, offset);
150 void clearSelection(BufferView * bv);
152 InsetOld * getInsetFromID(int id) const;
154 ParagraphList * getParagraphs(int) const;
156 LyXText * getText(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;
206 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
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 *);
218 void lfunMousePress(FuncRequest const &);
220 bool lfunMouseRelease(FuncRequest const &);
222 void lfunMouseMotion(FuncRequest const &);
225 DispatchResult moveRight(BufferView *);
227 DispatchResult moveLeft(BufferView *);
229 DispatchResult moveRightIntern(BufferView *, bool front,
230 bool activate_inset = true,
231 bool selecting = false);
233 DispatchResult moveLeftIntern(BufferView *, bool front,
234 bool activate_inset = true,
235 bool selecting = false);
238 DispatchResult moveUp(BufferView *);
240 DispatchResult moveDown(BufferView *);
242 void setCharFont(Buffer const &, int pos, LyXFont const & font);
244 bool checkAndActivateInset(BufferView * bv, bool front);
246 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
247 mouse_button::state button = mouse_button::none);
249 void removeNewlines();
255 lyx::pos_type cpos() const;
257 ParagraphList::iterator cpar() const;
259 bool cboundary() const;
261 RowList::iterator crow() const;
263 void drawFrame(Painter &, int x) const;
265 void clearInset(BufferView *, int start_x, int baseline) const;
267 void collapseParagraphs(BufferView *);
269 /* Private structures and variables */
273 DrawFrame drawFrame_;
274 /** We store the LColor::color value as an int to get LColor.h out
275 * of the header file.
283 lyx::paroffset_type inset_par;
285 lyx::pos_type inset_pos;
295 UpdatableInset * the_locking_inset;
297 mutable lyx::paroffset_type old_par;
300 // to remember old painted frame dimensions to clear it on the right spot!
302 mutable bool in_insetAllowed;
304 // these are used to check for mouse movement in Motion selection code
310 mutable LyXText text_;
312 mutable int textwidth_;