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"
37 /// This class encapsulates the main text data and operations in LyX
43 /// \return true if there's no content at all.
44 /// \warning a non standard layout on an empty paragraph doesn't
49 Font getLayoutFont(Buffer const & buffer, pit_type pit) const;
51 Font getLabelFont(Buffer const & buffer,
52 Paragraph const & par) const;
53 /** Set font of character at position \p pos in paragraph \p pit.
54 * Must not be called if \p pos denotes an inset with text contents,
55 * and the inset is not allowed inside a font change (see below).
57 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
58 Font const & font, Font const & display_font);
60 /** Needed to propagate font changes to all text cells of insets
61 * that are not allowed inside a font change (bug 1973).
62 * Must not be called if \p pos denotes an ordinary character or an
63 * inset that is alowed inside a font change.
64 * FIXME: This should be removed, see documentation of noFontChange
67 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
68 Font const & font, bool toggleall = false);
70 /// what you expect when pressing \<enter\> at cursor position
71 void breakParagraph(Cursor & cur, bool inverse_logic = false);
73 /// set layout over selection
74 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
75 docstring const & layout);
76 /// Set given layout to current cursor position.
77 /// FIXME: replace Cursor with DocIterator.
78 void setLayout(Cursor & cur, docstring const & layout);
80 /// what type of depth change to make
85 /// Increase or decrease the nesting depth of the selected paragraph(s)
86 /// FIXME: replace Cursor with DocIterator.
87 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
89 /// Returns whether something would be changed by changeDepth
90 /// FIXME: replace Cursor with DocIterator.
91 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
93 /// Set font over selection paragraphs and rebreak.
94 /// FIXME: replace Cursor with DocIterator.
95 void setFont(Cursor & cur, Font const &, bool toggleall = false);
96 /// Set font from \p begin to \p end and rebreak.
97 void setFont(BufferView const & bv, CursorSlice const & begin,
98 CursorSlice const & end, Font const &,
99 bool toggleall = false);
102 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
105 /// FIXME: replace Cursor with DocIterator.
106 docstring getStringToIndex(Cursor const & cur);
108 /// insert a character at cursor position
109 /// FIXME: replace Cursor with DocIterator.
110 void insertChar(Cursor & cur, char_type c);
111 /// insert an inset at cursor position
112 /// FIXME: replace Cursor with DocIterator.
113 void insertInset(Cursor & cur, Inset * inset);
115 /// try to handle that request
116 /// FIXME: replace Cursor with DocIterator.
117 void dispatch(Cursor & cur, FuncRequest & cmd);
118 /// do we want to handle this event?
119 bool getStatus(Cursor & cur, FuncRequest const & cmd,
120 FuncStatus & status) const;
122 /// read-only access to individual paragraph
123 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
124 /// read-write access to individual paragraph
125 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
126 // Returns the current font and depth as a message.
127 /// FIXME: replace Cursor with DocIterator.
128 docstring currentState(Cursor & cur);
130 /** Find the word under \c from in the relative location
131 * defined by \c word_location.
132 * @param from return here the start of the word
133 * @param to return here the end of the word
135 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
136 /// just selects the word the cursor is in
137 void selectWord(Cursor & cur, word_location loc);
139 /// what type of change operation to make
144 /// accept or reject the selected change
145 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
146 /// accept the changes within the complete Text
147 void acceptChanges(BufferParams const & bparams);
148 /// reject the changes within the complete Text
149 void rejectChanges(BufferParams const & bparams);
151 /// returns true if par was empty and was removed
152 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
153 bool setfont = true, bool boundary = false);
155 void setCursor(CursorSlice &, pit_type par, pos_type pos);
157 void setCursorIntern(Cursor & cur, pit_type par,
158 pos_type pos, bool setfont = true, bool boundary = false);
161 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
163 void recUndo(Cursor & cur, pit_type first) const;
165 /// Move cursor one position backwards
167 * Returns true if an update is needed after the move.
169 bool cursorBackward(Cursor & cur);
170 /// Move cursor one position forward
172 * Returns true if an update is needed after the move.
174 bool cursorForward(Cursor & cur);
176 bool cursorLeftOneWord(Cursor & cur);
178 bool cursorRightOneWord(Cursor & cur);
179 /// Delete from cursor up to the end of the current or next word.
180 void deleteWordForward(Cursor & cur);
181 /// Delete from cursor to start of current or prior word.
182 void deleteWordBackward(Cursor & cur);
184 bool cursorUpParagraph(Cursor & cur);
186 bool cursorDownParagraph(Cursor & cur);
188 bool cursorTop(Cursor & cur);
190 bool cursorBottom(Cursor & cur);
191 /// Erase character at cursor. Honour change tracking
192 /// FIXME: replace Cursor with DocIterator.
193 bool erase(Cursor & cur);
194 /// Delete character before cursor. Honour CT
195 /// FIXME: replace Cursor with DocIterator.
196 bool backspace(Cursor & cur);
197 // Dissolve the inset under cursor
198 /// FIXME: replace Cursor with DocIterator.
199 bool dissolveInset(Cursor & cur);
201 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
202 /// Change the case of the word at cursor position.
203 void changeCase(Cursor & cur, TextCase action);
204 /// Transposes the character at the cursor with the one before it
205 void charsTranspose(Cursor & cur);
207 /** the DTP switches for paragraphs. LyX will store the top settings
208 always in the first physical paragraph, the bottom settings in the
209 last. When a paragraph is broken, the top settings rest, the bottom
210 settings are given to the new one.
211 This function will handle a multi-paragraph selection.
213 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
214 /// Sets parameters for current or selected paragraphs
215 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
217 /* these things are for search and replace */
219 /// needed to insert the selection
220 /// FIXME: replace Cursor with DocIterator.
221 void insertStringAsLines(Cursor & cur, docstring const & str);
222 /// needed to insert the selection
223 /// FIXME: replace Cursor with DocIterator.
224 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
226 /// access to our paragraphs
227 ParagraphList const & paragraphs() const { return pars_; }
228 ParagraphList & paragraphs() { return pars_; }
229 /// return true if this is the main text
230 bool isMainText(Buffer const &) const;
233 double spacing(Buffer const & buffer, Paragraph const & par) const;
234 /// make a suggestion for a label
235 /// FIXME: replace Cursor with DocIterator.
236 docstring getPossibleLabel(Cursor & cur) const;
237 /// is this paragraph right-to-left?
238 bool isRTL(Buffer const &, Paragraph const & par) const;
241 bool checkAndActivateInset(Cursor & cur, bool front);
244 void write(Buffer const & buf, std::ostream & os) const;
245 /// returns whether we've seen our usual 'end' marker
246 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
248 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
249 /// \retval true if a change has happened and we need a redraw.
250 /// FIXME: replace Cursor with DocIterator. This is not possible right
251 /// now because recordUndo() is called which needs a Cursor.
252 static bool deleteEmptyParagraphMechanism(Cursor & cur,
253 Cursor & old, bool & need_anchor_change);
255 /// delete double spaces, leading spaces, and empty paragraphs
256 /// from \first to \last paragraph
257 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
266 /// return past-the-last paragraph influenced by a layout
268 pit_type undoSpan(pit_type pit);
270 // fix the cursor `cur' after a characters has been deleted at `where'
271 // position. Called by deleteEmptyParagraphMechanism
272 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
274 // At cursor position 0, try to merge the paragraph with the one before it.
275 // Ignore change tracking, i.e., physically remove the end-of-par character
276 bool backspacePos0(Cursor & cur);
277 /// handle the case where bibitems were deleted
278 bool handleBibitems(Cursor & cur);
280 void charInserted(Cursor & cur);
281 /// set 'number' font property
282 void number(Cursor & cur);
284 /// paste plain text at current cursor.
285 /// \param str string to paste
286 /// \param asParagraphs whether to paste as paragraphs or as lines
287 void pasteString(Cursor & cur, docstring const & str,