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 &,
87 LatexRunParams const &) const;
89 int linuxdoc(Buffer const &, std::ostream &,
90 LatexRunParams const &) const ;
92 int docbook(Buffer const &, std::ostream &,
93 LatexRunParams const &) 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 writeParagraphData(Buffer const &, std::ostream &) const;
121 void setText(std::string const &, LyXFont const &);
123 void setAutoBreakRows(bool);
125 bool getAutoBreakRows() const { return autoBreakRows_; }
127 void setDrawFrame(DrawFrame);
129 LColor_color frameColor() const;
130 void setFrameColor(LColor_color);
132 LyXText * getLyXText(BufferView const *,
133 bool const recursive = false) const;
135 void setViewCache(BufferView const * bv) const;
137 void deleteLyXText(BufferView *, bool recursive = true) const;
139 bool showInsetDialog(BufferView *) const;
140 /// Appends \c list with all labels found within this inset.
141 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
143 int scroll(bool recursive = true) const;
145 void scroll(BufferView * bv, float sx) const {
146 UpdatableInset::scroll(bv, sx);
149 void scroll(BufferView * bv, int offset) const {
150 UpdatableInset::scroll(bv, offset);
153 void clearSelection(BufferView * bv);
155 InsetOld * getInsetFromID(int id) const;
157 ParagraphList * getParagraphs(int) const;
159 LyXText * getText(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 *, std::string const &,
185 bool = true, bool = false);
187 bool searchBackward(BufferView *, std::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;
209 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
211 void updateLocal(BufferView *, bool mark_dirty);
212 /// set parameters for an initial lock of this inset
213 void lockInset(BufferView *);
214 /// lock an inset inside this one
215 void lockInset(BufferView *, UpdatableInset *);
221 void lfunMousePress(FuncRequest const &);
223 bool lfunMouseRelease(FuncRequest const &);
225 void lfunMouseMotion(FuncRequest const &);
228 DispatchResult moveRight(BufferView *);
230 DispatchResult moveLeft(BufferView *);
232 DispatchResult moveRightIntern(BufferView *, bool front,
233 bool activate_inset = true,
234 bool selecting = false);
236 DispatchResult moveLeftIntern(BufferView *, bool front,
237 bool activate_inset = true,
238 bool selecting = false);
241 DispatchResult moveUp(BufferView *);
243 DispatchResult 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 */
276 DrawFrame drawFrame_;
277 /** We store the LColor::color value as an int to get LColor.h out
278 * of the header file.
286 lyx::paroffset_type inset_par;
288 lyx::pos_type inset_pos;
298 UpdatableInset * the_locking_inset;
300 mutable lyx::paroffset_type old_par;
303 // to remember old painted frame dimensions to clear it on the right spot!
305 mutable bool in_insetAllowed;
307 // these are used to check for mouse movement in Motion selection code
313 mutable LyXText text_;
315 mutable int textwidth_;