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.
17 #include "bufferview_funcs.h"
19 #include "dispatchresult.h"
20 #include "dimension.h"
23 #include "lyxlayout_ptr_fwd.h"
24 #include "ParagraphList.h"
51 /// This class encapsulates the main text data and operations in LyX
55 explicit LyXText(BufferView *);
57 void init(BufferView *);
60 LyXFont getFont(Paragraph const & par, pos_type pos) const;
62 void applyOuterFont(LyXFont &) const;
64 LyXFont getLayoutFont(pit_type pit) const;
66 LyXFont getLabelFont(Paragraph const & par) const;
68 void setCharFont(pit_type pit, pos_type pos, LyXFont const & font);
70 void setCharFont(pit_type pit, pos_type pos, LyXFont const & font,
73 /// what you expect when pressing <enter> at cursor position
74 void breakParagraph(LCursor & cur, bool keep_layout = false);
76 /// set layout over selection
77 void setLayout(pit_type start, pit_type end,
78 std::string const & layout);
80 void setLayout(LCursor & cur, std::string const & layout);
82 /// what type of depth change to make
87 /// Increase or decrease the nesting depth of the selected paragraph(s)
88 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
90 /// Returns whether something would be changed by changeDepth
91 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
93 /// Set font over selection paragraphs and rebreak.
94 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
96 /// rebreaks the given par
97 bool redoParagraph(pit_type pit);
99 /// returns pos in given par at given x coord
100 pos_type x2pos(pit_type pit, int row, int x) const;
101 int pos2x(pit_type pit, pos_type pos) const;
104 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
107 std::string getStringToIndex(LCursor const & cur);
109 /// insert a character at cursor position
110 void insertChar(LCursor & cur, char_type c);
111 /// insert an inset at cursor position
112 void insertInset(LCursor & cur, InsetBase * inset);
114 /// compute text metrics
115 void metrics(MetricsInfo & mi, Dimension & dim);
116 /// draw text (only used for insets)
117 void draw(PainterInfo & pi, int x, int y) const;
118 /// draw textselection
119 void drawSelection(PainterInfo & pi, int x, int y) const;
121 /// try to handle that request
122 void dispatch(LCursor & cur, FuncRequest & cmd);
123 /// do we want to handle this event?
124 bool getStatus(LCursor & cur, FuncRequest const & cmd,
125 FuncStatus & status) const;
127 /// access to out BufferView. This should go...
128 BufferView * bv() const;
130 /// read-only access to individual paragraph
131 Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
132 /// read-write access to individual paragraph
133 Paragraph & getPar(pit_type pit) { return pars_[pit]; }
134 // Returns the current font and depth as a message.
135 std::string currentState(LCursor & cur);
137 /** returns row near the specified
138 * y-coordinate in given paragraph (relative to the screen).
140 Row const & getRowNearY(int y, pit_type pit) const;
141 pit_type getPitNearY(int y) const;
143 /** returns the column near the specified x-coordinate of the row
144 x is set to the real beginning of this column
146 pos_type getColumnNearX(pit_type pit,
147 Row const & row, int & x, bool & boundary) const;
149 /** Find the word under \c from in the relative location
150 * defined by \c word_location.
151 * @param from return here the start of the word
152 * @param to return here the end of the word
154 void getWord(CursorSlice & from, CursorSlice & to, word_location const);
155 /// just selects the word the cursor is in
156 void selectWord(LCursor & cur, word_location loc);
158 /// accept selected change
159 void acceptChange(LCursor & cur);
160 /// reject selected change
161 void rejectChange(LCursor & cur);
163 /// returns true if par was empty and was removed
164 bool setCursor(LCursor & 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(LCursor & cur, pit_type par,
170 pos_type pos, bool setfont = true, bool boundary = false);
172 void setCurrentFont(LCursor & cur);
175 void recUndo(pit_type first, pit_type last) const;
177 void recUndo(pit_type first) const;
178 /// returns true if par was empty and was removed
179 bool setCursorFromCoordinates(LCursor & cur, int x, int y);
181 InsetBase * editXY(LCursor & cur, int x, int y);
182 /// Move cursor one line up.
184 * Returns true if an update is needed after the move.
186 bool cursorUp(LCursor & cur);
187 /// Move cursor one line down.
189 * Returns true if an update is needed after the move.
191 bool cursorDown(LCursor & cur);
192 /// Move cursor one position left
194 * Returns true if an update is needed after the move.
196 bool cursorLeft(LCursor & cur);
197 /// Move cursor one position right
199 * Returns true if an update is needed after the move.
201 bool cursorRight(LCursor & cur);
203 bool cursorLeftOneWord(LCursor & cur);
205 bool cursorRightOneWord(LCursor & cur);
207 bool cursorUpParagraph(LCursor & cur);
209 bool cursorDownParagraph(LCursor & cur);
211 bool cursorHome(LCursor & cur);
213 bool cursorEnd(LCursor & cur);
215 bool cursorPrevious(LCursor & cur);
217 bool cursorNext(LCursor & cur);
219 bool cursorTop(LCursor & cur);
221 bool cursorBottom(LCursor & cur);
222 /// Erase character at cursor. Honour change tracking
223 bool erase(LCursor & cur);
224 /** At cursor position 0, merge paragraph with the one before it.
225 * Ignore CT (this is used in \c acceptChange, \c rejectChange for
226 * physical deletion of paragraph break)
228 bool backspacePos0(LCursor & cur);
229 /// Delete character before cursor. Honour CT
230 bool backspace(LCursor & cur);
231 // Dissolve the inset under cursor
232 bool dissolveInset(LCursor & cur);
234 bool selectWordWhenUnderCursor(LCursor & cur, word_location);
240 text_capitalization = 1,
244 /// Change the case of the word at cursor position.
245 void changeCase(LCursor & cur, TextCase action);
247 /** the DTP switches for paragraphs. LyX will store the top settings
248 always in the first physical paragraph, the bottom settings in the
249 last. When a paragraph is broken, the top settings rest, the bottom
250 settings are given to the new one.
252 void setParagraph(LCursor & cur,
253 Spacing const & spacing,
255 std::string const & labelwidthstring,
258 /* these things are for search and replace */
260 /// needed to insert the selection
261 void insertStringAsLines(LCursor & cur, docstring const & str);
262 /// needed to insert the selection
263 void insertStringAsParagraphs(LCursor & cur, docstring const & str);
265 /// current text width
268 /// current text heigth
271 /// Returns an inset if inset was hit, or 0 if not.
272 InsetBase * checkInsetHit(int x, int y) const;
275 int singleWidth(Paragraph const & par, pos_type pos) const;
277 int singleWidth(Paragraph const & par,
278 pos_type pos, char_type c, LyXFont const & Font) const;
280 /// return the color of the canvas
281 LColor_color backgroundColor() const;
284 * Returns the left beginning of the text.
285 * This information cannot be taken from the layout object, because
286 * in LaTeX the beginning of the text fits in some cases
287 * (for example sections) exactly the label-width.
289 int leftMargin(pit_type pit, pos_type pos) const;
290 int leftMargin(pit_type pit) const;
292 int rightMargin(Paragraph const & par) const;
294 /** this calculates the specified parameters. needed when setting
295 * the cursor and when creating a visible row */
296 RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
298 /// access to our paragraphs
299 ParagraphList const & paragraphs() const { return pars_; }
300 ParagraphList & paragraphs() { return pars_; }
301 /// return true if this is the main text
302 bool isMainText() const;
304 /// return first row of text
305 Row const & firstRow() const;
307 /// is this row the last in the text?
308 bool isLastRow(pit_type pit, Row const & row) const;
309 /// is this row the first in the text?
310 bool isFirstRow(pit_type pit, Row const & row) const;
313 double spacing(Paragraph const & par) const;
314 /// make a suggestion for a label
315 std::string getPossibleLabel(LCursor & cur) const;
316 /// is this paragraph right-to-left?
317 bool isRTL(Paragraph const & par) const;
319 bool checkAndActivateInset(LCursor & cur, bool front);
322 void write(Buffer const & buf, std::ostream & os) const;
323 /// returns whether we've seen our usual 'end' marker
324 bool read(Buffer const & buf, LyXLex & lex, ErrorList & errorList);
331 int cursorX(CursorSlice const & cursor, bool boundary) const;
333 int cursorY(CursorSlice const & cursor, bool boundary) const;
335 /// delete double space or empty paragraphs around old cursor
336 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
343 /// the current font settings
344 LyXFont current_font;
346 LyXFont real_current_font;
348 int background_color_;
350 /// only the top-level LyXText has this non-zero
351 BufferView * bv_owner;
358 /// our 'outermost' font. This is handed down from the surrounding
359 // inset through the pi/mi parameter (pi.base.font)
365 /// return past-the-last paragraph influenced by a layout
367 pit_type undoSpan(pit_type pit);
369 /// Calculate and set the height of the row
370 void setHeightOfRow(pit_type, Row & row);
372 // fix the cursor `cur' after a characters has been deleted at `where'
373 // position. Called by deleteEmptyParagraphMechanism
374 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
377 void deleteWordForward(LCursor & cur);
379 void deleteWordBackward(LCursor & cur);
381 void deleteLineForward(LCursor & cur);
383 /// sets row.end to the pos value *after* which a row should break.
384 /// for example, the pos after which isNewLine(pos) == true
385 void rowBreakPoint(pit_type pit, Row & row) const;
386 /// sets row.width to the minimum space a row needs on the screen in pixel
387 void setRowWidth(pit_type pit, Row & row) const;
388 /// the minimum space a manual label needs on the screen in pixels
389 int labelFill(Paragraph const & par, Row const & row) const;
391 int labelEnd(pit_type pit) const;
395 /// set 'number' font property
396 void number(LCursor & cur);
399 /// return the default height of a row in pixels, considering font zoom
400 int defaultRowHeight();