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"
31 This class holds the mapping between buffer paragraphs and screen rows.
44 NEED_VERY_LITTLE_REFRESH
54 /// points to Buffer.params
55 BufferParams * parameters;
59 mutable int number_of_rows;
62 /// the current font settings
63 mutable LyXFont current_font;
65 mutable LyXFont real_current_font;
68 LyXText(BufferView *, int paperwidth, Buffer *);
74 void owner(BufferView *);
77 LyXFont GetFont(LyXParagraph * par,
78 LyXParagraph::size_type pos) const;
80 void SetCharFont(LyXParagraph * par,
81 LyXParagraph::size_type pos,
82 LyXFont const & font);
83 /// returns a pointer to the very first LyXParagraph
84 LyXParagraph * FirstParagraph() const;
86 /// what you expect when pressing <enter> at cursor position
87 void BreakParagraph(char keep_layout = 0);
89 /** set layout over selection and make a total rebreak of
92 void SetLayout(LyXTextClass::size_type layout);
95 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
97 /** increment depth over selection and make a total rebreak of those
102 /** decrement depth over selection and make a total rebreak of those
106 /** Get the depth at current cursor position
108 int GetDepth() const { return cursor.par->GetDepth(); }
110 /** set font over selection and make a total rebreak of those
112 toggleall defaults to false.
114 void SetFont(LyXFont const & font, bool toggleall = false);
116 /** deletes and inserts again all paragaphs between the cursor
117 and the specified par. The Cursor is needed to set the refreshing
119 This function is needed after SetLayout and SetFont etc.
121 void RedoParagraphs(LyXCursor const & cursor,
122 LyXParagraph const * end_par) const;
124 void RedoParagraph() const;
127 void ToggleFree(LyXFont const & font, bool toggleall = false);
129 /** recalculates the heights of all previous rows of the
130 specified paragraph. needed, if the last characters font
133 void RedoHeightOfParagraph(LyXCursor const & cursor);
135 /** forces the redrawing of a paragraph. Needed when manipulating a
138 void RedoDrawingOfParagraph(LyXCursor const & cursor);
140 /** insert a character, moves all the following breaks in the
141 same Paragraph one to the right and make a little rebreak
143 void InsertChar(char c);
145 void InsertInset(Inset * inset);
147 /// completes the insertion with a full rebreak
151 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
153 Row * need_break_row;
155 mutable long refresh_y;
163 mutable Row * refresh_row;
167 /** wether the screen needs a refresh,
168 starting with refresh_y
170 mutable text_status status;
172 /** returns a pointer to the row near the specified y-coordinate
173 (relative to the whole text). y is set to the real beginning
176 Row * GetRowNearY(long & y) const;
178 /** returns the column near the specified x-coordinate of the row
179 x is set to the real beginning of this column
181 int GetColumnNearX(Row * row, int & x) const;
183 /** returns a pointer to a specified row. y is set to the beginning
186 Row * GetRow(LyXParagraph * par,
187 LyXParagraph::size_type pos, long & y) const;
188 /** returns the height of a default row, needed for scrollbar
190 int DefaultHeight() const;
193 Later this variable has to be removed. There should be now internal
194 cursor in a text (and thus not in a buffer). By keeping this it is
195 (I think) impossible to have several views with the same buffer, but
196 the cursor placed at different places.
198 Since the LyXText now has been moved from Buffer to BufferView
199 it should not be absolutely needed to move the cursor...
201 mutable LyXCursor cursor;
203 /* the selection cursor */
205 mutable bool selection;
207 mutable bool mark_set;
210 mutable LyXCursor sel_cursor;
212 LyXCursor sel_start_cursor;
214 mutable LyXCursor sel_end_cursor;
215 /// needed for the toggling
216 LyXCursor last_sel_cursor;
218 LyXCursor toggle_cursor;
220 LyXCursor toggle_end_cursor;
222 /// need the selection cursor:
225 void ClearSelection() const;
227 /// just selects the word the cursor is in
230 /** 'selects" the next word, where the cursor is not in
231 and returns this word as string. THe cursor will be moved
232 to the beginning of this word.
233 With SelectSelectedWord can this be highlighted really
235 char * SelectNextWord(float & value);
237 void SelectSelectedWord();
239 void SetCursor(LyXParagraph * par,
240 LyXParagraph::size_type pos,
241 bool setfont = true) const;
243 void SetCursorIntern(LyXParagraph * par,
244 LyXParagraph::size_type pos,
245 bool setfont = true) const;
247 void SetCursorFromCoordinates(int x, long y) const;
248 void SetCursorFromCoordinates(LyXCursor &, int x, long y) const;
250 void CursorUp() const;
252 void CursorDown() const;
254 void CursorLeft() const;
256 void CursorRight() const;
258 void CursorLeftOneWord() const;
260 void CursorRightOneWord() const;
262 void CursorUpParagraph() const;
264 void CursorDownParagraph() const;
266 void CursorHome() const;
268 void CursorEnd() const;
270 void CursorTab() const;
272 void CursorTop() const;
274 void CursorBottom() const;
280 void DeleteWordForward();
282 void DeleteWordBackward();
284 void DeleteLineForward();
286 int SelectWordWhenUnderCursor();
290 text_capitalization = 1,
293 /// Change the case of the word at cursor position.
294 void ChangeWordCase(TextCase action);
296 /** returns a printed row in a pixmap. The y value is needed to
297 decide, wether it is selected text or not. This is a strange
300 void GetVisibleRow(int offset,
301 Row * row_ptr, long y);
305 void ToggleFootnote();
309 void OpenFootnotes();
313 void CloseFootnotes();
315 void CloseFootnote();
317 /** turn the selection into a new environment. If there is no
318 selection, create an empty environment
320 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
322 void MeltFootnoteEnvironment();
324 void CutSelection(bool = true);
326 void CopySelection();
328 void PasteSelection();
330 void copyEnvironmentType();
332 void pasteEnvironmentType();
334 void InsertFootnote();
336 void InsertMarginpar();
340 void InsertTabular();
342 /** the DTP switches for paragraphs. LyX will store the top settings
343 always in the first physical paragraph, the bottom settings in the
344 last. When a paragraph is broken, the top settings rest, the bottom
345 settings are given to the new one. So I can make shure, they do not
346 duplicate themself (and you cannnot make dirty things with them! )
348 void SetParagraph(bool line_top, bool line_bottom,
349 bool pagebreak_top, bool pagebreak_bottom,
350 VSpace const & space_top,
351 VSpace const & space_bottom,
353 string labelwidthstring,
355 void SetParagraphExtraOpt(int type,
358 int alignment, bool hfill,
359 bool start_minipage);
361 /* these things are for search and replace */
363 /** returns true if the specified string is at the specified
366 bool IsStringInText(LyXParagraph * par,
367 LyXParagraph::size_type pos,
368 char const * str) const;
369 /** sets the selection over the number of characters of string,
372 void SetSelectionOverString(char const * str);
374 /** simple replacing. The font of the first selected character
377 void ReplaceSelectionWithString(char const * str);
379 /** if the string can be found: return true and set the cursor to
381 bool SearchForward(char const * str) const;
382 bool SearchBackward(char const * str) const;
384 /// needed to insert the selection
385 void InsertStringA(string const & str);
386 /// needed to insert the selection
387 void InsertStringB(string const & str);
389 /// usefull when texing from within LyX
390 bool GotoNextError() const;
392 /// just another feature :)
393 bool GotoNextNote() const;
395 /** needed to switch between different classes this works
396 for a list of paragraphs beginning with the specified par
397 return value is the number of wrong conversions
399 int SwitchLayoutsBetweenClasses(LyXTextClassList::size_type class1,
400 LyXTextClassList::size_type class2,
403 /* for the greater insets */
405 /// returns 0 if inset wasn't found
406 int UpdateInset(Inset * inset);
408 void CheckParagraph(LyXParagraph * par,
409 LyXParagraph::size_type pos);
411 int NumberOfCell(LyXParagraph * par,
412 LyXParagraph::size_type pos) const;
413 /* table stuff -- begin*/
415 /** all table features of the text-class are put together in
416 this function. Possible values of feature are defined in table.h
418 void TableFeatures(int feature, string const & val) const;
420 void TableFeatures(int feature) const;
422 /** pos points at the beginning of the next cell (if there is one)
424 int WidthOfCell(LyXParagraph * par,
425 LyXParagraph::size_type & pos) const;
427 void CheckParagraphInTable(LyXParagraph * par,
428 LyXParagraph::size_type pos);
430 void InsertCharInTable(char c);
432 void BackspaceInTable();
434 bool HitInTable(Row * row, int x) const;
436 bool MouseHitInTable(int x, long y) const;
437 /* table stuff -- end*/
439 LyXParagraph * GetParFromID(int id);
442 /// returns false if no undo possible
444 /// returns false if no redo possible
446 /// used by TextUndo/TextRedo
447 bool TextHandleUndo(Undo * undo);
448 /// makes sure the next operation will be stored
450 /// this is dangerous and for internal use only
452 /// this is dangerous and for internal use only
454 /// the flag used by FinishUndo();
455 mutable bool undo_finished;
459 void SetUndo(Undo::undo_kind kind,
460 LyXParagraph const * before,
461 LyXParagraph const * end) const;
463 void SetRedo(Undo::undo_kind kind,
464 LyXParagraph const * before,
465 LyXParagraph const * end);
467 Undo * CreateUndo(Undo::undo_kind kind,
468 LyXParagraph const * before,
469 LyXParagraph const * end) const;
470 /// for external use in lyx_cb.C
471 void SetCursorParUndo();
473 void CursorLeftIntern() const;
475 void CursorRightIntern() const;
477 void RemoveTableRow(LyXCursor * cursor) const;
479 bool IsEmptyTableCell() const;
481 void toggleAppendix();
483 unsigned short paperWidth() const { return paperwidth; }
488 /// width of the paper
489 unsigned short paperwidth;
492 mutable Row * firstrow;
494 mutable Row * lastrow;
496 /** Copybuffer for copy environment type
497 Asger has learned that this should be a buffer-property instead
498 Lgb has learned that 'char' is a lousy type for non-characters
500 LyXTextClass::size_type copylayouttype;
502 /// the currentrow is needed to access rows faster*/
503 mutable Row * currentrow; // pointer to the current row
504 /// position in the text
505 mutable long currentrow_y;
507 /** inserts a new row behind the specified row, increments
508 * the touched counters */
509 void InsertRow(Row * row, LyXParagraph * par,
510 LyXParagraph::size_type pos) const;
511 /** removes the row and reset the touched counters */
512 void RemoveRow(Row * row) const;
514 /** remove all following rows of the paragraph of the specified row. */
515 void RemoveParagraph(Row * row) const;
517 /** insert the specified paragraph behind the specified row */
518 void InsertParagraph(LyXParagraph * par, Row * row) const;
520 /** appends the implizit specified paragraph behind the specified row,
521 * start at the implizit given position */
522 void AppendParagraph(Row * row) const;
525 void BreakAgain(Row * row) const;
527 void BreakAgainOneRow(Row * row);
528 /// Calculate and set the height of the row
529 void SetHeightOfRow(Row * row_ptr) const;
531 /** this calculates the specified parameters. needed when setting
532 * the cursor and when creating a visible row */
533 void PrepareToPrint(Row * row, float & x,
534 float & fill_separator,
536 float & fill_label_hfill,
537 bool bidi = true) const;
539 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
541 /** Updates all counters starting BEHIND the row. Changed paragraphs
542 * with a dynamic left margin will be rebroken. */
543 void UpdateCounters(Row * row) const;
545 void SetCounter(LyXParagraph * par) const;
548 * some low level functions
552 int SingleWidth(LyXParagraph * par,
553 LyXParagraph::size_type pos) const;
555 int SingleWidth(LyXParagraph * par,
556 LyXParagraph::size_type pos, char c) const;
558 void draw(Row const * row,
559 LyXParagraph::size_type & pos,
560 int offset, float & x);
562 /// get the next breakpoint in a given paragraph
563 LyXParagraph::size_type NextBreakPoint(Row const * row,
565 /// returns the minimum space a row needs on the screen in pixel
566 int Fill(Row const * row, int paperwidth) const;
568 /** returns the minimum space a manual label needs on the
570 int LabelFill(Row const * row) const;
573 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
575 /** Returns the left beginning of the text.
576 This information cannot be taken from the layouts-objekt, because
577 in LaTeX the beginning of the text fits in some cases
578 (for example sections) exactly the label-width.
580 int LeftMargin(Row const * row) const;
582 int RightMargin(Row const * row) const;
584 int LabelEnd (Row const * row) const;
586 /** returns the number of separators in the specified row.
587 The separator on the very last column doesnt count
589 int NumberOfSeparators(Row const * row) const;
591 /** returns the number of hfills in the specified row. The
592 LyX-Hfill is a LaTeX \hfill so that the hfills at the
593 beginning and at the end were ignored. This is {\em MUCH}
594 more usefull than not to ignore!
596 int NumberOfHfills(Row const * row) const;
598 /// like NumberOfHfills, but only those in the manual label!
599 int NumberOfLabelHfills(Row const * row) const;
601 /** returns true, if a expansion is needed. Rules are given by
604 bool HfillExpansion(Row const * row_ptr,
605 LyXParagraph::size_type pos) const;
608 mutable vector<LyXParagraph::size_type> log2vis_list;
611 mutable vector<LyXParagraph::size_type> vis2log_list;
614 mutable LyXParagraph::size_type bidi_start;
617 void ComputeBidiTables(Row *row) const;
620 void ComputeBidiTablesFromTo(Row *row,
621 LyXParagraph::size_type from,
622 LyXParagraph::size_type to,
623 LyXParagraph::size_type offset) const;
625 /// Maps positions in the visual string to positions in logical string.
627 LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const {
628 if (bidi_start == -1)
631 return log2vis_list[pos-bidi_start];
634 /// Maps positions in the logical string to positions in visual string.
636 LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
637 if (bidi_start == -1)
640 return vis2log_list[pos-bidi_start];
644 unsigned char TransformChar(unsigned char c, Letter_Form form) const;
647 unsigned char TransformChar(unsigned char c, LyXParagraph * par,
648 LyXParagraph::size_type pos) const;
650 /** returns the paragraph position of the last character in the
653 LyXParagraph::size_type RowLast(Row const * row) const;