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 "ParagraphList.h"
38 /// This class encapsulates the main text data and operations in LyX
44 /// \return true if there's no content at all.
45 /// \warning a non standard layout on an empty paragraph doesn't
50 Font getLayoutFont(Buffer const & buffer, pit_type pit) const;
52 Font getLabelFont(Buffer const & buffer,
53 Paragraph const & par) const;
54 /** Set font of character at position \p pos in paragraph \p pit.
55 * Must not be called if \p pos denotes an inset with text contents,
56 * and the inset is not allowed inside a font change (see below).
58 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
59 Font const & font, Font const & display_font);
61 /** Needed to propagate font changes to all text cells of insets
62 * that are not allowed inside a font change (bug 1973).
63 * Must not be called if \p pos denotes an ordinary character or an
64 * inset that is alowed inside a font change.
65 * FIXME: This should be removed, see documentation of noFontChange
68 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
69 Font const & font, bool toggleall = false);
71 /// what you expect when pressing \<enter\> at cursor position
72 void breakParagraph(Cursor & cur, bool inverse_logic = false);
74 /// set layout over selection
75 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
76 docstring const & layout);
77 /// Set given layout to current cursor position.
78 /// FIXME: replace Cursor with DocIterator.
79 void setLayout(Cursor & cur, docstring const & layout);
81 /// what type of depth change to make
86 /// Increase or decrease the nesting depth of the selected paragraph(s)
87 /// FIXME: replace Cursor with DocIterator.
88 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
90 /// Returns whether something would be changed by changeDepth
91 /// FIXME: replace Cursor with DocIterator.
92 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
94 /// Set font over selection paragraphs and rebreak.
95 /// FIXME: replace Cursor with DocIterator.
96 void setFont(Cursor & cur, Font const &, bool toggleall = false);
97 /// Set font from \p begin to \p end and rebreak.
98 void setFont(BufferView const & bv, CursorSlice const & begin,
99 CursorSlice const & end, Font const &,
100 bool toggleall = false);
103 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
106 /// FIXME: replace Cursor with DocIterator.
107 docstring getStringToIndex(Cursor const & cur);
109 /// insert a character at cursor position
110 /// FIXME: replace Cursor with DocIterator.
111 void insertChar(Cursor & cur, char_type c);
112 /// insert an inset at cursor position
113 /// FIXME: replace Cursor with DocIterator.
114 void insertInset(Cursor & cur, Inset * inset);
116 /// try to handle that request
117 /// FIXME: replace Cursor with DocIterator.
118 void dispatch(Cursor & cur, FuncRequest & cmd);
119 /// do we want to handle this event?
120 bool getStatus(Cursor & cur, FuncRequest const & cmd,
121 FuncStatus & status) const;
123 /// read-only access to individual paragraph
124 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
125 /// read-write access to individual paragraph
126 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
127 // Returns the current font and depth as a message.
128 /// FIXME: replace Cursor with DocIterator.
129 docstring currentState(Cursor & cur);
131 /** Find the word under \c from in the relative location
132 * defined by \c word_location.
133 * @param from return here the start of the word
134 * @param to return here the end of the word
136 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
137 /// just selects the word the cursor is in
138 void selectWord(Cursor & cur, word_location loc);
140 /// what type of change operation to make
145 /// accept or reject the selected change
146 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
147 /// accept the changes within the complete Text
148 void acceptChanges(BufferParams const & bparams);
149 /// reject the changes within the complete Text
150 void rejectChanges(BufferParams const & bparams);
152 /// returns true if par was empty and was removed
153 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
154 bool setfont = true, bool boundary = false);
156 void setCursor(CursorSlice &, pit_type par, pos_type pos);
158 void setCursorIntern(Cursor & cur, pit_type par,
159 pos_type pos, bool setfont = true, bool boundary = false);
162 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
164 void recUndo(Cursor & cur, pit_type first) const;
166 /// Move cursor one position left
168 * Returns true if an update is needed after the move.
170 bool cursorLeft(Cursor & cur);
171 /// Move cursor one position right
173 * Returns true if an update is needed after the move.
175 bool cursorRight(Cursor & cur);
177 bool cursorLeftOneWord(Cursor & cur);
179 bool cursorRightOneWord(Cursor & cur);
180 /// Delete from cursor up to the end of the current or next word.
181 void deleteWordForward(Cursor & cur);
182 /// Delete from cursor to start of current or prior word.
183 void deleteWordBackward(Cursor & cur);
185 bool cursorUpParagraph(Cursor & cur);
187 bool cursorDownParagraph(Cursor & cur);
189 bool cursorTop(Cursor & cur);
191 bool cursorBottom(Cursor & cur);
192 /// Erase character at cursor. Honour change tracking
193 /// FIXME: replace Cursor with DocIterator.
194 bool erase(Cursor & cur);
195 /// Delete character before cursor. Honour CT
196 /// FIXME: replace Cursor with DocIterator.
197 bool backspace(Cursor & cur);
198 // Dissolve the inset under cursor
199 /// FIXME: replace Cursor with DocIterator.
200 bool dissolveInset(Cursor & cur);
202 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
208 text_capitalization = 1,
212 /// Change the case of the word at cursor position.
213 void changeCase(Cursor & cur, TextCase action);
214 /// Transposes the character at the cursor with the one before it
215 void charsTranspose(Cursor & cur);
217 /** the DTP switches for paragraphs. LyX will store the top settings
218 always in the first physical paragraph, the bottom settings in the
219 last. When a paragraph is broken, the top settings rest, the bottom
220 settings are given to the new one.
221 This function will handle a multi-paragraph selection.
223 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
224 /// Sets parameters for current or selected paragraphs
225 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
227 /* these things are for search and replace */
229 /// needed to insert the selection
230 /// FIXME: replace Cursor with DocIterator.
231 void insertStringAsLines(Cursor & cur, docstring const & str);
232 /// needed to insert the selection
233 /// FIXME: replace Cursor with DocIterator.
234 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
236 /// access to our paragraphs
237 ParagraphList const & paragraphs() const { return pars_; }
238 ParagraphList & paragraphs() { return pars_; }
239 /// return true if this is the main text
240 bool isMainText(Buffer const &) const;
243 double spacing(Buffer const & buffer, Paragraph const & par) const;
244 /// make a suggestion for a label
245 /// FIXME: replace Cursor with DocIterator.
246 docstring getPossibleLabel(Cursor & cur) const;
247 /// is this paragraph right-to-left?
248 bool isRTL(Buffer const &, Paragraph const & par) const;
251 bool checkAndActivateInset(Cursor & cur, bool front);
254 void write(Buffer const & buf, std::ostream & os) const;
255 /// returns whether we've seen our usual 'end' marker
256 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
258 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
259 /// \retval true if a change has happened and we need a redraw.
260 /// FIXME: replace Cursor with DocIterator. This is not possible right
261 /// now because recordUndo() is called which needs a Cursor.
262 static bool deleteEmptyParagraphMechanism(Cursor & cur,
263 Cursor & old, bool & need_anchor_change);
265 /// delete double spaces, leading spaces, and empty paragraphs
266 /// from \first to \last paragraph
267 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
276 /// return past-the-last paragraph influenced by a layout
278 pit_type undoSpan(pit_type pit);
280 // fix the cursor `cur' after a characters has been deleted at `where'
281 // position. Called by deleteEmptyParagraphMechanism
282 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
284 // At cursor position 0, try to merge the paragraph with the one before it.
285 // Ignore change tracking, i.e., physically remove the end-of-par character
286 bool backspacePos0(Cursor & cur);
287 /// handle the case where bibitems were deleted
288 bool handleBibitems(Cursor & cur);
291 /// set 'number' font property
292 void number(Cursor & cur);
294 /// paste plain text at current cursor.
295 /// \param str string to paste
296 /// \param asParagraphs whether to paste as paragraphs or as lines
297 void pasteString(Cursor & cur, docstring const & str,