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 * ======================================================*/
19 #include "definitions.h"
23 #include "lyxcursor.h"
24 #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;
55 /// the current font settings
58 LyXFont real_current_font;
61 LyXText(int paperwidth, Buffer *);
68 LyXFont GetFont(LyXParagraph * par,
69 LyXParagraph::size_type pos);
71 void SetCharFont(LyXParagraph * par,
72 LyXParagraph::size_type pos,
76 LyXFont GetFont(LyXParagraph * par, int pos);
78 void SetCharFont(LyXParagraph * par, int pos, LyXFont font);
80 /// returns a pointer to the very first LyXParagraph
81 LyXParagraph * FirstParagraph();
83 /// what you expect when pressing <enter> at cursor position
84 void BreakParagraph(char keep_layout = 0);
86 /** set layout over selection and make a total rebreak of
89 void SetLayout(char layout);
92 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
94 /** increment depth over selection and make a total rebreak of those
99 /** decrement depth over selection and make a total rebreak of those
103 /** Get the depth at current cursor position
105 int GetDepth() { return cursor.par->GetDepth(); }
107 /** set font over selection and make a total rebreak of those
109 toggleall defaults to false.
111 void SetFont(LyXFont font, bool toggleall = false);
113 /** deletes and inserts again all paragaphs between the cursor
114 and the specified par .The Cursor is needed to set the refreshing
116 This function is needed after SetLayout and SetFont etc.
118 void RedoParagraphs(LyXCursor cursor, LyXParagraph * end_par);
120 void RedoParagraph();
123 void ToggleFree(LyXFont font, bool toggleall = false);
125 /** recalculates the heights of all previous rows of the
126 specified paragraph. needed, if the last characters font
129 void RedoHeightOfParagraph(LyXCursor cursor);
131 /** forces the redrawing of a paragraph. Needed when manipulating a
134 void RedoDrawingOfParagraph(LyXCursor cursor);
136 /** insert a character, moves all the following breaks in the
137 same Paragraph one to the right and make a little rebreak
139 void InsertChar(char c);
141 void InsertInset(Inset * inset);
143 /// completes the insertion with a full rebreak
146 /// may be important for the menu
147 char * GetLayout(int row);
149 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
151 Row * need_break_row;
165 /** wether the screen needs a refresh,
166 starting with refresh_y
170 /** returns a pointer to the row near the specified y-coordinate
171 (relative to the whole text). y is set to the real beginning
174 Row * GetRowNearY(long & y);
176 /** returns the column near the specified x-coordinate of the row
177 x is set to the real beginning of this column
179 int GetColumnNearX(Row * row, int & x);
181 /** returns a pointer to a specified row. y is set to the beginning
185 Row * GetRow(LyXParagraph * par,
186 LyXParagraph::size_type pos, long & y);
188 Row * GetRow(LyXParagraph * par, int pos, long & y);
190 /** returns the height of a default row, needed for scrollbar
195 Later this variable has to be removed. There should be now internal
196 cursor in a text (and thus not in a buffer). By keeping this it is
197 (I think) impossible to have several views with the same buffer, but
198 the cursor placed at different places.
202 /* the selection cursor */
209 LyXCursor sel_cursor;
211 LyXCursor sel_start_cursor;
213 LyXCursor sel_end_cursor;
214 /// needed for the toggling
215 LyXCursor last_sel_cursor;
217 LyXCursor toggle_cursor;
219 LyXCursor toggle_end_cursor;
221 /// need the selection cursor:
224 void ClearSelection();
226 /// just selects the word the cursor is in
229 /** 'selects" the next word, where the cursor is not in
230 and returns this word as string. THe cursor will be moved
231 to the beginning of this word.
232 With SelectSelectedWord can this be highlighted really
234 char * SelectNextWord(float & value);
236 void SelectSelectedWord();
239 void SetCursor(LyXParagraph * par,
240 LyXParagraph::size_type pos);
242 void SetCursorIntern(LyXParagraph * par,
243 LyXParagraph::size_type pos);
246 void SetCursor(LyXParagraph * par, int pos);
248 void SetCursorIntern(LyXParagraph * par, int pos);
251 void SetCursorFromCoordinates(int x, long y);
261 void CursorLeftOneWord();
263 void CursorRightOneWord();
265 void CursorUpParagraph();
267 void CursorDownParagraph();
283 void DeleteWordForward();
285 void DeleteWordBackward();
287 void DeleteLineForward();
289 int SelectWordWhenUnderCursor();
290 /// Change the case of the word at cursor position
291 /** Change the case of the word at cursor position.
292 action is 0 for lower case, 1 for capitalization and 2 for
297 text_capitalization = 1,
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(LyXScreen & scr, int offset,
307 Row * row_ptr, long y);
311 void ToggleFootnote();
315 void OpenFootnotes();
319 void CloseFootnotes();
321 void CloseFootnote();
323 /** turn the selection into a new environment. If there is no
324 selection, create an empty environment
326 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
328 void MeltFootnoteEnvironment();
330 void CutSelection(bool = true);
332 void CopySelection();
334 void PasteSelection();
336 void copyEnvironmentType();
338 void pasteEnvironmentType();
340 void InsertFootnote();
342 void InsertMarginpar();
346 void InsertTabular();
348 /** the DTP switches for paragraphs. LyX will store the top settings
349 always in the first physical paragraph, the bottom settings in the
350 last. When a paragraph is broken, the top settings rest, the bottom
351 settings are given to the new one. So I can make shure, they do not
352 duplicate themself (and you cannnot make dirty things with them! )
354 void SetParagraph(bool line_top, bool line_bottom,
355 bool pagebreak_top, bool pagebreak_bottom,
356 VSpace space_top, VSpace 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
372 bool IsStringInText(LyXParagraph * par,
373 LyXParagraph::size_type pos,
376 bool IsStringInText(LyXParagraph * par, int pos, char const * str);
378 /** sets the selection over the number of characters of string,
381 void SetSelectionOverString(char const * str);
383 /** simple replacing. The font of the first selected character
386 void ReplaceSelectionWithString(char const * string);
388 /** if the string can be found: return true and set the cursor to
390 bool SearchForward(char const * string);
391 bool SearchBackward(char const * string);
394 /// needed to insert the selection
395 void InsertStringA(LyXParagraph::TextContainer const & text);
396 /// needed to insert the selection
397 void InsertStringB(LyXParagraph::TextContainer const & text);
399 /// needed to insert the selection
400 void InsertStringA(char const * string);
401 /// needed to insert the selection
402 void InsertStringB(char const * string);
404 /// usefull when texing from within LyX
405 bool GotoNextError();
407 /// just another feature :)
410 /** needed to switch between different classes this works
411 for a list of paragraphs beginning with the specified par
412 return value is the number of wrong conversions
414 int SwitchLayoutsBetweenClasses(char class1, char class2,
417 /* for the greater insets */
419 /// returns 0 if inset wasn't found
420 int UpdateInset(Inset * inset);
423 void CheckParagraph(LyXParagraph * par,
424 LyXParagraph::size_type pos);
426 int NumberOfCell(LyXParagraph * par,
427 LyXParagraph::size_type pos);
430 void CheckParagraph(LyXParagraph * par, int pos);
432 int NumberOfCell(LyXParagraph * par, int pos);
434 /* table stuff -- begin*/
436 /** all table features of the text-class are put together in
437 this function. Possible values of feature are defined in table.h
439 void TableFeatures(int feature, string val);
441 void TableFeatures(int feature);
443 /** pos points at the beginning of the next cell (if there is one)
446 int WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos);
448 void CheckParagraphInTable(LyXParagraph * par,
449 LyXParagraph::size_type pos);
451 int WidthOfCell(LyXParagraph * par, int & pos);
453 void CheckParagraphInTable(LyXParagraph * par, int pos);
456 void InsertCharInTable(char c);
458 void BackspaceInTable();
460 char HitInTable(Row * row, int x);
462 bool MouseHitInTable(int x, long y);
463 /* table stuff -- end*/
465 LyXParagraph * GetParFromID(int id);
468 /// returns false if no undo possible
470 /// returns false if no redo possible
472 /// used by TextUndo/TextRedo
473 bool TextHandleUndo(Undo * undo);
474 /// makes sure the next operation will be stored
476 /// this is dangerous and for internal use only
478 /// this is dangerous and for internal use only
480 /// the flag used by FinishUndo();
485 void SetUndo(Undo::undo_kind kind, LyXParagraph * before,
488 void SetRedo(Undo::undo_kind kind, LyXParagraph * before,
491 Undo * CreateUndo(Undo::undo_kind kind, LyXParagraph * before,
493 /// for external use in lyx_cb.C
494 void SetCursorParUndo();
496 void CursorLeftIntern();
498 void CursorRightIntern();
500 void RemoveTableRow(LyXCursor * cursor);
502 bool IsEmptyTableRow(LyXCursor * cursor);
504 bool IsEmptyTableCell();
506 void toggleAppendix();
514 /** Copybuffer for copy environment type
515 Asger has learned that this should be a buffer-property instead
516 Lgb has learned that 'char' is a lousy type for non-characters
520 /// the currentrow is needed to access rows faster*/
521 Row * currentrow; /* pointer to the current row */
522 /// position in the text
524 /// width of the paper
525 unsigned short paperwidth;
527 /** inserts a new row behind the specified row, increments
528 * the touched counters */
530 void InsertRow(Row * row, LyXParagraph * par,
531 LyXParagraph::size_type pos );
533 void InsertRow(Row * row, LyXParagraph * par, int pos );
535 /** removes the row and reset the touched counters */
536 void RemoveRow(Row * row);
538 /** remove all following rows of the paragraph of the specified row. */
539 void RemoveParagraph(Row * row);
541 /** insert the specified paragraph behind the specified row */
542 void InsertParagraph(LyXParagraph * par, Row * row);
544 /** appends the implizit specified paragraph behind the specified row,
545 * start at the implizit given position */
546 void AppendParagraph(Row * row);
549 void BreakAgain(Row * row);
551 void BreakAgainOneRow(Row * row);
553 void SetHeightOfRow(Row * row_ptr); /* calculate and set the height
556 /** this calculates the specified parameters. needed when setting
557 * the cursor and when creating a visible row */
558 void PrepareToPrint(Row * row, float & x, float & fill_separator,
559 float & fill_hfill, float & fill_label_hfill);
561 void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
563 /** Updates all counters starting BEHIND the row. Changed paragraphs
564 * with a dynamic left margin will be rebroken. */
565 void UpdateCounters(Row * row);
567 void SetCounter(LyXParagraph * par);
570 * some low level functions
575 int SingleWidth(LyXParagraph * par,
576 LyXParagraph::size_type pos);
578 int SingleWidth(LyXParagraph * par,
579 LyXParagraph::size_type pos, char c);
581 void Draw(Row * row, LyXParagraph::size_type & pos,
583 int offset, float & x);
584 /// get the next breakpoint in a given paragraph
585 LyXParagraph::size_type NextBreakPoint(Row * row,
589 int SingleWidth(LyXParagraph * par, int pos);
591 int SingleWidth(LyXParagraph * par, int pos, char c);
593 void Draw(Row * row, int & pos, LyXScreen & scr,
594 int offset, float & x);
595 /// get the next breakpoint in a given paragraph
596 int NextBreakPoint(Row * row, int width);
598 /// returns the minimum space a row needs on the screen in pixel
599 int Fill(Row * row, int paperwidth);
601 /** returns the minimum space a manual label needs on the
603 int LabelFill(Row * row);
607 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par);
610 int BeginningOfMainBody(LyXParagraph * par);
612 /** Returns the left beginning of the text.
613 This information cannot be taken from the layouts-objekt, because
614 in LaTeX the beginning of the text fits in some cases
615 (for example sections) exactly the label-width.
617 int LeftMargin(Row * row);
619 int RightMargin(Row * row);
621 int LabelEnd (Row * row);
623 /** returns the number of separators in the specified row.
624 The separator on the very last column doesnt count
626 int NumberOfSeparators(Row * row);
628 /** returns the number of hfills in the specified row. The
629 LyX-Hfill is a LaTeX \hfill so that the hfills at the
630 beginning and at the end were ignored. This is {\em MUCH}
631 more usefull than not to ignore!
633 int NumberOfHfills(Row * row);
635 /// like NumberOfHfills, but only those in the manual label!
636 int NumberOfLabelHfills(Row * row);
638 /** returns true, if a expansion is needed. Rules are given by
642 bool HfillExpansion(Row * row_ptr,
643 LyXParagraph::size_type pos);
644 /** returns the paragraph position of the last character in the
647 LyXParagraph::size_type RowLast(Row * row);
649 bool HfillExpansion(Row * row_ptr, int pos);
650 /** returns the paragraph position of the last character in the
653 int RowLast(Row * row);