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 visually one position to the left
174 * \param skip_inset if true, don't enter insets
175 * Returns true if an update is needed after the move.
177 bool cursorVisLeft(Cursor & cur, bool skip_inset = false);
178 /// Move cursor one position forward
180 * Returns true if an update is needed after the move.
182 bool cursorForward(Cursor & cur);
183 /// Move cursor visually one position to the right
185 * \param skip_inset if true, don't enter insets
186 * Returns true if an update is needed after the move.
188 bool cursorVisRight(Cursor & cur, bool skip_inset = false);
190 bool cursorBackwardOneWord(Cursor & cur);
192 bool cursorForwardOneWord(Cursor & cur);
193 /// Delete from cursor up to the end of the current or next word.
194 void deleteWordForward(Cursor & cur);
195 /// Delete from cursor to start of current or prior word.
196 void deleteWordBackward(Cursor & cur);
198 bool cursorUpParagraph(Cursor & cur);
200 bool cursorDownParagraph(Cursor & cur);
202 bool cursorTop(Cursor & cur);
204 bool cursorBottom(Cursor & cur);
205 /// Erase character at cursor. Honour change tracking
206 /// FIXME: replace Cursor with DocIterator.
207 bool erase(Cursor & cur);
208 /// Delete character before cursor. Honour CT
209 /// FIXME: replace Cursor with DocIterator.
210 bool backspace(Cursor & cur);
211 // Dissolve the inset under cursor
212 /// FIXME: replace Cursor with DocIterator.
213 bool dissolveInset(Cursor & cur);
215 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
216 /// Change the case of the word at cursor position.
217 void changeCase(Cursor & cur, TextCase action);
218 /// Transposes the character at the cursor with the one before it
219 void charsTranspose(Cursor & cur);
221 /** the DTP switches for paragraphs. LyX will store the top settings
222 always in the first physical paragraph, the bottom settings in the
223 last. When a paragraph is broken, the top settings rest, the bottom
224 settings are given to the new one.
225 This function will handle a multi-paragraph selection.
227 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
228 /// Sets parameters for current or selected paragraphs
229 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
231 /* these things are for search and replace */
233 /// needed to insert the selection
234 /// FIXME: replace Cursor with DocIterator.
235 void insertStringAsLines(Cursor & cur, docstring const & str);
236 /// needed to insert the selection
237 /// FIXME: replace Cursor with DocIterator.
238 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
240 /// access to our paragraphs
241 ParagraphList const & paragraphs() const { return pars_; }
242 ParagraphList & paragraphs() { return pars_; }
243 /// return true if this is the main text
244 bool isMainText(Buffer const &) const;
247 double spacing(Buffer const & buffer, Paragraph const & par) const;
248 /// make a suggestion for a label
249 /// FIXME: replace Cursor with DocIterator.
250 docstring getPossibleLabel(Cursor & cur) const;
251 /// is this paragraph right-to-left?
252 bool isRTL(Buffer const &, Paragraph const & par) const;
255 bool checkAndActivateInset(Cursor & cur, bool front);
257 bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft);
260 void write(Buffer const & buf, std::ostream & os) const;
261 /// returns whether we've seen our usual 'end' marker
262 /// insetPtr is the containing Inset
263 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList,
264 InsetText * insetPtr);
266 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
267 /// \retval true if a change has happened and we need a redraw.
268 /// FIXME: replace Cursor with DocIterator. This is not possible right
269 /// now because recordUndo() is called which needs a Cursor.
270 static bool deleteEmptyParagraphMechanism(Cursor & cur,
271 Cursor & old, bool & need_anchor_change);
273 /// delete double spaces, leading spaces, and empty paragraphs
274 /// from \first to \last paragraph
275 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
277 /// To resolve macros properly the texts get their DocIterator.
278 /// Every macro definition is stored with its DocIterator
279 /// as well. Only those macros with a smaller iterator become
280 /// visible in a paragraph.
281 DocIterator macrocontextPosition() const;
283 void setMacrocontextPosition(DocIterator const & pos);
292 /// return past-the-last paragraph influenced by a layout
294 pit_type undoSpan(pit_type pit);
296 // fix the cursor `cur' after a characters has been deleted at `where'
297 // position. Called by deleteEmptyParagraphMechanism
298 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
300 // At cursor position 0, try to merge the paragraph with the one before it.
301 // Ignore change tracking, i.e., physically remove the end-of-par character
302 bool backspacePos0(Cursor & cur);
303 /// handle the case where bibitems were deleted
304 bool handleBibitems(Cursor & cur);
306 void charInserted(Cursor & cur);
307 /// set 'number' font property
308 void number(Cursor & cur);
310 /// paste plain text at current cursor.
311 /// \param str string to paste
312 /// \param asParagraphs whether to paste as paragraphs or as lines
313 void pasteString(Cursor & cur, docstring const & str,
316 /// position of the text in the buffer.
317 DocIterator macrocontext_position_;