4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Lars Gullik Bjønnes
11 * Full author contact details are available in file CREDITS.
17 #include "DocIterator.h"
18 #include "ParagraphList.h"
40 /// This class encapsulates the main text data and operations in LyX
44 explicit Text(InsetText * owner)
45 : autoBreakRows_(false), owner_(owner)
48 /// \return true if there's no content at all.
49 /// \warning a non standard layout on an empty paragraph doesn't
53 InsetText const * inset() { return owner_; }
56 FontInfo layoutFont(Buffer const & buffer, pit_type pit) const;
58 FontInfo labelFont(Buffer const & buffer,
59 Paragraph const & par) const;
60 /** Set font of character at position \p pos in paragraph \p pit.
61 * Must not be called if \p pos denotes an inset with text contents,
62 * and the inset is not allowed inside a font change (see below).
64 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
65 Font const & font, Font const & display_font);
67 /** Needed to propagate font changes to all text cells of insets
68 * that are not allowed inside a font change (bug 1973).
69 * Must not be called if \p pos denotes an ordinary character or an
70 * inset that is alowed inside a font change.
71 * FIXME: This should be removed, see documentation of noFontChange
74 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
75 Font const & font, bool toggleall = false);
77 /// what you expect when pressing \<enter\> at cursor position
78 void breakParagraph(Cursor & cur, bool inverse_logic = false);
80 /// set layout over selection
81 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
82 docstring const & layout);
83 /// Set given layout to current cursor position.
84 /// FIXME: replace Cursor with DocIterator.
85 void setLayout(Cursor & cur, docstring const & layout);
87 /// what type of depth change to make
92 /// Increase or decrease the nesting depth of the selected paragraph(s)
93 /// FIXME: replace Cursor with DocIterator.
94 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
96 /// Returns whether something would be changed by changeDepth
97 /// FIXME: replace Cursor with DocIterator.
98 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
100 /// Set font over selection paragraphs and rebreak.
101 /// FIXME: replace Cursor with DocIterator.
102 void setFont(Cursor & cur, Font const &, bool toggleall = false);
103 /// Set font from \p begin to \p end and rebreak.
104 void setFont(BufferView const & bv, CursorSlice const & begin,
105 CursorSlice const & end, Font const &,
106 bool toggleall = false);
109 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
112 /// FIXME: replace Cursor with DocIterator.
113 docstring getStringToIndex(Cursor const & cur);
115 /// Convert the paragraphs to a string.
116 /// \param AsStringParameter options. This can contain any combination of
117 /// asStringParameter values. Valid examples:
118 /// asString(AS_STR_LABEL)
119 /// asString(AS_STR_LABEL | AS_STR_INSETS)
120 /// asString(AS_STR_INSETS)
121 docstring asString(int options = AS_STR_NONE) const;
123 docstring asString(pit_type beg, pit_type end,
124 int options = AS_STR_NONE) const;
126 /// insert a character at cursor position
127 /// FIXME: replace Cursor with DocIterator.
128 void insertChar(Cursor & cur, char_type c);
129 /// insert an inset at cursor position
130 /// FIXME: replace Cursor with DocIterator.
131 void insertInset(Cursor & cur, Inset * inset);
133 /// try to handle that request
134 /// FIXME: replace Cursor with DocIterator.
135 void dispatch(Cursor & cur, FuncRequest & cmd);
136 /// do we want to handle this event?
137 bool getStatus(Cursor & cur, FuncRequest const & cmd,
138 FuncStatus & status) const;
140 /// read-only access to individual paragraph
141 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
142 /// read-write access to individual paragraph
143 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
144 // Returns the current font and depth as a message.
145 /// FIXME: replace Cursor with DocIterator.
146 docstring currentState(Cursor const & cur) const;
148 /** Find the word under \c from in the relative location
149 * defined by \c word_location.
150 * @param from return here the start of the word
151 * @param to return here the end of the word
153 void getWord(CursorSlice & from, CursorSlice & to, word_location const) const;
154 /// just selects the word the cursor is in
155 void selectWord(Cursor & cur, word_location loc);
157 void selectAll(Cursor & cur);
158 /// convenience function get the previous word or an empty string
159 docstring previousWord(CursorSlice const & sl) const;
161 /// what type of change operation to make
166 /// accept or reject the selected change
167 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
168 /// accept the changes within the complete Text
169 void acceptChanges(BufferParams const & bparams);
170 /// reject the changes within the complete Text
171 void rejectChanges(BufferParams const & bparams);
173 /// returns true if par was empty and was removed
174 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
175 bool setfont = true, bool boundary = false);
177 void setCursor(CursorSlice &, pit_type par, pos_type pos);
179 void setCursorIntern(Cursor & cur, pit_type par,
180 pos_type pos, bool setfont = true, bool boundary = false);
183 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
185 void recUndo(Cursor & cur, pit_type first) const;
187 /// Move cursor one position backwards
189 * Returns true if an update is needed after the move.
191 bool cursorBackward(Cursor & cur);
192 /// Move cursor visually one position to the left
194 * \param skip_inset if true, don't enter insets
195 * Returns true if an update is needed after the move.
197 bool cursorVisLeft(Cursor & cur, bool skip_inset = false);
198 /// Move cursor one position forward
200 * Returns true if an update is needed after the move.
202 bool cursorForward(Cursor & cur);
203 /// Move cursor visually one position to the right
205 * \param skip_inset if true, don't enter insets
206 * Returns true if an update is needed after the move.
208 bool cursorVisRight(Cursor & cur, bool skip_inset = false);
210 bool cursorBackwardOneWord(Cursor & cur);
212 bool cursorForwardOneWord(Cursor & cur);
214 bool cursorVisLeftOneWord(Cursor & cur);
216 bool cursorVisRightOneWord(Cursor & cur);
217 /// Delete from cursor up to the end of the current or next word.
218 void deleteWordForward(Cursor & cur);
219 /// Delete from cursor to start of current or prior word.
220 void deleteWordBackward(Cursor & cur);
222 bool cursorUpParagraph(Cursor & cur);
224 bool cursorDownParagraph(Cursor & cur);
226 bool cursorTop(Cursor & cur);
228 bool cursorBottom(Cursor & cur);
229 /// Erase character at cursor. Honour change tracking
230 /// FIXME: replace Cursor with DocIterator.
231 bool erase(Cursor & cur);
232 /// Delete character before cursor. Honour CT
233 /// FIXME: replace Cursor with DocIterator.
234 bool backspace(Cursor & cur);
235 // Dissolve the inset under cursor
236 /// FIXME: replace Cursor with DocIterator.
237 bool dissolveInset(Cursor & cur);
239 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
240 /// Change the case of the word at cursor position.
241 void changeCase(Cursor & cur, TextCase action);
242 /// Transposes the character at the cursor with the one before it
243 void charsTranspose(Cursor & cur);
245 /** the DTP switches for paragraphs. LyX will store the top settings
246 always in the first physical paragraph, the bottom settings in the
247 last. When a paragraph is broken, the top settings rest, the bottom
248 settings are given to the new one.
249 This function will handle a multi-paragraph selection.
251 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
252 /// Sets parameters for current or selected paragraphs
253 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
255 /* these things are for search and replace */
257 /// needed to insert the selection
258 /// FIXME: replace Cursor with DocIterator.
259 void insertStringAsLines(Cursor & cur, docstring const & str);
260 /// needed to insert the selection
261 /// FIXME: replace Cursor with DocIterator.
262 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
264 /// access to our paragraphs
265 ParagraphList const & paragraphs() const { return pars_; }
266 ParagraphList & paragraphs() { return pars_; }
267 /// return true if this is the main text
268 bool isMainText(Buffer const &) const;
271 double spacing(Buffer const & buffer, Paragraph const & par) const;
272 /// make a suggestion for a label
273 /// FIXME: replace Cursor with DocIterator.
274 docstring getPossibleLabel(Cursor const & cur) const;
275 /// is this paragraph right-to-left?
276 bool isRTL(Buffer const &, Paragraph const & par) const;
279 bool checkAndActivateInset(Cursor & cur, bool front);
281 bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft);
284 void write(Buffer const & buf, std::ostream & os) const;
285 /// returns true if \end_document has not been read
286 /// insetPtr is the containing Inset
287 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList,
288 InsetText * insetPtr);
290 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
291 /// \retval true if a change has happened and we need a redraw.
292 /// FIXME: replace Cursor with DocIterator. This is not possible right
293 /// now because recordUndo() is called which needs a Cursor.
294 static bool deleteEmptyParagraphMechanism(Cursor & cur,
295 Cursor & old, bool & need_anchor_change);
297 /// delete double spaces, leading spaces, and empty paragraphs
298 /// from \first to \last paragraph
299 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
301 /// To resolve macros properly the texts get their DocIterator.
302 /// Every macro definition is stored with its DocIterator
303 /// as well. Only those macros with a smaller iterator become
304 /// visible in a paragraph.
305 DocIterator macrocontextPosition() const;
307 void setMacrocontextPosition(DocIterator const & pos);
310 bool completionSupported(Cursor const & cur) const;
312 CompletionList const * createCompletionList(Cursor const & cur) const;
314 bool insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/);
316 docstring completionPrefix(Cursor const & cur) const;
325 /// return past-the-last paragraph influenced by a layout
327 pit_type undoSpan(pit_type pit);
329 // fix the cursor `cur' after a characters has been deleted at `where'
330 // position. Called by deleteEmptyParagraphMechanism
331 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
333 // At cursor position 0, try to merge the paragraph with the one before it.
334 // Ignore change tracking, i.e., physically remove the end-of-par character
335 bool backspacePos0(Cursor & cur);
336 /// handle the case where bibitems were deleted
337 bool handleBibitems(Cursor & cur);
338 /// are we in a list item (description etc.)?
339 bool inDescriptionItem(Cursor & cur) const;
341 void charInserted(Cursor & cur);
342 /// set 'number' font property
343 void number(Cursor & cur);
345 /// paste plain text at current cursor.
346 /// \param str string to paste
347 /// \param asParagraphs whether to paste as paragraphs or as lines
348 void pasteString(Cursor & cur, docstring const & str,
354 /// position of the text in the buffer.
355 DocIterator macrocontext_position_;