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 /// just selects the word the cursor is in
234 /** 'selects" the next word, where the cursor is not in
235 and returns this word as string. THe cursor will be moved
236 to the beginning of this word.
237 With SelectSelectedWord can this be highlighted really
239 char * SelectNextWord(float & value);
241 void SelectSelectedWord();
243 void SetCursor(LyXParagraph * par,
244 LyXParagraph::size_type pos,
245 bool setfont = true) const;
246 void SetCursor(LyXCursor &, LyXParagraph * par,
247 LyXParagraph::size_type pos) const;
249 void SetCursorIntern(LyXParagraph * par,
250 LyXParagraph::size_type pos,
251 bool setfont = true) const;
253 void SetCursorFromCoordinates(int x, long y) const;
254 void SetCursorFromCoordinates(LyXCursor &, int x, long y) const;
256 void CursorUp() const;
258 void CursorDown() const;
260 void CursorLeft() const;
262 void CursorRight() const;
264 void CursorLeftOneWord() const;
266 void CursorRightOneWord() const;
268 void CursorUpParagraph() const;
270 void CursorDownParagraph() const;
272 void CursorHome() const;
274 void CursorEnd() const;
276 void CursorTab() const;
278 void CursorTop() const;
280 void CursorBottom() const;
286 void DeleteWordForward();
288 void DeleteWordBackward();
290 void DeleteLineForward();
292 bool SelectWordWhenUnderCursor();
296 text_capitalization = 1,
299 /// Change the case of the word at cursor position.
300 void ChangeWordCase(TextCase action);
302 /** returns a printed row in a pixmap. The y value is needed to
303 decide, wether it is selected text or not. This is a strange
306 void GetVisibleRow(int offset, Row * row_ptr, long y);
310 void ToggleFootnote();
314 void OpenFootnotes();
318 void CloseFootnotes();
320 void CloseFootnote();
322 /** turn the selection into a new environment. If there is no
323 selection, create an empty environment
325 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
327 void MeltFootnoteEnvironment();
329 void CutSelection(bool = true);
331 void CopySelection();
333 void PasteSelection();
335 void copyEnvironmentType();
337 void pasteEnvironmentType();
339 void InsertFootnote();
341 void InsertMarginpar();
345 void InsertTabular();
347 /** the DTP switches for paragraphs. LyX will store the top settings
348 always in the first physical paragraph, the bottom settings in the
349 last. When a paragraph is broken, the top settings rest, the bottom
350 settings are given to the new one. So I can make shure, they do not
351 duplicate themself (and you cannnot make dirty things with them! )
353 void SetParagraph(bool line_top, bool line_bottom,
354 bool pagebreak_top, bool pagebreak_bottom,
355 VSpace const & space_top,
356 VSpace const & space_bottom,
358 string labelwidthstring,
360 void SetParagraphExtraOpt(int type,
363 int alignment, bool hfill,
364 bool start_minipage);
366 /* these things are for search and replace */
368 /** returns true if the specified string is at the specified
371 bool IsStringInText(LyXParagraph * par,
372 LyXParagraph::size_type pos,
373 char const * str) const;
374 /** sets the selection over the number of characters of string,
377 void SetSelectionOverString(char const * str);
379 /** simple replacing. The font of the first selected character
382 void ReplaceSelectionWithString(char const * str);
384 /** if the string can be found: return true and set the cursor to
386 bool SearchForward(char const * str) const;
387 bool SearchBackward(char const * str) const;
389 /// needed to insert the selection
390 void InsertStringA(string const & str);
391 /// needed to insert the selection
392 void InsertStringB(string const & str);
394 /// usefull when texing from within LyX
395 bool GotoNextError() const;
397 /// just another feature :)
398 bool GotoNextNote() const;
400 /* for the greater insets */
402 /// returns 0 if inset wasn't found
403 int UpdateInset(Inset * inset);
405 void CheckParagraph(LyXParagraph * par,
406 LyXParagraph::size_type pos);
408 int NumberOfCell(LyXParagraph * par,
409 LyXParagraph::size_type pos) const;
410 /* table stuff -- begin*/
412 /** all table features of the text-class are put together in
413 this function. Possible values of feature are defined in table.h
415 void TableFeatures(int feature, string const & val) const;
417 void TableFeatures(int feature) const;
419 /** pos points at the beginning of the next cell (if there is one)
421 int WidthOfCell(LyXParagraph * par,
422 LyXParagraph::size_type & pos) const;
424 void CheckParagraphInTable(LyXParagraph * par,
425 LyXParagraph::size_type pos);
427 void InsertCharInTable(char c);
429 void BackspaceInTable();
431 bool HitInTable(Row * row, int x) const;
433 bool MouseHitInTable(int x, long y) const;
434 /* table stuff -- end*/
436 LyXParagraph * GetParFromID(int id);
439 /// returns false if no undo possible
441 /// returns false if no redo possible
443 /// used by TextUndo/TextRedo
444 bool TextHandleUndo(Undo * undo);
445 /// makes sure the next operation will be stored
447 /// this is dangerous and for internal use only
449 /// this is dangerous and for internal use only
451 /// the flag used by FinishUndo();
452 mutable bool undo_finished;
456 void SetUndo(Undo::undo_kind kind,
457 LyXParagraph const * before,
458 LyXParagraph const * end) const;
460 void SetRedo(Undo::undo_kind kind,
461 LyXParagraph const * before,
462 LyXParagraph const * end);
464 Undo * CreateUndo(Undo::undo_kind kind,
465 LyXParagraph const * before,
466 LyXParagraph const * end) const;
467 /// for external use in lyx_cb.C
468 void SetCursorParUndo();
470 void CursorLeftIntern() const;
472 void CursorRightIntern() const;
474 void RemoveTableRow(LyXCursor * cursor) const;
476 bool IsEmptyTableCell() const;
478 void toggleAppendix();
480 unsigned short paperWidth() const { return paperwidth; }
485 /// width of the paper
486 unsigned short paperwidth;
489 mutable Row * firstrow;
491 mutable Row * lastrow;
493 /** Copybuffer for copy environment type
494 Asger has learned that this should be a buffer-property instead
495 Lgb has learned that 'char' is a lousy type for non-characters
497 LyXTextClass::size_type copylayouttype;
499 /** inserts a new row behind the specified row, increments
500 * the touched counters */
501 void InsertRow(Row * row, LyXParagraph * par,
502 LyXParagraph::size_type pos) const;
503 /** removes the row and reset the touched counters */
504 void RemoveRow(Row * row) const;
506 /** remove all following rows of the paragraph of the specified row. */
507 void RemoveParagraph(Row * row) const;
509 /** insert the specified paragraph behind the specified row */
510 void InsertParagraph(LyXParagraph * par, Row * row) const;
512 /** appends the implizit specified paragraph behind the specified row,
513 * start at the implizit given position */
514 void AppendParagraph(Row * row) const;
517 void BreakAgain(Row * row) const;
519 void BreakAgainOneRow(Row * row);
520 /// Calculate and set the height of the row
521 void SetHeightOfRow(Row * row_ptr) const;
523 /** this calculates the specified parameters. needed when setting
524 * the cursor and when creating a visible row */
525 void PrepareToPrint(Row * row, float & x,
526 float & fill_separator,
528 float & fill_label_hfill,
529 bool bidi = true) const;
531 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
533 /** Updates all counters starting BEHIND the row. Changed paragraphs
534 * with a dynamic left margin will be rebroken. */
535 void UpdateCounters(Row * row) const;
537 void SetCounter(LyXParagraph * par) const;
540 * some low level functions
544 int SingleWidth(LyXParagraph * par,
545 LyXParagraph::size_type pos) const;
547 int SingleWidth(LyXParagraph * par,
548 LyXParagraph::size_type pos, char c) const;
550 void draw(Row const * row,
551 LyXParagraph::size_type & pos,
552 int offset, float & x);
554 /// get the next breakpoint in a given paragraph
555 LyXParagraph::size_type NextBreakPoint(Row const * row,
557 /// returns the minimum space a row needs on the screen in pixel
558 int Fill(Row const * row, int paperwidth) const;
560 /** returns the minimum space a manual label needs on the
562 int LabelFill(Row const * row) const;
565 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
567 /** Returns the left beginning of the text.
568 This information cannot be taken from the layouts-objekt, because
569 in LaTeX the beginning of the text fits in some cases
570 (for example sections) exactly the label-width.
572 int LeftMargin(Row const * row) const;
574 int RightMargin(Row const * row) const;
576 int LabelEnd (Row const * row) const;
578 /** returns the number of separators in the specified row.
579 The separator on the very last column doesnt count
581 int NumberOfSeparators(Row const * row) const;
583 /** returns the number of hfills in the specified row. The
584 LyX-Hfill is a LaTeX \hfill so that the hfills at the
585 beginning and at the end were ignored. This is {\em MUCH}
586 more usefull than not to ignore!
588 int NumberOfHfills(Row const * row) const;
590 /// like NumberOfHfills, but only those in the manual label!
591 int NumberOfLabelHfills(Row const * row) const;
592 /** returns true, if a expansion is needed. Rules are given by
595 bool HfillExpansion(Row const * row_ptr,
596 LyXParagraph::size_type pos) const;
600 mutable std::vector<LyXParagraph::size_type> log2vis_list;
603 mutable std::vector<LyXParagraph::size_type> vis2log_list;
606 mutable std::vector<LyXParagraph::size_type> bidi_levels;
609 mutable LyXParagraph::size_type bidi_start;
612 mutable bool bidi_same_direction;
615 void ComputeBidiTables(Row *row) const;
617 /// Maps positions in the visual string to positions in logical string.
619 LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const {
620 if (bidi_start == -1)
623 return log2vis_list[pos-bidi_start];
626 /// Maps positions in the logical string to positions in visual string.
628 LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
629 if (bidi_start == -1)
632 return vis2log_list[pos-bidi_start];
636 int bidi_level(LyXParagraph::size_type pos) const {
637 if (bidi_start == -1)
640 return bidi_levels[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;
655 LyXParagraph::size_type RowLastPrintable(Row const * row) const;