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"
38 /// This class encapsulates the main text data and operations in LyX
42 explicit Text(InsetText * owner)
43 : autoBreakRows_(false), owner_(owner)
46 /// \return true if there's no content at all.
47 /// \warning a non standard layout on an empty paragraph doesn't
51 InsetText const * inset() const { return owner_; }
54 FontInfo layoutFont(pit_type pit) const;
56 FontInfo labelFont(Paragraph const & par) const;
57 /** Set font of character at position \p pos in paragraph \p pit.
58 * Must not be called if \p pos denotes an inset with text contents,
59 * and the inset is not allowed inside a font change (see below).
61 void setCharFont(pit_type pit, pos_type pos,
62 Font const & font, Font const & display_font);
64 /** Needed to propagate font changes to all text cells of insets
65 * that are not allowed inside a font change (bug 1973).
66 * Must not be called if \p pos denotes an ordinary character or an
67 * inset that is alowed inside a font change.
68 * FIXME: This should be removed, see documentation of noFontChange
71 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
72 Font const & font, bool toggleall = false);
74 /// what you expect when pressing \<enter\> at cursor position
75 void breakParagraph(Cursor & cur, bool inverse_logic = false);
77 /// set layout over selection
78 void setLayout(pit_type start, pit_type end,
79 docstring const & layout);
80 /// Set given layout to current cursor position.
81 /// FIXME: replace Cursor with DocIterator.
82 void setLayout(Cursor & cur, docstring const & layout);
84 /// what type of depth change to make
89 /// Increase or decrease the nesting depth of the selected paragraph(s)
90 /// FIXME: replace Cursor with DocIterator.
91 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
93 /// Returns whether something would be changed by changeDepth
94 /// FIXME: replace Cursor with DocIterator.
95 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
97 /// Set font over selection paragraphs and rebreak.
98 /// FIXME: replace Cursor with DocIterator.
99 void setFont(Cursor & cur, Font const &, bool toggleall = false);
100 /// Set font from \p begin to \p end and rebreak.
101 void setFont(BufferView const & bv, CursorSlice const & begin,
102 CursorSlice const & end, Font const &,
103 bool toggleall = false);
106 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
109 /// FIXME: replace Cursor with DocIterator.
110 docstring getStringToIndex(Cursor const & cur);
112 /// Convert the paragraphs to a string.
113 /// \param AsStringParameter options. This can contain any combination of
114 /// asStringParameter values. Valid examples:
115 /// asString(AS_STR_LABEL)
116 /// asString(AS_STR_LABEL | AS_STR_INSETS)
117 /// asString(AS_STR_INSETS)
118 docstring asString(int options = AS_STR_NONE) const;
120 docstring asString(pit_type beg, pit_type end,
121 int options = AS_STR_NONE) const;
123 /// insert a character at cursor position
124 /// FIXME: replace Cursor with DocIterator.
125 void insertChar(Cursor & cur, char_type c);
126 /// insert an inset at cursor position
127 /// FIXME: replace Cursor with DocIterator.
128 void insertInset(Cursor & cur, Inset * inset);
130 /// try to handle that request
131 /// FIXME: replace Cursor with DocIterator.
132 void dispatch(Cursor & cur, FuncRequest & cmd);
133 /// do we want to handle this event?
134 bool getStatus(Cursor & cur, FuncRequest const & cmd,
135 FuncStatus & status) const;
137 /// read-only access to individual paragraph
138 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
139 /// read-write access to individual paragraph
140 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
141 // Returns the current font and depth as a message.
142 /// FIXME: replace Cursor with DocIterator.
143 docstring currentState(Cursor const & cur) const;
145 /** Find the word under \c from in the relative location
146 * defined by \c word_location.
147 * @param from return here the start of the word
148 * @param to return here the end of the word
150 void getWord(CursorSlice & from, CursorSlice & to, word_location const) const;
151 /// just selects the word the cursor is in
152 void selectWord(Cursor & cur, word_location loc);
154 void selectAll(Cursor & cur);
155 /// convenience function get the previous word or an empty string
156 docstring previousWord(CursorSlice const & sl) const;
158 /// what type of change operation to make
163 /// accept or reject the selected change
164 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
165 /// accept the changes within the complete Text
166 void acceptChanges();
167 /// reject the changes within the complete Text
168 void rejectChanges();
170 /// returns true if par was empty and was removed
171 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
172 bool setfont = true, bool boundary = false);
174 void setCursor(CursorSlice &, pit_type par, pos_type pos);
176 void setCursorIntern(Cursor & cur, pit_type par,
177 pos_type pos, bool setfont = true, bool boundary = false);
180 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
182 void recUndo(Cursor & cur, pit_type first) const;
184 /// Move cursor one position backwards
186 * Returns true if an update is needed after the move.
188 bool cursorBackward(Cursor & cur);
189 /// Move cursor visually one position to the left
191 * \param skip_inset if true, don't enter insets
192 * Returns true if an update is needed after the move.
194 bool cursorVisLeft(Cursor & cur, bool skip_inset = false);
195 /// Move cursor one position forward
197 * Returns true if an update is needed after the move.
199 bool cursorForward(Cursor & cur);
200 /// Move cursor visually one position to the right
202 * \param skip_inset if true, don't enter insets
203 * Returns true if an update is needed after the move.
205 bool cursorVisRight(Cursor & cur, bool skip_inset = false);
207 bool cursorBackwardOneWord(Cursor & cur);
209 bool cursorForwardOneWord(Cursor & cur);
211 bool cursorVisLeftOneWord(Cursor & cur);
213 bool cursorVisRightOneWord(Cursor & cur);
214 /// Delete from cursor up to the end of the current or next word.
215 void deleteWordForward(Cursor & cur);
216 /// Delete from cursor to start of current or prior word.
217 void deleteWordBackward(Cursor & cur);
219 bool cursorUpParagraph(Cursor & cur);
221 bool cursorDownParagraph(Cursor & cur);
223 bool cursorTop(Cursor & cur);
225 bool cursorBottom(Cursor & cur);
226 /// Erase character at cursor. Honour change tracking
227 /// FIXME: replace Cursor with DocIterator.
228 bool erase(Cursor & cur);
229 /// Delete character before cursor. Honour CT
230 /// FIXME: replace Cursor with DocIterator.
231 bool backspace(Cursor & cur);
232 // Dissolve the inset under cursor
233 /// FIXME: replace Cursor with DocIterator.
234 bool dissolveInset(Cursor & cur);
236 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
237 /// Change the case of the word at cursor position.
238 void changeCase(Cursor & cur, TextCase action);
239 /// Transposes the character at the cursor with the one before it
240 void charsTranspose(Cursor & cur);
242 /** the DTP switches for paragraphs. LyX will store the top settings
243 always in the first physical paragraph, the bottom settings in the
244 last. When a paragraph is broken, the top settings rest, the bottom
245 settings are given to the new one.
246 This function will handle a multi-paragraph selection.
248 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
249 /// Sets parameters for current or selected paragraphs
250 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
252 /* these things are for search and replace */
254 /// needed to insert the selection
255 /// FIXME: replace Cursor with DocIterator.
256 void insertStringAsLines(Cursor & cur, docstring const & str);
257 /// needed to insert the selection
258 /// FIXME: replace Cursor with DocIterator.
259 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
261 /// access to our paragraphs
262 ParagraphList const & paragraphs() const { return pars_; }
263 ParagraphList & paragraphs() { return pars_; }
264 /// return true if this is the main text
265 bool isMainText() const;
268 double spacing(Paragraph const & par) const;
269 /// make a suggestion for a label
270 /// FIXME: replace Cursor with DocIterator.
271 docstring getPossibleLabel(Cursor const & cur) const;
272 /// is this paragraph right-to-left?
273 bool isRTL(Paragraph const & par) const;
276 bool checkAndActivateInset(Cursor & cur, bool front);
278 bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft);
281 void write(std::ostream & os) const;
282 /// returns true if \end_document has not been read
283 /// insetPtr is the containing Inset
284 bool read(Lexer & lex, ErrorList & errorList,
285 InsetText * insetPtr);
287 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
288 /// \retval true if a change has happened and we need a redraw.
289 /// FIXME: replace Cursor with DocIterator. This is not possible right
290 /// now because recordUndo() is called which needs a Cursor.
291 static bool deleteEmptyParagraphMechanism(Cursor & cur,
292 Cursor & old, bool & need_anchor_change);
294 /// delete double spaces, leading spaces, and empty paragraphs
295 /// from \first to \last paragraph
296 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
298 /// To resolve macros properly the texts get their DocIterator.
299 /// Every macro definition is stored with its DocIterator
300 /// as well. Only those macros with a smaller iterator become
301 /// visible in a paragraph.
302 DocIterator macrocontextPosition() const;
304 void setMacrocontextPosition(DocIterator const & pos);
307 bool completionSupported(Cursor const & cur) const;
309 CompletionList const * createCompletionList(Cursor const & cur) const;
311 bool insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/);
313 docstring completionPrefix(Cursor const & cur) const;
322 /// return past-the-last paragraph influenced by a layout
324 pit_type undoSpan(pit_type pit);
326 // fix the cursor `cur' after a characters has been deleted at `where'
327 // position. Called by deleteEmptyParagraphMechanism
328 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
330 // At cursor position 0, try to merge the paragraph with the one before it.
331 // Ignore change tracking, i.e., physically remove the end-of-par character
332 bool backspacePos0(Cursor & cur);
333 /// handle the case where bibitems were deleted
334 bool handleBibitems(Cursor & cur);
335 /// are we in a list item (description etc.)?
336 bool inDescriptionItem(Cursor & cur) const;
338 void charInserted(Cursor & cur);
339 /// set 'number' font property
340 void number(Cursor & cur);
342 /// paste plain text at current cursor.
343 /// \param str string to paste
344 /// \param asParagraphs whether to paste as paragraphs or as lines
345 void pasteString(Cursor & cur, docstring const & str,
348 void readParToken(Paragraph & par, Lexer & lex, std::string const & token,
349 Font & font, Change & change, ErrorList & errorList);
351 void readParagraph(Paragraph & par, Lexer & lex, ErrorList & errorList);
356 /// position of the text in the buffer.
357 DocIterator macrocontext_position_;