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 "textcursor.h"
19 #include "ParagraphList.h"
21 #include "dimension.h"
24 #include "support/types.h"
26 #include "frontends/mouse_state.h"
28 #include <boost/shared_ptr.hpp>
40 A text inset is like a TeX box to write full text
41 (including styles and other insets) in a given space.
44 class InsetText : public UpdatableInset {
56 InsetText(BufferParams const &);
58 explicit InsetText(InsetText const &);
60 virtual std::auto_ptr<InsetBase> clone() const;
62 InsetText & operator=(InsetText const & it);
63 /// empty inset to empty par, or just mark as erased
64 void clear(bool just_mark_erased);
66 void read(Buffer const *, LyXLex &);
68 void write(Buffer const *, std::ostream &) const;
70 void metrics(MetricsInfo &, Dimension &) const;
72 int textWidth() const;
74 void draw(PainterInfo & pi, int x, int y) const;
76 string const editMessage() const;
78 bool isTextInset() const { return true; }
80 void insetUnlock(BufferView *);
82 bool lockInsetInInset(BufferView *, UpdatableInset *);
84 bool unlockInsetInInset(BufferView *,
85 UpdatableInset *, bool lr = false);
87 RESULT localDispatch(FuncRequest const &);
89 int latex(Buffer const *, std::ostream &,
90 LatexRunParams const &) const;
92 int ascii(Buffer const *, std::ostream &, int linelen) const;
94 int linuxdoc(Buffer const *, std::ostream &) const ;
96 int docbook(Buffer const *, std::ostream &, bool mixcont) const ;
98 void validate(LaTeXFeatures & features) const;
100 InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; }
102 void getCursorPos(BufferView *, int & x, int & y) const;
103 /// Get the absolute document x,y of the cursor
104 virtual void getCursor(BufferView &, int &, int &) const;
106 int insetInInsetY() const;
108 void fitInsetCursor(BufferView *) const;
110 bool insertInset(BufferView *, InsetOld *);
112 bool insetAllowed(InsetOld::Code) const;
114 UpdatableInset * getLockingInset() const;
116 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
118 void setFont(BufferView *, LyXFont const &,
119 bool toggleall = false,
120 bool selectall = false);
122 void init(InsetText const * ins);
124 void writeParagraphData(Buffer const *, std::ostream &) const;
126 void setText(string const &, LyXFont const &);
128 void setAutoBreakRows(bool);
130 bool getAutoBreakRows() const { return autoBreakRows; }
132 void setDrawFrame(BufferView *, DrawFrame);
134 void setFrameColor(BufferView *, LColor::color);
136 LyXText * getLyXText(BufferView const *,
137 bool const recursive = false) const;
139 void setViewCache(BufferView const * bv) const;
141 void deleteLyXText(BufferView *, bool recursive = true) const;
143 void resizeLyXText(BufferView *, bool force = false) const;
145 bool showInsetDialog(BufferView *) const;
147 void getLabelList(std::vector<string> &) const;
149 int scroll(bool recursive = true) const;
151 void scroll(BufferView * bv, float sx) const {
152 UpdatableInset::scroll(bv, sx);
155 void scroll(BufferView * bv, int offset) const {
156 UpdatableInset::scroll(bv, offset);
159 void clearSelection(BufferView * bv);
161 InsetOld * getInsetFromID(int id) const;
163 ParagraphList * getParagraphs(int) const;
165 LyXCursor const & cursor(BufferView *) const;
167 bool allowSpellcheck() const { return true; }
170 selectNextWordToSpellcheck(BufferView *, float & value) const;
172 void selectSelectedWord(BufferView *);
174 /// mark as erased for change tracking
175 void markErased() { clear(true); };
177 * Mark as new. Used when pasting in tabular, and adding rows
178 * or columns. Note that pasting will ensure that tracking already
179 * happens, and this just resets the changes for the copied text,
180 * whereas for row/col add, we need to start tracking changes
181 * for the (empty) paragraph contained.
183 void markNew(bool track_changes = false);
185 bool nextChange(BufferView *, lyx::pos_type & length);
188 bool searchForward(BufferView *, string const &,
189 bool = true, bool = false);
191 bool searchBackward(BufferView *, string const &,
192 bool = true, bool = false);
194 bool checkInsertChar(LyXFont &);
196 void getDrawFont(LyXFont &) const;
197 /// append text onto the existing text
198 void appendParagraphs(Buffer * bp, ParagraphList &);
201 void addPreview(lyx::graphics::PreviewLoader &) const;
204 bool haveParagraphs() const {
208 ParagraphList paragraphs;
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 *);
217 mutable int drawTextXOffset;
219 mutable int drawTextYOffset;
223 DrawFrame drawFrame_;
225 LColor::color frame_color;
229 void lfunMousePress(FuncRequest const &);
231 bool lfunMouseRelease(FuncRequest const &);
233 void lfunMouseMotion(FuncRequest const &);
236 RESULT moveRight(BufferView *);
238 RESULT moveLeft(BufferView *);
240 RESULT moveRightIntern(BufferView *, bool front,
241 bool activate_inset = true,
242 bool selecting = false);
244 RESULT moveLeftIntern(BufferView *, bool front,
245 bool activate_inset = true,
246 bool selecting = false);
249 RESULT moveUp(BufferView *);
251 RESULT moveDown(BufferView *);
253 void setCharFont(Buffer const *, int pos, LyXFont const & font);
255 bool checkAndActivateInset(BufferView * bv, bool front);
257 bool checkAndActivateInset(BufferView * bv, int x = 0, int y = 0,
258 mouse_button::state button = mouse_button::none);
260 void removeNewlines();
270 lyx::pos_type cpos() const;
272 ParagraphList::iterator cpar() const;
274 bool cboundary() const;
276 RowList::iterator crow() const;
278 void drawFrame(Painter &, int x) const;
280 void clearInset(BufferView *, int start_x, int baseline) const;
282 void saveLyXTextState() const;
284 void restoreLyXTextState() const;
286 void collapseParagraphs(BufferView *);
288 /* Private structures and variables */
294 ParagraphList::iterator inset_par;
296 lyx::pos_type inset_pos;
306 UpdatableInset * the_locking_inset;
308 mutable ParagraphList::iterator old_par;
310 /// some funny 'temporarily saved state'
311 mutable TextCursor sstate;
314 // to remember old painted frame dimensions to clear it on the right spot!
316 mutable bool in_insetAllowed;
318 // these are used to check for mouse movement in Motion selection code
324 void reinitLyXText() const;
326 mutable LyXText text_;
328 mutable int textwidth_;