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.
46 NEED_VERY_LITTLE_REFRESH
56 /// points to Buffer.params
57 BufferParams * parameters;
61 mutable int number_of_rows;
64 /// the current font settings
65 mutable LyXFont current_font;
67 mutable LyXFont real_current_font;
70 LyXText(BufferView *, int paperwidth, Buffer *);
76 void owner(BufferView *);
79 LyXFont GetFont(LyXParagraph * par,
80 LyXParagraph::size_type pos) const;
82 void SetCharFont(LyXParagraph * par,
83 LyXParagraph::size_type pos,
84 LyXFont const & font);
85 /// returns a pointer to the very first LyXParagraph
86 LyXParagraph * FirstParagraph() const;
88 /// what you expect when pressing <enter> at cursor position
89 void BreakParagraph(char keep_layout = 0);
91 /** set layout over selection and make a total rebreak of
94 void SetLayout(LyXTextClass::size_type layout);
97 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
99 /** increment depth over selection and make a total rebreak of those
104 /** decrement depth over selection and make a total rebreak of those
108 /** Get the depth at current cursor position
110 int GetDepth() const { return cursor.par->GetDepth(); }
112 /** set font over selection and make a total rebreak of those
114 toggleall defaults to false.
116 void SetFont(LyXFont const & font, bool toggleall = false);
118 /** deletes and inserts again all paragaphs between the cursor
119 and the specified par. The Cursor is needed to set the refreshing
121 This function is needed after SetLayout and SetFont etc.
123 void RedoParagraphs(LyXCursor const & cursor,
124 LyXParagraph const * end_par) const;
126 void RedoParagraph() const;
129 void ToggleFree(LyXFont const & font, bool toggleall = false);
131 /** recalculates the heights of all previous rows of the
132 specified paragraph. needed, if the last characters font
135 void RedoHeightOfParagraph(LyXCursor const & cursor);
137 /** forces the redrawing of a paragraph. Needed when manipulating a
140 void RedoDrawingOfParagraph(LyXCursor const & cursor);
142 /** insert a character, moves all the following breaks in the
143 same Paragraph one to the right and make a little rebreak
145 void InsertChar(char c);
147 void InsertInset(Inset * inset);
149 /// completes the insertion with a full rebreak
153 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
155 Row * need_break_row;
157 mutable long refresh_y;
165 mutable Row * refresh_row;
169 /** wether the screen needs a refresh,
170 starting with refresh_y
172 mutable text_status status;
174 /** returns a pointer to the row near the specified y-coordinate
175 (relative to the whole text). y is set to the real beginning
178 Row * GetRowNearY(long & y) const;
180 /** returns the column near the specified x-coordinate of the row
181 x is set to the real beginning of this column
183 int GetColumnNearX(Row * row, int & x) const;
185 /** returns a pointer to a specified row. y is set to the beginning
188 Row * GetRow(LyXParagraph * par,
189 LyXParagraph::size_type pos, long & y) const;
190 /** returns the height of a default row, needed for scrollbar
192 int DefaultHeight() const;
195 Later this variable has to be removed. There should be now internal
196 cursor in a text (and thus not in a buffer). By keeping this it is
197 (I think) impossible to have several views with the same buffer, but
198 the cursor placed at different places.
200 Since the LyXText now has been moved from Buffer to BufferView
201 it should not be absolutely needed to move the cursor...
203 mutable LyXCursor cursor;
205 /* the selection cursor */
207 mutable bool selection;
209 mutable bool mark_set;
212 mutable LyXCursor sel_cursor;
214 LyXCursor sel_start_cursor;
216 mutable LyXCursor sel_end_cursor;
217 /// needed for the toggling
218 LyXCursor last_sel_cursor;
220 LyXCursor toggle_cursor;
222 LyXCursor toggle_end_cursor;
224 /// need the selection cursor:
227 void ClearSelection() const;
229 /// just selects the word the cursor is in
232 /** 'selects" the next word, where the cursor is not in
233 and returns this word as string. THe cursor will be moved
234 to the beginning of this word.
235 With SelectSelectedWord can this be highlighted really
237 char * SelectNextWord(float & value);
239 void SelectSelectedWord();
241 void SetCursor(LyXParagraph * par,
242 LyXParagraph::size_type pos,
243 bool setfont = true) const;
245 void SetCursorIntern(LyXParagraph * par,
246 LyXParagraph::size_type pos,
247 bool setfont = true) const;
249 void SetCursorFromCoordinates(int x, long y) const;
250 void SetCursorFromCoordinates(LyXCursor &, int x, long y) const;
252 void CursorUp() const;
254 void CursorDown() const;
256 void CursorLeft() const;
258 void CursorRight() const;
260 void CursorLeftOneWord() const;
262 void CursorRightOneWord() const;
264 void CursorUpParagraph() const;
266 void CursorDownParagraph() const;
268 void CursorHome() const;
270 void CursorEnd() const;
272 void CursorTab() const;
274 void CursorTop() const;
276 void CursorBottom() const;
282 void DeleteWordForward();
284 void DeleteWordBackward();
286 void DeleteLineForward();
288 int SelectWordWhenUnderCursor();
292 text_capitalization = 1,
295 /// Change the case of the word at cursor position.
296 void ChangeWordCase(TextCase action);
298 /** returns a printed row in a pixmap. The y value is needed to
299 decide, wether it is selected text or not. This is a strange
302 void GetVisibleRow(int offset,
303 Row * row_ptr, long y);
307 void ToggleFootnote();
311 void OpenFootnotes();
315 void CloseFootnotes();
317 void CloseFootnote();
319 /** turn the selection into a new environment. If there is no
320 selection, create an empty environment
322 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
324 void MeltFootnoteEnvironment();
326 void CutSelection(bool = true);
328 void CopySelection();
330 void PasteSelection();
332 void copyEnvironmentType();
334 void pasteEnvironmentType();
336 void InsertFootnote();
338 void InsertMarginpar();
342 void InsertTabular();
344 /** the DTP switches for paragraphs. LyX will store the top settings
345 always in the first physical paragraph, the bottom settings in the
346 last. When a paragraph is broken, the top settings rest, the bottom
347 settings are given to the new one. So I can make shure, they do not
348 duplicate themself (and you cannnot make dirty things with them! )
350 void SetParagraph(bool line_top, bool line_bottom,
351 bool pagebreak_top, bool pagebreak_bottom,
352 VSpace const & space_top,
353 VSpace const & space_bottom,
355 string labelwidthstring,
357 void SetParagraphExtraOpt(int type,
360 int alignment, bool hfill,
361 bool start_minipage);
363 /* these things are for search and replace */
365 /** returns true if the specified string is at the specified
368 bool IsStringInText(LyXParagraph * par,
369 LyXParagraph::size_type pos,
370 char const * str) const;
371 /** sets the selection over the number of characters of string,
374 void SetSelectionOverString(char const * str);
376 /** simple replacing. The font of the first selected character
379 void ReplaceSelectionWithString(char const * str);
381 /** if the string can be found: return true and set the cursor to
383 bool SearchForward(char const * str) const;
384 bool SearchBackward(char const * str) const;
386 /// needed to insert the selection
387 void InsertStringA(string const & str);
388 /// needed to insert the selection
389 void InsertStringB(string const & str);
391 /// usefull when texing from within LyX
392 bool GotoNextError() const;
394 /// just another feature :)
395 bool GotoNextNote() const;
397 /** needed to switch between different classes this works
398 for a list of paragraphs beginning with the specified par
399 return value is the number of wrong conversions
401 int SwitchLayoutsBetweenClasses(LyXTextClassList::size_type class1,
402 LyXTextClassList::size_type class2,
405 /* for the greater insets */
407 /// returns 0 if inset wasn't found
408 int UpdateInset(Inset * inset);
410 void CheckParagraph(LyXParagraph * par,
411 LyXParagraph::size_type pos);
413 int NumberOfCell(LyXParagraph * par,
414 LyXParagraph::size_type pos) const;
415 /* table stuff -- begin*/
417 /** all table features of the text-class are put together in
418 this function. Possible values of feature are defined in table.h
420 void TableFeatures(int feature, string const & val) const;
422 void TableFeatures(int feature) const;
424 /** pos points at the beginning of the next cell (if there is one)
426 int WidthOfCell(LyXParagraph * par,
427 LyXParagraph::size_type & pos) const;
429 void CheckParagraphInTable(LyXParagraph * par,
430 LyXParagraph::size_type pos);
432 void InsertCharInTable(char c);
434 void BackspaceInTable();
436 bool HitInTable(Row * row, int x) const;
438 bool MouseHitInTable(int x, long y) const;
439 /* table stuff -- end*/
441 LyXParagraph * GetParFromID(int id);
444 /// returns false if no undo possible
446 /// returns false if no redo possible
448 /// used by TextUndo/TextRedo
449 bool TextHandleUndo(Undo * undo);
450 /// makes sure the next operation will be stored
452 /// this is dangerous and for internal use only
454 /// this is dangerous and for internal use only
456 /// the flag used by FinishUndo();
457 mutable bool undo_finished;
461 void SetUndo(Undo::undo_kind kind,
462 LyXParagraph const * before,
463 LyXParagraph const * end) const;
465 void SetRedo(Undo::undo_kind kind,
466 LyXParagraph const * before,
467 LyXParagraph const * end);
469 Undo * CreateUndo(Undo::undo_kind kind,
470 LyXParagraph const * before,
471 LyXParagraph const * end) const;
472 /// for external use in lyx_cb.C
473 void SetCursorParUndo();
475 void CursorLeftIntern() const;
477 void CursorRightIntern() const;
479 void RemoveTableRow(LyXCursor * cursor) const;
481 bool IsEmptyTableCell() const;
483 void toggleAppendix();
485 unsigned short paperWidth() const { return paperwidth; }
490 /// width of the paper
491 unsigned short paperwidth;
494 mutable Row * firstrow;
496 mutable Row * lastrow;
498 /** Copybuffer for copy environment type
499 Asger has learned that this should be a buffer-property instead
500 Lgb has learned that 'char' is a lousy type for non-characters
502 LyXTextClass::size_type copylayouttype;
504 /// the currentrow is needed to access rows faster*/
505 mutable Row * currentrow; // pointer to the current row
506 /// position in the text
507 mutable long currentrow_y;
509 /** inserts a new row behind the specified row, increments
510 * the touched counters */
511 void InsertRow(Row * row, LyXParagraph * par,
512 LyXParagraph::size_type pos) const;
513 /** removes the row and reset the touched counters */
514 void RemoveRow(Row * row) const;
516 /** remove all following rows of the paragraph of the specified row. */
517 void RemoveParagraph(Row * row) const;
519 /** insert the specified paragraph behind the specified row */
520 void InsertParagraph(LyXParagraph * par, Row * row) const;
522 /** appends the implizit specified paragraph behind the specified row,
523 * start at the implizit given position */
524 void AppendParagraph(Row * row) const;
527 void BreakAgain(Row * row) const;
529 void BreakAgainOneRow(Row * row);
530 /// Calculate and set the height of the row
531 void SetHeightOfRow(Row * row_ptr) const;
533 /** this calculates the specified parameters. needed when setting
534 * the cursor and when creating a visible row */
535 void PrepareToPrint(Row * row, float & x,
536 float & fill_separator,
538 float & fill_label_hfill,
539 bool bidi = true) const;
541 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
543 /** Updates all counters starting BEHIND the row. Changed paragraphs
544 * with a dynamic left margin will be rebroken. */
545 void UpdateCounters(Row * row) const;
547 void SetCounter(LyXParagraph * par) const;
550 * some low level functions
554 int SingleWidth(LyXParagraph * par,
555 LyXParagraph::size_type pos) const;
557 int SingleWidth(LyXParagraph * par,
558 LyXParagraph::size_type pos, char c) const;
560 void draw(Row const * row,
561 LyXParagraph::size_type & pos,
562 int offset, float & x);
564 /// get the next breakpoint in a given paragraph
565 LyXParagraph::size_type NextBreakPoint(Row const * row,
567 /// returns the minimum space a row needs on the screen in pixel
568 int Fill(Row const * row, int paperwidth) const;
570 /** returns the minimum space a manual label needs on the
572 int LabelFill(Row const * row) const;
575 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
577 /** Returns the left beginning of the text.
578 This information cannot be taken from the layouts-objekt, because
579 in LaTeX the beginning of the text fits in some cases
580 (for example sections) exactly the label-width.
582 int LeftMargin(Row const * row) const;
584 int RightMargin(Row const * row) const;
586 int LabelEnd (Row const * row) const;
588 /** returns the number of separators in the specified row.
589 The separator on the very last column doesnt count
591 int NumberOfSeparators(Row const * row) const;
593 /** returns the number of hfills in the specified row. The
594 LyX-Hfill is a LaTeX \hfill so that the hfills at the
595 beginning and at the end were ignored. This is {\em MUCH}
596 more usefull than not to ignore!
598 int NumberOfHfills(Row const * row) const;
600 /// like NumberOfHfills, but only those in the manual label!
601 int NumberOfLabelHfills(Row const * row) const;
603 /** returns true, if a expansion is needed. Rules are given by
606 bool HfillExpansion(Row const * row_ptr,
607 LyXParagraph::size_type pos) const;
610 mutable vector<LyXParagraph::size_type> log2vis_list;
613 mutable vector<LyXParagraph::size_type> vis2log_list;
616 mutable LyXParagraph::size_type bidi_start;
619 void ComputeBidiTables(Row *row) const;
622 void ComputeBidiTablesFromTo(Row *row,
623 LyXParagraph::size_type from,
624 LyXParagraph::size_type to,
625 LyXParagraph::size_type offset) const;
627 /// Maps positions in the visual string to positions in logical string.
629 LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const {
630 if (bidi_start == -1)
633 return log2vis_list[pos-bidi_start];
636 /// Maps positions in the logical string to positions in visual string.
638 LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
639 if (bidi_start == -1)
642 return vis2log_list[pos-bidi_start];
646 unsigned char TransformChar(unsigned char c, Letter_Form form) const;
649 unsigned char TransformChar(unsigned char c, LyXParagraph * par,
650 LyXParagraph::size_type pos) const;
652 /** returns the paragraph position of the last character in the
655 LyXParagraph::size_type RowLast(Row const * row) const;