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 getFont(Buffer const & buffer, Paragraph const & par,
59 void applyOuterFont(Buffer const & buffer, Font &) const;
61 Font getLayoutFont(Buffer const & buffer, pit_type pit) const;
63 Font getLabelFont(Buffer const & buffer,
64 Paragraph const & par) const;
65 /** Set font of character at position \p pos in paragraph \p pit.
66 * Must not be called if \p pos denotes an inset with text contents,
67 * and the inset is not allowed inside a font change (see below).
69 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
72 /** Needed to propagate font changes to all text cells of insets
73 * that are not allowed inside a font change (bug 1973).
74 * Must not be called if \p pos denotes an ordinary character or an
75 * inset that is alowed inside a font change.
76 * FIXME: This should be removed, see documentation of noFontChange
79 void setInsetFont(Buffer const & buffer, pit_type pit, pos_type pos,
80 Font const & font, bool toggleall = false);
82 /// what you expect when pressing \<enter\> at cursor position
83 void breakParagraph(Cursor & cur, bool keep_layout = false);
85 /// set layout over selection
86 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
87 docstring const & layout);
88 /// Set given layout to current cursor position.
89 /// FIXME: replace Cursor with DocIterator.
90 void setLayout(Cursor & cur, docstring const & layout);
92 /// what type of depth change to make
97 /// Increase or decrease the nesting depth of the selected paragraph(s)
98 /// FIXME: replace Cursor with DocIterator.
99 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
101 /// Returns whether something would be changed by changeDepth
102 /// FIXME: replace Cursor with DocIterator.
103 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
105 /// Set font over selection paragraphs and rebreak.
106 /// FIXME: replace Cursor with DocIterator.
107 void setFont(Cursor & cur, Font const &, bool toggleall = false);
108 /// Set font from \p begin to \p end and rebreak.
109 void setFont(Buffer const & buffer, CursorSlice const & begin,
110 CursorSlice const & end, Font const &,
111 bool toggleall = false);
114 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
117 /// FIXME: replace Cursor with DocIterator.
118 docstring getStringToIndex(Cursor const & cur);
120 /// insert a character at cursor position
121 /// FIXME: replace Cursor with DocIterator.
122 void insertChar(Cursor & cur, char_type c);
123 /// insert an inset at cursor position
124 /// FIXME: replace Cursor with DocIterator.
125 void insertInset(Cursor & cur, Inset * inset);
127 /// try to handle that request
128 /// FIXME: replace Cursor with DocIterator.
129 void dispatch(Cursor & cur, FuncRequest & cmd);
130 /// do we want to handle this event?
131 bool getStatus(Cursor & cur, FuncRequest const & cmd,
132 FuncStatus & status) const;
134 /// read-only access to individual paragraph
135 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
136 /// read-write access to individual paragraph
137 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
138 // Returns the current font and depth as a message.
139 /// FIXME: replace Cursor with DocIterator.
140 docstring currentState(Cursor & cur);
142 /** Find the word under \c from in the relative location
143 * defined by \c word_location.
144 * @param from return here the start of the word
145 * @param to return here the end of the word
147 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
148 /// just selects the word the cursor is in
149 void selectWord(Cursor & cur, word_location loc);
151 /// what type of change operation to make
156 /// accept or reject the selected change
157 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
158 /// accept the changes within the complete Text
159 void acceptChanges(BufferParams const & bparams);
160 /// reject the changes within the complete Text
161 void rejectChanges(BufferParams const & bparams);
163 /// returns true if par was empty and was removed
164 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
165 bool setfont = true, bool boundary = false);
167 void setCursor(CursorSlice &, pit_type par, pos_type pos);
169 void setCursorIntern(Cursor & cur, pit_type par,
170 pos_type pos, bool setfont = true, bool boundary = false);
173 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
175 void recUndo(Cursor & cur, pit_type first) const;
177 /// Move cursor one position left
179 * Returns true if an update is needed after the move.
181 bool cursorLeft(Cursor & cur);
182 /// Move cursor one position right
184 * Returns true if an update is needed after the move.
186 bool cursorRight(Cursor & cur);
188 bool cursorLeftOneWord(Cursor & cur);
190 bool cursorRightOneWord(Cursor & cur);
191 /// Delete from cursor up to the end of the current or next word.
192 void deleteWordForward(Cursor & cur);
193 /// Delete from cursor to start of current or prior word.
194 void deleteWordBackward(Cursor & cur);
196 bool cursorUpParagraph(Cursor & cur);
198 bool cursorDownParagraph(Cursor & cur);
200 bool cursorTop(Cursor & cur);
202 bool cursorBottom(Cursor & cur);
203 /// Erase character at cursor. Honour change tracking
204 /// FIXME: replace Cursor with DocIterator.
205 bool erase(Cursor & cur);
206 /// Delete character before cursor. Honour CT
207 /// FIXME: replace Cursor with DocIterator.
208 bool backspace(Cursor & cur);
209 // Dissolve the inset under cursor
210 /// FIXME: replace Cursor with DocIterator.
211 bool dissolveInset(Cursor & cur);
213 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
219 text_capitalization = 1,
223 /// Change the case of the word at cursor position.
224 void changeCase(Cursor & cur, TextCase action);
225 /// Transposes the character at the cursor with the one before it
226 void charsTranspose(Cursor & cur);
228 /** the DTP switches for paragraphs. LyX will store the top settings
229 always in the first physical paragraph, the bottom settings in the
230 last. When a paragraph is broken, the top settings rest, the bottom
231 settings are given to the new one.
232 This function will handle a multi-paragraph selection.
234 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
235 /// Sets parameters for current or selected paragraphs
236 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
238 /* these things are for search and replace */
240 /// needed to insert the selection
241 /// FIXME: replace Cursor with DocIterator.
242 void insertStringAsLines(Cursor & cur, docstring const & str);
243 /// needed to insert the selection
244 /// FIXME: replace Cursor with DocIterator.
245 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
247 /// return the color of the canvas
248 Color_color backgroundColor() const;
250 /// access to our paragraphs
251 ParagraphList const & paragraphs() const { return pars_; }
252 ParagraphList & paragraphs() { return pars_; }
253 /// return true if this is the main text
254 bool isMainText(Buffer const &) const;
257 double spacing(Buffer const & buffer, Paragraph const & par) const;
258 /// make a suggestion for a label
259 /// FIXME: replace Cursor with DocIterator.
260 docstring getPossibleLabel(Cursor & cur) const;
261 /// is this paragraph right-to-left?
262 bool isRTL(Buffer const &, Paragraph const & par) const;
263 /// is this position in the paragraph right-to-left?
264 bool isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const;
265 /// is between pos-1 and pos an RTL<->LTR boundary?
266 bool isRTLBoundary(Buffer const & buffer, Paragraph const & par,
268 /// would be a RTL<->LTR boundary between pos and the given font?
269 bool isRTLBoundary(Buffer const & buffer, Paragraph const & par,
270 pos_type pos, Font const & font) const;
273 bool checkAndActivateInset(Cursor & cur, bool front);
276 void write(Buffer const & buf, std::ostream & os) const;
277 /// returns whether we've seen our usual 'end' marker
278 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
280 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
281 /// \retval true if a change has happened and we need a redraw.
282 /// FIXME: replace Cursor with DocIterator. This is not possible right
283 /// now because recordUndo() is called which needs a Cursor.
284 static bool deleteEmptyParagraphMechanism(Cursor & cur,
285 Cursor & old, bool & need_anchor_change);
287 /// delete double spaces, leading spaces, and empty paragraphs
288 /// from \first to \last paragraph
289 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
293 int background_color_;
298 /// our 'outermost' font. This is handed down from the surrounding
299 // inset through the pi/mi parameter (pi.base.font)
305 /// return past-the-last paragraph influenced by a layout
307 pit_type undoSpan(pit_type pit);
309 // fix the cursor `cur' after a characters has been deleted at `where'
310 // position. Called by deleteEmptyParagraphMechanism
311 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
313 // At cursor position 0, try to merge the paragraph with the one before it.
314 // Ignore change tracking, i.e., physically remove the end-of-par character
315 bool backspacePos0(Cursor & cur);
316 /// handle the case where bibitems were deleted
317 bool handleBibitems(Cursor & cur);
320 /// set 'number' font property
321 void number(Cursor & cur);
323 /// paste plain text at current cursor.
324 /// \param str string to paste
325 /// \param asParagraphs whether to paste as paragraphs or as lines
326 void pasteString(Cursor & cur, docstring const & str,