* de/Tutorial.lyx: minor corrections reported on lyx-docs.
[lyx.git] / src / Text.h
blobdf19ca7ae2dc71c20621bb692c9a4f4a9d274ae8
1 // -*- C++ -*-
2 /**
3 * \file Text.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author unknown
8 * \author Lars Gullik Bjønnes
9 * \author John Levon
11 * Full author contact details are available in file CREDITS.
14 #ifndef TEXT_H
15 #define TEXT_H
17 #include "DocIterator.h"
18 #include "ParagraphList.h"
20 namespace lyx {
22 class Buffer;
23 class BufferParams;
24 class BufferView;
25 class CompletionList;
26 class CursorSlice;
27 class DocIterator;
28 class ErrorList;
29 class Font;
30 class FontInfo;
31 class FuncRequest;
32 class FuncStatus;
33 class Inset;
34 class Cursor;
35 class Lexer;
36 class PainterInfo;
37 class Spacing;
40 /// This class encapsulates the main text data and operations in LyX
41 class Text {
42 public:
43 /// constructor
44 explicit Text();
46 /// \return true if there's no content at all.
47 /// \warning a non standard layout on an empty paragraph doesn't
48 // count as empty.
49 bool empty() const;
51 ///
52 FontInfo layoutFont(Buffer const & buffer, pit_type pit) const;
53 ///
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
68 * in insetbase.h
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
84 enum DEPTH_CHANGE {
85 INC_DEPTH,
86 DEC_DEPTH
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);
107 /// ???
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 /// select all text
153 void selectAll(Cursor & cur);
154 /// convenience function get the previous word or an empty string
155 docstring previousWord(CursorSlice const & sl) const;
157 /// what type of change operation to make
158 enum ChangeOp {
159 ACCEPT,
160 REJECT
162 /// accept or reject the selected change
163 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
164 /// accept the changes within the complete Text
165 void acceptChanges(BufferParams const & bparams);
166 /// reject the changes within the complete Text
167 void rejectChanges(BufferParams const & bparams);
169 /// returns true if par was empty and was removed
170 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
171 bool setfont = true, bool boundary = false);
173 void setCursor(CursorSlice &, pit_type par, pos_type pos);
175 void setCursorIntern(Cursor & cur, pit_type par,
176 pos_type pos, bool setfont = true, bool boundary = false);
179 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
181 void recUndo(Cursor & cur, pit_type first) const;
183 /// Move cursor one position backwards
185 * Returns true if an update is needed after the move.
187 bool cursorBackward(Cursor & cur);
188 /// Move cursor visually one position to the left
190 * \param skip_inset if true, don't enter insets
191 * Returns true if an update is needed after the move.
193 bool cursorVisLeft(Cursor & cur, bool skip_inset = false);
194 /// Move cursor one position forward
196 * Returns true if an update is needed after the move.
198 bool cursorForward(Cursor & cur);
199 /// Move cursor visually one position to the right
201 * \param skip_inset if true, don't enter insets
202 * Returns true if an update is needed after the move.
204 bool cursorVisRight(Cursor & cur, bool skip_inset = false);
206 bool cursorBackwardOneWord(Cursor & cur);
208 bool cursorForwardOneWord(Cursor & cur);
210 bool cursorVisLeftOneWord(Cursor & cur);
212 bool cursorVisRightOneWord(Cursor & cur);
213 /// Delete from cursor up to the end of the current or next word.
214 void deleteWordForward(Cursor & cur);
215 /// Delete from cursor to start of current or prior word.
216 void deleteWordBackward(Cursor & cur);
218 bool cursorUpParagraph(Cursor & cur);
220 bool cursorDownParagraph(Cursor & cur);
222 bool cursorTop(Cursor & cur);
224 bool cursorBottom(Cursor & cur);
225 /// Erase character at cursor. Honour change tracking
226 /// FIXME: replace Cursor with DocIterator.
227 bool erase(Cursor & cur);
228 /// Delete character before cursor. Honour CT
229 /// FIXME: replace Cursor with DocIterator.
230 bool backspace(Cursor & cur);
231 // Dissolve the inset under cursor
232 /// FIXME: replace Cursor with DocIterator.
233 bool dissolveInset(Cursor & cur);
235 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
236 /// Change the case of the word at cursor position.
237 void changeCase(Cursor & cur, TextCase action);
238 /// Transposes the character at the cursor with the one before it
239 void charsTranspose(Cursor & cur);
241 /** the DTP switches for paragraphs. LyX will store the top settings
242 always in the first physical paragraph, the bottom settings in the
243 last. When a paragraph is broken, the top settings rest, the bottom
244 settings are given to the new one.
245 This function will handle a multi-paragraph selection.
247 void setParagraphs(Cursor & cur, docstring arg, bool modify = false);
248 /// Sets parameters for current or selected paragraphs
249 void setParagraphs(Cursor & cur, ParagraphParameters const & p);
251 /* these things are for search and replace */
253 /// needed to insert the selection
254 /// FIXME: replace Cursor with DocIterator.
255 void insertStringAsLines(Cursor & cur, docstring const & str);
256 /// needed to insert the selection
257 /// FIXME: replace Cursor with DocIterator.
258 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
260 /// access to our paragraphs
261 ParagraphList const & paragraphs() const { return pars_; }
262 ParagraphList & paragraphs() { return pars_; }
263 /// return true if this is the main text
264 bool isMainText(Buffer const &) const;
267 double spacing(Buffer const & buffer, Paragraph const & par) const;
268 /// make a suggestion for a label
269 /// FIXME: replace Cursor with DocIterator.
270 docstring getPossibleLabel(Cursor const & cur) const;
271 /// is this paragraph right-to-left?
272 bool isRTL(Buffer const &, Paragraph const & par) const;
275 bool checkAndActivateInset(Cursor & cur, bool front);
277 bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft);
280 void write(Buffer const & buf, std::ostream & os) const;
281 /// returns true if \end_document has not been read
282 /// insetPtr is the containing Inset
283 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList,
284 InsetText * insetPtr);
286 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
287 /// \retval true if a change has happened and we need a redraw.
288 /// FIXME: replace Cursor with DocIterator. This is not possible right
289 /// now because recordUndo() is called which needs a Cursor.
290 static bool deleteEmptyParagraphMechanism(Cursor & cur,
291 Cursor & old, bool & need_anchor_change);
293 /// delete double spaces, leading spaces, and empty paragraphs
294 /// from \first to \last paragraph
295 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
297 /// To resolve macros properly the texts get their DocIterator.
298 /// Every macro definition is stored with its DocIterator
299 /// as well. Only those macros with a smaller iterator become
300 /// visible in a paragraph.
301 DocIterator macrocontextPosition() const;
303 void setMacrocontextPosition(DocIterator const & pos);
306 bool completionSupported(Cursor const & cur) const;
308 CompletionList const * createCompletionList(Cursor const & cur) const;
310 bool insertCompletion(Cursor & cur, docstring const & s, bool /*finished*/);
312 docstring completionPrefix(Cursor const & cur) const;
314 public:
316 ParagraphList pars_;
319 bool autoBreakRows_;
320 private:
321 /// return past-the-last paragraph influenced by a layout
322 /// change on pit
323 pit_type undoSpan(pit_type pit);
325 // fix the cursor `cur' after a characters has been deleted at `where'
326 // position. Called by deleteEmptyParagraphMechanism
327 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
329 // At cursor position 0, try to merge the paragraph with the one before it.
330 // Ignore change tracking, i.e., physically remove the end-of-par character
331 bool backspacePos0(Cursor & cur);
332 /// handle the case where bibitems were deleted
333 bool handleBibitems(Cursor & cur);
334 /// are we in a list item (description etc.)?
335 bool inDescriptionItem(Cursor & cur) const;
337 void charInserted(Cursor & cur);
338 /// set 'number' font property
339 void number(Cursor & cur);
341 /// paste plain text at current cursor.
342 /// \param str string to paste
343 /// \param asParagraphs whether to paste as paragraphs or as lines
344 void pasteString(Cursor & cur, docstring const & str,
345 bool asParagraphs);
347 /// position of the text in the buffer.
348 DocIterator macrocontext_position_;
351 } // namespace lyx
353 #endif // TEXT_H