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"
32 This class holds the mapping between buffer paragraphs and screen rows.
43 NEED_VERY_LITTLE_REFRESH
54 LyXText(BufferView *, int paperwidth, Buffer *);
59 /// points to Buffer.params
60 //BufferParams * bparams;
64 mutable int number_of_rows;
67 /// the current font settings
68 mutable LyXFont current_font;
70 mutable LyXFont real_current_font;
73 void owner(BufferView *);
76 LyXFont GetFont(LyXParagraph * par,
77 LyXParagraph::size_type pos) const;
79 void SetCharFont(LyXParagraph * par,
80 LyXParagraph::size_type pos,
81 LyXFont const & font);
82 /// returns a pointer to the very first LyXParagraph
83 LyXParagraph * FirstParagraph() const;
85 /// what you expect when pressing <enter> at cursor position
86 void BreakParagraph(char keep_layout = 0);
88 /** set layout over selection and make a total rebreak of
91 LyXParagraph * SetLayout(LyXCursor & actual_cursor,
92 LyXCursor & selection_start,
93 LyXCursor & selection_end,
94 LyXTextClass::size_type layout);
95 void SetLayout(LyXTextClass::size_type layout);
98 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
100 /** increment depth over selection and make a total rebreak of those
105 /** decrement depth over selection and make a total rebreak of those
109 /** Get the depth at current cursor position
111 int GetDepth() const { return cursor.par->GetDepth(); }
113 /** set font over selection and make a total rebreak of those
115 toggleall defaults to false.
117 void SetFont(LyXFont const & font, bool toggleall = false);
119 /** deletes and inserts again all paragaphs between the cursor
120 and the specified par. The Cursor is needed to set the refreshing
122 This function is needed after SetLayout and SetFont etc.
124 void RedoParagraphs(LyXCursor const & cursor,
125 LyXParagraph const * end_par) const;
127 void RedoParagraph() const;
130 void ToggleFree(LyXFont const & font, bool toggleall = false);
132 /** recalculates the heights of all previous rows of the
133 specified paragraph. needed, if the last characters font
136 void RedoHeightOfParagraph(LyXCursor const & cursor);
138 /** forces the redrawing of a paragraph. Needed when manipulating a
141 void RedoDrawingOfParagraph(LyXCursor const & cursor);
143 /** insert a character, moves all the following breaks in the
144 same Paragraph one to the right and make a little rebreak
146 void InsertChar(char c);
148 void InsertInset(Inset * inset);
150 /** Completes the insertion with a full rebreak.
151 Returns true if something was broken. */
155 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
157 Row * need_break_row;
159 mutable long refresh_y;
167 mutable Row * refresh_row;
171 /** wether the screen needs a refresh,
172 starting with refresh_y
174 mutable text_status status;
176 /** returns a pointer to the row near the specified y-coordinate
177 (relative to the whole text). y is set to the real beginning
180 Row * GetRowNearY(long & y) const;
182 /** returns the column near the specified x-coordinate of the row
183 x is set to the real beginning of this column
185 int GetColumnNearX(Row * row, int & x, bool & boundary) const;
187 /** returns a pointer to a specified row. y is set to the beginning
190 Row * GetRow(LyXParagraph * par,
191 LyXParagraph::size_type pos, long & y) const;
192 /** returns the height of a default row, needed for scrollbar
194 int DefaultHeight() const;
197 Later this variable has to be removed. There should be now internal
198 cursor in a text (and thus not in a buffer). By keeping this it is
199 (I think) impossible to have several views with the same buffer, but
200 the cursor placed at different places.
202 Since the LyXText now has been moved from Buffer to BufferView
203 it should not be absolutely needed to move the cursor...
205 mutable LyXCursor cursor;
207 /* the selection cursor */
209 mutable bool selection;
211 mutable bool mark_set;
214 mutable LyXCursor sel_cursor;
216 LyXCursor sel_start_cursor;
218 mutable LyXCursor sel_end_cursor;
219 /// needed for the toggling
220 LyXCursor last_sel_cursor;
222 LyXCursor toggle_cursor;
224 LyXCursor toggle_end_cursor;
226 /// need the selection cursor:
229 void ClearSelection() const;
231 string selectionAsString() const;
233 /// just selects the word the cursor is in
236 /** 'selects" the next word, where the cursor is not in
237 and returns this word as string. THe cursor will be moved
238 to the beginning of this word.
239 With SelectSelectedWord can this be highlighted really
241 char * SelectNextWord(float & value);
243 void SelectSelectedWord();
245 void SetCursor(LyXParagraph * par,
246 LyXParagraph::size_type pos,
248 bool boundary = false) const;
250 void SetCursor(LyXCursor &, LyXParagraph * par,
251 LyXParagraph::size_type pos,
252 bool boundary = false) const;
254 void SetCursorIntern(LyXParagraph * par,
255 LyXParagraph::size_type pos,
257 bool boundary = false) const;
259 void SetCurrentFont() const;
262 bool IsBoundary(LyXParagraph * par,
263 LyXParagraph::size_type pos) const;
265 bool IsBoundary(LyXParagraph * par,
266 LyXParagraph::size_type pos,
267 LyXFont const & font) const;
270 void SetCursorFromCoordinates(int x, long y) const;
271 void SetCursorFromCoordinates(LyXCursor &, int x, long y) const;
273 void CursorUp() const;
275 void CursorDown() const;
277 void CursorLeft(bool internal = true) const;
279 void CursorRight(bool internal = true) const;
281 void CursorLeftIntern(bool internal = true) const;
283 void CursorRightIntern(bool internal = true) const;
285 void CursorLeftOneWord() const;
287 void CursorRightOneWord() const;
289 void CursorUpParagraph() const;
291 void CursorDownParagraph() const;
293 void CursorHome() const;
295 void CursorEnd() const;
297 void CursorTab() const;
299 void CursorTop() const;
301 void CursorBottom() const;
307 void DeleteWordForward();
309 void DeleteWordBackward();
311 void DeleteLineForward();
313 bool SelectWordWhenUnderCursor();
317 text_capitalization = 1,
320 /// Change the case of the word at cursor position.
321 void ChangeWordCase(TextCase action);
323 /** returns a printed row in a pixmap. The y value is needed to
324 decide, wether it is selected text or not. This is a strange
327 void GetVisibleRow(int offset, Row * row_ptr, long y);
331 void ToggleFootnote();
335 void OpenFootnotes();
339 void CloseFootnotes();
341 void CloseFootnote();
343 /** turn the selection into a new environment. If there is no
344 selection, create an empty environment
346 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
348 void MeltFootnoteEnvironment();
350 void CutSelection(bool = true);
352 void CopySelection();
354 void PasteSelection();
356 void copyEnvironmentType();
358 void pasteEnvironmentType();
360 void InsertFootnote();
362 void InsertMarginpar();
366 void InsertTabular();
368 /** the DTP switches for paragraphs. LyX will store the top settings
369 always in the first physical paragraph, the bottom settings in the
370 last. When a paragraph is broken, the top settings rest, the bottom
371 settings are given to the new one. So I can make shure, they do not
372 duplicate themself (and you cannnot make dirty things with them! )
374 void SetParagraph(bool line_top, bool line_bottom,
375 bool pagebreak_top, bool pagebreak_bottom,
376 VSpace const & space_top,
377 VSpace const & space_bottom,
379 string labelwidthstring,
381 void SetParagraphExtraOpt(int type,
384 int alignment, bool hfill,
385 bool start_minipage);
387 /* these things are for search and replace */
389 /** returns true if the specified string is at the specified
392 bool IsStringInText(LyXParagraph * par,
393 LyXParagraph::size_type pos,
394 char const * str) const;
395 /** sets the selection over the number of characters of string,
398 void SetSelectionOverString(char const * str);
400 /** simple replacing. The font of the first selected character
403 void ReplaceSelectionWithString(char const * str);
405 /** if the string can be found: return true and set the cursor to
407 bool SearchForward(char const * str) const;
408 bool SearchBackward(char const * str) const;
410 /// needed to insert the selection
411 void InsertStringA(string const & str);
412 /// needed to insert the selection
413 void InsertStringB(string const & str);
415 /// usefull when texing from within LyX
416 bool GotoNextError() const;
418 /// just another feature :)
419 bool GotoNextNote() const;
421 /* for the greater insets */
423 /// returns 0 if inset wasn't found
424 int UpdateInset(Inset * inset);
426 void CheckParagraph(LyXParagraph * par,
427 LyXParagraph::size_type pos);
429 int NumberOfCell(LyXParagraph * par,
430 LyXParagraph::size_type pos) const;
431 /* table stuff -- begin*/
433 /** all table features of the text-class are put together in
434 this function. Possible values of feature are defined in table.h
436 void TableFeatures(int feature, string const & val) const;
438 void TableFeatures(int feature) const;
440 /** pos points at the beginning of the next cell (if there is one)
442 int WidthOfCell(LyXParagraph * par,
443 LyXParagraph::size_type & pos) const;
445 void CheckParagraphInTable(LyXParagraph * par,
446 LyXParagraph::size_type pos);
448 void InsertCharInTable(char c);
450 void BackspaceInTable();
452 bool HitInTable(Row * row, int x) const;
454 bool MouseHitInTable(int x, long y) const;
455 /* table stuff -- end*/
457 LyXParagraph * GetParFromID(int id);
460 /// returns false if no undo possible
462 /// returns false if no redo possible
464 /// used by TextUndo/TextRedo
465 bool TextHandleUndo(Undo * undo);
466 /// makes sure the next operation will be stored
468 /// this is dangerous and for internal use only
470 /// this is dangerous and for internal use only
472 /// the flag used by FinishUndo();
473 mutable bool undo_finished;
477 void SetUndo(Undo::undo_kind kind,
478 LyXParagraph const * before,
479 LyXParagraph const * end) const;
481 void SetRedo(Undo::undo_kind kind,
482 LyXParagraph const * before,
483 LyXParagraph const * end);
485 Undo * CreateUndo(Undo::undo_kind kind,
486 LyXParagraph const * before,
487 LyXParagraph const * end) const;
488 /// for external use in lyx_cb.C
489 void SetCursorParUndo();
491 void RemoveTableRow(LyXCursor * cursor) const;
493 bool IsEmptyTableCell() const;
495 void toggleAppendix();
497 unsigned short paperWidth() const { return paperwidth; }
500 void ComputeBidiTables(Row *row) const;
502 /// Maps positions in the visual string to positions in logical string.
504 LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const {
505 if (bidi_start == -1)
508 return log2vis_list[pos-bidi_start];
511 /// Maps positions in the logical string to positions in visual string.
513 LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
514 if (bidi_start == -1)
517 return vis2log_list[pos-bidi_start];
521 int bidi_level(LyXParagraph::size_type pos) const {
522 if (bidi_start == -1)
525 return bidi_levels[pos-bidi_start];
529 bool bidi_InRange(LyXParagraph::size_type pos) const {
530 return bidi_start == -1 ||
531 (bidi_start <= pos && pos <= bidi_end);
537 /// width of the paper
538 unsigned short paperwidth;
541 mutable Row * firstrow;
543 mutable Row * lastrow;
545 /** Copybuffer for copy environment type
546 Asger has learned that this should be a buffer-property instead
547 Lgb has learned that 'char' is a lousy type for non-characters
549 LyXTextClass::size_type copylayouttype;
551 /** inserts a new row behind the specified row, increments
552 * the touched counters */
553 void InsertRow(Row * row, LyXParagraph * par,
554 LyXParagraph::size_type pos) const;
555 /** removes the row and reset the touched counters */
556 void RemoveRow(Row * row) const;
558 /** remove all following rows of the paragraph of the specified row. */
559 void RemoveParagraph(Row * row) const;
561 /** insert the specified paragraph behind the specified row */
562 void InsertParagraph(LyXParagraph * par, Row * row) const;
564 /** appends the implizit specified paragraph behind the specified row,
565 * start at the implizit given position */
566 void AppendParagraph(Row * row) const;
569 void BreakAgain(Row * row) const;
571 void BreakAgainOneRow(Row * row);
572 /// Calculate and set the height of the row
573 void SetHeightOfRow(Row * row_ptr) const;
575 /** this calculates the specified parameters. needed when setting
576 * the cursor and when creating a visible row */
577 void PrepareToPrint(Row * row, float & x,
578 float & fill_separator,
580 float & fill_label_hfill,
581 bool bidi = true) const;
584 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
586 /** Updates all counters starting BEHIND the row. Changed paragraphs
587 * with a dynamic left margin will be rebroken. */
588 void UpdateCounters(Row * row) const;
590 void SetCounter(LyXParagraph * par) const;
593 * some low level functions
597 int SingleWidth(LyXParagraph * par,
598 LyXParagraph::size_type pos) const;
600 int SingleWidth(LyXParagraph * par,
601 LyXParagraph::size_type pos, char c) const;
603 void draw(Row const * row,
604 LyXParagraph::size_type & pos,
605 int offset, float & x);
607 /// get the next breakpoint in a given paragraph
608 LyXParagraph::size_type NextBreakPoint(Row const * row,
610 /// returns the minimum space a row needs on the screen in pixel
611 int Fill(Row const * row, int paperwidth) const;
613 /** returns the minimum space a manual label needs on the
615 int LabelFill(Row const * row) const;
618 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
620 /** Returns the left beginning of the text.
621 This information cannot be taken from the layouts-objekt, because
622 in LaTeX the beginning of the text fits in some cases
623 (for example sections) exactly the label-width.
625 int LeftMargin(Row const * row) const;
627 int RightMargin(Row const * row) const;
629 int LabelEnd (Row const * row) const;
631 /** returns the number of separators in the specified row.
632 The separator on the very last column doesnt count
634 int NumberOfSeparators(Row const * row) const;
636 /** returns the number of hfills in the specified row. The
637 LyX-Hfill is a LaTeX \hfill so that the hfills at the
638 beginning and at the end were ignored. This is {\em MUCH}
639 more usefull than not to ignore!
641 int NumberOfHfills(Row const * row) const;
643 /// like NumberOfHfills, but only those in the manual label!
644 int NumberOfLabelHfills(Row const * row) const;
645 /** returns true, if a expansion is needed. Rules are given by
648 bool HfillExpansion(Row const * row_ptr,
649 LyXParagraph::size_type pos) const;
653 mutable std::vector<LyXParagraph::size_type> log2vis_list;
656 mutable std::vector<LyXParagraph::size_type> vis2log_list;
659 mutable std::vector<LyXParagraph::size_type> bidi_levels;
662 mutable LyXParagraph::size_type bidi_start;
665 mutable LyXParagraph::size_type bidi_end;
668 mutable bool bidi_same_direction;
671 unsigned char TransformChar(unsigned char c, Letter_Form form) const;
674 unsigned char TransformChar(unsigned char c, LyXParagraph * par,
675 LyXParagraph::size_type pos) const;
677 /** returns the paragraph position of the last character in the
680 LyXParagraph::size_type RowLast(Row const * row) const;
682 LyXParagraph::size_type RowLastPrintable(Row const * row) const;