2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 1995 Matthias Ettrich
8 * Copyright 1995-1999 The LyX Team.
10 * ====================================================== */
22 #include "lyxcursor.h"
23 #include "lyxparagraph.h"
31 This class holds the mapping between buffer paragraphs and screen rows.
44 NEED_VERY_LITTLE_REFRESH
47 /// points to Buffer.params
48 BufferParams * parameters;
52 mutable int number_of_rows;
55 /// the current font settings
56 mutable LyXFont current_font;
58 mutable LyXFont real_current_font;
61 LyXText(int paperwidth, Buffer *);
67 LyXFont GetFont(LyXParagraph * par,
68 LyXParagraph::size_type pos) const;
70 void SetCharFont(LyXParagraph * par,
71 LyXParagraph::size_type pos,
72 LyXFont const & font);
73 /// returns a pointer to the very first LyXParagraph
74 LyXParagraph * FirstParagraph() const;
76 /// what you expect when pressing <enter> at cursor position
77 void BreakParagraph(char keep_layout = 0);
79 /** set layout over selection and make a total rebreak of
82 void SetLayout(char layout);
85 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
87 /** increment depth over selection and make a total rebreak of those
92 /** decrement depth over selection and make a total rebreak of those
96 /** Get the depth at current cursor position
98 int GetDepth() const { return cursor.par->GetDepth(); }
100 /** set font over selection and make a total rebreak of those
102 toggleall defaults to false.
104 void SetFont(LyXFont const & font, bool toggleall = false);
106 /** deletes and inserts again all paragaphs between the cursor
107 and the specified par. The Cursor is needed to set the refreshing
109 This function is needed after SetLayout and SetFont etc.
111 void RedoParagraphs(LyXCursor const & cursor,
112 LyXParagraph const * end_par) const;
114 void RedoParagraph() const;
117 void ToggleFree(LyXFont const & font, bool toggleall = false);
119 /** recalculates the heights of all previous rows of the
120 specified paragraph. needed, if the last characters font
123 void RedoHeightOfParagraph(LyXCursor const & cursor);
125 /** forces the redrawing of a paragraph. Needed when manipulating a
128 void RedoDrawingOfParagraph(LyXCursor const & cursor);
130 /** insert a character, moves all the following breaks in the
131 same Paragraph one to the right and make a little rebreak
133 void InsertChar(char c);
135 void InsertInset(Inset * inset);
137 /// completes the insertion with a full rebreak
141 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
143 Row * need_break_row;
145 mutable long refresh_y;
153 mutable Row * refresh_row;
157 /** wether the screen needs a refresh,
158 starting with refresh_y
160 mutable text_status status;
162 /** returns a pointer to the row near the specified y-coordinate
163 (relative to the whole text). y is set to the real beginning
166 Row * GetRowNearY(long & y) const;
168 /** returns the column near the specified x-coordinate of the row
169 x is set to the real beginning of this column
171 int GetColumnNearX(Row * row, int & x) const;
173 /** returns a pointer to a specified row. y is set to the beginning
176 Row * GetRow(LyXParagraph * par,
177 LyXParagraph::size_type pos, long & y) const;
178 /** returns the height of a default row, needed for scrollbar
180 int DefaultHeight() const;
183 Later this variable has to be removed. There should be now internal
184 cursor in a text (and thus not in a buffer). By keeping this it is
185 (I think) impossible to have several views with the same buffer, but
186 the cursor placed at different places.
188 Since the LyXText now has been moved from Buffer to BufferView
189 it should not be absolutely needed to move the cursor...
191 mutable LyXCursor cursor;
193 /* the selection cursor */
195 mutable bool selection;
197 mutable bool mark_set;
200 mutable LyXCursor sel_cursor;
202 LyXCursor sel_start_cursor;
204 mutable LyXCursor sel_end_cursor;
205 /// needed for the toggling
206 LyXCursor last_sel_cursor;
208 LyXCursor toggle_cursor;
210 LyXCursor toggle_end_cursor;
212 /// need the selection cursor:
215 void ClearSelection() const;
217 /// just selects the word the cursor is in
220 /** 'selects" the next word, where the cursor is not in
221 and returns this word as string. THe cursor will be moved
222 to the beginning of this word.
223 With SelectSelectedWord can this be highlighted really
225 char * SelectNextWord(float & value);
227 void SelectSelectedWord();
229 void SetCursor(LyXParagraph * par,
230 LyXParagraph::size_type pos,
231 bool setfont = true) const;
233 void SetCursorIntern(LyXParagraph * par,
234 LyXParagraph::size_type pos,
235 bool setfont = true) const;
237 void SetCursorFromCoordinates(int x, long y) const;
239 void CursorUp() const;
241 void CursorDown() const;
243 void CursorLeft() const;
245 void CursorRight() const;
247 void CursorLeftOneWord() const;
249 void CursorRightOneWord() const;
251 void CursorUpParagraph() const;
253 void CursorDownParagraph() const;
255 void CursorHome() const;
257 void CursorEnd() const;
259 void CursorTab() const;
261 void CursorTop() const;
263 void CursorBottom() const;
269 void DeleteWordForward();
271 void DeleteWordBackward();
273 void DeleteLineForward();
275 int SelectWordWhenUnderCursor();
279 text_capitalization = 1,
282 /// Change the case of the word at cursor position.
283 void ChangeWordCase(TextCase action);
285 /** returns a printed row in a pixmap. The y value is needed to
286 decide, wether it is selected text or not. This is a strange
289 void GetVisibleRow(LyXScreen & scr, int offset,
290 Row * row_ptr, long y);
294 void ToggleFootnote();
298 void OpenFootnotes();
302 void CloseFootnotes();
304 void CloseFootnote();
306 /** turn the selection into a new environment. If there is no
307 selection, create an empty environment
309 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
311 void MeltFootnoteEnvironment();
313 void CutSelection(bool = true);
315 void CopySelection();
317 void PasteSelection();
319 void copyEnvironmentType();
321 void pasteEnvironmentType();
323 void InsertFootnote();
325 void InsertMarginpar();
329 void InsertTabular();
331 /** the DTP switches for paragraphs. LyX will store the top settings
332 always in the first physical paragraph, the bottom settings in the
333 last. When a paragraph is broken, the top settings rest, the bottom
334 settings are given to the new one. So I can make shure, they do not
335 duplicate themself (and you cannnot make dirty things with them! )
337 void SetParagraph(bool line_top, bool line_bottom,
338 bool pagebreak_top, bool pagebreak_bottom,
339 VSpace const & space_top,
340 VSpace const & space_bottom,
342 string labelwidthstring,
344 void SetParagraphExtraOpt(int type,
347 int alignment, bool hfill,
348 bool start_minipage);
350 /* these things are for search and replace */
352 /** returns true if the specified string is at the specified
355 bool IsStringInText(LyXParagraph * par,
356 LyXParagraph::size_type pos,
357 char const * str) const;
358 /** sets the selection over the number of characters of string,
361 void SetSelectionOverString(char const * str);
363 /** simple replacing. The font of the first selected character
366 void ReplaceSelectionWithString(char const * str);
368 /** if the string can be found: return true and set the cursor to
370 bool SearchForward(char const * str) const;
371 bool SearchBackward(char const * str) const;
373 /// needed to insert the selection
374 void InsertStringA(LyXParagraph::TextContainer const & text);
375 /// needed to insert the selection
376 void InsertStringB(LyXParagraph::TextContainer const & text);
377 /// needed to insert the selection
378 void InsertStringA(char const * str);
379 /// needed to insert the selection
380 void InsertStringB(char const * str);
382 /// usefull when texing from within LyX
383 bool GotoNextError() const;
385 /// just another feature :)
386 bool GotoNextNote() const;
388 /** needed to switch between different classes this works
389 for a list of paragraphs beginning with the specified par
390 return value is the number of wrong conversions
392 int SwitchLayoutsBetweenClasses(char class1, char class2,
395 /* for the greater insets */
397 /// returns 0 if inset wasn't found
398 int UpdateInset(Inset * inset);
400 void CheckParagraph(LyXParagraph * par,
401 LyXParagraph::size_type pos);
403 int NumberOfCell(LyXParagraph * par,
404 LyXParagraph::size_type pos) const;
405 /* table stuff -- begin*/
407 /** all table features of the text-class are put together in
408 this function. Possible values of feature are defined in table.h
410 void TableFeatures(int feature, string const & val) const;
412 void TableFeatures(int feature) const;
414 /** pos points at the beginning of the next cell (if there is one)
416 int WidthOfCell(LyXParagraph * par,
417 LyXParagraph::size_type & pos) const;
419 void CheckParagraphInTable(LyXParagraph * par,
420 LyXParagraph::size_type pos);
422 void InsertCharInTable(char c);
424 void BackspaceInTable();
426 bool HitInTable(Row * row, int x) const;
428 bool MouseHitInTable(int x, long y) const;
429 /* table stuff -- end*/
431 LyXParagraph * GetParFromID(int id);
434 /// returns false if no undo possible
436 /// returns false if no redo possible
438 /// used by TextUndo/TextRedo
439 bool TextHandleUndo(Undo * undo);
440 /// makes sure the next operation will be stored
442 /// this is dangerous and for internal use only
444 /// this is dangerous and for internal use only
446 /// the flag used by FinishUndo();
447 mutable bool undo_finished;
451 void SetUndo(Undo::undo_kind kind,
452 LyXParagraph const * before,
453 LyXParagraph const * end) const;
455 void SetRedo(Undo::undo_kind kind,
456 LyXParagraph const * before,
457 LyXParagraph const * end);
459 Undo * CreateUndo(Undo::undo_kind kind,
460 LyXParagraph const * before,
461 LyXParagraph const * end) const;
462 /// for external use in lyx_cb.C
463 void SetCursorParUndo();
465 void CursorLeftIntern() const;
467 void CursorRightIntern() const;
469 void RemoveTableRow(LyXCursor * cursor) const;
472 bool IsEmptyTableRow(LyXCursor const & cursor) const;
475 bool IsEmptyTableCell() const;
477 void toggleAppendix();
479 unsigned short paperWidth() const { return paperwidth; }
482 LyXDirection GetDocumentDirection() const;
484 LyXDirection GetParDirection(LyXParagraph * par) const;
487 LyXDirection GetFontDirection(LyXFont const &font) const;
490 LyXDirection GetLetterDirection(LyXParagraph * par, LyXParagraph::size_type pos) const;
493 /// width of the paper
494 unsigned short paperwidth;
497 mutable Row * firstrow;
499 mutable Row * lastrow;
501 /** Copybuffer for copy environment type
502 Asger has learned that this should be a buffer-property instead
503 Lgb has learned that 'char' is a lousy type for non-characters
507 /// the currentrow is needed to access rows faster*/
508 mutable Row * currentrow; // pointer to the current row
509 /// position in the text
510 mutable long currentrow_y;
512 /** inserts a new row behind the specified row, increments
513 * the touched counters */
514 void InsertRow(Row * row, LyXParagraph * par,
515 LyXParagraph::size_type pos) const;
516 /** removes the row and reset the touched counters */
517 void RemoveRow(Row * row) const;
519 /** remove all following rows of the paragraph of the specified row. */
520 void RemoveParagraph(Row * row) const;
522 /** insert the specified paragraph behind the specified row */
523 void InsertParagraph(LyXParagraph * par, Row * row) const;
525 /** appends the implizit specified paragraph behind the specified row,
526 * start at the implizit given position */
527 void AppendParagraph(Row * row) const;
530 void BreakAgain(Row * row) const;
532 void BreakAgainOneRow(Row * row);
533 /// Calculate and set the height of the row
534 void SetHeightOfRow(Row * row_ptr) const;
536 /** this calculates the specified parameters. needed when setting
537 * the cursor and when creating a visible row */
538 void PrepareToPrint(Row * row, float & x,
539 float & fill_separator,
541 float & fill_label_hfill,
542 bool bidi = true) const;
544 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
546 /** Updates all counters starting BEHIND the row. Changed paragraphs
547 * with a dynamic left margin will be rebroken. */
548 void UpdateCounters(Row * row) const;
550 void SetCounter(LyXParagraph * par) const;
553 * some low level functions
557 int SingleWidth(LyXParagraph * par,
558 LyXParagraph::size_type pos) const;
560 int SingleWidth(LyXParagraph * par,
561 LyXParagraph::size_type pos, char c) const;
563 void Draw(Row const * row, LyXParagraph::size_type & pos,
565 int offset, float & x);
566 /// get the next breakpoint in a given paragraph
567 LyXParagraph::size_type NextBreakPoint(Row const * row,
569 /// returns the minimum space a row needs on the screen in pixel
570 int Fill(Row const * row, int paperwidth) const;
572 /** returns the minimum space a manual label needs on the
574 int LabelFill(Row const * row) const;
577 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
578 /** Returns the left beginning of the text.
579 This information cannot be taken from the layouts-objekt, because
580 in LaTeX the beginning of the text fits in some cases
581 (for example sections) exactly the label-width.
583 int LeftMargin(Row const * row) const;
585 int RightMargin(Row const * row) const;
587 int LabelEnd (Row const * row) const;
589 /** returns the number of separators in the specified row.
590 The separator on the very last column doesnt count
592 int NumberOfSeparators(Row const * row) const;
594 /** returns the number of hfills in the specified row. The
595 LyX-Hfill is a LaTeX \hfill so that the hfills at the
596 beginning and at the end were ignored. This is {\em MUCH}
597 more usefull than not to ignore!
599 int NumberOfHfills(Row const * row) const;
601 /// like NumberOfHfills, but only those in the manual label!
602 int NumberOfLabelHfills(Row const * row) const;
604 /** returns true, if a expansion is needed. Rules are given by
607 bool HfillExpansion(Row const * row_ptr,
608 LyXParagraph::size_type pos) const;
611 mutable vector<LyXParagraph::size_type> log2vis_list;
614 mutable vector<LyXParagraph::size_type> vis2log_list;
617 mutable LyXParagraph::size_type bidi_start;
620 void ComputeBidiTables(Row *row) const;
623 void ComputeBidiTablesFromTo(Row *row,
624 LyXParagraph::size_type from,
625 LyXParagraph::size_type to,
626 LyXParagraph::size_type offset) const;
628 /// Maps positions in the visual string to positions in logical string.
629 inline 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.
637 inline LyXParagraph::size_type vis2log(LyXParagraph::size_type pos) const {
638 if (bidi_start == -1)
641 return vis2log_list[pos-bidi_start];
644 /** returns the paragraph position of the last character in the
647 LyXParagraph::size_type RowLast(Row const * row) const;