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"
40 /// This class encapsulates the main text data and operations in LyX
46 /// \return true if there's no content at all.
47 /// \warning a non standard layout on an empty paragraph doesn't
52 FontInfo layoutFont(Buffer const & buffer, pit_type pit) const;
54 FontInfo labelFont(Buffer const & buffer,
55 Paragraph const & par) const;
56 /** Set font of character at position \p pos in paragraph \p pit.
57 * Must not be called if \p pos denotes an inset with text contents,
58 * and the inset is not allowed inside a font change (see below).
60 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
61 Font const & font, Font const & display_font);
63 /** Needed to propagate font changes to all text cells of insets
64 * that are not allowed inside a font change (bug 1973).
65 * Must not be called if \p pos denotes an ordinary character or an
66 * inset that is alowed inside a font change.
67 * FIXME: This should be removed, see documentation of noFontChange
70 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
71 Font const & font, bool toggleall = false);
73 /// what you expect when pressing \<enter\> at cursor position
74 void breakParagraph(Cursor & cur, bool inverse_logic = false);
76 /// set layout over selection
77 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
78 docstring const & layout);
79 /// Set given layout to current cursor position.
80 /// FIXME: replace Cursor with DocIterator.
81 void setLayout(Cursor & cur, docstring const & layout);
83 /// what type of depth change to make
88 /// Increase or decrease the nesting depth of the selected paragraph(s)
89 /// FIXME: replace Cursor with DocIterator.
90 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
92 /// Returns whether something would be changed by changeDepth
93 /// FIXME: replace Cursor with DocIterator.
94 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
96 /// Set font over selection paragraphs and rebreak.
97 /// FIXME: replace Cursor with DocIterator.
98 void setFont(Cursor & cur, Font const &, bool toggleall = false);
99 /// Set font from \p begin to \p end and rebreak.
100 void setFont(BufferView const & bv, CursorSlice const & begin,
101 CursorSlice const & end, Font const &,
102 bool toggleall = false);
105 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
108 /// FIXME: replace Cursor with DocIterator.
109 docstring getStringToIndex(Cursor const & cur);
111 /// Convert the paragraphs to a string.
112 /// \param AsStringParameter options. This can contain any combination of
113 /// asStringParameter values. Valid examples:
114 /// asString(AS_STR_LABEL)
115 /// asString(AS_STR_LABEL | AS_STR_INSETS)
116 /// asString(AS_STR_INSETS)
117 docstring asString(int options = AS_STR_NONE) const;
119 docstring asString(pit_type beg, pit_type end,
120 int options = AS_STR_NONE) const;
122 /// insert a character at cursor position
123 /// FIXME: replace Cursor with DocIterator.
124 void insertChar(Cursor & cur, char_type c);
125 /// insert an inset at cursor position
126 /// FIXME: replace Cursor with DocIterator.
127 void insertInset(Cursor & cur, Inset * inset);
129 /// try to handle that request
130 /// FIXME: replace Cursor with DocIterator.
131 void dispatch(Cursor & cur, FuncRequest & cmd);
132 /// do we want to handle this event?
133 bool getStatus(Cursor & cur, FuncRequest const & cmd,
134 FuncStatus & status) const;
136 /// read-only access to individual paragraph
137 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
138 /// read-write access to individual paragraph
139 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
140 // Returns the current font and depth as a message.
141 /// FIXME: replace Cursor with DocIterator.
142 docstring currentState(Cursor const & cur) const;
144 /** Find the word under \c from in the relative location
145 * defined by \c word_location.
146 * @param from return here the start of the word
147 * @param to return here the end of the word
149 void getWord(CursorSlice & from, CursorSlice & to, word_location const) const;
150 /// just selects the word the cursor is in
151 void selectWord(Cursor & cur, word_location loc);
152 /// convenience function get the previous word or an empty string
153 docstring previousWord(CursorSlice const & sl) const;
155 /// what type of change operation to make
160 /// accept or reject the selected change
161 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
162 /// accept the changes within the complete Text
163 void acceptChanges(BufferParams const & bparams);
164 /// reject the changes within the complete Text
165 void rejectChanges(BufferParams const & bparams);
167 /// returns true if par was empty and was removed
168 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
169 bool setfont = true, bool boundary = false);
171 void setCursor(CursorSlice &, pit_type par, pos_type pos);
173 void setCursorIntern(Cursor & cur, pit_type par,
174 pos_type pos, bool setfont = true, bool boundary = false);
177 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
179 void recUndo(Cursor & cur, pit_type first) const;
181 /// Move cursor one position backwards
183 * Returns true if an update is needed after the move.
185 bool cursorBackward(Cursor & cur);
186 /// Move cursor visually one position to the left
188 * \param skip_inset if true, don't enter insets
189 * Returns true if an update is needed after the move.
191 bool cursorVisLeft(Cursor & cur, bool skip_inset = false);
192 /// Move cursor one position forward
194 * Returns true if an update is needed after the move.
196 bool cursorForward(Cursor & cur);
197 /// Move cursor visually one position to the right
199 * \param skip_inset if true, don't enter insets
200 * Returns true if an update is needed after the move.
202 bool cursorVisRight(Cursor & cur, bool skip_inset = false);
204 bool cursorBackwardOneWord(Cursor & cur);
206 bool cursorForwardOneWord(Cursor & cur);
208 bool cursorVisLeftOneWord(Cursor & cur);
210 bool cursorVisRightOneWord(Cursor & cur);
211 /// Delete from cursor up to the end of the current or next word.
212 void deleteWordForward(Cursor & cur);
213 /// Delete from cursor to start of current or prior word.
214 void deleteWordBackward(Cursor & cur);
216 bool cursorUpParagraph(Cursor & cur);
218 bool cursorDownParagraph(Cursor & cur);
220 bool cursorTop(Cursor & cur);
222 bool cursorBottom(Cursor & cur);
223 /// Erase character at cursor. Honour change tracking
224 /// FIXME: replace Cursor with DocIterator.
225 bool erase(Cursor & cur);
226 /// Delete character before cursor. Honour CT
227 /// FIXME: replace Cursor with DocIterator.
228 bool backspace(Cursor & cur);
229 // Dissolve the inset under cursor
230 /// FIXME: replace Cursor with DocIterator.
231 bool dissolveInset(Cursor & cur);
233 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
234 /// Change the case of the word at cursor position.
235 void changeCase(Cursor & cur, TextCase action);
236 /// Transposes the character at the cursor with the one before it
237 void charsTranspose(Cursor & cur);
239 /** the DTP switches for paragraphs. LyX will store the top settings
240 always in the first physical paragraph, the bottom settings in the
241 last. When a paragraph is broken, the top settings rest, the bottom
242 settings are given to the new one.
243 This function will handle a multi-paragraph selection.
245 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
246 /// Sets parameters for current or selected paragraphs
247 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
249 /* these things are for search and replace */
251 /// needed to insert the selection
252 /// FIXME: replace Cursor with DocIterator.
253 void insertStringAsLines(Cursor & cur, docstring const & str);
254 /// needed to insert the selection
255 /// FIXME: replace Cursor with DocIterator.
256 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
258 /// access to our paragraphs
259 ParagraphList const & paragraphs() const { return pars_; }
260 ParagraphList & paragraphs() { return pars_; }
261 /// return true if this is the main text
262 bool isMainText(Buffer const &) const;
265 double spacing(Buffer const & buffer, Paragraph const & par) const;
266 /// make a suggestion for a label
267 /// FIXME: replace Cursor with DocIterator.
268 docstring getPossibleLabel(Cursor const & cur) const;
269 /// is this paragraph right-to-left?
270 bool isRTL(Buffer const &, Paragraph const & par) const;
273 bool checkAndActivateInset(Cursor & cur, bool front);
275 bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft);
278 void write(Buffer const & buf, std::ostream & os) const;
279 /// returns whether we've seen our usual 'end' marker
280 /// insetPtr is the containing Inset
281 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList,
282 InsetText * insetPtr);
284 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
285 /// \retval true if a change has happened and we need a redraw.
286 /// FIXME: replace Cursor with DocIterator. This is not possible right
287 /// now because recordUndo() is called which needs a Cursor.
288 static bool deleteEmptyParagraphMechanism(Cursor & cur,
289 Cursor & old, bool & need_anchor_change);
291 /// delete double spaces, leading spaces, and empty paragraphs
292 /// from \first to \last paragraph
293 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
295 /// To resolve macros properly the texts get their DocIterator.
296 /// Every macro definition is stored with its DocIterator
297 /// as well. Only those macros with a smaller iterator become
298 /// visible in a paragraph.
299 DocIterator macrocontextPosition() const;
301 void setMacrocontextPosition(DocIterator const & pos);
304 bool completionSupported(Cursor const & cur) const;
306 CompletionList const * createCompletionList(Cursor const & cur) const;
308 bool insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/);
310 docstring completionPrefix(Cursor const & cur) const;
319 /// return past-the-last paragraph influenced by a layout
321 pit_type undoSpan(pit_type pit);
323 // fix the cursor `cur' after a characters has been deleted at `where'
324 // position. Called by deleteEmptyParagraphMechanism
325 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
327 // At cursor position 0, try to merge the paragraph with the one before it.
328 // Ignore change tracking, i.e., physically remove the end-of-par character
329 bool backspacePos0(Cursor & cur);
330 /// handle the case where bibitems were deleted
331 bool handleBibitems(Cursor & cur);
332 /// are we in a list item (description etc.)?
333 bool inDescriptionItem(Cursor & cur) const;
335 void charInserted(Cursor & cur);
336 /// set 'number' font property
337 void number(Cursor & cur);
339 /// paste plain text at current cursor.
340 /// \param str string to paste
341 /// \param asParagraphs whether to paste as paragraphs or as lines
342 void pasteString(Cursor & cur, docstring const & str,
345 /// position of the text in the buffer.
346 DocIterator macrocontext_position_;