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"
30 This class holds the mapping between buffer paragraphs and screen rows.
43 NEED_VERY_LITTLE_REFRESH
46 /// points to Buffer.params
47 BufferParams * parameters;
54 /// the current font settings
57 LyXFont real_current_font;
60 LyXText(int paperwidth, Buffer *);
66 LyXFont GetFont(LyXParagraph * par,
67 LyXParagraph::size_type pos);
69 void SetCharFont(LyXParagraph * par,
70 LyXParagraph::size_type pos,
72 /// returns a pointer to the very first LyXParagraph
73 LyXParagraph * FirstParagraph();
75 /// what you expect when pressing <enter> at cursor position
76 void BreakParagraph(char keep_layout = 0);
78 /** set layout over selection and make a total rebreak of
81 void SetLayout(char layout);
84 void MakeFontEntriesLayoutSpecific(LyXParagraph * par);
86 /** increment depth over selection and make a total rebreak of those
91 /** decrement depth over selection and make a total rebreak of those
95 /** Get the depth at current cursor position
97 int GetDepth() { return cursor.par->GetDepth(); }
99 /** set font over selection and make a total rebreak of those
101 toggleall defaults to false.
103 void SetFont(LyXFont font, bool toggleall = false);
105 /** deletes and inserts again all paragaphs between the cursor
106 and the specified par .The Cursor is needed to set the refreshing
108 This function is needed after SetLayout and SetFont etc.
110 void RedoParagraphs(LyXCursor cursor, LyXParagraph * end_par);
112 void RedoParagraph();
115 void ToggleFree(LyXFont font, bool toggleall = false);
117 /** recalculates the heights of all previous rows of the
118 specified paragraph. needed, if the last characters font
121 void RedoHeightOfParagraph(LyXCursor cursor);
123 /** forces the redrawing of a paragraph. Needed when manipulating a
126 void RedoDrawingOfParagraph(LyXCursor cursor);
128 /** insert a character, moves all the following breaks in the
129 same Paragraph one to the right and make a little rebreak
131 void InsertChar(char c);
133 void InsertInset(Inset * inset);
135 /// completes the insertion with a full rebreak
138 /// may be important for the menu
139 char * GetLayout(int row);
141 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
143 Row * need_break_row;
157 /** wether the screen needs a refresh,
158 starting with refresh_y
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);
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);
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);
178 /** returns the height of a default row, needed for scrollbar
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.
190 /* the selection cursor */
197 LyXCursor sel_cursor;
199 LyXCursor sel_start_cursor;
201 LyXCursor sel_end_cursor;
202 /// needed for the toggling
203 LyXCursor last_sel_cursor;
205 LyXCursor toggle_cursor;
207 LyXCursor toggle_end_cursor;
209 /// need the selection cursor:
212 void ClearSelection();
214 /// just selects the word the cursor is in
217 /** 'selects" the next word, where the cursor is not in
218 and returns this word as string. THe cursor will be moved
219 to the beginning of this word.
220 With SelectSelectedWord can this be highlighted really
222 char * SelectNextWord(float & value);
224 void SelectSelectedWord();
226 void SetCursor(LyXParagraph * par,
227 LyXParagraph::size_type pos);
229 void SetCursorIntern(LyXParagraph * par,
230 LyXParagraph::size_type pos);
232 void SetCursorFromCoordinates(int x, long y);
242 void CursorLeftOneWord();
244 void CursorRightOneWord();
246 void CursorUpParagraph();
248 void CursorDownParagraph();
264 void DeleteWordForward();
266 void DeleteWordBackward();
268 void DeleteLineForward();
270 int SelectWordWhenUnderCursor();
271 /// Change the case of the word at cursor position
272 /** Change the case of the word at cursor position.
273 action is 0 for lower case, 1 for capitalization and 2 for
278 text_capitalization = 1,
281 void ChangeWordCase(TextCase action);
283 /** returns a printed row in a pixmap. The y value is needed to
284 decide, wether it is selected text or not. This is a strange
287 void GetVisibleRow(LyXScreen & scr, int offset,
288 Row * row_ptr, long y);
292 void ToggleFootnote();
296 void OpenFootnotes();
300 void CloseFootnotes();
302 void CloseFootnote();
304 /** turn the selection into a new environment. If there is no
305 selection, create an empty environment
307 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
309 void MeltFootnoteEnvironment();
311 void CutSelection(bool = true);
313 void CopySelection();
315 void PasteSelection();
317 void copyEnvironmentType();
319 void pasteEnvironmentType();
321 void InsertFootnote();
323 void InsertMarginpar();
327 void InsertTabular();
329 /** the DTP switches for paragraphs. LyX will store the top settings
330 always in the first physical paragraph, the bottom settings in the
331 last. When a paragraph is broken, the top settings rest, the bottom
332 settings are given to the new one. So I can make shure, they do not
333 duplicate themself (and you cannnot make dirty things with them! )
335 void SetParagraph(bool line_top, bool line_bottom,
336 bool pagebreak_top, bool pagebreak_bottom,
337 VSpace space_top, VSpace space_bottom,
339 string labelwidthstring,
341 void SetParagraphExtraOpt(int type,
344 int alignment, bool hfill,
345 bool start_minipage);
347 /* these things are for search and replace */
349 /** returns true if the specified string is at the specified
352 bool IsStringInText(LyXParagraph * par,
353 LyXParagraph::size_type pos,
355 /** sets the selection over the number of characters of string,
358 void SetSelectionOverString(char const * str);
360 /** simple replacing. The font of the first selected character
363 void ReplaceSelectionWithString(char const * string);
365 /** if the string can be found: return true and set the cursor to
367 bool SearchForward(char const * string);
368 bool SearchBackward(char const * string);
370 /// needed to insert the selection
371 void InsertStringA(LyXParagraph::TextContainer const & text);
372 /// needed to insert the selection
373 void InsertStringB(LyXParagraph::TextContainer const & text);
374 /// needed to insert the selection
375 void InsertStringA(char const * string);
376 /// needed to insert the selection
377 void InsertStringB(char const * string);
379 /// usefull when texing from within LyX
380 bool GotoNextError();
382 /// just another feature :)
385 /** needed to switch between different classes this works
386 for a list of paragraphs beginning with the specified par
387 return value is the number of wrong conversions
389 int SwitchLayoutsBetweenClasses(char class1, char class2,
392 /* for the greater insets */
394 /// returns 0 if inset wasn't found
395 int UpdateInset(Inset * inset);
397 void CheckParagraph(LyXParagraph * par,
398 LyXParagraph::size_type pos);
400 int NumberOfCell(LyXParagraph * par,
401 LyXParagraph::size_type pos);
402 /* table stuff -- begin*/
404 /** all table features of the text-class are put together in
405 this function. Possible values of feature are defined in table.h
407 void TableFeatures(int feature, string val);
409 void TableFeatures(int feature);
411 /** pos points at the beginning of the next cell (if there is one)
413 int WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos);
415 void CheckParagraphInTable(LyXParagraph * par,
416 LyXParagraph::size_type pos);
418 void InsertCharInTable(char c);
420 void BackspaceInTable();
422 char HitInTable(Row * row, int x);
424 bool MouseHitInTable(int x, long y);
425 /* table stuff -- end*/
427 LyXParagraph * GetParFromID(int id);
430 /// returns false if no undo possible
432 /// returns false if no redo possible
434 /// used by TextUndo/TextRedo
435 bool TextHandleUndo(Undo * undo);
436 /// makes sure the next operation will be stored
438 /// this is dangerous and for internal use only
440 /// this is dangerous and for internal use only
442 /// the flag used by FinishUndo();
447 void SetUndo(Undo::undo_kind kind, LyXParagraph * before,
450 void SetRedo(Undo::undo_kind kind, LyXParagraph * before,
453 Undo * CreateUndo(Undo::undo_kind kind, LyXParagraph * before,
455 /// for external use in lyx_cb.C
456 void SetCursorParUndo();
458 void CursorLeftIntern();
460 void CursorRightIntern();
462 void RemoveTableRow(LyXCursor * cursor);
464 bool IsEmptyTableRow(LyXCursor * cursor);
466 bool IsEmptyTableCell();
468 void toggleAppendix();
476 /** Copybuffer for copy environment type
477 Asger has learned that this should be a buffer-property instead
478 Lgb has learned that 'char' is a lousy type for non-characters
482 /// the currentrow is needed to access rows faster*/
483 Row * currentrow; /* pointer to the current row */
484 /// position in the text
486 /// width of the paper
487 unsigned short paperwidth;
489 /** inserts a new row behind the specified row, increments
490 * the touched counters */
491 void InsertRow(Row * row, LyXParagraph * par,
492 LyXParagraph::size_type pos );
493 /** removes the row and reset the touched counters */
494 void RemoveRow(Row * row);
496 /** remove all following rows of the paragraph of the specified row. */
497 void RemoveParagraph(Row * row);
499 /** insert the specified paragraph behind the specified row */
500 void InsertParagraph(LyXParagraph * par, Row * row);
502 /** appends the implizit specified paragraph behind the specified row,
503 * start at the implizit given position */
504 void AppendParagraph(Row * row);
507 void BreakAgain(Row * row);
509 void BreakAgainOneRow(Row * row);
511 void SetHeightOfRow(Row * row_ptr); /* calculate and set the height
514 /** this calculates the specified parameters. needed when setting
515 * the cursor and when creating a visible row */
516 void PrepareToPrint(Row * row, float & x, float & fill_separator,
517 float & fill_hfill, float & fill_label_hfill);
519 void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
521 /** Updates all counters starting BEHIND the row. Changed paragraphs
522 * with a dynamic left margin will be rebroken. */
523 void UpdateCounters(Row * row);
525 void SetCounter(LyXParagraph * par);
528 * some low level functions
532 int SingleWidth(LyXParagraph * par,
533 LyXParagraph::size_type pos);
535 int SingleWidth(LyXParagraph * par,
536 LyXParagraph::size_type pos, char c);
538 void Draw(Row * row, LyXParagraph::size_type & pos,
540 int offset, float & x);
541 /// get the next breakpoint in a given paragraph
542 LyXParagraph::size_type NextBreakPoint(Row * row,
544 /// returns the minimum space a row needs on the screen in pixel
545 int Fill(Row * row, int paperwidth);
547 /** returns the minimum space a manual label needs on the
549 int LabelFill(Row * row);
552 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par);
553 /** Returns the left beginning of the text.
554 This information cannot be taken from the layouts-objekt, because
555 in LaTeX the beginning of the text fits in some cases
556 (for example sections) exactly the label-width.
558 int LeftMargin(Row * row);
560 int RightMargin(Row * row);
562 int LabelEnd (Row * row);
564 /** returns the number of separators in the specified row.
565 The separator on the very last column doesnt count
567 int NumberOfSeparators(Row * row);
569 /** returns the number of hfills in the specified row. The
570 LyX-Hfill is a LaTeX \hfill so that the hfills at the
571 beginning and at the end were ignored. This is {\em MUCH}
572 more usefull than not to ignore!
574 int NumberOfHfills(Row * row);
576 /// like NumberOfHfills, but only those in the manual label!
577 int NumberOfLabelHfills(Row * row);
579 /** returns true, if a expansion is needed. Rules are given by
582 bool HfillExpansion(Row * row_ptr,
583 LyXParagraph::size_type pos);
584 /** returns the paragraph position of the last character in the
587 LyXParagraph::size_type RowLast(Row * row);