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"
46 /// This class encapsulates the main text data and operations in LyX
53 Font getFont(Buffer const & buffer, Paragraph const & par,
56 void applyOuterFont(Buffer const & buffer, Font &) const;
58 Font getLayoutFont(Buffer const & buffer, pit_type pit) const;
60 Font getLabelFont(Buffer const & buffer,
61 Paragraph const & par) const;
62 /** Set font of character at position \p pos in paragraph \p pit.
63 * Must not be called if \p pos denotes an inset with text contents,
64 * and the inset is not allowed inside a font change (see below).
66 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
69 /** Needed to propagate font changes to all text cells of insets
70 * that are not allowed inside a font change (bug 1973).
71 * Must not be called if \p pos denotes an ordinary character or an
72 * inset that is alowed inside a font change.
73 * FIXME: This should be removed, see documentation of noFontChange
76 void setInsetFont(Buffer const & buffer, pit_type pit, pos_type pos,
77 Font const & font, bool toggleall = false);
79 /// what you expect when pressing \<enter\> at cursor position
80 void breakParagraph(Cursor & cur, bool keep_layout = false);
82 /// set layout over selection
83 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
84 std::string const & layout);
85 /// Set given layout to current cursor position.
86 /// FIXME: replace Cursor with DocIterator.
87 void setLayout(Cursor & cur, std::string const & layout);
89 /// what type of depth change to make
94 /// Increase or decrease the nesting depth of the selected paragraph(s)
95 /// FIXME: replace Cursor with DocIterator.
96 void changeDepth(Cursor & cur, DEPTH_CHANGE type);
98 /// Returns whether something would be changed by changeDepth
99 /// FIXME: replace Cursor with DocIterator.
100 bool changeDepthAllowed(Cursor & cur, DEPTH_CHANGE type) const;
102 /// Set font over selection paragraphs and rebreak.
103 /// FIXME: replace Cursor with DocIterator.
104 void setFont(Cursor & cur, Font const &, bool toggleall = false);
105 /// Set font from \p begin to \p end and rebreak.
106 void setFont(Buffer const & buffer, DocIterator const & begin,
107 DocIterator const & end, Font const &,
108 bool toggleall = false);
111 void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
114 /// FIXME: replace Cursor with DocIterator.
115 docstring getStringToIndex(Cursor const & cur);
117 /// insert a character at cursor position
118 /// FIXME: replace Cursor with DocIterator.
119 void insertChar(Cursor & cur, char_type c);
120 /// insert an inset at cursor position
121 /// FIXME: replace Cursor with DocIterator.
122 void insertInset(Cursor & cur, Inset * inset);
124 /// draw text (only used for insets)
125 void draw(PainterInfo & pi, int x, int y) const;
126 /// draw textselection
127 void drawSelection(PainterInfo & pi, int x, int y) const;
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 & cur);
144 /** returns row near the specified
145 * y-coordinate in given paragraph (relative to the screen).
147 /// FIXME: move to TextMetrics.
148 Row const & getRowNearY(BufferView const & bv, int y,
151 /// returns the paragraph number closest to screen y-coordinate.
152 /// This method uses the BufferView CoordCache to locate the
153 /// paragraph. The y-coodinate is allowed to be off-screen and
154 /// the CoordCache will be automatically updated if needed. This is
155 /// the reason why we need a non const BufferView.
156 /// FIXME: move to TextMetrics.
157 pit_type getPitNearY(BufferView & bv, int y) const;
159 /** Find the word under \c from in the relative location
160 * defined by \c word_location.
161 * @param from return here the start of the word
162 * @param to return here the end of the word
164 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
165 /// just selects the word the cursor is in
166 void selectWord(Cursor & cur, word_location loc);
168 /// what type of change operation to make
173 /// accept or reject the selected change
174 void acceptOrRejectChanges(Cursor & cur, ChangeOp op);
175 /// accept the changes within the complete Text
176 void acceptChanges(BufferParams const & bparams);
177 /// reject the changes within the complete Text
178 void rejectChanges(BufferParams const & bparams);
180 /// returns true if par was empty and was removed
181 bool setCursor(Cursor & cur, pit_type par, pos_type pos,
182 bool setfont = true, bool boundary = false);
184 void setCursor(CursorSlice &, pit_type par, pos_type pos);
186 void setCursorIntern(Cursor & cur, pit_type par,
187 pos_type pos, bool setfont = true, bool boundary = false);
189 void setCurrentFont(Cursor & cur);
192 void recUndo(Cursor & cur, pit_type first, pit_type last) const;
194 void recUndo(Cursor & cur, pit_type first) const;
196 /// sets cursor only within this Text.
197 /// x,y are screen coordinates
198 void setCursorFromCoordinates(Cursor & cur, int x, int y);
200 /// sets cursor recursively descending into nested editable insets
202 \return the inset pointer if x,y is covering that inset
203 \param x,y are absolute screen coordinates.
204 \retval inset is non-null if the cursor is positionned inside
206 /// FIXME: move to TextMetrics.
207 /// FIXME: cleanup to use BufferView::getCoveringInset() and
208 /// setCursorFromCoordinates() instead of checkInsetHit().
209 Inset * editXY(Cursor & cur, int x, int y);
211 /// Move cursor one line up.
213 * Returns true if an update is needed after the move.
215 /// FIXME: move to TextMetrics.
216 bool cursorUp(Cursor & cur);
217 /// Move cursor one line down.
219 * Returns true if an update is needed after the move.
221 /// FIXME: move to TextMetrics.
222 bool cursorDown(Cursor & cur);
223 /// Move cursor one position left
225 * Returns true if an update is needed after the move.
227 bool cursorLeft(Cursor & cur);
228 /// Move cursor one position right
230 * Returns true if an update is needed after the move.
232 bool cursorRight(Cursor & cur);
234 bool cursorLeftOneWord(Cursor & cur);
236 bool cursorRightOneWord(Cursor & cur);
238 bool cursorUpParagraph(Cursor & cur);
240 bool cursorDownParagraph(Cursor & cur);
242 /// FIXME: move to TextMetrics.
243 bool cursorHome(Cursor & cur);
245 /// FIXME: move to TextMetrics.
246 bool cursorEnd(Cursor & cur);
248 void cursorPrevious(Cursor & cur);
250 void cursorNext(Cursor & cur);
252 bool cursorTop(Cursor & cur);
254 bool cursorBottom(Cursor & cur);
255 /// Erase character at cursor. Honour change tracking
256 /// FIXME: replace Cursor with DocIterator.
257 bool erase(Cursor & cur);
258 /// Delete character before cursor. Honour CT
259 /// FIXME: replace Cursor with DocIterator.
260 bool backspace(Cursor & cur);
261 // Dissolve the inset under cursor
262 /// FIXME: replace Cursor with DocIterator.
263 bool dissolveInset(Cursor & cur);
265 bool selectWordWhenUnderCursor(Cursor & cur, word_location);
271 text_capitalization = 1,
275 /// Change the case of the word at cursor position.
276 void changeCase(Cursor & cur, TextCase action);
277 /// Transposes the character at the cursor with the one before it
278 void charsTranspose(Cursor & cur);
280 /** the DTP switches for paragraphs. LyX will store the top settings
281 always in the first physical paragraph, the bottom settings in the
282 last. When a paragraph is broken, the top settings rest, the bottom
283 settings are given to the new one.
285 void setParagraph(Cursor & cur,
286 Spacing const & spacing,
288 docstring const & labelwidthstring,
291 /* these things are for search and replace */
293 /// needed to insert the selection
294 /// FIXME: replace Cursor with DocIterator.
295 void insertStringAsLines(Cursor & cur, docstring const & str);
296 /// needed to insert the selection
297 /// FIXME: replace Cursor with DocIterator.
298 void insertStringAsParagraphs(Cursor & cur, docstring const & str);
300 /// Returns an inset if inset was hit, or 0 if not.
301 /// \warning This method is not recursive! It will return the
302 /// outermost inset within this Text.
303 /// \sa BufferView::getCoveringInset() to get the innermost inset.
304 Inset * checkInsetHit(BufferView &, int x, int y);
307 /// FIXME: move to TextMetrics.
308 int singleWidth(Buffer const &, Paragraph const & par,
311 /// FIXME: move to TextMetrics.
312 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
313 Font const & Font) const;
315 /// return the color of the canvas
316 Color_color backgroundColor() const;
319 * Returns the left beginning of the text.
320 * This information cannot be taken from the layout object, because
321 * in LaTeX the beginning of the text fits in some cases
322 * (for example sections) exactly the label-width.
324 /// FIXME: move to TextMetrics.
325 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
326 int leftMargin(Buffer const &, int max_width, pit_type pit) const;
328 /// access to our paragraphs
329 ParagraphList const & paragraphs() const { return pars_; }
330 ParagraphList & paragraphs() { return pars_; }
331 /// return true if this is the main text
332 bool isMainText(Buffer const &) const;
334 /// is this row the last in the text?
335 /// FIXME: move to TextMetrics.
336 bool isLastRow(pit_type pit, Row const & row) const;
337 /// is this row the first in the text?
338 /// FIXME: move to TextMetrics.
339 bool isFirstRow(pit_type pit, Row const & row) const;
342 double spacing(Buffer const & buffer, Paragraph const & par) const;
343 /// make a suggestion for a label
344 /// FIXME: replace Cursor with DocIterator.
345 docstring getPossibleLabel(Cursor & cur) const;
346 /// is this paragraph right-to-left?
347 bool isRTL(Buffer const &, Paragraph const & par) const;
349 bool checkAndActivateInset(Cursor & cur, bool front);
352 void write(Buffer const & buf, std::ostream & os) const;
353 /// returns whether we've seen our usual 'end' marker
354 bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList);
357 /// FIXME: move to TextMetrics.
358 int cursorX(BufferView const &, CursorSlice const & cursor,
359 bool boundary) const;
361 /// FIXME: move to TextMetrics.
362 int cursorY(BufferView const & bv, CursorSlice const & cursor,
363 bool boundary) const;
365 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
366 /// \retval true if a change has happened and we need a redraw.
367 /// FIXME: replace Cursor with DocIterator. This is not possible right
368 /// now because recordUndo() is called which needs a Cursor.
369 static bool deleteEmptyParagraphMechanism(Cursor & cur,
370 Cursor & old, bool & need_anchor_change);
372 /// delete double spaces, leading spaces, and empty paragraphs
373 /// from \first to \last paragraph
374 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
377 /// the current font settings
380 Font real_current_font;
382 int background_color_;
389 /// our 'outermost' font. This is handed down from the surrounding
390 // inset through the pi/mi parameter (pi.base.font)
396 /// return past-the-last paragraph influenced by a layout
398 pit_type undoSpan(pit_type pit);
400 // fix the cursor `cur' after a characters has been deleted at `where'
401 // position. Called by deleteEmptyParagraphMechanism
402 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
404 // At cursor position 0, try to merge the paragraph with the one before it.
405 // Ignore change tracking, i.e., physically remove the end-of-par character
406 bool backspacePos0(Cursor & cur);
407 /// handle the case where bibitems were deleted
408 bool handleBibitems(Cursor & cur);
411 void deleteWordForward(Cursor & cur);
413 void deleteWordBackward(Cursor & cur);
415 void deleteLineForward(Cursor & cur);
418 /// set 'number' font property
419 void number(Cursor & cur);
421 /// paste plain text at current cursor.
422 /// \param str string to paste
423 /// \param asParagraphs whether to paste as paragraphs or as lines
424 void pasteString(Cursor & cur, docstring const & str,