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 * ====================================================== */
21 #include "lyxcursor.h"
22 #include "lyxparagraph.h"
32 This class holds the mapping between buffer paragraphs and screen rows.
45 NEED_VERY_LITTLE_REFRESH
48 /// points to Buffer.params
49 BufferParams * parameters;
53 mutable int number_of_rows;
56 /// the current font settings
57 mutable LyXFont current_font;
59 mutable LyXFont real_current_font;
62 LyXText(BufferView *, int paperwidth, Buffer *);
68 void owner(BufferView *);
71 LyXFont GetFont(LyXParagraph * par,
72 LyXParagraph::size_type pos) const;
74 void SetCharFont(LyXParagraph * par,
75 LyXParagraph::size_type pos,
76 LyXFont const & font);
77 /// returns a pointer to the very first LyXParagraph
78 LyXParagraph * FirstParagraph() const;
80 /// what you expect when pressing <enter> at cursor position
81 void BreakParagraph(char keep_layout = 0);
83 /** set layout over selection and make a total rebreak of
86 void SetLayout(char layout);
89 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
91 /** increment depth over selection and make a total rebreak of those
96 /** decrement depth over selection and make a total rebreak of those
100 /** Get the depth at current cursor position
102 int GetDepth() const { return cursor.par->GetDepth(); }
104 /** set font over selection and make a total rebreak of those
106 toggleall defaults to false.
108 void SetFont(LyXFont const & font, bool toggleall = false);
110 /** deletes and inserts again all paragaphs between the cursor
111 and the specified par. The Cursor is needed to set the refreshing
113 This function is needed after SetLayout and SetFont etc.
115 void RedoParagraphs(LyXCursor const & cursor,
116 LyXParagraph const * end_par) const;
118 void RedoParagraph() const;
121 void ToggleFree(LyXFont const & font, bool toggleall = false);
123 /** recalculates the heights of all previous rows of the
124 specified paragraph. needed, if the last characters font
127 void RedoHeightOfParagraph(LyXCursor const & cursor);
129 /** forces the redrawing of a paragraph. Needed when manipulating a
132 void RedoDrawingOfParagraph(LyXCursor const & cursor);
134 /** insert a character, moves all the following breaks in the
135 same Paragraph one to the right and make a little rebreak
137 void InsertChar(char c);
139 void InsertInset(Inset * inset);
141 /// completes the insertion with a full rebreak
145 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
147 Row * need_break_row;
149 mutable long refresh_y;
157 mutable Row * refresh_row;
161 /** wether the screen needs a refresh,
162 starting with refresh_y
164 mutable text_status status;
166 /** returns a pointer to the row near the specified y-coordinate
167 (relative to the whole text). y is set to the real beginning
170 Row * GetRowNearY(long & y) const;
172 /** returns the column near the specified x-coordinate of the row
173 x is set to the real beginning of this column
175 int GetColumnNearX(Row * row, int & x) const;
177 /** returns a pointer to a specified row. y is set to the beginning
180 Row * GetRow(LyXParagraph * par,
181 LyXParagraph::size_type pos, long & y) const;
182 /** returns the height of a default row, needed for scrollbar
184 int DefaultHeight() const;
187 Later this variable has to be removed. There should be now internal
188 cursor in a text (and thus not in a buffer). By keeping this it is
189 (I think) impossible to have several views with the same buffer, but
190 the cursor placed at different places.
192 Since the LyXText now has been moved from Buffer to BufferView
193 it should not be absolutely needed to move the cursor...
195 mutable LyXCursor cursor;
197 /* the selection cursor */
199 mutable bool selection;
201 mutable bool mark_set;
204 mutable LyXCursor sel_cursor;
206 LyXCursor sel_start_cursor;
208 mutable LyXCursor sel_end_cursor;
209 /// needed for the toggling
210 LyXCursor last_sel_cursor;
212 LyXCursor toggle_cursor;
214 LyXCursor toggle_end_cursor;
216 /// need the selection cursor:
219 void ClearSelection() const;
221 /// just selects the word the cursor is in
224 /** 'selects" the next word, where the cursor is not in
225 and returns this word as string. THe cursor will be moved
226 to the beginning of this word.
227 With SelectSelectedWord can this be highlighted really
229 char * SelectNextWord(float & value);
231 void SelectSelectedWord();
233 void SetCursor(LyXParagraph * par,
234 LyXParagraph::size_type pos,
235 bool setfont = true) const;
237 void SetCursorIntern(LyXParagraph * par,
238 LyXParagraph::size_type pos,
239 bool setfont = true) const;
241 void SetCursorFromCoordinates(int x, long y) const;
243 void CursorUp() const;
245 void CursorDown() const;
247 void CursorLeft() const;
249 void CursorRight() const;
251 void CursorLeftOneWord() const;
253 void CursorRightOneWord() const;
255 void CursorUpParagraph() const;
257 void CursorDownParagraph() const;
259 void CursorHome() const;
261 void CursorEnd() const;
263 void CursorTab() const;
265 void CursorTop() const;
267 void CursorBottom() const;
273 void DeleteWordForward();
275 void DeleteWordBackward();
277 void DeleteLineForward();
279 int SelectWordWhenUnderCursor();
283 text_capitalization = 1,
286 /// Change the case of the word at cursor position.
287 void ChangeWordCase(TextCase action);
289 /** returns a printed row in a pixmap. The y value is needed to
290 decide, wether it is selected text or not. This is a strange
293 void GetVisibleRow(int offset,
294 Row * row_ptr, long y);
298 void ToggleFootnote();
302 void OpenFootnotes();
306 void CloseFootnotes();
308 void CloseFootnote();
310 /** turn the selection into a new environment. If there is no
311 selection, create an empty environment
313 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
315 void MeltFootnoteEnvironment();
317 void CutSelection(bool = true);
319 void CopySelection();
321 void PasteSelection();
323 void copyEnvironmentType();
325 void pasteEnvironmentType();
327 void InsertFootnote();
329 void InsertMarginpar();
333 void InsertTabular();
335 /** the DTP switches for paragraphs. LyX will store the top settings
336 always in the first physical paragraph, the bottom settings in the
337 last. When a paragraph is broken, the top settings rest, the bottom
338 settings are given to the new one. So I can make shure, they do not
339 duplicate themself (and you cannnot make dirty things with them! )
341 void SetParagraph(bool line_top, bool line_bottom,
342 bool pagebreak_top, bool pagebreak_bottom,
343 VSpace const & space_top,
344 VSpace const & space_bottom,
346 string labelwidthstring,
348 void SetParagraphExtraOpt(int type,
351 int alignment, bool hfill,
352 bool start_minipage);
354 /* these things are for search and replace */
356 /** returns true if the specified string is at the specified
359 bool IsStringInText(LyXParagraph * par,
360 LyXParagraph::size_type pos,
361 char const * str) const;
362 /** sets the selection over the number of characters of string,
365 void SetSelectionOverString(char const * str);
367 /** simple replacing. The font of the first selected character
370 void ReplaceSelectionWithString(char const * str);
372 /** if the string can be found: return true and set the cursor to
374 bool SearchForward(char const * str) const;
375 bool SearchBackward(char const * str) const;
377 /// needed to insert the selection
378 void InsertStringA(LyXParagraph::TextContainer const & text);
379 /// needed to insert the selection
380 void InsertStringB(LyXParagraph::TextContainer const & text);
381 /// needed to insert the selection
382 void InsertStringA(char const * str);
383 /// needed to insert the selection
384 void InsertStringB(char const * str);
386 /// usefull when texing from within LyX
387 bool GotoNextError() const;
389 /// just another feature :)
390 bool GotoNextNote() const;
392 /** needed to switch between different classes this works
393 for a list of paragraphs beginning with the specified par
394 return value is the number of wrong conversions
396 int SwitchLayoutsBetweenClasses(char class1, char class2,
399 /* for the greater insets */
401 /// returns 0 if inset wasn't found
402 int UpdateInset(Inset * inset);
404 void CheckParagraph(LyXParagraph * par,
405 LyXParagraph::size_type pos);
407 int NumberOfCell(LyXParagraph * par,
408 LyXParagraph::size_type pos) const;
409 /* table stuff -- begin*/
411 /** all table features of the text-class are put together in
412 this function. Possible values of feature are defined in table.h
414 void TableFeatures(int feature, string const & val) const;
416 void TableFeatures(int feature) const;
418 /** pos points at the beginning of the next cell (if there is one)
420 int WidthOfCell(LyXParagraph * par,
421 LyXParagraph::size_type & pos) const;
423 void CheckParagraphInTable(LyXParagraph * par,
424 LyXParagraph::size_type pos);
426 void InsertCharInTable(char c);
428 void BackspaceInTable();
430 bool HitInTable(Row * row, int x) const;
432 bool MouseHitInTable(int x, long y) const;
433 /* table stuff -- end*/
435 LyXParagraph * GetParFromID(int id);
438 /// returns false if no undo possible
440 /// returns false if no redo possible
442 /// used by TextUndo/TextRedo
443 bool TextHandleUndo(Undo * undo);
444 /// makes sure the next operation will be stored
446 /// this is dangerous and for internal use only
448 /// this is dangerous and for internal use only
450 /// the flag used by FinishUndo();
451 mutable bool undo_finished;
455 void SetUndo(Undo::undo_kind kind,
456 LyXParagraph const * before,
457 LyXParagraph const * end) const;
459 void SetRedo(Undo::undo_kind kind,
460 LyXParagraph const * before,
461 LyXParagraph const * end);
463 Undo * CreateUndo(Undo::undo_kind kind,
464 LyXParagraph const * before,
465 LyXParagraph const * end) const;
466 /// for external use in lyx_cb.C
467 void SetCursorParUndo();
469 void CursorLeftIntern() const;
471 void CursorRightIntern() const;
473 void RemoveTableRow(LyXCursor * cursor) const;
475 bool IsEmptyTableCell() const;
477 void toggleAppendix();
479 unsigned short paperWidth() const { return paperwidth; }
484 /// width of the paper
485 unsigned short paperwidth;
488 mutable Row * firstrow;
490 mutable Row * lastrow;
492 /** Copybuffer for copy environment type
493 Asger has learned that this should be a buffer-property instead
494 Lgb has learned that 'char' is a lousy type for non-characters
498 /// the currentrow is needed to access rows faster*/
499 mutable Row * currentrow; // pointer to the current row
500 /// position in the text
501 mutable long currentrow_y;
503 /** inserts a new row behind the specified row, increments
504 * the touched counters */
505 void InsertRow(Row * row, LyXParagraph * par,
506 LyXParagraph::size_type pos) const;
507 /** removes the row and reset the touched counters */
508 void RemoveRow(Row * row) const;
510 /** remove all following rows of the paragraph of the specified row. */
511 void RemoveParagraph(Row * row) const;
513 /** insert the specified paragraph behind the specified row */
514 void InsertParagraph(LyXParagraph * par, Row * row) const;
516 /** appends the implizit specified paragraph behind the specified row,
517 * start at the implizit given position */
518 void AppendParagraph(Row * row) const;
521 void BreakAgain(Row * row) const;
523 void BreakAgainOneRow(Row * row);
524 /// Calculate and set the height of the row
525 void SetHeightOfRow(Row * row_ptr) const;
527 /** this calculates the specified parameters. needed when setting
528 * the cursor and when creating a visible row */
529 void PrepareToPrint(Row * row, float & x,
530 float & fill_separator,
532 float & fill_label_hfill,
533 bool bidi = true) const;
535 void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const;
537 /** Updates all counters starting BEHIND the row. Changed paragraphs
538 * with a dynamic left margin will be rebroken. */
539 void UpdateCounters(Row * row) const;
541 void SetCounter(LyXParagraph * par) const;
544 * some low level functions
548 int SingleWidth(LyXParagraph * par,
549 LyXParagraph::size_type pos) const;
551 int SingleWidth(LyXParagraph * par,
552 LyXParagraph::size_type pos, char c) const;
554 void draw(Row const * row,
555 LyXParagraph::size_type & pos,
556 int offset, float & x);
558 /// get the next breakpoint in a given paragraph
559 LyXParagraph::size_type NextBreakPoint(Row const * row,
561 /// returns the minimum space a row needs on the screen in pixel
562 int Fill(Row const * row, int paperwidth) const;
564 /** returns the minimum space a manual label needs on the
566 int LabelFill(Row const * row) const;
569 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;
596 /** returns true, if a expansion is needed. Rules are given by
599 bool HfillExpansion(Row const * row_ptr,
600 LyXParagraph::size_type pos) const;
603 mutable vector<LyXParagraph::size_type> log2vis_list;
606 mutable vector<LyXParagraph::size_type> vis2log_list;
609 mutable LyXParagraph::size_type bidi_start;
612 void ComputeBidiTables(Row *row) const;
615 void ComputeBidiTablesFromTo(Row *row,
616 LyXParagraph::size_type from,
617 LyXParagraph::size_type to,
618 LyXParagraph::size_type offset) 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];
638 /** returns the paragraph position of the last character in the
641 LyXParagraph::size_type RowLast(Row const * row) const;