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 keep_layout = 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 left
167 * Returns true if an update is needed after the move.
169 bool cursorLeft(Cursor & cur);
170 /// Move cursor one position right
172 * Returns true if an update is needed after the move.
174 bool cursorRight(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);
207 text_capitalization = 1,
211 /// Change the case of the word at cursor position.
212 void changeCase(Cursor & cur, TextCase action);
213 /// Transposes the character at the cursor with the one before it
214 void charsTranspose(Cursor & cur);
216 /** the DTP switches for paragraphs. LyX will store the top settings
217 always in the first physical paragraph, the bottom settings in the
218 last. When a paragraph is broken, the top settings rest, the bottom
219 settings are given to the new one.
220 This function will handle a multi-paragraph selection.
222 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
223 /// Sets parameters for current or selected paragraphs
224 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
226 /* these things are for search and replace */
228 /// needed to insert the selection
229 /// FIXME: replace Cursor with DocIterator.
230 void insertStringAsLines(Cursor & cur, docstring const & str);
231 /// needed to insert the selection
232 /// FIXME: replace Cursor with DocIterator.
233 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
235 /// access to our paragraphs
236 ParagraphList const & paragraphs() const { return pars_; }
237 ParagraphList & paragraphs() { return pars_; }
238 /// return true if this is the main text
239 bool isMainText(Buffer const &) const;
242 double spacing(Buffer const & buffer, Paragraph const & par) const;
243 /// make a suggestion for a label
244 /// FIXME: replace Cursor with DocIterator.
245 docstring getPossibleLabel(Cursor & cur) const;
246 /// is this paragraph right-to-left?
247 bool isRTL(Buffer const &, Paragraph const & par) const;
250 bool checkAndActivateInset(Cursor & cur, bool front);
253 void write(Buffer const & buf, std::ostream & os) const;
254 /// returns whether we've seen our usual 'end' marker
255 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
257 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
258 /// \retval true if a change has happened and we need a redraw.
259 /// FIXME: replace Cursor with DocIterator. This is not possible right
260 /// now because recordUndo() is called which needs a Cursor.
261 static bool deleteEmptyParagraphMechanism(Cursor & cur,
262 Cursor & old, bool & need_anchor_change);
264 /// delete double spaces, leading spaces, and empty paragraphs
265 /// from \first to \last paragraph
266 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
275 /// return past-the-last paragraph influenced by a layout
277 pit_type undoSpan(pit_type pit);
279 // fix the cursor `cur' after a characters has been deleted at `where'
280 // position. Called by deleteEmptyParagraphMechanism
281 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
283 // At cursor position 0, try to merge the paragraph with the one before it.
284 // Ignore change tracking, i.e., physically remove the end-of-par character
285 bool backspacePos0(Cursor & cur);
286 /// handle the case where bibitems were deleted
287 bool handleBibitems(Cursor & cur);
290 /// set 'number' font property
291 void number(Cursor & cur);
293 /// paste plain text at current cursor.
294 /// \param str string to paste
295 /// \param asParagraphs whether to paste as paragraphs or as lines
296 void pasteString(Cursor & cur, docstring const & str,