2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-2000 The LyX Team.
10 * ====================================================== */
21 #include "lyxcursor.h"
22 #include "lyxparagraph.h"
33 This class holds the mapping between buffer paragraphs and screen rows.
44 NEED_VERY_LITTLE_REFRESH,
50 LyXText(BufferView *);
57 void init(BufferView *);
59 mutable int number_of_rows;
63 mutable unsigned int width;
64 /// the current font settings
65 mutable LyXFont current_font;
67 mutable LyXFont real_current_font;
68 /// first visible pixel-row is set from LyXScreen!!!
71 BufferView * bv_owner;
73 InsetText * inset_owner;
75 UpdatableInset * the_locking_inset;
78 LyXFont const GetFont(Buffer const *, LyXParagraph * par,
79 LyXParagraph::size_type pos) const;
81 void SetCharFont(Buffer const *, LyXParagraph * par,
82 LyXParagraph::size_type pos,
83 LyXFont const & font);
84 /// returns a pointer to the very first LyXParagraph
85 LyXParagraph * FirstParagraph() const;
87 /// what you expect when pressing <enter> at cursor position
88 void BreakParagraph(BufferView *, char keep_layout = 0);
90 /** set layout over selection and make a total rebreak of
93 LyXParagraph * SetLayout(BufferView *, LyXCursor & actual_cursor,
94 LyXCursor & selection_start,
95 LyXCursor & selection_end,
96 LyXTextClass::size_type layout);
97 void SetLayout(BufferView *, LyXTextClass::size_type layout);
100 void MakeFontEntriesLayoutSpecific(Buffer const *, LyXParagraph * par);
102 /** increment depth over selection and make a total rebreak of those
105 void IncDepth(BufferView *);
107 /** decrement depth over selection and make a total rebreak of those
109 void DecDepth(BufferView *);
111 /** Get the depth at current cursor position
113 int GetDepth() const { return cursor.par()->GetDepth(); }
115 /** set font over selection and make a total rebreak of those
117 toggleall defaults to false.
119 void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
121 /** deletes and inserts again all paragaphs between the cursor
122 and the specified par. The Cursor is needed to set the refreshing
124 This function is needed after SetLayout and SetFont etc.
126 void RedoParagraphs(BufferView *, LyXCursor const & cursor,
127 LyXParagraph const * end_par) const;
129 void RedoParagraph(BufferView *) const;
132 void ToggleFree(BufferView *, LyXFont const &, bool toggleall = false);
134 /** recalculates the heights of all previous rows of the
135 specified paragraph. needed, if the last characters font
138 void RedoHeightOfParagraph(BufferView *, LyXCursor const & cursor);
140 /** forces the redrawing of a paragraph. Needed when manipulating a
143 void RedoDrawingOfParagraph(BufferView *, LyXCursor const & cursor);
145 /** insert a character, moves all the following breaks in the
146 same Paragraph one to the right and make a little rebreak
148 void InsertChar(BufferView *, char c);
150 void InsertInset(BufferView *, Inset * inset);
152 /** Completes the insertion with a full rebreak.
153 Returns true if something was broken. */
154 bool FullRebreak(BufferView *);
158 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
161 Row * need_break_row;
163 mutable int refresh_y;
171 mutable Row * refresh_row;
175 /** wether the screen needs a refresh,
176 starting with refresh_y
178 mutable text_status status;
180 /** returns a pointer to the row near the specified y-coordinate
181 (relative to the whole text). y is set to the real beginning
184 Row * GetRowNearY(int & y) const;
186 /** returns the column near the specified x-coordinate of the row
187 x is set to the real beginning of this column
189 int GetColumnNearX(BufferView *, Row * row,
190 int & x, bool & boundary) const;
192 /** returns a pointer to a specified row. y is set to the beginning
195 Row * GetRow(LyXParagraph * par,
196 LyXParagraph::size_type pos, int & y) const;
198 /** returns the height of a default row, needed for scrollbar
200 int DefaultHeight() const;
203 Later this variable has to be removed. There should be now internal
204 cursor in a text (and thus not in a buffer). By keeping this it is
205 (I think) impossible to have several views with the same buffer, but
206 the cursor placed at different places.
208 Since the LyXText now has been moved from Buffer to BufferView
209 it should not be absolutely needed to move the cursor...
211 mutable LyXCursor cursor;
213 /* the selection cursor */
215 mutable bool selection;
217 mutable bool mark_set;
220 mutable LyXCursor sel_cursor;
222 LyXCursor sel_start_cursor;
224 mutable LyXCursor sel_end_cursor;
225 /// needed for the toggling
226 LyXCursor last_sel_cursor;
228 LyXCursor toggle_cursor;
230 LyXCursor toggle_end_cursor;
232 /// need the selection cursor:
235 void ClearSelection() const;
237 string const selectionAsString(Buffer const *) const;
239 /// just selects the word the cursor is in
240 void SelectWord(BufferView *);
242 /** 'selects" the next word, where the cursor is not in
243 and returns this word as string. THe cursor will be moved
244 to the beginning of this word.
245 With SelectSelectedWord can this be highlighted really
247 string const SelectNextWord(BufferView *, float & value) const;
249 void SelectSelectedWord(BufferView *);
251 void SetCursor(BufferView *, LyXParagraph * par,
252 LyXParagraph::size_type pos,
254 bool boundary = false) const;
256 void SetCursor(BufferView *, LyXCursor &, LyXParagraph * par,
257 LyXParagraph::size_type pos,
258 bool boundary = false) const;
260 void SetCursorIntern(BufferView *, LyXParagraph * par,
261 LyXParagraph::size_type pos,
263 bool boundary = false) const;
265 void SetCurrentFont(BufferView *) const;
268 bool IsBoundary(Buffer const *, LyXParagraph * par,
269 LyXParagraph::size_type pos) const;
271 bool IsBoundary(Buffer const *, LyXParagraph * par,
272 LyXParagraph::size_type pos,
273 LyXFont const & font) const;
276 void SetCursorFromCoordinates(BufferView *, int x, int y) const;
278 void SetCursorFromCoordinates(BufferView *, LyXCursor &,
281 void CursorUp(BufferView *) const;
283 void CursorDown(BufferView *) const;
285 void CursorLeft(BufferView *, bool internal = true) const;
287 void CursorRight(BufferView *, bool internal = true) const;
289 void CursorLeftOneWord(BufferView *) const;
291 void CursorRightOneWord(BufferView *) const;
293 void CursorUpParagraph(BufferView *) const;
295 void CursorDownParagraph(BufferView *) const;
297 void CursorHome(BufferView *) const;
299 void CursorEnd(BufferView *) const;
301 void CursorTab(BufferView *) const;
303 void CursorTop(BufferView *) const;
305 void CursorBottom(BufferView *) const;
307 void Delete(BufferView *);
309 void Backspace(BufferView *);
311 void DeleteWordForward(BufferView *);
313 void DeleteWordBackward(BufferView *);
315 void DeleteLineForward(BufferView *);
317 bool SelectWordWhenUnderCursor(BufferView *);
323 text_capitalization = 1,
327 /// Change the case of the word at cursor position.
328 void ChangeWordCase(BufferView *, TextCase action);
330 /** returns a printed row in a pixmap. The y value is needed to
331 decide, wether it is selected text or not. This is a strange
334 void GetVisibleRow(BufferView *, int y_offset, int x_offset,
335 Row * row_ptr, int y, bool cleared=false);
340 void ToggleFootnote(BufferView *);
342 void OpenStuff(BufferView *);
344 void OpenFootnotes();
346 void OpenFootnote(BufferView *);
348 void CloseFootnotes();
350 void CloseFootnote(BufferView *);
352 /** turn the selection into a new environment. If there is no
353 selection, create an empty environment
355 void InsertFootnoteEnvironment(BufferView *,
356 LyXParagraph::footnote_kind kind);
358 void MeltFootnoteEnvironment(BufferView *);
361 void CutSelection(BufferView *, bool = true);
363 void CopySelection(BufferView *);
365 void PasteSelection(BufferView *);
367 void copyEnvironmentType();
369 void pasteEnvironmentType(BufferView *);
371 void InsertFootnote();
373 void InsertMarginpar();
377 void InsertTabular();
379 /** the DTP switches for paragraphs. LyX will store the top settings
380 always in the first physical paragraph, the bottom settings in the
381 last. When a paragraph is broken, the top settings rest, the bottom
382 settings are given to the new one. So I can make shure, they do not
383 duplicate themself (and you cannnot make dirty things with them! )
385 void SetParagraph(BufferView *,
386 bool line_top, bool line_bottom,
387 bool pagebreak_top, bool pagebreak_bottom,
388 VSpace const & space_top,
389 VSpace const & space_bottom,
391 string labelwidthstring,
394 void SetParagraphExtraOpt(BufferView *, int type,
395 string const & width,
396 string const & widthp,
397 int alignment, bool hfill,
398 bool start_minipage);
400 /* these things are for search and replace */
402 /** returns true if the specified string is at the specified
405 bool IsStringInText(LyXParagraph * par,
406 LyXParagraph::size_type pos,
407 string const & str) const;
408 /** sets the selection over the number of characters of string,
411 void SetSelectionOverString(BufferView *, string const & str);
413 /** simple replacing. The font of the first selected character
416 void ReplaceSelectionWithString(BufferView *, string const & str);
418 /** if the string can be found: return true and set the cursor to
420 bool SearchForward(BufferView *, string const & str) const;
422 bool SearchBackward(BufferView *, string const & str) const;
424 /// needed to insert the selection
425 void InsertStringA(BufferView *, string const & str);
426 /// needed to insert the selection
427 void InsertStringB(BufferView *, string const & str);
429 /// usefull when texing from within LyX
430 bool GotoNextError(BufferView *) const;
432 /// just another feature :)
433 bool GotoNextNote(BufferView *) const;
435 /* for the greater insets */
437 /// returns false if inset wasn't found
438 bool UpdateInset(BufferView *, Inset *);
440 void CheckParagraph(BufferView *, LyXParagraph * par,
441 LyXParagraph::size_type pos);
443 int NumberOfCell(LyXParagraph * par,
444 LyXParagraph::size_type pos) const;
446 LyXParagraph * GetParFromID(int id);
449 /// returns false if no undo possible
450 bool TextUndo(BufferView *);
451 /// returns false if no redo possible
452 bool TextRedo(BufferView *);
453 /// used by TextUndo/TextRedo
454 bool TextHandleUndo(BufferView *, Undo * undo);
455 /// makes sure the next operation will be stored
457 /// this is dangerous and for internal use only
459 /// this is dangerous and for internal use only
461 /// the flag used by FinishUndo();
462 mutable bool undo_finished;
466 void SetUndo(Buffer *, Undo::undo_kind kind,
467 LyXParagraph const * before,
468 LyXParagraph const * end) const;
470 void SetRedo(Buffer *, Undo::undo_kind kind,
471 LyXParagraph const * before,
472 LyXParagraph const * end);
474 Undo * CreateUndo(Buffer *, Undo::undo_kind kind,
475 LyXParagraph const * before,
476 LyXParagraph const * end) const;
477 /// for external use in lyx_cb.C
478 void SetCursorParUndo(Buffer *);
480 void RemoveTableRow(LyXCursor & cursor) const;
482 bool IsEmptyTableCell() const;
484 void toggleAppendix(BufferView *);
486 int workWidth(BufferView *) const;
488 void ComputeBidiTables(Buffer const *, Row * row) const;
490 /// Maps positions in the visual string to positions in logical string.
492 LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const {
493 if (bidi_start == -1)
496 return log2vis_list[pos-bidi_start];
499 /// Maps positions in the logical string to positions in visual string.
501 LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
502 if (bidi_start == -1)
505 return vis2log_list[pos-bidi_start];
509 int bidi_level(LyXParagraph::size_type pos) const {
510 if (bidi_start == -1)
513 return bidi_levels[pos-bidi_start];
517 bool bidi_InRange(LyXParagraph::size_type pos) const {
518 return bidi_start == -1 ||
519 (bidi_start <= pos && pos <= bidi_end);
525 mutable Row * firstrow;
527 mutable Row * lastrow;
529 /** Copybuffer for copy environment type.
530 Asger has learned that this should be a buffer-property instead
531 Lgb has learned that 'char' is a lousy type for non-characters
533 LyXTextClass::size_type copylayouttype;
535 /** inserts a new row behind the specified row, increments
536 the touched counters */
537 void InsertRow(Row * row, LyXParagraph * par,
538 LyXParagraph::size_type pos) const;
539 /** removes the row and reset the touched counters */
540 void RemoveRow(Row * row) const;
542 /** remove all following rows of the paragraph of the specified row. */
543 void RemoveParagraph(Row * row) const;
545 /** insert the specified paragraph behind the specified row */
546 void InsertParagraph(BufferView *,
547 LyXParagraph * par, Row * row) const;
549 /** appends the implizit specified paragraph behind the specified row,
550 * start at the implizit given position */
551 void AppendParagraph(BufferView *, Row * row) const;
554 void BreakAgain(BufferView *, Row * row) const;
556 void BreakAgainOneRow(BufferView *, Row * row);
557 /// Calculate and set the height of the row
558 void SetHeightOfRow(BufferView *, Row * row_ptr) const;
560 /** this calculates the specified parameters. needed when setting
561 * the cursor and when creating a visible row */
562 void PrepareToPrint(BufferView *, Row * row, float & x,
563 float & fill_separator,
565 float & fill_label_hfill,
566 bool bidi = true) const;
569 void DeleteEmptyParagraphMechanism(BufferView *,
570 LyXCursor const & old_cursor) const;
572 /** Updates all counters starting BEHIND the row. Changed paragraphs
573 * with a dynamic left margin will be rebroken. */
574 void UpdateCounters(BufferView *, Row * row) const;
576 void SetCounter(Buffer const *, LyXParagraph * par) const;
579 * some low level functions
583 int SingleWidth(BufferView *, LyXParagraph * par,
584 LyXParagraph::size_type pos) const;
586 int SingleWidth(BufferView *, LyXParagraph * par,
587 LyXParagraph::size_type pos, char c) const;
589 void draw(BufferView *, Row const * row,
590 LyXParagraph::size_type & pos,
591 int offset, float & x, bool cleared);
593 /// get the next breakpoint in a given paragraph
594 LyXParagraph::size_type NextBreakPoint(BufferView *, Row const * row,
596 /// returns the minimum space a row needs on the screen in pixel
597 int Fill(BufferView *, Row * row, int workwidth) const;
599 /** returns the minimum space a manual label needs on the
601 int LabelFill(BufferView *, Row const * row) const;
604 LyXParagraph::size_type
605 BeginningOfMainBody(Buffer const *, LyXParagraph const * par) const;
607 /** Returns the left beginning of the text.
608 This information cannot be taken from the layouts-objekt, because
609 in LaTeX the beginning of the text fits in some cases
610 (for example sections) exactly the label-width.
612 int LeftMargin(BufferView *, Row const * row) const;
614 int RightMargin(Buffer const *, Row const * row) const;
616 int LabelEnd (BufferView *, Row const * row) const;
618 /** returns the number of separators in the specified row.
619 The separator on the very last column doesnt count
621 int NumberOfSeparators(Buffer const *, Row const * row) const;
623 /** returns the number of hfills in the specified row. The
624 LyX-Hfill is a LaTeX \hfill so that the hfills at the
625 beginning and at the end were ignored. This is {\em MUCH}
626 more usefull than not to ignore!
628 int NumberOfHfills(Buffer const *, Row const * row) const;
630 /// like NumberOfHfills, but only those in the manual label!
631 int NumberOfLabelHfills(Buffer const *, Row const * row) const;
632 /** returns true, if a expansion is needed. Rules are given by
635 bool HfillExpansion(Buffer const *, Row const * row_ptr,
636 LyXParagraph::size_type pos) const;
640 mutable std::vector<LyXParagraph::size_type> log2vis_list;
643 mutable std::vector<LyXParagraph::size_type> vis2log_list;
646 mutable std::vector<LyXParagraph::size_type> bidi_levels;
649 mutable LyXParagraph::size_type bidi_start;
652 mutable LyXParagraph::size_type bidi_end;
655 mutable bool bidi_same_direction;
658 unsigned char TransformChar(unsigned char c, LyXParagraph * par,
659 LyXParagraph::size_type pos) const;
661 /** returns the paragraph position of the last character in the
664 LyXParagraph::size_type RowLast(Row const * row) const;
666 LyXParagraph::size_type RowLastPrintable(Row const * row) const;
671 // special owner functions
673 LyXParagraph * OwnerParagraph() const;
675 LyXParagraph * OwnerParagraph(LyXParagraph *) const;