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 backwards
168 * Returns true if an update is needed after the move.
170 bool cursorBackward(Cursor & cur);
171 /// Move cursor one position forward
173 * Returns true if an update is needed after the move.
175 bool cursorForward(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);
203 /// Change the case of the word at cursor position.
204 void changeCase(Cursor & cur, TextCase action);
205 /// Transposes the character at the cursor with the one before it
206 void charsTranspose(Cursor & cur);
208 /** the DTP switches for paragraphs. LyX will store the top settings
209 always in the first physical paragraph, the bottom settings in the
210 last. When a paragraph is broken, the top settings rest, the bottom
211 settings are given to the new one.
212 This function will handle a multi-paragraph selection.
214 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
215 /// Sets parameters for current or selected paragraphs
216 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
218 /* these things are for search and replace */
220 /// needed to insert the selection
221 /// FIXME: replace Cursor with DocIterator.
222 void insertStringAsLines(Cursor & cur, docstring const & str);
223 /// needed to insert the selection
224 /// FIXME: replace Cursor with DocIterator.
225 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
227 /// access to our paragraphs
228 ParagraphList const & paragraphs() const { return pars_; }
229 ParagraphList & paragraphs() { return pars_; }
230 /// return true if this is the main text
231 bool isMainText(Buffer const &) const;
234 double spacing(Buffer const & buffer, Paragraph const & par) const;
235 /// make a suggestion for a label
236 /// FIXME: replace Cursor with DocIterator.
237 docstring getPossibleLabel(Cursor & cur) const;
238 /// is this paragraph right-to-left?
239 bool isRTL(Buffer const &, Paragraph const & par) const;
242 bool checkAndActivateInset(Cursor & cur, bool front);
245 void write(Buffer const & buf, std::ostream & os) const;
246 /// returns whether we've seen our usual 'end' marker
247 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
249 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
250 /// \retval true if a change has happened and we need a redraw.
251 /// FIXME: replace Cursor with DocIterator. This is not possible right
252 /// now because recordUndo() is called which needs a Cursor.
253 static bool deleteEmptyParagraphMechanism(Cursor & cur,
254 Cursor & old, bool & need_anchor_change);
256 /// delete double spaces, leading spaces, and empty paragraphs
257 /// from \first to \last paragraph
258 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
267 /// return past-the-last paragraph influenced by a layout
269 pit_type undoSpan(pit_type pit);
271 // fix the cursor `cur' after a characters has been deleted at `where'
272 // position. Called by deleteEmptyParagraphMechanism
273 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
275 // At cursor position 0, try to merge the paragraph with the one before it.
276 // Ignore change tracking, i.e., physically remove the end-of-par character
277 bool backspacePos0(Cursor & cur);
278 /// handle the case where bibitems were deleted
279 bool handleBibitems(Cursor & cur);
281 void charInserted(Cursor & cur);
282 /// set 'number' font property
283 void number(Cursor & cur);
285 /// paste plain text at current cursor.
286 /// \param str string to paste
287 /// \param asParagraphs whether to paste as paragraphs or as lines
288 void pasteString(Cursor & cur, docstring const & str,