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"
22 #include "lyxlayout_ptr_fwd.h"
23 #include "RowList_fwd.h"
24 #include "ParagraphList_fwd.h"
47 /// This class encapsulates the main text data and operations in LyX
51 typedef lyx::pos_type pos_type;
53 typedef lyx::par_type par_type;
56 explicit LyXText(BufferView *);
58 void init(BufferView *);
60 /// update y coordinate cache of all paragraphs
61 void updateParPositions();
63 LyXFont getFont(par_type pit, pos_type pos) const;
65 LyXFont getLayoutFont(par_type pit) const;
67 LyXFont getLabelFont(par_type pit) const;
69 void setCharFont(par_type pit, pos_type pos, LyXFont const & font);
71 void setCharFont(par_type pit, pos_type pos, LyXFont const & font,
74 /// what you expect when pressing <enter> at cursor position
75 void breakParagraph(LCursor & cur, char keep_layout = 0);
77 /// set layout over selection
78 par_type setLayout(par_type start, par_type end,
79 std::string const & layout);
81 void setLayout(LCursor & cur, std::string const & layout);
83 /// what type of depth change to make
88 /// Increase or decrease the nesting depth of the selected paragraph(s)
89 void changeDepth(LCursor & cur, DEPTH_CHANGE type);
91 /// Returns whether something would be changed by changeDepth
92 bool changeDepthAllowed(LCursor & cur, DEPTH_CHANGE type) const;
94 /// Set font over selection paragraphs and rebreak.
95 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
97 /// rebreaks all paragaphs between the given pars.
98 void redoParagraphs(par_type begin, par_type end);
99 /// rebreaks the given par
100 void redoParagraph(par_type pit);
101 /// rebreaks the cursor par
102 void redoParagraph(LCursor & cur);
105 void toggleFree(LCursor & cur, LyXFont const &, bool toggleall = false);
108 std::string getStringToIndex(LCursor & cur);
110 /// insert a character at cursor position
111 void insertChar(LCursor & cur, char c);
112 /// insert an inset at cursor position
113 void insertInset(LCursor & cur, InsetBase * inset);
115 /// a full rebreak of the whole text
117 /// compute text metrics
118 void metrics(MetricsInfo & mi, Dimension & dim);
119 /// draw text (only used for insets)
120 void draw(PainterInfo & pi, int x, int y) const;
121 /// draw textselection
122 void drawSelection(PainterInfo & pi, int x, int y) const;
123 /// returns distance of this cell to the point given by x and y
124 // assumes valid position and size cache
125 int dist(int x, int y) const;
127 /// try to handle that request
128 void dispatch(LCursor & cur, FuncRequest & cmd);
129 /// do we want to handle this event?
130 bool getStatus(LCursor & cur, FuncRequest const & cmd,
131 FuncStatus & status) const;
133 /// access to out BufferView. This should go...
135 /// access to out BufferView. This should go...
136 BufferView * bv() const;
138 /// access to individual paragraphs
139 Paragraph & getPar(par_type par) const;
140 // Returns the current font and depth as a message.
141 std::string LyXText::currentState(LCursor & cur);
143 /** returns an iterator pointing to the row near the specified
144 * y-coordinate (relative to the whole text). y is set to the
145 * real beginning of this row
147 RowList::iterator getRowNearY(int y, par_type & pit) const;
149 /** returns the column near the specified x-coordinate of the row
150 x is set to the real beginning of this column
152 pos_type getColumnNearX(par_type pit,
153 Row const & row, int & x, bool & boundary) const;
155 /** Find the word under \c from in the relative location
156 * defined by \c word_location.
157 * @param from return here the start of the word
158 * @param to return here the end of the word
160 void getWord(CursorSlice & from, CursorSlice & to, lyx::word_location const);
161 /// just selects the word the cursor is in
162 void selectWord(LCursor & cur, lyx::word_location loc);
164 /// accept selected change
165 void acceptChange(LCursor & cur);
166 /// reject selected change
167 void rejectChange(LCursor & cur);
169 /// returns true if par was empty and was removed
170 bool setCursor(LCursor & cur, par_type par, pos_type pos,
171 bool setfont = true, bool boundary = false);
173 void setCursor(CursorSlice &, par_type par,
174 pos_type pos, bool boundary = false);
176 void setCursorIntern(LCursor & cur, par_type par,
177 pos_type pos, bool setfont = true, bool boundary = false);
179 void setCurrentFont(LCursor & cur);
182 void recUndo(par_type first, par_type last) const;
184 void recUndo(par_type first) const;
186 void setCursorFromCoordinates(LCursor & cur, int x, int y);
188 InsetBase * editXY(LCursor & cur, int x, int y);
190 void cursorUp(LCursor & cur);
192 void cursorDown(LCursor & cur);
194 void cursorLeft(LCursor & cur);
196 void cursorRight(LCursor & cur);
198 void cursorLeftOneWord(LCursor & cur);
200 void cursorRightOneWord(LCursor & cur);
202 void cursorUpParagraph(LCursor & cur);
204 void cursorDownParagraph(LCursor & cur);
206 void cursorHome(LCursor & cur);
208 void cursorEnd(LCursor & cur);
210 void cursorPrevious(LCursor & cur);
212 void cursorNext(LCursor & cur);
214 void cursorTop(LCursor & cur);
216 void cursorBottom(LCursor & cur);
218 void Delete(LCursor & cur);
220 void backspace(LCursor & cur);
222 bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
228 text_capitalization = 1,
232 /// Change the case of the word at cursor position.
233 void changeCase(LCursor & cur, TextCase action);
235 bool toggleInset(LCursor & cur);
237 /** the DTP switches for paragraphs. LyX will store the top settings
238 always in the first physical paragraph, the bottom settings in the
239 last. When a paragraph is broken, the top settings rest, the bottom
240 settings are given to the new one.
242 void setParagraph(LCursor & cur,
243 Spacing const & spacing,
245 std::string const & labelwidthstring,
248 /* these things are for search and replace */
250 /// needed to insert the selection
251 void insertStringAsLines(LCursor & cur, std::string const & str);
252 /// needed to insert the selection
253 void insertStringAsParagraphs(LCursor & cur, std::string const & str);
255 /// Find next inset of some specified type.
256 bool gotoNextInset(LCursor & cur,
257 std::vector<InsetOld_code> const & codes,
258 std::string const & contents = std::string());
260 void gotoInset(LCursor & cur,
261 std::vector<InsetOld_code> const & codes, bool same_content);
263 void gotoInset(LCursor & cur, InsetOld_code code, bool same_content);
265 /// current text width
268 /// current text heigth
271 /// updates all counters
272 void updateCounters();
273 /// Returns an inset if inset was hit, or 0 if not.
274 InsetBase * checkInsetHit(int x, int y);
277 int singleWidth(par_type pit, pos_type pos) const;
279 int singleWidth(par_type pit,
280 pos_type pos, char c, LyXFont const & Font) const;
282 /// return the color of the canvas
283 LColor_color backgroundColor() const;
286 * Returns the left beginning of the text.
287 * This information cannot be taken from the layout object, because
288 * in LaTeX the beginning of the text fits in some cases
289 * (for example sections) exactly the label-width.
291 int leftMargin(par_type pit, pos_type pos) const;
292 int leftMargin(par_type pit) const;
294 int rightMargin(Paragraph const & par) const;
296 /** this calculates the specified parameters. needed when setting
297 * the cursor and when creating a visible row */
298 RowMetrics computeRowMetrics(par_type pit, Row const & row) const;
300 /// access to our paragraphs
301 ParagraphList & paragraphs() const;
302 /// return true if this is the main text
303 bool isMainText() const;
305 /// return first row of text
306 RowList::iterator firstRow() const;
307 /// return last row of text
308 RowList::iterator lastRow() const;
309 /// return row "behind" last row of text
310 RowList::iterator endRow() const;
311 /// return next row crossing paragraph boundaries
312 void nextRow(par_type & pit, RowList::iterator & rit) const;
313 /// return previous row crossing paragraph boundaries
314 void previousRow(par_type & pit, RowList::iterator & rit) const;
316 /// is this row the last in the text?
317 bool isLastRow(par_type pit, Row const & row) const;
318 /// is this row the first in the text?
319 bool isFirstRow(par_type pit, Row const & row) const;
322 double spacing(Paragraph const & par) const;
323 /// make a suggestion for a label
324 std::string getPossibleLabel(LCursor & cur) const;
325 /// is this paragraph right-to-left?
326 bool isRTL(Paragraph const & par) const;
328 bool checkAndActivateInset(LCursor & cur, bool front);
331 void write(Buffer const & buf, std::ostream & os) const;
332 /// returns whether we've seen our usual 'end' marker
333 bool read(Buffer const & buf, LyXLex & lex);
340 int cursorX(CursorSlice const & cursor) const;
342 int cursorY(CursorSlice const & cursor) const;
345 friend class LyXScreen;
354 /// the current font settings
355 LyXFont current_font;
357 LyXFont real_current_font;
358 /// our buffer's default layout font
359 LyXFont defaultfont_;
361 int background_color_;
363 /// only the top-level LyXText has this non-zero
364 BufferView * bv_owner;
371 /// absolute document pixel coordinates of this LyXText
375 /// our 'outermost' Font
379 /// return past-the-last paragraph influenced by a layout
381 par_type undoSpan(par_type pit);
383 /// rebreaks the given par
384 void redoParagraphInternal(par_type pit);
385 /// used in setlayout
386 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
388 /// Calculate and set the height of the row
389 void setHeightOfRow(par_type, Row & row);
391 // fix the cursor `cur' after a characters has been deleted at `where'
392 // position. Called by deleteEmptyParagraphMechanism
393 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
395 /// delete double space or empty paragraphs around old cursor
396 bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
399 void setCounter(Buffer const &, par_type pit);
401 void deleteWordForward(LCursor & cur);
403 void deleteWordBackward(LCursor & cur);
405 void deleteLineForward(LCursor & cur);
407 /// sets row.end to the pos value *after* which a row should break.
408 /// for example, the pos after which isNewLine(pos) == true
409 void rowBreakPoint(par_type pit, Row & row) const;
410 /// sets row.width to the minimum space a row needs on the screen in pixel
411 void setRowWidth(par_type pit, Row & row) const;
412 /// the minimum space a manual label needs on the screen in pixels
413 int labelFill(par_type pit, Row const & row) const;
415 int labelEnd(par_type pit) const;
419 /// set 'number' font property
420 void number(LCursor & cur);
423 /// return the default height of a row in pixels, considering font zoom
424 int defaultRowHeight();
427 std::string expandLabel(LyXTextClass const & textclass,
428 LyXLayout_ptr const & layout, bool appendix);