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.
18 #include "DispatchResult.h"
21 #include "lyxlayout_ptr_fwd.h"
22 #include "ParagraphList.h"
44 /// This class encapsulates the main text data and operations in LyX
50 /// \return true if there's no content at all.
51 /// \warning a non standard layout on an empty paragraph doesn't
56 Font getLayoutFont(Buffer const & buffer, pit_type pit) const;
58 Font getLabelFont(Buffer const & buffer,
59 Paragraph const & par) const;
60 /** Set font of character at position \p pos in paragraph \p pit.
61 * Must not be called if \p pos denotes an inset with text contents,
62 * and the inset is not allowed inside a font change (see below).
64 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
65 Font const & font, Font const & display_font);
67 /** Needed to propagate font changes to all text cells of insets
68 * that are not allowed inside a font change (bug 1973).
69 * Must not be called if \p pos denotes an ordinary character or an
70 * inset that is alowed inside a font change.
71 * FIXME: This should be removed, see documentation of noFontChange
74 void setInsetFont(BufferView const & bv, pit_type pit, pos_type pos,
75 Font const & font, bool toggleall = false);
77 /// what you expect when pressing \<enter\> at cursor position
78 void breakParagraph(Cursor & cur, bool keep_layout = false);
80 /// set layout over selection
81 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
82 docstring const & layout);
83 /// Set given layout to current cursor position.
84 /// FIXME: replace Cursor with DocIterator.
85 void setLayout(Cursor & cur, docstring const & layout);
87 /// what type of depth change to make
92 /// Increase or decrease the nesting depth of the selected paragraph(s)
93 /// FIXME: replace Cursor with DocIterator.
94 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
96 /// Returns whether something would be changed by changeDepth
97 /// FIXME: replace Cursor with DocIterator.
98 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
100 /// Set font over selection paragraphs and rebreak.
101 /// FIXME: replace Cursor with DocIterator.
102 void setFont(Cursor & cur, Font const &, bool toggleall = false);
103 /// Set font from \p begin to \p end and rebreak.
104 void setFont(BufferView const & bv, CursorSlice const & begin,
105 CursorSlice const & end, Font const &,
106 bool toggleall = false);
109 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
112 /// FIXME: replace Cursor with DocIterator.
113 docstring getStringToIndex(Cursor const & cur);
115 /// insert a character at cursor position
116 /// FIXME: replace Cursor with DocIterator.
117 void insertChar(Cursor & cur, char_type c);
118 /// insert an inset at cursor position
119 /// FIXME: replace Cursor with DocIterator.
120 void insertInset(Cursor & cur, Inset * inset);
122 /// try to handle that request
123 /// FIXME: replace Cursor with DocIterator.
124 void dispatch(Cursor & cur, FuncRequest & cmd);
125 /// do we want to handle this event?
126 bool getStatus(Cursor & cur, FuncRequest const & cmd,
127 FuncStatus & status) const;
129 /// read-only access to individual paragraph
130 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
131 /// read-write access to individual paragraph
132 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
133 // Returns the current font and depth as a message.
134 /// FIXME: replace Cursor with DocIterator.
135 docstring currentState(Cursor & cur);
137 /** Find the word under \c from in the relative location
138 * defined by \c word_location.
139 * @param from return here the start of the word
140 * @param to return here the end of the word
142 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
143 /// just selects the word the cursor is in
144 void selectWord(Cursor & cur, word_location loc);
146 /// what type of change operation to make
151 /// accept or reject the selected change
152 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
153 /// accept the changes within the complete Text
154 void acceptChanges(BufferParams const & bparams);
155 /// reject the changes within the complete Text
156 void rejectChanges(BufferParams const & bparams);
158 /// returns true if par was empty and was removed
159 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
160 bool setfont = true, bool boundary = false);
162 void setCursor(CursorSlice &, pit_type par, pos_type pos);
164 void setCursorIntern(Cursor & cur, pit_type par,
165 pos_type pos, bool setfont = true, bool boundary = false);
168 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
170 void recUndo(Cursor & cur, pit_type first) const;
172 /// Move cursor one position left
174 * Returns true if an update is needed after the move.
176 bool cursorLeft(Cursor & cur);
177 /// Move cursor one position right
179 * Returns true if an update is needed after the move.
181 bool cursorRight(Cursor & cur);
183 bool cursorLeftOneWord(Cursor & cur);
185 bool cursorRightOneWord(Cursor & cur);
186 /// Delete from cursor up to the end of the current or next word.
187 void deleteWordForward(Cursor & cur);
188 /// Delete from cursor to start of current or prior word.
189 void deleteWordBackward(Cursor & cur);
191 bool cursorUpParagraph(Cursor & cur);
193 bool cursorDownParagraph(Cursor & cur);
195 bool cursorTop(Cursor & cur);
197 bool cursorBottom(Cursor & cur);
198 /// Erase character at cursor. Honour change tracking
199 /// FIXME: replace Cursor with DocIterator.
200 bool erase(Cursor & cur);
201 /// Delete character before cursor. Honour CT
202 /// FIXME: replace Cursor with DocIterator.
203 bool backspace(Cursor & cur);
204 // Dissolve the inset under cursor
205 /// FIXME: replace Cursor with DocIterator.
206 bool dissolveInset(Cursor & cur);
208 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
214 text_capitalization = 1,
218 /// Change the case of the word at cursor position.
219 void changeCase(Cursor & cur, TextCase action);
220 /// Transposes the character at the cursor with the one before it
221 void charsTranspose(Cursor & cur);
223 /** the DTP switches for paragraphs. LyX will store the top settings
224 always in the first physical paragraph, the bottom settings in the
225 last. When a paragraph is broken, the top settings rest, the bottom
226 settings are given to the new one.
227 This function will handle a multi-paragraph selection.
229 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
230 /// Sets parameters for current or selected paragraphs
231 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
233 /* these things are for search and replace */
235 /// needed to insert the selection
236 /// FIXME: replace Cursor with DocIterator.
237 void insertStringAsLines(Cursor & cur, docstring const & str);
238 /// needed to insert the selection
239 /// FIXME: replace Cursor with DocIterator.
240 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
242 /// access to our paragraphs
243 ParagraphList const & paragraphs() const { return pars_; }
244 ParagraphList & paragraphs() { return pars_; }
245 /// return true if this is the main text
246 bool isMainText(Buffer const &) const;
249 double spacing(Buffer const & buffer, Paragraph const & par) const;
250 /// make a suggestion for a label
251 /// FIXME: replace Cursor with DocIterator.
252 docstring getPossibleLabel(Cursor & cur) const;
253 /// is this paragraph right-to-left?
254 bool isRTL(Buffer const &, Paragraph const & par) const;
257 bool checkAndActivateInset(Cursor & cur, bool front);
260 void write(Buffer const & buf, std::ostream & os) const;
261 /// returns whether we've seen our usual 'end' marker
262 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
264 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
265 /// \retval true if a change has happened and we need a redraw.
266 /// FIXME: replace Cursor with DocIterator. This is not possible right
267 /// now because recordUndo() is called which needs a Cursor.
268 static bool deleteEmptyParagraphMechanism(Cursor & cur,
269 Cursor & old, bool & need_anchor_change);
271 /// delete double spaces, leading spaces, and empty paragraphs
272 /// from \first to \last paragraph
273 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
282 /// return past-the-last paragraph influenced by a layout
284 pit_type undoSpan(pit_type pit);
286 // fix the cursor `cur' after a characters has been deleted at `where'
287 // position. Called by deleteEmptyParagraphMechanism
288 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
290 // At cursor position 0, try to merge the paragraph with the one before it.
291 // Ignore change tracking, i.e., physically remove the end-of-par character
292 bool backspacePos0(Cursor & cur);
293 /// handle the case where bibitems were deleted
294 bool handleBibitems(Cursor & cur);
297 /// set 'number' font property
298 void number(Cursor & cur);
300 /// paste plain text at current cursor.
301 /// \param str string to paste
302 /// \param asParagraphs whether to paste as paragraphs or as lines
303 void pasteString(Cursor & cur, docstring const & str,