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 "ParagraphList_fwd.h"
24 #include "RowList_fwd.h"
48 /// This class encapsulates the main text data and operations in LyX
52 LyXText(BufferView *, bool ininset);
54 void init(BufferView *);
56 /// update y coordinate cache of all paragraphs
57 void updateParPositions();
59 LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
61 LyXFont getLayoutFont(ParagraphList::iterator pit) const;
63 LyXFont getLabelFont(ParagraphList::iterator pit) const;
65 void setCharFont(ParagraphList::iterator pit,
66 lyx::pos_type pos, LyXFont const & font);
67 void setCharFont(ParagraphList::iterator pit,
69 LyXFont const & font, bool toggleall);
71 /// what you expect when pressing <enter> at cursor position
72 void breakParagraph(LCursor & cur, char keep_layout = 0);
74 /** set layout over selection and make a total rebreak of
77 ParagraphList::iterator
78 setLayout(ParagraphList::iterator start,
79 ParagraphList::iterator end,
80 std::string const & layout);
82 void setLayout(LCursor & cur, std::string const & layout);
84 /// Increase or decrease the nesting depth of the selected paragraph(s)
85 void changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type);
87 /// Returns whether something would be changed by changeDepth
88 bool changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type);
90 /// get the depth at current cursor position
93 /// Set font over selection paragraphs and rebreak.
94 void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
96 /// rebreaks all paragaphs between the given pars.
97 void redoParagraphs(ParagraphList::iterator begin,
98 ParagraphList::iterator end);
99 /// rebreaks the given par
100 void redoParagraph(ParagraphList::iterator 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;
124 /// try to handle that request
125 DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd);
126 /// access to out BufferView. This should go...
128 /// access to out BufferView. This should go...
129 BufferView * bv() const;
131 /// returns an iterator pointing to a cursor paragraph
132 ParagraphList::iterator getPar(CursorSlice const & cursor) const;
134 ParagraphList::iterator getPar(lyx::paroffset_type par) const;
136 int parOffset(ParagraphList::iterator pit) const;
137 /// # FIXME: should not be used
138 ParagraphList::iterator cursorPar() const;
139 // Returns the current font and depth as a message.
140 std::string LyXText::currentState(LCursor & cur);
142 /** returns an iterator pointing to the row near the specified
143 * y-coordinate (relative to the whole text). y is set to the
144 * real beginning of this row
146 RowList::iterator getRowNearY(int y,
147 ParagraphList::iterator & 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 lyx::pos_type getColumnNearX(ParagraphList::iterator 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(lyx::paroffset_type par, lyx::pos_type pos,
171 bool setfont = true, bool boundary = false);
173 void setCursor(CursorSlice &, lyx::paroffset_type par,
174 lyx::pos_type pos, bool boundary = false);
176 void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
177 bool setfont = true, bool boundary = false);
179 void setCurrentFont();
182 void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
184 void recUndo(lyx::paroffset_type first) const;
186 void setCursorFromCoordinates(int x, int y);
188 void setCursorFromCoordinates(CursorSlice &, int x, int y);
190 void edit(LCursor & cur, int x, int y);
192 void cursorUp(LCursor & cur, bool selecting = false);
194 void cursorDown(LCursor & cur, bool selecting = false);
196 bool cursorLeft(LCursor & cur, bool internal = true);
198 bool cursorRight(LCursor & cur, bool internal = true);
200 void cursorLeftOneWord(LCursor & cur);
202 void cursorRightOneWord(LCursor & cur);
204 void cursorUpParagraph(LCursor & cur);
206 void cursorDownParagraph(LCursor & cur);
208 void cursorHome(LCursor & cur);
210 void cursorEnd(LCursor & cur);
212 void cursorPrevious(LCursor & cur);
214 void cursorNext(LCursor & cur);
216 void cursorTop(LCursor & cur);
218 void cursorBottom(LCursor & cur);
220 void Delete(LCursor & cur);
222 void backspace(LCursor & cur);
224 bool selectWordWhenUnderCursor(LCursor & cur, lyx::word_location);
230 text_capitalization = 1,
234 /// Change the case of the word at cursor position.
235 void changeCase(LCursor & cur, TextCase action);
238 bool toggleInset(LCursor & cur);
240 void cutSelection(bool doclear = true, bool realcut = true);
242 void copySelection();
244 void pasteSelection(LCursor & cur, size_t sel_index = 0);
246 /** the DTP switches for paragraphs. LyX will store the top settings
247 always in the first physical paragraph, the bottom settings in the
248 last. When a paragraph is broken, the top settings rest, the bottom
249 settings are given to the new one.
252 Spacing const & spacing,
254 std::string const & labelwidthstring,
257 /* these things are for search and replace */
260 * Sets the selection from the current cursor position to length
261 * characters to the right. No safety checks.
263 void setSelectionRange(LCursor & cur, lyx::pos_type length);
264 /// simply replace using the font of the first selected character
265 void replaceSelectionWithString(LCursor & cur, std::string const & str);
266 /// replace selection helper
267 void replaceSelection(LCursor & cur);
269 /// needed to insert the selection
270 void insertStringAsLines(LCursor & cur, std::string const & str);
271 /// needed to insert the selection
272 void insertStringAsParagraphs(LCursor & cur, std::string const & str);
274 /// Find next inset of some specified type.
275 bool gotoNextInset(std::vector<InsetOld_code> const & codes,
276 std::string const & contents = std::string());
278 void gotoInset(std::vector<InsetOld_code> const & codes,
281 void gotoInset(InsetOld_code code, bool same_content);
283 /// current max text width
284 int textWidth() const;
286 /// updates all counters
287 void updateCounters();
288 /// Returns an inset if inset was hit, or 0 if not.
289 InsetBase * checkInsetHit(int x, int y);
292 int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
294 int singleWidth(ParagraphList::iterator pit,
295 lyx::pos_type pos, char c, LyXFont const & Font) const;
297 /// return the color of the canvas
298 LColor_color backgroundColor() const;
301 * Returns the left beginning of the text.
302 * This information cannot be taken from the layout object, because
303 * in LaTeX the beginning of the text fits in some cases
304 * (for example sections) exactly the label-width.
306 int leftMargin(ParagraphList::iterator pit, lyx::pos_type pos) const;
307 int leftMargin(ParagraphList::iterator pit) const;
309 int rightMargin(Paragraph const & par) const;
311 /** this calculates the specified parameters. needed when setting
312 * the cursor and when creating a visible row */
313 void prepareToPrint(ParagraphList::iterator pit, Row & row) const;
315 /// access to our paragraphs
316 ParagraphList & paragraphs() const;
317 /// return true if this is owned by an inset.
318 bool isInInset() const;
320 /// return first row of text
321 RowList::iterator firstRow() const;
322 /// return last row of text
323 RowList::iterator lastRow() const;
324 /// return row "behind" last row of text
325 RowList::iterator endRow() const;
326 /// return next row crossing paragraph boundaries
327 void nextRow(ParagraphList::iterator & pit,
328 RowList::iterator & rit) const;
329 /// return previous row crossing paragraph boundaries
330 void previousRow(ParagraphList::iterator & pit,
331 RowList::iterator & rit) const;
333 /// is this row the last in the text?
334 bool isLastRow(ParagraphList::iterator pit, Row const & row) const;
335 /// is this row the first in the text?
336 bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
339 double spacing(Paragraph const &) const;
342 DispatchResult moveRight(LCursor & cur);
344 DispatchResult moveLeft(LCursor & cur);
346 DispatchResult moveRightIntern(LCursor & cur, bool front,
347 bool activate_inset, bool selecting);
349 DispatchResult moveLeftIntern(LCursor & cur, bool front,
350 bool activate_inset, bool selecting);
352 DispatchResult moveUp(LCursor & cur);
354 DispatchResult moveDown(LCursor & cur);
356 bool checkAndActivateInset(LCursor & cur, bool front);
359 void write(Buffer const & buf, std::ostream & os) const;
360 /// returns whether we've seen our usual 'end' marker
361 bool read(Buffer const & buf, LyXLex & lex);
368 int cursorX(CursorSlice const & cursor) const;
370 int cursorY(CursorSlice const & cursor) const;
372 /// the current cursor slice
373 CursorSlice & cursor();
374 /// the current cursor slice
375 CursorSlice const & cursor() const;
377 friend class LyXScreen;
386 /// the current font settings
387 LyXFont current_font;
389 LyXFont real_current_font;
390 /// our buffer's default layout font
391 LyXFont defaultfont_;
393 int background_color_;
395 /// only the top-level LyXText has this non-zero
396 BufferView * bv_owner;
403 ParagraphList paragraphs_;
405 /// absolute document pixel coordinates of this LyXText
409 /// our 'outermost' Font
414 /// return past-the-last paragraph influenced by a layout
416 ParagraphList::iterator undoSpan(ParagraphList::iterator pit);
418 /// rebreaks the given par
419 void redoParagraphInternal(ParagraphList::iterator pit);
420 /// used in setlayout
421 void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
423 /// Calculate and set the height of the row
424 void setHeightOfRow(ParagraphList::iterator, Row & row);
426 // fix the cursor `cur' after a characters has been deleted at `where'
427 // position. Called by deleteEmptyParagraphMechanism
428 void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
430 /// delete double space (false) or empty paragraphs (true) around old_cursor
431 bool deleteEmptyParagraphMechanism(CursorSlice const & old_cursor);
434 void setCounter(Buffer const &, ParagraphList::iterator pit);
436 void deleteWordForward(LCursor & cur);
438 void deleteWordBackward(LCursor & cur);
440 void deleteLineForward(LCursor & cur);
442 /// sets row.end to the pos value *after* which a row should break.
443 /// for example, the pos after which isNewLine(pos) == true
444 void rowBreakPoint(ParagraphList::iterator pit, Row & row) const;
445 /// sets row.witdh to the minimum space a row needs on the screen in pixel
446 void fill(ParagraphList::iterator pit, Row & row, int workwidth) const;
447 /// the minimum space a manual label needs on the screen in pixels
448 int labelFill(ParagraphList::iterator pit, Row const & row) const;
450 int labelEnd(ParagraphList::iterator pit) const;
454 /// set 'number' font property
456 /// is the cursor paragraph right-to-left?
460 /// return the default height of a row in pixels, considering font zoom
461 int defaultRowHeight();
464 std::string expandLabel(LyXTextClass const & textclass,
465 LyXLayout_ptr const & layout, bool appendix);