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) 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,
247 bool setfont = true) const;
248 void SetCursor(LyXCursor &, LyXParagraph * par,
249 LyXParagraph::size_type pos) const;
251 void SetCursorIntern(LyXParagraph * par,
252 LyXParagraph::size_type pos,
253 bool setfont = true) const;
255 void SetCursorFromCoordinates(int x, long y) const;
256 void SetCursorFromCoordinates(LyXCursor &, int x, long y) const;
258 void CursorUp() const;
260 void CursorDown() const;
262 void CursorLeft() const;
264 void CursorRight() const;
266 void CursorLeftOneWord() const;
268 void CursorRightOneWord() const;
270 void CursorUpParagraph() const;
272 void CursorDownParagraph() const;
274 void CursorHome() const;
276 void CursorEnd() const;
278 void CursorTab() const;
280 void CursorTop() const;
282 void CursorBottom() const;
288 void DeleteWordForward();
290 void DeleteWordBackward();
292 void DeleteLineForward();
294 bool SelectWordWhenUnderCursor();
298 text_capitalization = 1,
301 /// Change the case of the word at cursor position.
302 void ChangeWordCase(TextCase action);
304 /** returns a printed row in a pixmap. The y value is needed to
305 decide, wether it is selected text or not. This is a strange
308 void GetVisibleRow(int offset, Row * row_ptr, long y);
312 void ToggleFootnote();
316 void OpenFootnotes();
320 void CloseFootnotes();
322 void CloseFootnote();
324 /** turn the selection into a new environment. If there is no
325 selection, create an empty environment
327 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
329 void MeltFootnoteEnvironment();
331 void CutSelection(bool = true);
333 void CopySelection();
335 void PasteSelection();
337 void copyEnvironmentType();
339 void pasteEnvironmentType();
341 void InsertFootnote();
343 void InsertMarginpar();
347 void InsertTabular();
349 /** the DTP switches for paragraphs. LyX will store the top settings
350 always in the first physical paragraph, the bottom settings in the
351 last. When a paragraph is broken, the top settings rest, the bottom
352 settings are given to the new one. So I can make shure, they do not
353 duplicate themself (and you cannnot make dirty things with them! )
355 void SetParagraph(bool line_top, bool line_bottom,
356 bool pagebreak_top, bool pagebreak_bottom,
357 VSpace const & space_top,
358 VSpace const & space_bottom,
360 string labelwidthstring,
362 void SetParagraphExtraOpt(int type,
365 int alignment, bool hfill,
366 bool start_minipage);
368 /* these things are for search and replace */
370 /** returns true if the specified string is at the specified
373 bool IsStringInText(LyXParagraph * par,
374 LyXParagraph::size_type pos,
375 char const * str) const;
376 /** sets the selection over the number of characters of string,
379 void SetSelectionOverString(char const * str);
381 /** simple replacing. The font of the first selected character
384 void ReplaceSelectionWithString(char const * str);
386 /** if the string can be found: return true and set the cursor to
388 bool SearchForward(char const * str) const;
389 bool SearchBackward(char const * str) const;
391 /// needed to insert the selection
392 void InsertStringA(string const & str);
393 /// needed to insert the selection
394 void InsertStringB(string const & str);
396 /// usefull when texing from within LyX
397 bool GotoNextError() const;
399 /// just another feature :)
400 bool GotoNextNote() const;
402 /* for the greater insets */
404 /// returns 0 if inset wasn't found
405 int UpdateInset(Inset * inset);
407 void CheckParagraph(LyXParagraph * par,
408 LyXParagraph::size_type pos);
410 int NumberOfCell(LyXParagraph * par,
411 LyXParagraph::size_type pos) const;
412 /* table stuff -- begin*/
414 /** all table features of the text-class are put together in
415 this function. Possible values of feature are defined in table.h
417 void TableFeatures(int feature, string const & val) const;
419 void TableFeatures(int feature) const;
421 /** pos points at the beginning of the next cell (if there is one)
423 int WidthOfCell(LyXParagraph * par,
424 LyXParagraph::size_type & pos) const;
426 void CheckParagraphInTable(LyXParagraph * par,
427 LyXParagraph::size_type pos);
429 void InsertCharInTable(char c);
431 void BackspaceInTable();
433 bool HitInTable(Row * row, int x) const;
435 bool MouseHitInTable(int x, long y) const;
436 /* table stuff -- end*/
438 LyXParagraph * GetParFromID(int id);
441 /// returns false if no undo possible
443 /// returns false if no redo possible
445 /// used by TextUndo/TextRedo
446 bool TextHandleUndo(Undo * undo);
447 /// makes sure the next operation will be stored
449 /// this is dangerous and for internal use only
451 /// this is dangerous and for internal use only
453 /// the flag used by FinishUndo();
454 mutable bool undo_finished;
458 void SetUndo(Undo::undo_kind kind,
459 LyXParagraph const * before,
460 LyXParagraph const * end) const;
462 void SetRedo(Undo::undo_kind kind,
463 LyXParagraph const * before,
464 LyXParagraph const * end);
466 Undo * CreateUndo(Undo::undo_kind kind,
467 LyXParagraph const * before,
468 LyXParagraph const * end) const;
469 /// for external use in lyx_cb.C
470 void SetCursorParUndo();
472 void CursorLeftIntern() const;
474 void CursorRightIntern() const;
476 void RemoveTableRow(LyXCursor * cursor) const;
478 bool IsEmptyTableCell() const;
480 void toggleAppendix();
482 unsigned short paperWidth() const { return paperwidth; }
487 /// width of the paper
488 unsigned short paperwidth;
491 mutable Row * firstrow;
493 mutable Row * lastrow;
495 /** Copybuffer for copy environment type
496 Asger has learned that this should be a buffer-property instead
497 Lgb has learned that 'char' is a lousy type for non-characters
499 LyXTextClass::size_type copylayouttype;
501 /** inserts a new row behind the specified row, increments
502 * the touched counters */
503 void InsertRow(Row * row, LyXParagraph * par,
504 LyXParagraph::size_type pos) const;
505 /** removes the row and reset the touched counters */
506 void RemoveRow(Row * row) const;
508 /** remove all following rows of the paragraph of the specified row. */
509 void RemoveParagraph(Row * row) const;
511 /** insert the specified paragraph behind the specified row */
512 void InsertParagraph(LyXParagraph * par, Row * row) const;
514 /** appends the implizit specified paragraph behind the specified row,
515 * start at the implizit given position */
516 void AppendParagraph(Row * row) const;
519 void BreakAgain(Row * row) const;
521 void BreakAgainOneRow(Row * row);
522 /// Calculate and set the height of the row
523 void SetHeightOfRow(Row * row_ptr) const;
525 /** this calculates the specified parameters. needed when setting
526 * the cursor and when creating a visible row */
527 void PrepareToPrint(Row * row, float & x,
528 float & fill_separator,
530 float & fill_label_hfill,
531 bool bidi = true) const;
534 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
536 /** Updates all counters starting BEHIND the row. Changed paragraphs
537 * with a dynamic left margin will be rebroken. */
538 void UpdateCounters(Row * row) const;
540 void SetCounter(LyXParagraph * par) const;
543 * some low level functions
547 int SingleWidth(LyXParagraph * par,
548 LyXParagraph::size_type pos) const;
550 int SingleWidth(LyXParagraph * par,
551 LyXParagraph::size_type pos, char c) const;
553 void draw(Row const * row,
554 LyXParagraph::size_type & pos,
555 int offset, float & x);
557 /// get the next breakpoint in a given paragraph
558 LyXParagraph::size_type NextBreakPoint(Row const * row,
560 /// returns the minimum space a row needs on the screen in pixel
561 int Fill(Row const * row, int paperwidth) const;
563 /** returns the minimum space a manual label needs on the
565 int LabelFill(Row const * row) const;
568 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
570 /** Returns the left beginning of the text.
571 This information cannot be taken from the layouts-objekt, because
572 in LaTeX the beginning of the text fits in some cases
573 (for example sections) exactly the label-width.
575 int LeftMargin(Row const * row) const;
577 int RightMargin(Row const * row) const;
579 int LabelEnd (Row const * row) const;
581 /** returns the number of separators in the specified row.
582 The separator on the very last column doesnt count
584 int NumberOfSeparators(Row const * row) const;
586 /** returns the number of hfills in the specified row. The
587 LyX-Hfill is a LaTeX \hfill so that the hfills at the
588 beginning and at the end were ignored. This is {\em MUCH}
589 more usefull than not to ignore!
591 int NumberOfHfills(Row const * row) const;
593 /// like NumberOfHfills, but only those in the manual label!
594 int NumberOfLabelHfills(Row const * row) const;
595 /** returns true, if a expansion is needed. Rules are given by
598 bool HfillExpansion(Row const * row_ptr,
599 LyXParagraph::size_type pos) const;
603 mutable std::vector<LyXParagraph::size_type> log2vis_list;
606 mutable std::vector<LyXParagraph::size_type> vis2log_list;
609 mutable std::vector<LyXParagraph::size_type> bidi_levels;
612 mutable LyXParagraph::size_type bidi_start;
615 mutable bool bidi_same_direction;
618 void ComputeBidiTables(Row *row) const;
620 /// Maps positions in the visual string to positions in logical string.
622 LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const {
623 if (bidi_start == -1)
626 return log2vis_list[pos-bidi_start];
629 /// Maps positions in the logical string to positions in visual string.
631 LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
632 if (bidi_start == -1)
635 return vis2log_list[pos-bidi_start];
639 int bidi_level(LyXParagraph::size_type pos) const {
640 if (bidi_start == -1)
643 return bidi_levels[pos-bidi_start];
647 unsigned char TransformChar(unsigned char c, Letter_Form form) const;
650 unsigned char TransformChar(unsigned char c, LyXParagraph * par,
651 LyXParagraph::size_type pos) const;
653 /** returns the paragraph position of the last character in the
656 LyXParagraph::size_type RowLast(Row const * row) const;
658 LyXParagraph::size_type RowLastPrintable(Row const * row) const;