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);
172 void setCurrentFont(Cursor & cur);
175 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
177 void recUndo(Cursor & cur, pit_type first) const;
179 /// Move cursor one position left
181 * Returns true if an update is needed after the move.
183 bool cursorLeft(Cursor & cur);
184 /// Move cursor one position right
186 * Returns true if an update is needed after the move.
188 bool cursorRight(Cursor & cur);
190 bool cursorLeftOneWord(Cursor & cur);
192 bool cursorRightOneWord(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);
221 text_capitalization = 1,
225 /// Change the case of the word at cursor position.
226 void changeCase(Cursor & cur, TextCase action);
227 /// Transposes the character at the cursor with the one before it
228 void charsTranspose(Cursor & cur);
230 /** the DTP switches for paragraphs. LyX will store the top settings
231 always in the first physical paragraph, the bottom settings in the
232 last. When a paragraph is broken, the top settings rest, the bottom
233 settings are given to the new one.
234 This function will handle a multi-paragraph selection.
236 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
237 /// Sets parameters for current or selected paragraphs
238 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
240 /* these things are for search and replace */
242 /// needed to insert the selection
243 /// FIXME: replace Cursor with DocIterator.
244 void insertStringAsLines(Cursor & cur, docstring const & str);
245 /// needed to insert the selection
246 /// FIXME: replace Cursor with DocIterator.
247 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
249 /// return the color of the canvas
250 Color_color backgroundColor() const;
252 /// access to our paragraphs
253 ParagraphList const & paragraphs() const { return pars_; }
254 ParagraphList & paragraphs() { return pars_; }
255 /// return true if this is the main text
256 bool isMainText(Buffer const &) const;
259 double spacing(Buffer const & buffer, Paragraph const & par) const;
260 /// make a suggestion for a label
261 /// FIXME: replace Cursor with DocIterator.
262 docstring getPossibleLabel(Cursor & cur) const;
263 /// is this paragraph right-to-left?
264 bool isRTL(Buffer const &, Paragraph const & par) const;
265 /// is this position in the paragraph right-to-left?
266 bool isRTL(Buffer const & buffer, CursorSlice const & sl, bool boundary) const;
267 /// is between pos-1 and pos an RTL<->LTR boundary?
268 bool isRTLBoundary(Buffer const & buffer, Paragraph const & par,
270 /// would be a RTL<->LTR boundary between pos and the given font?
271 bool isRTLBoundary(Buffer const & buffer, Paragraph const & par,
272 pos_type pos, Font const & font) const;
275 bool checkAndActivateInset(Cursor & cur, bool front);
278 void write(Buffer const & buf, std::ostream & os) const;
279 /// returns whether we've seen our usual 'end' marker
280 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
282 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
283 /// \retval true if a change has happened and we need a redraw.
284 /// FIXME: replace Cursor with DocIterator. This is not possible right
285 /// now because recordUndo() is called which needs a Cursor.
286 static bool deleteEmptyParagraphMechanism(Cursor & cur,
287 Cursor & old, bool & need_anchor_change);
289 /// delete double spaces, leading spaces, and empty paragraphs
290 /// from \first to \last paragraph
291 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
294 /// the current font settings
297 Font real_current_font;
299 int background_color_;
304 /// our 'outermost' font. This is handed down from the surrounding
305 // inset through the pi/mi parameter (pi.base.font)
311 /// return past-the-last paragraph influenced by a layout
313 pit_type undoSpan(pit_type pit);
315 // fix the cursor `cur' after a characters has been deleted at `where'
316 // position. Called by deleteEmptyParagraphMechanism
317 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
319 // At cursor position 0, try to merge the paragraph with the one before it.
320 // Ignore change tracking, i.e., physically remove the end-of-par character
321 bool backspacePos0(Cursor & cur);
322 /// handle the case where bibitems were deleted
323 bool handleBibitems(Cursor & cur);
326 /// set 'number' font property
327 void number(Cursor & cur);
329 /// paste plain text at current cursor.
330 /// \param str string to paste
331 /// \param asParagraphs whether to paste as paragraphs or as lines
332 void pasteString(Cursor & cur, docstring const & str,