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 LyXFont getFont(Buffer const & buffer, Paragraph const & par,
56 void applyOuterFont(Buffer const & buffer, LyXFont &) const;
58 LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const;
60 LyXFont getLabelFont(Buffer const & buffer,
61 Paragraph const & par) const;
63 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
64 LyXFont const & font);
66 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
67 LyXFont const & font, bool toggleall);
69 /// what you expect when pressing \<enter\> at cursor position
70 void breakParagraph(LCursor & cur, bool keep_layout = false);
72 /// set layout over selection
73 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
74 std::string const & layout);
75 /// Set given layout to current cursor position.
76 /// FIXME: replace LCursor with DocIterator.
77 void setLayout(LCursor & cur, std::string const & layout);
79 /// what type of depth change to make
84 /// Increase or decrease the nesting depth of the selected paragraph(s)
85 /// FIXME: replace LCursor with DocIterator.
86 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
88 /// Returns whether something would be changed by changeDepth
89 /// FIXME: replace LCursor with DocIterator.
90 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
92 /// Set font over selection paragraphs and rebreak.
93 /// FIXME: replace LCursor with DocIterator.
94 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
97 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
100 /// FIXME: replace LCursor with DocIterator.
101 docstring getStringToIndex(LCursor const & cur);
103 /// insert a character at cursor position
104 /// FIXME: replace LCursor with DocIterator.
105 void insertChar(LCursor & cur, char_type c);
106 /// insert an inset at cursor position
107 /// FIXME: replace LCursor with DocIterator.
108 void insertInset(LCursor & cur, InsetBase * inset);
110 /// draw text (only used for insets)
111 void draw(PainterInfo & pi, int x, int y) const;
112 /// draw textselection
113 void drawSelection(PainterInfo & pi, int x, int y) const;
115 /// try to handle that request
116 /// FIXME: replace LCursor with DocIterator.
117 void dispatch(LCursor & cur, FuncRequest & cmd);
118 /// do we want to handle this event?
119 bool getStatus(LCursor & cur, FuncRequest const & cmd,
120 FuncStatus & status) const;
122 /// read-only access to individual paragraph
123 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
124 /// read-write access to individual paragraph
125 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
126 // Returns the current font and depth as a message.
127 /// FIXME: replace LCursor with DocIterator.
128 docstring currentState(LCursor & cur);
130 /** returns row near the specified
131 * y-coordinate in given paragraph (relative to the screen).
133 /// FIXME: move to TextMetrics.
134 Row const & getRowNearY(BufferView const & bv, int y,
137 /// returns the paragraph number closest to screen y-coordinate.
138 /// This method uses the BufferView CoordCache to locate the
139 /// paragraph. The y-coodinate is allowed to be off-screen and
140 /// the CoordCache will be automatically updated if needed. This is
141 /// the reason why we need a non const BufferView.
142 /// FIXME: move to TextMetrics.
143 pit_type getPitNearY(BufferView & bv, int y) const;
145 /** Find the word under \c from in the relative location
146 * defined by \c word_location.
147 * @param from return here the start of the word
148 * @param to return here the end of the word
150 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
151 /// just selects the word the cursor is in
152 void selectWord(LCursor & cur, word_location loc);
154 /// what type of change operation to make
159 /// accept or reject the selected change
160 void acceptOrRejectChanges(LCursor & cur, ChangeOp op);
161 /// accept the changes within the complete LyXText
162 void acceptChanges(BufferParams const & bparams);
163 /// reject the changes within the complete LyXText
164 void rejectChanges(BufferParams const & bparams);
166 /// returns true if par was empty and was removed
167 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
168 bool setfont = true, bool boundary = false);
170 void setCursor(CursorSlice &, pit_type par, pos_type pos);
172 void setCursorIntern(LCursor & cur, pit_type par,
173 pos_type pos, bool setfont = true, bool boundary = false);
175 void setCurrentFont(LCursor & cur);
178 void recUndo(LCursor & cur, pit_type first, pit_type last) const;
180 void recUndo(LCursor & cur, pit_type first) const;
182 /// sets cursor only within this LyXText.
183 /// x,y are screen coordinates
184 void setCursorFromCoordinates(LCursor & cur, int x, int y);
186 /// sets cursor recursively descending into nested editable insets
188 \return the inset pointer if x,y is covering that inset
189 \param x,y are absolute screen coordinates.
190 \retval inset is non-null if the cursor is positionned inside
192 /// FIXME: move to TextMetrics.
193 /// FIXME: cleanup to use BufferView::getCoveringInset() and
194 /// setCursorFromCoordinates() instead of checkInsetHit().
195 InsetBase * editXY(LCursor & cur, int x, int y);
197 /// Move cursor one line up.
199 * Returns true if an update is needed after the move.
201 /// FIXME: move to TextMetrics.
202 bool cursorUp(LCursor & cur);
203 /// Move cursor one line down.
205 * Returns true if an update is needed after the move.
207 /// FIXME: move to TextMetrics.
208 bool cursorDown(LCursor & cur);
209 /// Move cursor one position left
211 * Returns true if an update is needed after the move.
213 bool cursorLeft(LCursor & cur);
214 /// Move cursor one position right
216 * Returns true if an update is needed after the move.
218 bool cursorRight(LCursor & cur);
220 bool cursorLeftOneWord(LCursor & cur);
222 bool cursorRightOneWord(LCursor & cur);
224 bool cursorUpParagraph(LCursor & cur);
226 bool cursorDownParagraph(LCursor & cur);
228 /// FIXME: move to TextMetrics.
229 bool cursorHome(LCursor & cur);
231 /// FIXME: move to TextMetrics.
232 bool cursorEnd(LCursor & cur);
234 void cursorPrevious(LCursor & cur);
236 void cursorNext(LCursor & cur);
238 bool cursorTop(LCursor & cur);
240 bool cursorBottom(LCursor & cur);
241 /// Erase character at cursor. Honour change tracking
242 /// FIXME: replace LCursor with DocIterator.
243 bool erase(LCursor & cur);
244 /// Delete character before cursor. Honour CT
245 /// FIXME: replace LCursor with DocIterator.
246 bool backspace(LCursor & cur);
247 // Dissolve the inset under cursor
248 /// FIXME: replace LCursor with DocIterator.
249 bool dissolveInset(LCursor & cur);
251 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
257 text_capitalization = 1,
261 /// Change the case of the word at cursor position.
262 void changeCase(LCursor & cur, TextCase action);
263 /// Transposes the character at the cursor with the one before it
264 void charsTranspose(LCursor & cur);
266 /** the DTP switches for paragraphs. LyX will store the top settings
267 always in the first physical paragraph, the bottom settings in the
268 last. When a paragraph is broken, the top settings rest, the bottom
269 settings are given to the new one.
271 void setParagraph(LCursor & cur,
272 Spacing const & spacing,
274 docstring const & labelwidthstring,
277 /* these things are for search and replace */
279 /// needed to insert the selection
280 /// FIXME: replace LCursor with DocIterator.
281 void insertStringAsLines(LCursor & cur, docstring const & str);
282 /// needed to insert the selection
283 /// FIXME: replace LCursor with DocIterator.
284 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
286 /// Returns an inset if inset was hit, or 0 if not.
287 /// \warning This method is not recursive! It will return the
288 /// outermost inset within this LyXText.
289 /// \sa BufferView::getCoveringInset() to get the innermost inset.
290 InsetBase * checkInsetHit(BufferView &, int x, int y);
293 /// FIXME: move to TextMetrics.
294 int singleWidth(Buffer const &, Paragraph const & par,
297 /// FIXME: move to TextMetrics.
298 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
299 LyXFont const & Font) const;
301 /// return the color of the canvas
302 LColor_color backgroundColor() const;
305 * Returns the left beginning of the text.
306 * This information cannot be taken from the layout object, because
307 * in LaTeX the beginning of the text fits in some cases
308 * (for example sections) exactly the label-width.
310 /// FIXME: move to TextMetrics.
311 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
312 int leftMargin(Buffer const &, int max_width, pit_type pit) const;
314 /// access to our paragraphs
315 ParagraphList const & paragraphs() const { return pars_; }
316 ParagraphList & paragraphs() { return pars_; }
317 /// return true if this is the main text
318 bool isMainText(Buffer const &) const;
320 /// is this row the last in the text?
321 /// FIXME: move to TextMetrics.
322 bool isLastRow(pit_type pit, Row const & row) const;
323 /// is this row the first in the text?
324 /// FIXME: move to TextMetrics.
325 bool isFirstRow(pit_type pit, Row const & row) const;
328 double spacing(Buffer const & buffer, Paragraph const & par) const;
329 /// make a suggestion for a label
330 /// FIXME: replace LCursor with DocIterator.
331 docstring getPossibleLabel(LCursor & cur) const;
332 /// is this paragraph right-to-left?
333 bool isRTL(Buffer const &, Paragraph const & par) const;
335 bool checkAndActivateInset(LCursor & cur, bool front);
338 void write(Buffer const & buf, std::ostream & os) const;
339 /// returns whether we've seen our usual 'end' marker
340 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
343 /// FIXME: move to TextMetrics.
344 int cursorX(BufferView const &, CursorSlice const & cursor,
345 bool boundary) const;
347 /// FIXME: move to TextMetrics.
348 int cursorY(BufferView const & bv, CursorSlice const & cursor,
349 bool boundary) const;
351 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
352 /// \retval true if a change has happened and we need a redraw.
353 /// FIXME: replace LCursor with DocIterator. This is not possible right
354 /// now because recordUndo() is called which needs a LCursor.
355 static bool deleteEmptyParagraphMechanism(LCursor & cur,
356 LCursor & old, bool & need_anchor_change);
358 /// delete double spaces, leading spaces, and empty paragraphs
359 /// from \first to \last paragraph
360 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
363 /// the current font settings
364 LyXFont current_font;
366 LyXFont real_current_font;
368 int background_color_;
375 /// our 'outermost' font. This is handed down from the surrounding
376 // inset through the pi/mi parameter (pi.base.font)
382 /// return past-the-last paragraph influenced by a layout
384 pit_type undoSpan(pit_type pit);
386 // fix the cursor `cur' after a characters has been deleted at `where'
387 // position. Called by deleteEmptyParagraphMechanism
388 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
390 // At cursor position 0, try to merge the paragraph with the one before it.
391 // Ignore change tracking, i.e., physically remove the end-of-par character
392 bool backspacePos0(LCursor & cur);
395 void deleteWordForward(LCursor & cur);
397 void deleteWordBackward(LCursor & cur);
399 void deleteLineForward(LCursor & cur);
402 /// set 'number' font property
403 void number(LCursor & cur);
405 /// paste plain text at current cursor.
406 /// \param str string to paste
407 /// \param asParagraphs whether to paste as paragraphs or as lines
408 void pasteString(LCursor & cur, docstring const & str,