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"
47 /// This class encapsulates the main text data and operations in LyX
54 LyXFont getFont(Buffer const & buffer, Paragraph const & par,
57 void applyOuterFont(Buffer const & buffer, LyXFont &) const;
59 LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const;
61 LyXFont getLabelFont(Buffer const & buffer,
62 Paragraph const & par) const;
64 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
65 LyXFont const & font);
67 void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
68 LyXFont const & font, bool toggleall);
70 /// what you expect when pressing <enter> at cursor position
71 void breakParagraph(LCursor & cur, bool keep_layout = false);
73 /// set layout over selection
74 void setLayout(Buffer const & buffer, pit_type start, pit_type end,
75 std::string const & layout);
76 /// Set given layout to current cursor position.
77 /// FIXME: replace LCursor with DocIterator.
78 void setLayout(LCursor & cur, std::string const & layout);
80 /// what type of depth change to make
85 /// Increase or decrease the nesting depth of the selected paragraph(s)
86 /// FIXME: replace LCursor with DocIterator.
87 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
89 /// Returns whether something would be changed by changeDepth
90 /// FIXME: replace LCursor with DocIterator.
91 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
93 /// Set font over selection paragraphs and rebreak.
94 /// FIXME: replace LCursor with DocIterator.
95 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
98 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
101 /// FIXME: replace LCursor with DocIterator.
102 docstring getStringToIndex(LCursor const & cur);
104 /// insert a character at cursor position
105 /// FIXME: replace LCursor with DocIterator.
106 void insertChar(LCursor & cur, char_type c);
107 /// insert an inset at cursor position
108 /// FIXME: replace LCursor with DocIterator.
109 void insertInset(LCursor & cur, InsetBase * inset);
111 /// draw text (only used for insets)
112 void draw(PainterInfo & pi, int x, int y) const;
113 /// draw textselection
114 void drawSelection(PainterInfo & pi, int x, int y) const;
116 /// try to handle that request
117 /// FIXME: replace LCursor with DocIterator.
118 void dispatch(LCursor & cur, FuncRequest & cmd);
119 /// do we want to handle this event?
120 bool getStatus(LCursor & cur, FuncRequest const & cmd,
121 FuncStatus & status) const;
123 /// read-only access to individual paragraph
124 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
125 /// read-write access to individual paragraph
126 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
127 // Returns the current font and depth as a message.
128 /// FIXME: replace LCursor with DocIterator.
129 docstring currentState(LCursor & cur);
131 /** returns row near the specified
132 * y-coordinate in given paragraph (relative to the screen).
134 /// FIXME: move to TextMetrics.
135 Row const & getRowNearY(BufferView const & bv, int y,
138 /// returns the paragraph number closest to screen y-coordinate.
139 /// This method uses the BufferView CoordCache to locate the
140 /// paragraph. The y-coodinate is allowed to be off-screen and
141 /// the CoordCache will be automatically updated if needed. This is
142 /// the reason why we need a non const BufferView.
143 /// FIXME: move to TextMetrics.
144 pit_type getPitNearY(BufferView & bv, int y) const;
146 /** Find the word under \c from in the relative location
147 * defined by \c word_location.
148 * @param from return here the start of the word
149 * @param to return here the end of the word
151 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
152 /// just selects the word the cursor is in
153 void selectWord(LCursor & cur, word_location loc);
155 /// what type of change operation to make
160 /// accept or reject the selected change
161 void acceptOrRejectChanges(LCursor & cur, ChangeOp op);
162 /// accept the changes within the complete LyXText
163 void acceptChanges(BufferParams const & bparams);
164 /// reject the changes within the complete LyXText
165 void rejectChanges(BufferParams const & bparams);
167 /// returns true if par was empty and was removed
168 bool setCursor(LCursor & cur, pit_type par, pos_type pos,
169 bool setfont = true, bool boundary = false);
171 void setCursor(CursorSlice &, pit_type par, pos_type pos);
173 void setCursorIntern(LCursor & cur, pit_type par,
174 pos_type pos, bool setfont = true, bool boundary = false);
176 void setCurrentFont(LCursor & cur);
179 void recUndo(LCursor & cur, pit_type first, pit_type last) const;
181 void recUndo(LCursor & cur, pit_type first) const;
183 /// sets cursor only within this LyXText.
184 /// x,y are screen coordinates
185 void setCursorFromCoordinates(LCursor & cur, int x, int y);
187 /// sets cursor recursively descending into nested editable insets
189 \return the inset pointer if x,y is covering that inset
190 \param x,y are absolute screen coordinates.
191 \retval inset is non-null if the cursor is positionned inside
193 /// FIXME: move to TextMetrics.
194 /// FIXME: cleanup to use BufferView::getCoveringInset() and
195 /// setCursorFromCoordinates() instead of checkInsetHit().
196 InsetBase * editXY(LCursor & cur, int x, int y);
198 /// Move cursor one line up.
200 * Returns true if an update is needed after the move.
202 /// FIXME: move to TextMetrics.
203 bool cursorUp(LCursor & cur);
204 /// Move cursor one line down.
206 * Returns true if an update is needed after the move.
208 /// FIXME: move to TextMetrics.
209 bool cursorDown(LCursor & cur);
210 /// Move cursor one position left
212 * Returns true if an update is needed after the move.
214 bool cursorLeft(LCursor & cur);
215 /// Move cursor one position right
217 * Returns true if an update is needed after the move.
219 bool cursorRight(LCursor & cur);
221 bool cursorLeftOneWord(LCursor & cur);
223 bool cursorRightOneWord(LCursor & cur);
225 bool cursorUpParagraph(LCursor & cur);
227 bool cursorDownParagraph(LCursor & cur);
229 /// FIXME: move to TextMetrics.
230 bool cursorHome(LCursor & cur);
232 /// FIXME: move to TextMetrics.
233 bool cursorEnd(LCursor & cur);
235 void cursorPrevious(LCursor & cur);
237 void cursorNext(LCursor & cur);
239 bool cursorTop(LCursor & cur);
241 bool cursorBottom(LCursor & cur);
242 /// Erase character at cursor. Honour change tracking
243 /// FIXME: replace LCursor with DocIterator.
244 bool erase(LCursor & cur);
245 /// Delete character before cursor. Honour CT
246 /// FIXME: replace LCursor with DocIterator.
247 bool backspace(LCursor & cur);
248 // Dissolve the inset under cursor
249 /// FIXME: replace LCursor with DocIterator.
250 bool dissolveInset(LCursor & cur);
252 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
258 text_capitalization = 1,
262 /// Change the case of the word at cursor position.
263 void changeCase(LCursor & cur, TextCase action);
264 /// Transposes the character at the cursor with the one before it
265 void charsTranspose(LCursor & cur);
267 /** the DTP switches for paragraphs. LyX will store the top settings
268 always in the first physical paragraph, the bottom settings in the
269 last. When a paragraph is broken, the top settings rest, the bottom
270 settings are given to the new one.
272 void setParagraph(LCursor & cur,
273 Spacing const & spacing,
275 docstring const & labelwidthstring,
278 /* these things are for search and replace */
280 /// needed to insert the selection
281 /// FIXME: replace LCursor with DocIterator.
282 void insertStringAsLines(LCursor & cur, docstring const & str);
283 /// needed to insert the selection
284 /// FIXME: replace LCursor with DocIterator.
285 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
287 /// Returns an inset if inset was hit, or 0 if not.
288 /// \warning This method is not recursive! It will return the
289 /// outermost inset within this LyXText.
290 /// \sa BufferView::getCoveringInset() to get the innermost inset.
291 InsetBase * checkInsetHit(BufferView &, int x, int y);
294 /// FIXME: move to TextMetrics.
295 int singleWidth(Buffer const &, Paragraph const & par,
298 /// FIXME: move to TextMetrics.
299 int singleWidth(Paragraph const & par, pos_type pos, char_type c,
300 LyXFont const & Font) const;
302 /// return the color of the canvas
303 LColor_color backgroundColor() const;
306 * Returns the left beginning of the text.
307 * This information cannot be taken from the layout object, because
308 * in LaTeX the beginning of the text fits in some cases
309 * (for example sections) exactly the label-width.
311 /// FIXME: move to TextMetrics.
312 int leftMargin(Buffer const &, int max_width, pit_type pit, pos_type pos) const;
313 int leftMargin(Buffer const &, int max_width, pit_type pit) const;
315 /// access to our paragraphs
316 ParagraphList const & paragraphs() const { return pars_; }
317 ParagraphList & paragraphs() { return pars_; }
318 /// return true if this is the main text
319 bool isMainText(Buffer const &) const;
321 /// is this row the last in the text?
322 /// FIXME: move to TextMetrics.
323 bool isLastRow(pit_type pit, Row const & row) const;
324 /// is this row the first in the text?
325 /// FIXME: move to TextMetrics.
326 bool isFirstRow(pit_type pit, Row const & row) const;
329 double spacing(Buffer const & buffer, Paragraph const & par) const;
330 /// make a suggestion for a label
331 /// FIXME: replace LCursor with DocIterator.
332 docstring getPossibleLabel(LCursor & cur) const;
333 /// is this paragraph right-to-left?
334 bool isRTL(Buffer const &, Paragraph const & par) const;
336 bool checkAndActivateInset(LCursor & cur, bool front);
339 void write(Buffer const & buf, std::ostream & os) const;
340 /// returns whether we've seen our usual 'end' marker
341 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
344 /// FIXME: move to TextMetrics.
345 int cursorX(BufferView const &, CursorSlice const & cursor,
346 bool boundary) const;
348 /// FIXME: move to TextMetrics.
349 int cursorY(BufferView const & bv, CursorSlice const & cursor,
350 bool boundary) const;
352 /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
353 /// \retval true if a change has happened and we need a redraw.
354 /// FIXME: replace LCursor with DocIterator. This is not possible right
355 /// now because recordUndo() is called which needs a LCursor.
356 static bool deleteEmptyParagraphMechanism(LCursor & cur,
357 LCursor & old, bool & need_anchor_change);
359 /// delete double spaces, leading spaces, and empty paragraphs
360 /// from \first to \last paragraph
361 void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
364 /// the current font settings
365 LyXFont current_font;
367 LyXFont real_current_font;
369 int background_color_;
376 /// our 'outermost' font. This is handed down from the surrounding
377 // inset through the pi/mi parameter (pi.base.font)
383 /// return past-the-last paragraph influenced by a layout
385 pit_type undoSpan(pit_type pit);
387 // fix the cursor `cur' after a characters has been deleted at `where'
388 // position. Called by deleteEmptyParagraphMechanism
389 static void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
391 // At cursor position 0, try to merge the paragraph with the one before it.
392 // Ignore change tracking, i.e., physically remove the end-of-par character
393 bool backspacePos0(LCursor & cur);
396 void deleteWordForward(LCursor & cur);
398 void deleteWordBackward(LCursor & cur);
400 void deleteLineForward(LCursor & cur);
403 /// set 'number' font property
404 void number(LCursor & cur);
406 /// paste plain text at current cursor.
407 /// \param str string to paste
408 /// \param asParagraphs whether to paste as paragraphs or as lines
409 void pasteString(LCursor & cur, docstring const & str,