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
139 LyXParagraph::footnote_flag GetFootnoteFlag(int row);
141 Row * need_break_row;
155 /** wether the screen needs a refresh,
156 starting with refresh_y
160 /** returns a pointer to the row near the specified y-coordinate
161 (relative to the whole text). y is set to the real beginning
164 Row * GetRowNearY(long & y);
166 /** returns the column near the specified x-coordinate of the row
167 x is set to the real beginning of this column
169 int GetColumnNearX(Row * row, int & x);
171 /** returns a pointer to a specified row. y is set to the beginning
174 Row * GetRow(LyXParagraph * par,
175 LyXParagraph::size_type pos, long & y);
176 /** returns the height of a default row, needed for scrollbar
181 Later this variable has to be removed. There should be now internal
182 cursor in a text (and thus not in a buffer). By keeping this it is
183 (I think) impossible to have several views with the same buffer, but
184 the cursor placed at different places.
188 /* the selection cursor */
195 LyXCursor sel_cursor;
197 LyXCursor sel_start_cursor;
199 LyXCursor sel_end_cursor;
200 /// needed for the toggling
201 LyXCursor last_sel_cursor;
203 LyXCursor toggle_cursor;
205 LyXCursor toggle_end_cursor;
207 /// need the selection cursor:
210 void ClearSelection();
212 /// just selects the word the cursor is in
215 /** 'selects" the next word, where the cursor is not in
216 and returns this word as string. THe cursor will be moved
217 to the beginning of this word.
218 With SelectSelectedWord can this be highlighted really
220 char * SelectNextWord(float & value);
222 void SelectSelectedWord();
224 void SetCursor(LyXParagraph * par,
225 LyXParagraph::size_type pos);
227 void SetCursorIntern(LyXParagraph * par,
228 LyXParagraph::size_type pos);
230 void SetCursorFromCoordinates(int x, long y);
240 void CursorLeftOneWord();
242 void CursorRightOneWord();
244 void CursorUpParagraph();
246 void CursorDownParagraph();
262 void DeleteWordForward();
264 void DeleteWordBackward();
266 void DeleteLineForward();
268 int SelectWordWhenUnderCursor();
272 text_capitalization = 1,
275 /// Change the case of the word at cursor position.
276 void ChangeWordCase(TextCase action);
278 /** returns a printed row in a pixmap. The y value is needed to
279 decide, wether it is selected text or not. This is a strange
282 void GetVisibleRow(LyXScreen & scr, int offset,
283 Row * row_ptr, long y);
287 void ToggleFootnote();
291 void OpenFootnotes();
295 void CloseFootnotes();
297 void CloseFootnote();
299 /** turn the selection into a new environment. If there is no
300 selection, create an empty environment
302 void InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind);
304 void MeltFootnoteEnvironment();
306 void CutSelection(bool = true);
308 void CopySelection();
310 void PasteSelection();
312 void copyEnvironmentType();
314 void pasteEnvironmentType();
316 void InsertFootnote();
318 void InsertMarginpar();
322 void InsertTabular();
324 /** the DTP switches for paragraphs. LyX will store the top settings
325 always in the first physical paragraph, the bottom settings in the
326 last. When a paragraph is broken, the top settings rest, the bottom
327 settings are given to the new one. So I can make shure, they do not
328 duplicate themself (and you cannnot make dirty things with them! )
330 void SetParagraph(bool line_top, bool line_bottom,
331 bool pagebreak_top, bool pagebreak_bottom,
332 VSpace space_top, VSpace space_bottom,
334 string labelwidthstring,
336 void SetParagraphExtraOpt(int type,
339 int alignment, bool hfill,
340 bool start_minipage);
342 /* these things are for search and replace */
344 /** returns true if the specified string is at the specified
347 bool IsStringInText(LyXParagraph * par,
348 LyXParagraph::size_type pos,
350 /** sets the selection over the number of characters of string,
353 void SetSelectionOverString(char const * str);
355 /** simple replacing. The font of the first selected character
358 void ReplaceSelectionWithString(char const * string);
360 /** if the string can be found: return true and set the cursor to
362 bool SearchForward(char const * string);
363 bool SearchBackward(char const * string);
365 /// needed to insert the selection
366 void InsertStringA(LyXParagraph::TextContainer const & text);
367 /// needed to insert the selection
368 void InsertStringB(LyXParagraph::TextContainer const & text);
369 /// needed to insert the selection
370 void InsertStringA(char const * string);
371 /// needed to insert the selection
372 void InsertStringB(char const * string);
374 /// usefull when texing from within LyX
375 bool GotoNextError();
377 /// just another feature :)
380 /** needed to switch between different classes this works
381 for a list of paragraphs beginning with the specified par
382 return value is the number of wrong conversions
384 int SwitchLayoutsBetweenClasses(char class1, char class2,
387 /* for the greater insets */
389 /// returns 0 if inset wasn't found
390 int UpdateInset(Inset * inset);
392 void CheckParagraph(LyXParagraph * par,
393 LyXParagraph::size_type pos);
395 int NumberOfCell(LyXParagraph * par,
396 LyXParagraph::size_type pos);
397 /* table stuff -- begin*/
399 /** all table features of the text-class are put together in
400 this function. Possible values of feature are defined in table.h
402 void TableFeatures(int feature, string val);
404 void TableFeatures(int feature);
406 /** pos points at the beginning of the next cell (if there is one)
408 int WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos);
410 void CheckParagraphInTable(LyXParagraph * par,
411 LyXParagraph::size_type pos);
413 void InsertCharInTable(char c);
415 void BackspaceInTable();
417 bool HitInTable(Row * row, int x);
419 bool MouseHitInTable(int x, long y);
420 /* table stuff -- end*/
422 LyXParagraph * GetParFromID(int id);
425 /// returns false if no undo possible
427 /// returns false if no redo possible
429 /// used by TextUndo/TextRedo
430 bool TextHandleUndo(Undo * undo);
431 /// makes sure the next operation will be stored
433 /// this is dangerous and for internal use only
435 /// this is dangerous and for internal use only
437 /// the flag used by FinishUndo();
442 void SetUndo(Undo::undo_kind kind, LyXParagraph * before,
445 void SetRedo(Undo::undo_kind kind, LyXParagraph * before,
448 Undo * CreateUndo(Undo::undo_kind kind, LyXParagraph * before,
450 /// for external use in lyx_cb.C
451 void SetCursorParUndo();
453 void CursorLeftIntern();
455 void CursorRightIntern();
457 void RemoveTableRow(LyXCursor * cursor);
459 bool IsEmptyTableRow(LyXCursor * cursor) const;
461 bool IsEmptyTableCell() const;
463 void toggleAppendix();
471 /** Copybuffer for copy environment type
472 Asger has learned that this should be a buffer-property instead
473 Lgb has learned that 'char' is a lousy type for non-characters
477 /// the currentrow is needed to access rows faster*/
478 Row * currentrow; /* pointer to the current row */
479 /// position in the text
481 /// width of the paper
482 unsigned short paperwidth;
484 /** inserts a new row behind the specified row, increments
485 * the touched counters */
486 void InsertRow(Row * row, LyXParagraph * par,
487 LyXParagraph::size_type pos );
488 /** removes the row and reset the touched counters */
489 void RemoveRow(Row * row);
491 /** remove all following rows of the paragraph of the specified row. */
492 void RemoveParagraph(Row * row);
494 /** insert the specified paragraph behind the specified row */
495 void InsertParagraph(LyXParagraph * par, Row * row);
497 /** appends the implizit specified paragraph behind the specified row,
498 * start at the implizit given position */
499 void AppendParagraph(Row * row);
502 void BreakAgain(Row * row);
504 void BreakAgainOneRow(Row * row);
506 void SetHeightOfRow(Row * row_ptr); /* calculate and set the height
509 /** this calculates the specified parameters. needed when setting
510 * the cursor and when creating a visible row */
511 void PrepareToPrint(Row * row, float & x, float & fill_separator,
512 float & fill_hfill, float & fill_label_hfill);
514 void DeleteEmptyParagraphMechanism(LyXCursor old_cursor);
516 /** Updates all counters starting BEHIND the row. Changed paragraphs
517 * with a dynamic left margin will be rebroken. */
518 void UpdateCounters(Row * row);
520 void SetCounter(LyXParagraph * par);
523 * some low level functions
527 int SingleWidth(LyXParagraph * par,
528 LyXParagraph::size_type pos);
530 int SingleWidth(LyXParagraph * par,
531 LyXParagraph::size_type pos, char c);
533 void Draw(Row * row, LyXParagraph::size_type & pos,
535 int offset, float & x);
536 /// get the next breakpoint in a given paragraph
537 LyXParagraph::size_type NextBreakPoint(Row * row,
539 /// returns the minimum space a row needs on the screen in pixel
540 int Fill(Row * row, int paperwidth);
542 /** returns the minimum space a manual label needs on the
544 int LabelFill(Row * row);
547 LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const;
548 /** Returns the left beginning of the text.
549 This information cannot be taken from the layouts-objekt, because
550 in LaTeX the beginning of the text fits in some cases
551 (for example sections) exactly the label-width.
553 int LeftMargin(Row * row);
555 int RightMargin(Row * row);
557 int LabelEnd (Row * row);
559 /** returns the number of separators in the specified row.
560 The separator on the very last column doesnt count
562 int NumberOfSeparators(Row * row);
564 /** returns the number of hfills in the specified row. The
565 LyX-Hfill is a LaTeX \hfill so that the hfills at the
566 beginning and at the end were ignored. This is {\em MUCH}
567 more usefull than not to ignore!
569 int NumberOfHfills(Row * row);
571 /// like NumberOfHfills, but only those in the manual label!
572 int NumberOfLabelHfills(Row * row);
574 /** returns true, if a expansion is needed. Rules are given by
577 bool HfillExpansion(Row * row_ptr,
578 LyXParagraph::size_type pos);
579 /** returns the paragraph position of the last character in the
582 LyXParagraph::size_type RowLast(Row * row);