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"
39 /// This class encapsulates the main text data and operations in LyX
45 /// \return true if there's no content at all.
46 /// \warning a non standard layout on an empty paragraph doesn't
51 FontInfo getLayoutFont(Buffer const & buffer, pit_type pit) const;
53 FontInfo getLabelFont(Buffer const & buffer,
54 Paragraph const & par) const;
55 /** Set font of character at position \p pos in paragraph \p pit.
56 * Must not be called if \p pos denotes an inset with text contents,
57 * and the inset is not allowed inside a font change (see below).
59 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
60 Font const & font, Font const & display_font);
62 /** Needed to propagate font changes to all text cells of insets
63 * that are not allowed inside a font change (bug 1973).
64 * Must not be called if \p pos denotes an ordinary character or an
65 * inset that is alowed inside a font change.
66 * FIXME: This should be removed, see documentation of noFontChange
69 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
70 Font const & font, bool toggleall = false);
72 /// what you expect when pressing \<enter\> at cursor position
73 void breakParagraph(Cursor & cur, bool inverse_logic = false);
75 /// set layout over selection
76 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
77 docstring const & layout);
78 /// Set given layout to current cursor position.
79 /// FIXME: replace Cursor with DocIterator.
80 void setLayout(Cursor & cur, docstring const & layout);
82 /// what type of depth change to make
87 /// Increase or decrease the nesting depth of the selected paragraph(s)
88 /// FIXME: replace Cursor with DocIterator.
89 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
91 /// Returns whether something would be changed by changeDepth
92 /// FIXME: replace Cursor with DocIterator.
93 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
95 /// Set font over selection paragraphs and rebreak.
96 /// FIXME: replace Cursor with DocIterator.
97 void setFont(Cursor & cur, Font const &, bool toggleall = false);
98 /// Set font from \p begin to \p end and rebreak.
99 void setFont(BufferView const & bv, CursorSlice const & begin,
100 CursorSlice const & end, Font const &,
101 bool toggleall = false);
104 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
107 /// FIXME: replace Cursor with DocIterator.
108 docstring getStringToIndex(Cursor const & cur);
110 /// insert a character at cursor position
111 /// FIXME: replace Cursor with DocIterator.
112 void insertChar(Cursor & cur, char_type c);
113 /// insert an inset at cursor position
114 /// FIXME: replace Cursor with DocIterator.
115 void insertInset(Cursor & cur, Inset * inset);
117 /// try to handle that request
118 /// FIXME: replace Cursor with DocIterator.
119 void dispatch(Cursor & cur, FuncRequest & cmd);
120 /// do we want to handle this event?
121 bool getStatus(Cursor & cur, FuncRequest const & cmd,
122 FuncStatus & status) const;
124 /// read-only access to individual paragraph
125 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
126 /// read-write access to individual paragraph
127 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
128 // Returns the current font and depth as a message.
129 /// FIXME: replace Cursor with DocIterator.
130 docstring currentState(Cursor & cur);
132 /** Find the word under \c from in the relative location
133 * defined by \c word_location.
134 * @param from return here the start of the word
135 * @param to return here the end of the word
137 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
138 /// just selects the word the cursor is in
139 void selectWord(Cursor & cur, word_location loc);
141 /// what type of change operation to make
146 /// accept or reject the selected change
147 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
148 /// accept the changes within the complete Text
149 void acceptChanges(BufferParams const & bparams);
150 /// reject the changes within the complete Text
151 void rejectChanges(BufferParams const & bparams);
153 /// returns true if par was empty and was removed
154 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
155 bool setfont = true, bool boundary = false);
157 void setCursor(CursorSlice &, pit_type par, pos_type pos);
159 void setCursorIntern(Cursor & cur, pit_type par,
160 pos_type pos, bool setfont = true, bool boundary = false);
163 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
165 void recUndo(Cursor & cur, pit_type first) const;
167 /// Move cursor one position backwards
169 * Returns true if an update is needed after the move.
171 bool cursorBackward(Cursor & cur);
172 /// Move cursor one position forward
174 * Returns true if an update is needed after the move.
176 bool cursorForward(Cursor & cur);
178 bool cursorBackwardOneWord(Cursor & cur);
180 bool cursorForwardOneWord(Cursor & cur);
181 /// Delete from cursor up to the end of the current or next word.
182 void deleteWordForward(Cursor & cur);
183 /// Delete from cursor to start of current or prior word.
184 void deleteWordBackward(Cursor & cur);
186 bool cursorUpParagraph(Cursor & cur);
188 bool cursorDownParagraph(Cursor & cur);
190 bool cursorTop(Cursor & cur);
192 bool cursorBottom(Cursor & cur);
193 /// Erase character at cursor. Honour change tracking
194 /// FIXME: replace Cursor with DocIterator.
195 bool erase(Cursor & cur);
196 /// Delete character before cursor. Honour CT
197 /// FIXME: replace Cursor with DocIterator.
198 bool backspace(Cursor & cur);
199 // Dissolve the inset under cursor
200 /// FIXME: replace Cursor with DocIterator.
201 bool dissolveInset(Cursor & cur);
203 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
204 /// Change the case of the word at cursor position.
205 void changeCase(Cursor & cur, TextCase action);
206 /// Transposes the character at the cursor with the one before it
207 void charsTranspose(Cursor & cur);
209 /** the DTP switches for paragraphs. LyX will store the top settings
210 always in the first physical paragraph, the bottom settings in the
211 last. When a paragraph is broken, the top settings rest, the bottom
212 settings are given to the new one.
213 This function will handle a multi-paragraph selection.
215 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
216 /// Sets parameters for current or selected paragraphs
217 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
219 /* these things are for search and replace */
221 /// needed to insert the selection
222 /// FIXME: replace Cursor with DocIterator.
223 void insertStringAsLines(Cursor & cur, docstring const & str);
224 /// needed to insert the selection
225 /// FIXME: replace Cursor with DocIterator.
226 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
228 /// access to our paragraphs
229 ParagraphList const & paragraphs() const { return pars_; }
230 ParagraphList & paragraphs() { return pars_; }
231 /// return true if this is the main text
232 bool isMainText(Buffer const &) const;
235 double spacing(Buffer const & buffer, Paragraph const & par) const;
236 /// make a suggestion for a label
237 /// FIXME: replace Cursor with DocIterator.
238 docstring getPossibleLabel(Cursor & cur) const;
239 /// is this paragraph right-to-left?
240 bool isRTL(Buffer const &, Paragraph const & par) const;
243 bool checkAndActivateInset(Cursor & cur, bool front);
246 void write(Buffer const & buf, std::ostream & os) const;
247 /// returns whether we've seen our usual 'end' marker
248 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
250 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
251 /// \retval true if a change has happened and we need a redraw.
252 /// FIXME: replace Cursor with DocIterator. This is not possible right
253 /// now because recordUndo() is called which needs a Cursor.
254 static bool deleteEmptyParagraphMechanism(Cursor & cur,
255 Cursor & old, bool & need_anchor_change);
257 /// delete double spaces, leading spaces, and empty paragraphs
258 /// from \first to \last paragraph
259 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
261 /// To resolve macros properly the texts get their DocIterator.
262 /// Every macro definition is stored with its DocIterator
263 /// as well. Only those macros with a smaller iterator become
264 /// visible in a paragraph.
265 DocIterator macrocontextPosition() const;
267 void setMacrocontextPosition(DocIterator const & pos);
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);
290 void charInserted(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,
300 /// position of the text in the buffer.
301 DocIterator macrocontext_position_;