From ed22adefc6ca3060a1d271d26f2908486182f396 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Thu, 13 Jan 2000 16:28:54 +0000 Subject: [PATCH] fix double space editing, small change to make Path more foolproof, dont use reserve in paragraph add some resize instead, fix a bug in LyXLeX::next that were only present on conforming std::istream. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@421 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 43 ++ src/LyXAction.C | 1 - src/bullet_forms.C | 3 +- src/bullet_forms_cb.C | 8 +- src/lyxdraw.C | 1 - src/lyxlex.C | 14 +- src/lyxrc.C | 2 + src/lyxrow.h | 2 +- src/lyxtext.h | 222 +++--- src/paragraph.C | 112 +-- src/screen.C | 7 +- src/support/LAssert.h | 4 + src/support/filetools.C | 2 +- src/support/path.h | 7 + src/text.C | 1481 ++++++++++++++++++++------------------ src/text2.C | 1505 +++++++++++++++++++++------------------ 16 files changed, 1821 insertions(+), 1593 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8021c523f5..5dcd323264 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,49 @@ where a "struct utimbuf" is allocated with "new" and deleted with "delete[]". +2000-01-13 Lars Gullik Bjønnes + + * src/text2.C (CutSelection): don't delete double spaces. + (PasteSelection): ditto + (CopySelection): ditto + + * src/text.C (Backspace): don't delete double spaces. + + * src/lyxlex.C (next): fix a bug that were only present with + conformant std::istream::get to read comment lines, use + std::istream::getline instead. This seems to fix the problem. + +2000-01-12 Lars Gullik Bjønnes + + * src/text2.C (DeleteEmptyParagraphMechanism): fix for the "not + allowed to insert space before space" editing problem. Please read + commends at the beginning of the function. Comments about usage + are very welcome. + + * src/text.C (InsertChar): fix for the "not allowed to insert + space before space" editing problem. + + * src/text2.C (DeleteEmptyParagraphMechanism): when + IsEmptyTableRow can only return false this last "else if" will + always be a no-op. Commented out. + + * src/text.C (RedoParagraph): As far as I can understand tmp + cursor is not really needed. + + * src/lyxtext.[Ch] (IsEmptyTableCell): commented out. As used at + present it could only return false anyway. + (several functions): Did something not so smart...added a const + specifier on a lot of methods. + + * src/paragraph.C (BreakParagraph): removed the tmp->text.reserve + and add a tmp->text.resize. The LyXParagraph constructor does the + resize for us. + (BreakParagraphConservative): ditto + + * src/support/path.h (Path): add a define so that the wrong usage + "Path("/tmp") will be flagged as a compilation error: + "`unnamed_Path' undeclared (first use this function)" + 2000-01-12 Jean-Marc Lasgouttes * config/lyxinclude.m4 (LYX_FUNC_PUTENV_ARGTYPE): fix the macro, diff --git a/src/LyXAction.C b/src/LyXAction.C index d8b92e9e8d..e2abaa1dcf 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -36,7 +36,6 @@ (May 19 1996, 12:04, RvdK) */ - // These are globals. LyXAction lyxaction; diff --git a/src/bullet_forms.C b/src/bullet_forms.C index 0aeeb97d6c..ba1fbfad35 100644 --- a/src/bullet_forms.C +++ b/src/bullet_forms.C @@ -33,8 +33,7 @@ FD_form_bullet *create_form_form_bullet(void) fl_set_bmtable_file(obj, 6, 6, LibFileSearch("images", "standard.xbm").c_str()); - } - else { + } else { fl_set_bmtable_pixmap_file(obj, 6, 6, LibFileSearch("images", "standard.xpm").c_str()); diff --git a/src/bullet_forms_cb.C b/src/bullet_forms_cb.C index 37ad85e2b2..7218992bec 100644 --- a/src/bullet_forms_cb.C +++ b/src/bullet_forms_cb.C @@ -12,6 +12,7 @@ #include "lyx_gui_misc.h" // CancelCloseBoxCB + WriteAlert extern int mono_video; + extern BufferView * current_view; FD_form_bullet * fd_form_bullet; @@ -23,8 +24,8 @@ static int current_bullet_depth; void bulletForm() { if (!fd_form_bullet) { - if (!mono_video - && (XpmVersion < 4 + if (!mono_video && + (XpmVersion < 4 || (XpmVersion == 4 && XpmRevision < 7))) { WriteAlert(_("Sorry, your libXpm is too old."), _("This feature requires xpm-4.7 (a.k.a 3.4g) or newer."), @@ -224,8 +225,7 @@ void BulletPanelCB(FL_OBJECT * /*ob*/, long data) new_panel += ".xbm"; fl_set_bmtable_file(fd_form_bullet->bmtable_bullet_panel, 6, 6, LibFileSearch("images", new_panel.c_str()).c_str()); - } - else { + } else { new_panel += ".xpm"; fl_set_bmtable_pixmap_file(fd_form_bullet->bmtable_bullet_panel, 6, 6, LibFileSearch("images", new_panel.c_str()).c_str()); diff --git a/src/lyxdraw.C b/src/lyxdraw.C index ae05fe6447..fe2e9d1859 100644 --- a/src/lyxdraw.C +++ b/src/lyxdraw.C @@ -372,7 +372,6 @@ GC GetSelectionGC() val.foreground= WhitePixel(fl_display, DefaultScreen(fl_display)); } - val.function= GXcopy; val.graphics_exposures = false; if (!fast_selection && selection_color[0] != 0) { diff --git a/src/lyxlex.C b/src/lyxlex.C index db0c8c44a4..88d7466476 100644 --- a/src/lyxlex.C +++ b/src/lyxlex.C @@ -261,9 +261,9 @@ bool LyXLex::next(bool esc) c = cc; if (c == '#') { // Read rest of line (fast :-) - is.get(buff, sizeof(buff)); - lyxerr[Debug::LYXLEX] << "Comment read: " << c - << buff << endl; + is.getline(buff, sizeof(buff)); + lyxerr[Debug::LYXLEX] << "Comment read: `" << c + << buff << "'" << endl; ++lineno; continue; } @@ -371,9 +371,9 @@ bool LyXLex::next(bool esc) if (c == '#') { // Read rest of line (fast :-) - is.get(buff, sizeof(buff)); - lyxerr[Debug::LYXLEX] << "Comment read: " << c - << buff << endl; + is.getline(buff, sizeof(buff)); + lyxerr[Debug::LYXLEX] << "Comment read: `" << c + << buff << "'" << endl; ++lineno; continue; } @@ -443,7 +443,7 @@ bool LyXLex::next(bool esc) if (status) return true; - status = is.eof() ? LEX_FEOF: LEX_UNDEF; + status = is.eof() ? LEX_FEOF : LEX_UNDEF; buff[0] = '\0'; return false; } diff --git a/src/lyxrc.C b/src/lyxrc.C index 8cca7ea27b..6dbaa190fb 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -822,10 +822,12 @@ int LyXRC::read(string const & filename) if (lexrc.next()) cursor_follows_scrollbar = lexrc.GetBool(); break; + case RC_FAST_SELECTION: if (lexrc.next()) fast_selection = lexrc.GetBool(); break; + case RC_BACKGROUND_COLOR: if (lexrc.next()) background_color = lexrc.GetString(); diff --git a/src/lyxrow.h b/src/lyxrow.h index db11a12088..e90d27caac 100644 --- a/src/lyxrow.h +++ b/src/lyxrow.h @@ -24,7 +24,7 @@ struct Row { unsigned short baseline; /** what is missing to a full row can be negative. Needed for hfills, flushright, block etc. */ - int fill; + mutable int fill; /// unsigned short height; /// diff --git a/src/lyxtext.h b/src/lyxtext.h index ee644335c4..e0f1ceb0cf 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -48,13 +48,13 @@ public: /// points to Buffer Buffer * params; /// - int number_of_rows; + mutable int number_of_rows; /// - long height; + mutable long height; /// the current font settings - LyXFont current_font; + mutable LyXFont current_font; /// the current font - LyXFont real_current_font; + mutable LyXFont real_current_font; /// Constructor LyXText(int paperwidth, Buffer *); @@ -64,13 +64,13 @@ public: /// LyXFont GetFont(LyXParagraph * par, - LyXParagraph::size_type pos); + LyXParagraph::size_type pos) const; /// void SetCharFont(LyXParagraph * par, LyXParagraph::size_type pos, - LyXFont font); + LyXFont const & font); /// returns a pointer to the very first LyXParagraph - LyXParagraph * FirstParagraph(); + LyXParagraph * FirstParagraph() const; /// what you expect when pressing at cursor position void BreakParagraph(char keep_layout = 0); @@ -94,36 +94,37 @@ public: /** Get the depth at current cursor position */ - int GetDepth() { return cursor.par->GetDepth(); } + int GetDepth() const { return cursor.par->GetDepth(); } /** set font over selection and make a total rebreak of those paragraphs. toggleall defaults to false. */ - void SetFont(LyXFont font, bool toggleall = false); + void SetFont(LyXFont const & font, bool toggleall = false); /** deletes and inserts again all paragaphs between the cursor - and the specified par .The Cursor is needed to set the refreshing + and the specified par. The Cursor is needed to set the refreshing parameters. This function is needed after SetLayout and SetFont etc. */ - void RedoParagraphs(LyXCursor cursor, LyXParagraph * end_par); + void RedoParagraphs(LyXCursor const & cursor, + LyXParagraph const * end_par) const; /// - void RedoParagraph(); + void RedoParagraph() const; /// - void ToggleFree(LyXFont font, bool toggleall = false); + void ToggleFree(LyXFont const & font, bool toggleall = false); /** recalculates the heights of all previous rows of the specified paragraph. needed, if the last characters font has changed. */ - void RedoHeightOfParagraph(LyXCursor cursor); + void RedoHeightOfParagraph(LyXCursor const & cursor); /** forces the redrawing of a paragraph. Needed when manipulating a right address box */ - void RedoDrawingOfParagraph(LyXCursor cursor); + void RedoDrawingOfParagraph(LyXCursor const & cursor); /** insert a character, moves all the following breaks in the same Paragraph one to the right and make a little rebreak @@ -140,7 +141,7 @@ public: /// Row * need_break_row; /// - long refresh_y; + mutable long refresh_y; /// int refresh_height; /// @@ -148,34 +149,34 @@ public: /// int refresh_x; /// - Row * refresh_row; + mutable Row * refresh_row; /// int refresh_pos; /** wether the screen needs a refresh, starting with refresh_y */ - text_status status; + mutable text_status status; /** returns a pointer to the row near the specified y-coordinate (relative to the whole text). y is set to the real beginning of this row */ - Row * GetRowNearY(long & y); + Row * GetRowNearY(long & y) const; /** returns the column near the specified x-coordinate of the row x is set to the real beginning of this column */ - int GetColumnNearX(Row * row, int & x); + int GetColumnNearX(Row * row, int & x) const; /** returns a pointer to a specified row. y is set to the beginning of the row */ Row * GetRow(LyXParagraph * par, - LyXParagraph::size_type pos, long & y); + LyXParagraph::size_type pos, long & y) const; /** returns the height of a default row, needed for scrollbar */ - int DefaultHeight(); + int DefaultHeight() const; /** The cursor. Later this variable has to be removed. There should be now internal @@ -186,20 +187,20 @@ public: Since the LyXText now has been moved from Buffer to BufferView it should not be absolutely needed to move the cursor... */ - LyXCursor cursor; + mutable LyXCursor cursor; /* the selection cursor */ /// - bool selection; + mutable bool selection; /// - bool mark_set; + mutable bool mark_set; /// - LyXCursor sel_cursor; + mutable LyXCursor sel_cursor; /// LyXCursor sel_start_cursor; /// - LyXCursor sel_end_cursor; + mutable LyXCursor sel_end_cursor; /// needed for the toggling LyXCursor last_sel_cursor; /// @@ -210,7 +211,7 @@ public: /// need the selection cursor: void SetSelection(); /// - void ClearSelection(); + void ClearSelection() const; /// just selects the word the cursor is in void SelectWord(); @@ -225,38 +226,38 @@ public: void SelectSelectedWord(); /// void SetCursor(LyXParagraph * par, - LyXParagraph::size_type pos); + LyXParagraph::size_type pos) const; /// void SetCursorIntern(LyXParagraph * par, - LyXParagraph::size_type pos); + LyXParagraph::size_type pos) const; /// - void SetCursorFromCoordinates(int x, long y); + void SetCursorFromCoordinates(int x, long y) const; /// - void CursorUp(); + void CursorUp() const; /// - void CursorDown(); + void CursorDown() const; /// - void CursorLeft(); + void CursorLeft() const; /// - void CursorRight(); + void CursorRight() const; /// - void CursorLeftOneWord(); + void CursorLeftOneWord() const; /// - void CursorRightOneWord(); + void CursorRightOneWord() const; /// - void CursorUpParagraph(); + void CursorUpParagraph() const; /// - void CursorDownParagraph(); + void CursorDownParagraph() const; /// - void CursorHome(); + void CursorHome() const; /// - void CursorEnd(); + void CursorEnd() const; /// - void CursorTab(); + void CursorTab() const; /// - void CursorTop(); + void CursorTop() const; /// - void CursorBottom(); + void CursorBottom() const; /// void Delete(); /// @@ -332,7 +333,8 @@ public: */ void SetParagraph(bool line_top, bool line_bottom, bool pagebreak_top, bool pagebreak_bottom, - VSpace space_top, VSpace space_bottom, + VSpace const & space_top, + VSpace const & space_bottom, LyXAlignment align, string labelwidthstring, bool noindent); @@ -349,7 +351,7 @@ public: */ bool IsStringInText(LyXParagraph * par, LyXParagraph::size_type pos, - char const * str); + char const * str) const; /** sets the selection over the number of characters of string, no check!! */ @@ -358,27 +360,27 @@ public: /** simple replacing. The font of the first selected character is used */ - void ReplaceSelectionWithString(char const * string); + void ReplaceSelectionWithString(char const * str); /** if the string can be found: return true and set the cursor to the new position */ - bool SearchForward(char const * string); - bool SearchBackward(char const * string); + bool SearchForward(char const * str) const; + bool SearchBackward(char const * str) const; /// needed to insert the selection void InsertStringA(LyXParagraph::TextContainer const & text); /// needed to insert the selection void InsertStringB(LyXParagraph::TextContainer const & text); /// needed to insert the selection - void InsertStringA(char const * string); + void InsertStringA(char const * str); /// needed to insert the selection - void InsertStringB(char const * string); + void InsertStringB(char const * str); /// usefull when texing from within LyX - bool GotoNextError(); + bool GotoNextError() const; /// just another feature :) - bool GotoNextNote(); + bool GotoNextNote() const; /** needed to switch between different classes this works for a list of paragraphs beginning with the specified par @@ -396,19 +398,20 @@ public: LyXParagraph::size_type pos); /// int NumberOfCell(LyXParagraph * par, - LyXParagraph::size_type pos); + LyXParagraph::size_type pos) const; /* table stuff -- begin*/ /** all table features of the text-class are put together in this function. Possible values of feature are defined in table.h */ - void TableFeatures(int feature, string val); + void TableFeatures(int feature, string const & val) const; /// - void TableFeatures(int feature); + void TableFeatures(int feature) const; /** pos points at the beginning of the next cell (if there is one) */ - int WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos); + int WidthOfCell(LyXParagraph * par, + LyXParagraph::size_type & pos) const; /// void CheckParagraphInTable(LyXParagraph * par, LyXParagraph::size_type pos); @@ -417,18 +420,18 @@ public: /// void BackspaceInTable(); /// - bool HitInTable(Row * row, int x); + bool HitInTable(Row * row, int x) const; /// - bool MouseHitInTable(int x, long y); + bool MouseHitInTable(int x, long y) const; /* table stuff -- end*/ /// LyXParagraph * GetParFromID(int id); // undo functions /// returns false if no undo possible - bool TextUndo(); + bool TextUndo(); /// returns false if no redo possible - bool TextRedo(); + bool TextRedo(); /// used by TextUndo/TextRedo bool TextHandleUndo(Undo * undo); /// makes sure the next operation will be stored @@ -438,43 +441,47 @@ public: /// this is dangerous and for internal use only void UnFreezeUndo(); /// the flag used by FinishUndo(); - bool undo_finished; + mutable bool undo_finished; /// a flag bool undo_frozen; /// - void SetUndo(Undo::undo_kind kind, LyXParagraph * before, - LyXParagraph * end); + void SetUndo(Undo::undo_kind kind, + LyXParagraph const * before, + LyXParagraph const * end) const; /// - void SetRedo(Undo::undo_kind kind, LyXParagraph * before, - LyXParagraph * end); + void SetRedo(Undo::undo_kind kind, + LyXParagraph const * before, + LyXParagraph const * end); /// - Undo * CreateUndo(Undo::undo_kind kind, LyXParagraph * before, - LyXParagraph * end); + Undo * CreateUndo(Undo::undo_kind kind, + LyXParagraph const * before, + LyXParagraph const * end) const; /// for external use in lyx_cb.C void SetCursorParUndo(); /// - void CursorLeftIntern(); + void CursorLeftIntern() const; /// - void CursorRightIntern(); + void CursorRightIntern() const; /// - void RemoveTableRow(LyXCursor * cursor); + void RemoveTableRow(LyXCursor * cursor) const; +#if 0 /// - bool IsEmptyTableRow(LyXCursor * cursor) const; + bool IsEmptyTableRow(LyXCursor const & cursor) const; +#endif /// bool IsEmptyTableCell() const; /// void toggleAppendix(); /// unsigned short paperWidth() const { return paperwidth; } - private: /// width of the paper unsigned short paperwidth; /// - Row * firstrow; + mutable Row * firstrow; /// - Row * lastrow; + mutable Row * lastrow; /** Copybuffer for copy environment type Asger has learned that this should be a buffer-property instead @@ -483,47 +490,48 @@ private: char copylayouttype; /// the currentrow is needed to access rows faster*/ - Row * currentrow; /* pointer to the current row */ + mutable Row * currentrow; // pointer to the current row /// position in the text - long currentrow_y; + mutable long currentrow_y; /** inserts a new row behind the specified row, increments * the touched counters */ void InsertRow(Row * row, LyXParagraph * par, - LyXParagraph::size_type pos ); + LyXParagraph::size_type pos) const; /** removes the row and reset the touched counters */ - void RemoveRow(Row * row); + void RemoveRow(Row * row) const; /** remove all following rows of the paragraph of the specified row. */ - void RemoveParagraph(Row * row); + void RemoveParagraph(Row * row) const; /** insert the specified paragraph behind the specified row */ - void InsertParagraph(LyXParagraph * par, Row * row); + void InsertParagraph(LyXParagraph * par, Row * row) const; /** appends the implizit specified paragraph behind the specified row, * start at the implizit given position */ - void AppendParagraph(Row * row); + void AppendParagraph(Row * row) const; /// - void BreakAgain(Row * row); + void BreakAgain(Row * row) const; /// void BreakAgainOneRow(Row * row); - /// - void SetHeightOfRow(Row * row_ptr); /* calculate and set the height - * of the row */ + /// Calculate and set the height of the row + void SetHeightOfRow(Row * row_ptr) const; /** this calculates the specified parameters. needed when setting * the cursor and when creating a visible row */ - void PrepareToPrint(Row * row, float & x, float & fill_separator, - float & fill_hfill, float & fill_label_hfill); + void PrepareToPrint(Row * row, float & x, + float & fill_separator, + float & fill_hfill, + float & fill_label_hfill) const; /// - void DeleteEmptyParagraphMechanism(LyXCursor old_cursor); + void DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const; /** Updates all counters starting BEHIND the row. Changed paragraphs * with a dynamic left margin will be rebroken. */ - void UpdateCounters(Row * row); + void UpdateCounters(Row * row) const; /// - void SetCounter(LyXParagraph * par); + void SetCounter(LyXParagraph * par) const; /* * some low level functions @@ -531,23 +539,23 @@ private: /// int SingleWidth(LyXParagraph * par, - LyXParagraph::size_type pos); + LyXParagraph::size_type pos) const; /// int SingleWidth(LyXParagraph * par, - LyXParagraph::size_type pos, char c); + LyXParagraph::size_type pos, char c) const; /// - void Draw(Row * row, LyXParagraph::size_type & pos, + void Draw(Row const * row, LyXParagraph::size_type & pos, LyXScreen & scr, int offset, float & x); /// get the next breakpoint in a given paragraph - LyXParagraph::size_type NextBreakPoint(Row * row, - int width); + LyXParagraph::size_type NextBreakPoint(Row const * row, + int width) const; /// returns the minimum space a row needs on the screen in pixel - int Fill(Row * row, int paperwidth); + int Fill(Row const * row, int paperwidth) const; /** returns the minimum space a manual label needs on the screen in pixel */ - int LabelFill(Row * row); + int LabelFill(Row const * row) const; /// LyXParagraph::size_type BeginningOfMainBody(LyXParagraph * par) const; @@ -556,36 +564,36 @@ private: in LaTeX the beginning of the text fits in some cases (for example sections) exactly the label-width. */ - int LeftMargin(Row * row); + int LeftMargin(Row const * row) const; /// - int RightMargin(Row * row); + int RightMargin(Row const * row) const; /// - int LabelEnd (Row * row); + int LabelEnd (Row const * row) const; /** returns the number of separators in the specified row. The separator on the very last column doesnt count */ - int NumberOfSeparators(Row * row); + int NumberOfSeparators(Row const * row) const; /** returns the number of hfills in the specified row. The LyX-Hfill is a LaTeX \hfill so that the hfills at the beginning and at the end were ignored. This is {\em MUCH} more usefull than not to ignore! */ - int NumberOfHfills(Row * row); + int NumberOfHfills(Row const * row) const; /// like NumberOfHfills, but only those in the manual label! - int NumberOfLabelHfills(Row * row); + int NumberOfLabelHfills(Row const * row) const; /** returns true, if a expansion is needed. Rules are given by LaTeX */ - bool HfillExpansion(Row * row_ptr, - LyXParagraph::size_type pos); + bool HfillExpansion(Row const * row_ptr, + LyXParagraph::size_type pos) const; /** returns the paragraph position of the last character in the specified row */ - LyXParagraph::size_type RowLast(Row * row); + LyXParagraph::size_type RowLast(Row const * row) const; /// void charInserted(); }; diff --git a/src/paragraph.C b/src/paragraph.C index d7c577671d..52cff71996 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -95,11 +95,13 @@ LyXParagraph::LyXParagraph(LyXParagraph * par) appendix = false; enumdepth = 0; itemdepth = 0; + // double linked list begin next = par->next; if (next) next->previous = this; previous = par; previous->next = this; + // end #ifndef NEW_FONTTABLE // OK fonttable = 0; #endif @@ -937,13 +939,13 @@ LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const else { // Why is it an error to ask for the font of a // position that does not exist? Would it be - // enough for this to be anable on debug? + // enough for this to be enabled on debug? // We want strict error checking, but it's ok to only // have it when debugging. (Asger) lyxerr << "ERROR (LyXParagraph::GetFontSettings): " "position does not exist. " << pos << " (" << static_cast(pos) - << ")\n"; + << ")" << endl; } } else if (pos) { return GetFontSettings(pos - 1); @@ -962,8 +964,9 @@ LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const { LyXFont tmpfont; - LyXLayout const & layout = textclasslist.Style(current_view->buffer()->params.textclass, - GetLayout()); + LyXLayout const & layout = + textclasslist.Style(current_view->buffer()->params.textclass, + GetLayout()); LyXParagraph::size_type main_body = 0; if (layout.labeltype == LABEL_MANUAL) main_body = BeginningOfMainBody(); @@ -1050,6 +1053,7 @@ char LyXParagraph::GetChar(LyXParagraph::size_type pos) "position does not exist." << pos << " (" << static_cast(pos) << ")\n"; + Assert(false); } return '\0'; } else { @@ -1094,10 +1098,11 @@ char LyXParagraph::GetChar(LyXParagraph::size_type pos) const return NextAfterFootnote() ->GetChar(pos - text.size() - 1); else { - lyxerr << "ERROR (LyXParagraph::GetChar): " + lyxerr << "ERROR (LyXParagraph::GetChar const): " "position does not exist." << pos << " (" << static_cast(pos) << ")\n"; + Assert(false); } return '\0'; } else { @@ -1133,10 +1138,10 @@ string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const { Assert(lastpos>=0); - // the current word is defined as starting at the first character from - // the immediate left of lastpospos which meets the definition of IsLetter(), - // continuing to the last character to the right of this meeting - // IsLetter. + // the current word is defined as starting at the first character + // from the immediate left of lastpospos which meets the definition + // of IsLetter(), continuing to the last character to the right + // of this meeting IsLetter. string theword; @@ -1157,11 +1162,11 @@ string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const // now find the beginning by looking for a nonletter while ((firstpos>= 0) && IsLetter(firstpos)) - firstpos--; + --firstpos; // the above is now pointing to the preceeding non-letter - firstpos++; - lastpos= firstpos; + ++firstpos; + lastpos = firstpos; // so copy characters into theword until we get a nonletter // note that this can easily exceed lastpos, wich means @@ -1170,7 +1175,7 @@ string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const while (IsLetter(lastpos)) theword += GetChar(lastpos++); - return theword; + return theword; } @@ -1199,8 +1204,7 @@ LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos) lyxerr << "ERROR (LyXParagraph::ParFromPos): " "position does not exist." << endl; return this; - } - else + } else return this; } @@ -1231,7 +1235,8 @@ void LyXParagraph::SetFont(LyXParagraph::size_type pos, // > because last is the next unused position, and you can // use it if you want if (pos > size()) { - if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) { + if (next && + next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) { NextAfterFootnote()->SetFont(pos - text.size() - 1, font); } else { @@ -1487,8 +1492,7 @@ LyXParagraph * LyXParagraph::Next() paragraph */ else return next; // This should never happen! - } - else + } else return next; } @@ -1504,8 +1508,7 @@ LyXParagraph * LyXParagraph::NextAfterFootnote() in a logical paragraph */ else return next; // This should never happen! - } - else + } else return next; } @@ -1521,8 +1524,7 @@ LyXParagraph const * LyXParagraph::NextAfterFootnote() const in a logical paragraph */ else return next; // This should never happen! - } - else + } else return next; } @@ -1539,8 +1541,7 @@ LyXParagraph * LyXParagraph::PreviousBeforeFootnote() in a logical paragraph */ else return previous; // This should never happen! - } - else + } else return previous; } @@ -1566,13 +1567,15 @@ LyXParagraph * LyXParagraph::FirstPhysicalPar() return this; LyXParagraph * tmppar = this; - while (tmppar && (tmppar->IsDummy() - || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE)) + while (tmppar && + (tmppar->IsDummy() + || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE)) tmppar = tmppar->previous; - if (!tmppar) + if (!tmppar) { + Assert(false); // let's get an abort then return this; // This should never happen! - else + } else return tmppar; } @@ -1587,9 +1590,10 @@ LyXParagraph const * LyXParagraph::FirstPhysicalPar() const || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE)) tmppar = tmppar->previous; - if (!tmppar) + if (!tmppar) { + Assert(false); // let's get an abort then return this; // This should never happen! - else + } else return tmppar; } @@ -1612,8 +1616,7 @@ LyXParagraph * LyXParagraph::Previous() else return previous; - } - else + } else return previous; } @@ -1636,8 +1639,7 @@ LyXParagraph const * LyXParagraph::Previous() const else return previous; - } - else + } else return previous; } @@ -1651,12 +1653,12 @@ void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos, LyXParagraph * firstpar = FirstPhysicalPar(); LyXParagraph * tmp = new LyXParagraph(par); - + tmp->footnoteflag = footnoteflag; tmp->footnotekind = footnotekind; // this is an idea for a more userfriendly layout handling, I will - // see what the users say */ + // see what the users say // layout stays the same with latex-environments if (flag) { @@ -1686,14 +1688,15 @@ void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos, pos_first++; pos_end = pos_first + par->text.size() - 1; - if (pos_end > pos) - tmp->text.reserve(pos_end - pos); + // The constructor has already reserved 500 elements + //if (pos_end > pos) + // tmp->text.reserve(pos_end - pos); for (i = pos; i <= pos_end; i++) { par->CutIntoMinibuffer(i - pos_first); tmp->InsertFromMinibuffer(i - pos); } - + tmp->text.resize(tmp->text.size()); for (i = pos_end; i >= pos; i--) par->Erase(i - pos_first); @@ -1833,36 +1836,38 @@ bool LyXParagraph::HasSameLayout(LyXParagraph const * par) void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos) { - size_type i, pos_end, pos_first; - // create a new paragraph LyXParagraph * par = ParFromPos(pos); LyXParagraph * tmp = new LyXParagraph(par); tmp->MakeSameLayout(par); - + + // When can pos < Last()? + // I guess pos == Last() is possible. if (Last() > pos) { // copy everything behind the break-position to the new // paragraph - pos_first = 0; + size_type pos_first = 0; while (ParFromPos(pos_first) != par) - pos_first++; - pos_end = pos_first + par->text.size() - 1; - // make shure there is enough memory for the now larger + ++pos_first; + size_type pos_end = pos_first + par->text.size() - 1; + // make sure there is enough memory for the now larger // paragraph. This is not neccessary, because // InsertFromMinibuffer will enlarge the memory (it uses // InsertChar of course). But doing it by hand // is MUCH faster! (only one time, not thousend times!!) - if (pos_end > pos) - tmp->text.reserve(pos_end - pos); + // Not needed since the constructor aleady have + // reserved 500 elements in text. + //if (pos_end > pos) + // tmp->text.reserve(pos_end - pos); - for (i = pos; i <= pos_end; i++) { - + for (size_type i = pos; i <= pos_end; ++i) { par->CutIntoMinibuffer(i - pos_first); tmp->InsertFromMinibuffer(i - pos); } - for (i = pos_end; i >= pos; i--) + tmp->text.resize(tmp->text.size()); + for (size_type i = pos_end; i >= pos; --i) par->Erase(i - pos_first); par->text.resize(par->text.size()); @@ -2271,8 +2276,9 @@ LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow, { lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl; LyXParagraph * par = next; - LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass, - layout); + LyXLayout const & style = + textclasslist.Style(current_view->buffer()->params.textclass, + layout); bool further_blank_line = false; if (IsDummy()) diff --git a/src/screen.C b/src/screen.C index d502a10ffd..dffcff0cf6 100644 --- a/src/screen.C +++ b/src/screen.C @@ -21,7 +21,6 @@ extern int mono_video; extern int fast_selection; - // Constructor LyXScreen::LyXScreen(Window window, Dimension width, @@ -280,7 +279,7 @@ void LyXScreen::ShowManualCursor(long x, long y, int asc, int desc) if (y2 > _height) y2 = _height; - if (fast_selection || mono_video){ + if (fast_selection || mono_video) { if (y2 > 0 && y1 < _height) { XDrawLine(fl_display, _window, getGC(gc_select), @@ -332,7 +331,7 @@ void LyXScreen::HideCursor() { if (!cursor_visible) return; - if (fast_selection || mono_video){ + if (fast_selection || mono_video) { cursor_visible = false; ShowCursor(); cursor_visible = false; @@ -489,7 +488,7 @@ void LyXScreen::ToggleSelection(bool kill_selection) long bottom = 0; - if (fast_selection || mono_video){ + if (fast_selection || mono_video) { /* selection only in one row ?*/ if (text->sel_start_cursor.y == text->sel_end_cursor.y) { diff --git a/src/support/LAssert.h b/src/support/LAssert.h index 20be3713c5..e429df8c11 100644 --- a/src/support/LAssert.h +++ b/src/support/LAssert.h @@ -18,6 +18,10 @@ template inline void Assert(A assertion) #ifdef HAVE_PARTIAL_SPECIALIZATION // Not too sure if this is the correct way to specialize template inline void Assert(A * ptr) +{ + Assert(ptr); +} +template<> inline void Assert(void const * ptr) { if (!ptr) { abort(); diff --git a/src/support/filetools.C b/src/support/filetools.C index 340da1cfa7..f79fd314a6 100644 --- a/src/support/filetools.C +++ b/src/support/filetools.C @@ -831,7 +831,7 @@ string MakeRelPath(string const & abspath0, string const & basepath0) int j = i; while (j < baselen) { if (basepath[j] == '/') { - if (j+1 == baselen) break; + if (j + 1 == baselen) break; buf += "../"; } ++j; diff --git a/src/support/path.h b/src/support/path.h index 532e808d4f..122e86fa20 100644 --- a/src/support/path.h +++ b/src/support/path.h @@ -53,4 +53,11 @@ private: string pushedDir_; }; +// To avoid the wrong usage: +// Path("/tmp"); // wrong +// Path p("/tmp"); // right +// we add this macro: +#define Path(x) unnamed_Path; +// Tip gotten from Bobby Schmidt's column in C/C++ Users Journal + #endif diff --git a/src/text.C b/src/text.C index ae73c68b5b..458930192c 100644 --- a/src/text.C +++ b/src/text.C @@ -36,13 +36,14 @@ extern int mono_video; extern int reverse_video; extern int fast_selection; extern BufferView * current_view; -//extern int UnlockInset(UpdatableInset * inset); // ale070405 extern int bibitemMaxWidth(LyXFont const &); +#define FIX_DOUBLE_SPACE 1 + int LyXText::SingleWidth(LyXParagraph * par, - LyXParagraph::size_type pos) + LyXParagraph::size_type pos) const { char c = par->GetChar(pos); return SingleWidth(par, pos, c); @@ -50,7 +51,7 @@ int LyXText::SingleWidth(LyXParagraph * par, int LyXText::SingleWidth(LyXParagraph * par, - LyXParagraph::size_type pos, char c) + LyXParagraph::size_type pos, char c) const { LyXFont font = GetFont(par, pos); @@ -115,18 +116,18 @@ int LyXText::SingleWidth(LyXParagraph * par, // Returns the paragraph position of the last character in the specified row -LyXParagraph::size_type LyXText::RowLast(Row * row) +LyXParagraph::size_type LyXText::RowLast(Row const * row) const { if (row->next == 0) - return row->par->Last()-1; + return row->par->Last() - 1; else if (row->next->par != row->par) - return row->par->Last()-1; + return row->par->Last() - 1; else return row->next->pos - 1; } -void LyXText::Draw(Row * row, LyXParagraph::size_type & pos, +void LyXText::Draw(Row const * row, LyXParagraph::size_type & pos, LyXScreen & scr, int offset, float & x) { char c = row->par->GetChar(pos); @@ -212,7 +213,7 @@ void LyXText::Draw(Row * row, LyXParagraph::size_type & pos, Inset * tmpinset = row->par->GetInset(pos); if (tmpinset) tmpinset->Draw(font, scr, offset + row->baseline, x); - pos++; + ++pos; return; } @@ -244,12 +245,16 @@ void LyXText::Draw(Row * row, LyXParagraph::size_type & pos, float tmpx = x; // If monochrome and LaTeX mode, provide reverse background - if (mono_video && font.latex() == LyXFont::ON) { - int a = font.maxAscent(), d = font.maxDescent(); - scr.fillRectangle(gc_copy, int(tmpx), offset + row->baseline-a, + if (mono_video && + font.latex() == LyXFont::ON) { + int a = font.maxAscent(); + int d = font.maxDescent(); + scr.fillRectangle(gc_copy, int(tmpx), + offset + row->baseline - a, font.textWidth(textstring.c_str(), - textstring.length()), a+d); + textstring.length()), a + d); } + // Draw text and set the new x position x += scr.drawText(font, textstring.c_str(), textstring.length(), offset + row->baseline, @@ -267,277 +272,304 @@ void LyXText::Draw(Row * row, LyXParagraph::size_type & pos, } -/* Returns the left beginning of the text. -* This information cannot be taken from the layouts-objekt, because in -* LaTeX the beginning of the text fits in some cases (for example sections) -* exactly the label-width. */ -int LyXText::LeftMargin(Row * row) +// Returns the left beginning of the text. +// This information cannot be taken from the layouts-objekt, because in +// LaTeX the beginning of the text fits in some cases (for example sections) +// exactly the label-width. +int LyXText::LeftMargin(Row const * row) const { - LyXFont labelfont; - LyXParagraph * newpar; - Row dummyrow; - LyXLayout const & layout = textclasslist.Style(parameters->textclass, - row->par->GetLayout()); - - string parindent = layout.parindent; - - /* table stuff -- begin*/ - if (row->par->table) - parindent.clear(); - /* table stuff -- end*/ - - int x = LYX_PAPER_MARGIN; - - x += textclasslist.TextClass(parameters->textclass). - defaultfont().signedStringWidth(textclasslist.TextClass(parameters->textclass).leftmargin()); - - if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { - LyXFont font(LyXFont::ALL_SANE); - font.setSize(LyXFont::SIZE_SMALL); - x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2; - } - - /* this is the way, LyX handles the LaTeX-Environments. - * I have had this idea very late, so it seems to be a - * later added hack and this is true */ - if (!row->par->GetDepth()) { - if (!row->par->GetLayout()) { - /* find the previous same level paragraph */ - if (row->par->FirstPhysicalPar()->Previous()) { - newpar = row->par->DepthHook(row->par->GetDepth()); - if (newpar && textclasslist.Style(parameters->textclass, - newpar->GetLayout()).nextnoindent) - parindent.clear(); - } - } - } - else { - /* find the next level paragraph */ - - newpar = row->par->DepthHook(row->par->GetDepth()-1); - - /* make a corresponding row. Needed to call LeftMargin() */ - - /* check wether it is a sufficent paragraph */ - if (newpar && newpar->footnoteflag == row->par->footnoteflag - && textclasslist.Style(parameters->textclass, - newpar->GetLayout()).isEnvironment()) { - dummyrow.par = newpar; - dummyrow.pos = newpar->Last(); - x = LeftMargin(&dummyrow); - } - else { - /* this is no longer an error, because this function is used - * to clear impossible depths after changing a layout. Since there - * is always a redo, LeftMargin() is always called */ - - /* printf("LYX_ERROR (text, LeftMargin()) impossible depth \n");*/ - row->par->FirstPhysicalPar()->depth = 0; - } - - if (newpar && !row->par->GetLayout()) { - if (newpar->FirstPhysicalPar()->noindent) - parindent.clear(); - else - parindent = textclasslist.Style(parameters->textclass, - newpar->GetLayout()).parindent; - } - - } - - labelfont = GetFont(row->par, -2); - switch (layout.margintype) { - case MARGIN_DYNAMIC: - if (!layout.leftmargin.empty()) { - x += textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin); - } - if (!row->par->GetLabestring().empty()) { - x += labelfont.signedStringWidth(layout.labelindent); - x += labelfont.stringWidth(row->par->GetLabestring()); - x += labelfont.stringWidth(layout.labelsep); - } - break; - case MARGIN_MANUAL: - x += labelfont.signedStringWidth(layout.labelindent); - if (row->pos >= BeginningOfMainBody(row->par)) { - if (!row->par->GetLabelWidthString().empty()) { - x += labelfont.stringWidth(row->par->GetLabelWidthString()); - x += labelfont.stringWidth(layout.labelsep); - } - } - break; - case MARGIN_STATIC: - x += ( textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin) * 4 - / (row->par->GetDepth() + 4)); - break; - case MARGIN_FIRST_DYNAMIC: - if (layout.labeltype == LABEL_MANUAL) { - if (row->pos >= BeginningOfMainBody(row->par)) { - x += labelfont.signedStringWidth(layout.leftmargin); - } else { - x += labelfont.signedStringWidth(layout.labelindent); - } - } else { - if (row->pos - // Special case to fix problems with theorems (JMarc) - || (layout.labeltype == LABEL_STATIC - && layout.latextype == LATEX_ENVIRONMENT - && ! row->par->IsFirstInSequence())) { - x += labelfont.signedStringWidth(layout.leftmargin); - } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT - && layout.labeltype != LABEL_BIBLIO - && layout.labeltype != LABEL_CENTERED_TOP_ENVIRONMENT) { - x += labelfont.signedStringWidth(layout.labelindent); - x += labelfont.stringWidth(layout.labelsep); - x += labelfont.stringWidth(row->par->GetLabestring()); - } - } - break; - - case MARGIN_RIGHT_ADDRESS_BOX: - { - /* ok, a terrible hack. The left margin depends on the widest row - * in this paragraph. Do not care about footnotes, they are *NOT* - * allowed in the LaTeX realisation of this layout. */ - - /* find the first row of this paragraph */ - Row * tmprow = row; - while (tmprow->previous && tmprow->previous->par == row->par) - tmprow = tmprow->previous; - - int minfill = tmprow->fill; - while (tmprow-> next && tmprow->next->par == row->par) { - tmprow = tmprow->next; - if (tmprow->fill < minfill) - minfill = tmprow->fill; - } - - x += textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.leftmargin); - x += minfill; - } - break; - } - if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) { - if (!row->par->pextra_widthp.empty()) { - x += paperwidth * atoi(row->par->pextra_widthp.c_str()) / 100; - } else if (!row->par->pextra_width.empty()) { - int xx = VSpace(row->par->pextra_width).inPixels(); - - if (xx > paperwidth) - xx = paperwidth * 80 / 100; - x += xx; - } else { // should not happen - LyXFont font(LyXFont::ALL_SANE); - x += font.stringWidth("XXXXXX"); - } - } - - int align; - if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT) - align = layout.align; - else - align = row->par->FirstPhysicalPar()->align; - - /* set the correct parindent */ - if (row->pos == 0) { - if ((layout.labeltype == LABEL_NO_LABEL - || layout.labeltype == LABEL_TOP_ENVIRONMENT - || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT - || (layout.labeltype == LABEL_STATIC - && layout.latextype == LATEX_ENVIRONMENT - && ! row->par->IsFirstInSequence())) - && row->par == row->par->FirstPhysicalPar() - && align == LYX_ALIGN_BLOCK - && !row->par->noindent - && (row->par->layout || - parameters->paragraph_separation == BufferParams::PARSEP_INDENT)) - x += textclasslist.TextClass(parameters->textclass).defaultfont().stringWidth(parindent); - else - if (layout.labeltype == LABEL_BIBLIO) { // ale970405 Right width for bibitems - x += bibitemMaxWidth(textclasslist.TextClass(parameters->textclass).defaultfont()); - } - } - - return x; + LyXFont labelfont; + LyXParagraph * newpar; + Row dummyrow; + LyXLayout const & layout = textclasslist.Style(parameters->textclass, + row->par->GetLayout()); + + string parindent = layout.parindent; + + /* table stuff -- begin */ + if (row->par->table) + parindent.clear(); + /* table stuff -- end */ + + int x = LYX_PAPER_MARGIN; + + x += textclasslist.TextClass(parameters->textclass) + .defaultfont() + .signedStringWidth(textclasslist + .TextClass(parameters->textclass) + .leftmargin()); + + if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { + LyXFont font(LyXFont::ALL_SANE); + font.setSize(LyXFont::SIZE_SMALL); + x += font.textWidth("Mwide-figM", 10) + LYX_PAPER_MARGIN/2; + } + + // this is the way, LyX handles the LaTeX-Environments. + // I have had this idea very late, so it seems to be a + // later added hack and this is true + if (!row->par->GetDepth()) { + if (!row->par->GetLayout()) { + // find the previous same level paragraph + if (row->par->FirstPhysicalPar()->Previous()) { + newpar = row->par + ->DepthHook(row->par->GetDepth()); + if (newpar && + textclasslist.Style(parameters->textclass, + newpar->GetLayout()) + .nextnoindent) + parindent.clear(); + } + } + } else { + // find the next level paragraph + + newpar = row->par->DepthHook(row->par->GetDepth()-1); + + // make a corresponding row. Needed to call LeftMargin() + + // check wether it is a sufficent paragraph + if (newpar && newpar->footnoteflag == row->par->footnoteflag + && textclasslist + .Style(parameters->textclass, + newpar->GetLayout()).isEnvironment()) { + dummyrow.par = newpar; + dummyrow.pos = newpar->Last(); + x = LeftMargin(&dummyrow); + } else { + // this is no longer an error, because this function + // is used to clear impossible depths after changing + // a layout. Since there is always a redo, + // LeftMargin() is always called + row->par->FirstPhysicalPar()->depth = 0; + } + + if (newpar && !row->par->GetLayout()) { + if (newpar->FirstPhysicalPar()->noindent) + parindent.clear(); + else + parindent = textclasslist + .Style(parameters->textclass, + newpar->GetLayout()).parindent; + } + + } + + labelfont = GetFont(row->par, -2); + switch (layout.margintype) { + case MARGIN_DYNAMIC: + if (!layout.leftmargin.empty()) { + x += textclasslist + .TextClass(parameters->textclass) + .defaultfont() + .signedStringWidth(layout.leftmargin); + } + if (!row->par->GetLabestring().empty()) { + x += labelfont.signedStringWidth(layout.labelindent); + x += labelfont.stringWidth(row->par->GetLabestring()); + x += labelfont.stringWidth(layout.labelsep); + } + break; + case MARGIN_MANUAL: + x += labelfont.signedStringWidth(layout.labelindent); + if (row->pos >= BeginningOfMainBody(row->par)) { + if (!row->par->GetLabelWidthString().empty()) { + x += labelfont + .stringWidth(row->par + ->GetLabelWidthString()); + x += labelfont.stringWidth(layout.labelsep); + } + } + break; + case MARGIN_STATIC: + x += textclasslist.TextClass(parameters->textclass) + .defaultfont().signedStringWidth(layout.leftmargin) * 4 + / (row->par->GetDepth() + 4); + break; + case MARGIN_FIRST_DYNAMIC: + if (layout.labeltype == LABEL_MANUAL) { + if (row->pos >= BeginningOfMainBody(row->par)) { + x += labelfont + .signedStringWidth(layout.leftmargin); + } else { + x += labelfont + .signedStringWidth(layout.labelindent); + } + } else if (row->pos + // Special case to fix problems with + // theorems (JMarc) + || (layout.labeltype == LABEL_STATIC + && layout.latextype == LATEX_ENVIRONMENT + && ! row->par->IsFirstInSequence())) { + x += labelfont.signedStringWidth(layout.leftmargin); + } else if (layout.labeltype != LABEL_TOP_ENVIRONMENT + && layout.labeltype != LABEL_BIBLIO + && layout.labeltype != + LABEL_CENTERED_TOP_ENVIRONMENT) { + x += labelfont.signedStringWidth(layout.labelindent); + x += labelfont.stringWidth(layout.labelsep); + x += labelfont.stringWidth(row->par->GetLabestring()); + } + break; + + case MARGIN_RIGHT_ADDRESS_BOX: + { + // ok, a terrible hack. The left margin depends on the widest + // row in this paragraph. Do not care about footnotes, they + // are *NOT* allowed in the LaTeX realisation of this layout. + + // find the first row of this paragraph + Row const * tmprow = row; + while (tmprow->previous && tmprow->previous->par == row->par) + tmprow = tmprow->previous; + + int minfill = tmprow->fill; + while (tmprow-> next && tmprow->next->par == row->par) { + tmprow = tmprow->next; + if (tmprow->fill < minfill) + minfill = tmprow->fill; + } + + x += textclasslist.TextClass(parameters->textclass) + .defaultfont().signedStringWidth(layout.leftmargin); + x += minfill; + } + break; + } + if (row->par->pextra_type == LyXParagraph::PEXTRA_INDENT) { + if (!row->par->pextra_widthp.empty()) { + x += paperwidth * + atoi(row->par->pextra_widthp.c_str()) / 100; + } else if (!row->par->pextra_width.empty()) { + int xx = VSpace(row->par->pextra_width).inPixels(); + + if (xx > paperwidth) + xx = paperwidth * 80 / 100; + x += xx; + } else { // should not happen + LyXFont font(LyXFont::ALL_SANE); + x += font.stringWidth("XXXXXX"); + } + } + + int align; + if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT) + align = layout.align; + else + align = row->par->FirstPhysicalPar()->align; + + // set the correct parindent + if (row->pos == 0) { + if ((layout.labeltype == LABEL_NO_LABEL + || layout.labeltype == LABEL_TOP_ENVIRONMENT + || layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT + || (layout.labeltype == LABEL_STATIC + && layout.latextype == LATEX_ENVIRONMENT + && ! row->par->IsFirstInSequence())) + && row->par == row->par->FirstPhysicalPar() + && align == LYX_ALIGN_BLOCK + && !row->par->noindent + && (row->par->layout || + parameters->paragraph_separation == + BufferParams::PARSEP_INDENT)) + x += textclasslist.TextClass(parameters->textclass) + .defaultfont().stringWidth(parindent); + else + if (layout.labeltype == LABEL_BIBLIO) { + // ale970405 Right width for bibitems + x += bibitemMaxWidth(textclasslist + .TextClass(parameters + ->textclass) + .defaultfont()); + } + } + + return x; } -int LyXText::RightMargin(Row *row) +int LyXText::RightMargin(Row const * row) const { - LyXParagraph * newpar; - Row dummyrow; - LyXLayout const & layout = textclasslist.Style(parameters->textclass, row->par->GetLayout()); - - int x = LYX_PAPER_MARGIN; - - x += textclasslist.TextClass(parameters->textclass). - defaultfont().signedStringWidth(textclasslist.TextClass(parameters->textclass).rightmargin()); - if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { - x += LYX_PAPER_MARGIN/2; - } - - /* this is the way, LyX handles the LaTeX-Environments. - * I have had this idea very late, so it seems to be a - * later added hack and this is true */ - if (row->par->GetDepth()) { - /* find the next level paragraph */ - - newpar = row->par; - - do { - newpar = newpar->FirstPhysicalPar()->Previous(); - if (newpar) - newpar = newpar->FirstPhysicalPar(); - } while (newpar && newpar->GetDepth() >= row->par->GetDepth() - && newpar->footnoteflag == row->par->footnoteflag); - - /* make a corresponding row. Needed to call LeftMargin() */ - - /* check wether it is a sufficent paragraph */ - if (newpar && newpar->footnoteflag == row->par->footnoteflag - && textclasslist.Style(parameters->textclass, - newpar->GetLayout()).isEnvironment()) { - dummyrow.par = newpar; - dummyrow.pos = 0; - x = RightMargin(&dummyrow); - } - else { - /* this is no longer an error, because this function is used - * to clear impossible depths after changing a layout. Since there - * is always a redo, LeftMargin() is always called */ - - /* printf("LYX_ERROR (text, LeftMargin()) impossible depth \n");*/ - row->par->FirstPhysicalPar()->depth = 0; - } - } - - //lyxerr << "rightmargin: " << layout->rightmargin << endl; - x += (textclasslist.TextClass(parameters->textclass).defaultfont().signedStringWidth(layout.rightmargin) * 4 - / (row->par->GetDepth() + 4)); - return x; - + LyXLayout const & layout = + textclasslist.Style(parameters->textclass, + row->par->GetLayout()); + + int x = LYX_PAPER_MARGIN + + textclasslist + .TextClass(parameters->textclass) + .defaultfont() + .signedStringWidth(textclasslist + .TextClass(parameters->textclass) + .rightmargin()); + + if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { + x += LYX_PAPER_MARGIN / 2; + } + + // this is the way, LyX handles the LaTeX-Environments. + // I have had this idea very late, so it seems to be a + // later added hack and this is true + if (row->par->GetDepth()) { + // find the next level paragraph + + LyXParagraph * newpar = row->par; + + do { + newpar = newpar->FirstPhysicalPar()->Previous(); + if (newpar) + newpar = newpar->FirstPhysicalPar(); + } while (newpar && newpar->GetDepth() >= row->par->GetDepth() + && newpar->footnoteflag == row->par->footnoteflag); + + // make a corresponding row. Needed to call LeftMargin() + + // check wether it is a sufficent paragraph + if (newpar && newpar->footnoteflag == row->par->footnoteflag + && textclasslist.Style(parameters->textclass, + newpar->GetLayout()) + .isEnvironment()) { + Row dummyrow; + dummyrow.par = newpar; + dummyrow.pos = 0; + x = RightMargin(&dummyrow); + } else { + // this is no longer an error, because this function + // is used to clear impossible depths after changing + // a layout. Since there is always a redo, + // LeftMargin() is always called + row->par->FirstPhysicalPar()->depth = 0; + } + } + + //lyxerr << "rightmargin: " << layout->rightmargin << endl; + x += textclasslist.TextClass(parameters->textclass) + .defaultfont() + .signedStringWidth(layout.rightmargin) * 4 + / (row->par->GetDepth() + 4); + return x; } -int LyXText::LabelEnd (Row * row) +int LyXText::LabelEnd (Row const * row) const { - if (textclasslist.Style(parameters->textclass, row->par->GetLayout()).margintype == MARGIN_MANUAL) { - Row tmprow; - tmprow = *row; - tmprow.pos = row->par->Last(); - return LeftMargin(&tmprow); /* just the beginning - * of the main body */ - } - else - return 0; /* LabelEnd is only needed, if the - * layout fills a flushleft - * label. */ + if (textclasslist.Style(parameters->textclass, + row->par->GetLayout()).margintype + == MARGIN_MANUAL) { + Row tmprow; + tmprow = *row; + tmprow.pos = row->par->Last(); + return LeftMargin(&tmprow); /* just the beginning + of the main body */ + } else + return 0; /* LabelEnd is only needed, if the + layout fills a flushleft + label. */ } /* table stuff -- begin*/ int LyXText::NumberOfCell(LyXParagraph * par, - LyXParagraph::size_type pos) + LyXParagraph::size_type pos) const { int cell = 0; LyXParagraph::size_type tmp_pos = 0; @@ -550,7 +582,8 @@ int LyXText::NumberOfCell(LyXParagraph * par, } -int LyXText::WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos) +int LyXText::WidthOfCell(LyXParagraph * par, + LyXParagraph::size_type & pos) const { int w = 0; while (pos < par->Last() && !par->IsNewline(pos)) { @@ -563,18 +596,19 @@ int LyXText::WidthOfCell(LyXParagraph * par, LyXParagraph::size_type & pos) } -bool LyXText::HitInTable(Row * row, int x) +bool LyXText::HitInTable(Row * row, int x) const { - float tmpx; - float fill_separator, fill_hfill, fill_label_hfill; - if (!row->par->table) - return false; - PrepareToPrint(row, tmpx, fill_separator, fill_hfill, fill_label_hfill); - return (x > tmpx && x < tmpx + row->par->table->WidthOfTable()); + float tmpx; + float fill_separator, fill_hfill, fill_label_hfill; + if (!row->par->table) + return false; + PrepareToPrint(row, tmpx, fill_separator, + fill_hfill, fill_label_hfill); + return (x > tmpx && x < tmpx + row->par->table->WidthOfTable()); } -bool LyXText::MouseHitInTable(int x, long y) +bool LyXText::MouseHitInTable(int x, long y) const { Row * row = GetRowNearY(y); return HitInTable(row, x); @@ -584,18 +618,11 @@ bool LyXText::MouseHitInTable(int x, long y) /* table stuff -- end*/ -/* get the next breakpoint in a given paragraph */ +// get the next breakpoint in a given paragraph LyXParagraph::size_type -LyXText::NextBreakPoint(Row * row, int width) +LyXText::NextBreakPoint(Row const * row, int width) const { - int x = 0; - LyXParagraph::size_type last_separator = -1; - /* position of the last possible breakpoint - * -1 isn't a suitable value, but a flag */ - int left_margin; - LyXParagraph * par = row->par; - LyXParagraph::size_type i = 0; LyXParagraph::size_type pos = row->pos; /* table stuff -- begin*/ @@ -607,56 +634,60 @@ LyXText::NextBreakPoint(Row * row, int width) par->GetInset(pos) && par->GetInset(pos)->display()){ par->GetInset(pos)->display(false); } - pos++; + ++pos; } return pos; } /* table stuff -- end*/ - left_margin = LabelEnd(row); + // position of the last possible breakpoint + // -1 isn't a suitable value, but a flag + LyXParagraph::size_type last_separator = -1; + int left_margin = LabelEnd(row); width -= RightMargin(row); - LyXParagraph::size_type main_body = - BeginningOfMainBody(par); - LyXLayout const & layout = textclasslist.Style(parameters->textclass, par->GetLayout()); - i = pos; - char c; + LyXParagraph::size_type main_body = BeginningOfMainBody(par); + LyXLayout const & layout = + textclasslist.Style(parameters->textclass, par->GetLayout()); + LyXParagraph::size_type i = pos; + if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) { /* special code for right address boxes, only newlines count */ while (i < par->Last()) { if (par->IsNewline(i)) { last_separator = i; - i = par->Last() - 1;/* this means break */ - x = width; + i = par->Last() - 1; // this means break + //x = width; } else if (par->GetChar(i) == LyXParagraph::META_INSET && par->GetInset(i) && par->GetInset(i)->display()){ par->GetInset(i)->display(false); } - i++; + ++i; } } else { // Last position is an invariant LyXParagraph::size_type const last = par->Last(); - /* this is the usual handling */ - x = LeftMargin(row); + // this is the usual handling + int x = LeftMargin(row); while (x < width && i < last) { - c = par->GetChar(i); + char c = par->GetChar(i); if (IsNewlineChar(c)) { last_separator = i; - x = width; /* this means break */ + x = width; // this means break } else if (c == LyXParagraph::META_INSET && par->GetInset(i) && par->GetInset(i)->display()){ - /* check wether a Display() inset is valid here . - if not, change it to non-display*/ + // check wether a Display() inset is + // valid here. if not, change it to + // non-display if (layout.isCommand() || (layout.labeltype == LABEL_MANUAL && i < BeginningOfMainBody(par))){ - /* display istn't allowd */ + // display istn't allowd par->GetInset(i)->display(false); x += SingleWidth(par, i, c); } else { - /* inset is display. So break the line here */ + // inset is display. So break the line here if (i == pos){ if (pos < last-1) { last_separator = i; @@ -666,14 +697,14 @@ LyXText::NextBreakPoint(Row * row, int width) last_separator = last; // to avoid extra rows } else last_separator = i - 1; - x = width; /* this means break */ + x = width; // this means break } } else { if (IsLineSeparatorChar(c)) last_separator = i; x += SingleWidth(par, i, c); } - i++; + ++i; if (i == main_body) { x += GetFont(par, -2).stringWidth(layout.labelsep); if (par->IsLineSeparator(i - 1)) @@ -682,18 +713,18 @@ LyXText::NextBreakPoint(Row * row, int width) x = left_margin; } } - /* end of paragraph is always a suitable separator */ + // end of paragraph is always a suitable separator if (i == last && x < width) last_separator = i; } - /* well, if last_separator is still 0, the line isn't breakable. - * don't care and cut simply at the end */ + // well, if last_separator is still 0, the line isn't breakable. + // don't care and cut simply at the end if (last_separator < 0) { last_separator = i; } - /* manual labels cannot be broken in LaTeX, do not care */ + // manual labels cannot be broken in LaTeX, do not care if (main_body && last_separator < main_body) last_separator = main_body - 1; @@ -701,221 +732,233 @@ LyXText::NextBreakPoint(Row * row, int width) } -/* returns the minimum space a row needs on the screen in pixel */ -int LyXText::Fill(Row * row, int paper_width) +// returns the minimum space a row needs on the screen in pixel +int LyXText::Fill(Row const * row, int paper_width) const { - int w, fill; - /* get the pure distance */ - LyXParagraph::size_type last = RowLast(row); - /* table stuff -- begin*/ - if (row->par->table) { - /* for tables FILL does calculate the widthes of each cell in - * the row */ - LyXParagraph::size_type pos = row->pos; - int cell = NumberOfCell(row->par, pos); - w = 0; - do { - row->par->table->SetWidthOfCell(cell, WidthOfCell(row->par, pos)); - cell++; - } while (pos <= last && !row->par->table->IsFirstCell(cell)); - /* don't forget the very last table cell without characters */ - if (cell == row->par->table->GetNumberOfCells()-1) - row->par->table->SetWidthOfCell(cell, WidthOfCell(row->par, pos)); - - return 0; /* width of table cannot be returned since - * we cannot guarantee its correct value at - * this point. */ - } - /* table stuff -- end*/ - - int left_margin = LabelEnd(row); - - /* if the row ends with newline, this newline will not be relevant */ - if (last >= 0 && row->par->IsNewline(last)) - last--; - - /* if the row ends with a space, this space will not be relevant */ - if (last >= 0 && row->par->IsLineSeparator(last)) - last--; - - /* special handling of the right address boxes */ - if (textclasslist.Style(parameters->textclass, - row->par->GetLayout()).margintype - == MARGIN_RIGHT_ADDRESS_BOX) { - int tmpfill = row->fill; - row->fill = 0; /* the minfill in MarginLeft() */ - w = LeftMargin(row); - row->fill = tmpfill; - } - else - w = LeftMargin(row); - - LyXLayout const & layout = textclasslist.Style(parameters->textclass, - row->par->GetLayout()); - LyXParagraph::size_type main_body = - BeginningOfMainBody(row->par); - LyXParagraph::size_type i = row->pos; - while (i <= last) { - w += SingleWidth(row->par, i); - ++i; - if (i == main_body) { - w += GetFont(row->par, -2).stringWidth(layout.labelsep); - if (row->par->IsLineSeparator(i - 1)) - w -= SingleWidth(row->par, i - 1); - if (w < left_margin) - w = left_margin; - } - } - - fill = paper_width - w - RightMargin(row); - return fill; + int w, fill; + // get the pure distance + LyXParagraph::size_type last = RowLast(row); + /* table stuff -- begin */ + if (row->par->table) { + // for tables FILL does calculate the widthes of each cell in + // the row + LyXParagraph::size_type pos = row->pos; + int cell = NumberOfCell(row->par, pos); + w = 0; + do { + row->par->table->SetWidthOfCell(cell, + WidthOfCell(row->par, + pos)); + ++cell; + } while (pos <= last && !row->par->table->IsFirstCell(cell)); + // don't forget the very last table cell without characters + if (cell == row->par->table->GetNumberOfCells() - 1) + row->par->table->SetWidthOfCell(cell, + WidthOfCell(row->par, + pos)); + + return 0; /* width of table cannot be returned since + * we cannot guarantee its correct value at + * this point. */ + } + /* table stuff -- end*/ + + int left_margin = LabelEnd(row); + + // if the row ends with newline, this newline will not be relevant + if (last >= 0 && row->par->IsNewline(last)) + --last; + + // if the row ends with a space, this space will not be relevant + if (last >= 0 && row->par->IsLineSeparator(last)) + --last; + + // special handling of the right address boxes + if (textclasslist.Style(parameters->textclass, + row->par->GetLayout()).margintype + == MARGIN_RIGHT_ADDRESS_BOX) { + int tmpfill = row->fill; + row->fill = 0; // the minfill in MarginLeft() + w = LeftMargin(row); + row->fill = tmpfill; + } else + w = LeftMargin(row); + + LyXLayout const & layout = textclasslist.Style(parameters->textclass, + row->par->GetLayout()); + LyXParagraph::size_type main_body = + BeginningOfMainBody(row->par); + LyXParagraph::size_type i = row->pos; + while (i <= last) { + w += SingleWidth(row->par, i); + ++i; + if (i == main_body) { + w += GetFont(row->par, -2) + .stringWidth(layout.labelsep); + if (row->par->IsLineSeparator(i - 1)) + w -= SingleWidth(row->par, i - 1); + if (w < left_margin) + w = left_margin; + } + } + + fill = paper_width - w - RightMargin(row); + return fill; } -/* returns the minimum space a manual label needs on the screen in pixel */ -int LyXText::LabelFill(Row * row) +// returns the minimum space a manual label needs on the screen in pixel +int LyXText::LabelFill(Row const * row) const { - - LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1; - /* -1 because a label ends either with a space that is in the label, - * or with the beginning of a footnote that is outside the label. */ - - // I don't understand this code in depth, but sometimes "last" is less than - // 0 and this causes a crash. This fix seems to work correctly, but I - // bet the real error is elsewhere. The bug is triggered when you have an - // open footnote in a paragraph environment with a manual label. (Asger) - if (last < 0) last = 0; - - if (row->par->IsLineSeparator(last)) /* a sepearator at this end - * does not count */ - last--; - - int w = 0; - int i = row->pos; - while (i<= last) { - w += SingleWidth(row->par, i); - i++; - } - - int fill = 0; - if (!row->par->labelwidthstring.empty()) { - fill = GetFont(row->par, -2).stringWidth(row->par->labelwidthstring) - w; - } - - if (fill < 0) - fill = 0; - - return fill; + LyXParagraph::size_type last = BeginningOfMainBody(row->par) - 1; + // -1 because a label ends either with a space that is in the label, + // or with the beginning of a footnote that is outside the label. + + // I don't understand this code in depth, but sometimes "last" is + // less than 0 and this causes a crash. This fix seems to work + // correctly, but I bet the real error is elsewhere. The bug is + // triggered when you have an open footnote in a paragraph + // environment with a manual label. (Asger) + if (last < 0) last = 0; + + if (row->par->IsLineSeparator(last)) /* a sepearator at this end + does not count */ + --last; + + int w = 0; + int i = row->pos; + while (i <= last) { + w += SingleWidth(row->par, i); + ++i; + } + + int fill = 0; + if (!row->par->labelwidthstring.empty()) { + fill = GetFont(row->par, -2) + .stringWidth(row->par->labelwidthstring) - w; + } + + if (fill < 0) + fill = 0; + + return fill; } -/* returns the number of separators in the specified row. The separator -* on the very last column doesnt count */ -int LyXText::NumberOfSeparators(Row *row) +// returns the number of separators in the specified row. The separator +// on the very last column doesnt count +int LyXText::NumberOfSeparators(Row const * row) const { - int last = RowLast(row); - int n = 0; - int p = row->pos; - int main_body = BeginningOfMainBody(row->par); - if (p < main_body) - p = main_body; - for (; p < last; p++) { - if (row->par->IsSeparator(p)) { - n++; - } - } - return n; + int last = RowLast(row); + //int p = row->pos; + //int main_body = BeginningOfMainBody(row->par); + //if (p < main_body) + // p = main_body; + // I think this is equivalent to the above. (Lgb) + int p = max(row->pos, BeginningOfMainBody(row->par)); + int n = 0; + for (; p < last; ++p) { + if (row->par->IsSeparator(p)) { + ++n; + } + } + return n; } -/* returns the number of hfills in the specified row. The LyX-Hfill is -* a LaTeX \hfill so that the hfills at the beginning and at the end were -* ignored. This is *MUCH* more usefull than not to ignore! */ -int LyXText::NumberOfHfills(Row * row) +// returns the number of hfills in the specified row. The LyX-Hfill is +// a LaTeX \hfill so that the hfills at the beginning and at the end were +// ignored. This is *MUCH* more usefull than not to ignore! +int LyXText::NumberOfHfills(Row const * row) const { - int last = RowLast(row); - int first = row->pos; - if (first) { /* hfill *DO* count at the beginning - * of paragraphs! */ - while(first <= last && row->par->IsHfill(first)) - first++; - } + int last = RowLast(row); + int first = row->pos; + if (first) { /* hfill *DO* count at the beginning + * of paragraphs! */ + while(first <= last && row->par->IsHfill(first)) + ++first; + } - int main_body = BeginningOfMainBody(row->par); - if (first < main_body) - first = main_body; - int n = 0; - for (int p = first; p <= last; p++) { // last, because the end is ignored! - if (row->par->IsHfill(p)) { - n++; - } - } - return n; + //int main_body = BeginningOfMainBody(row->par); + //if (first < main_body) + // first = main_body; + // I think this is equivalent to the above. (Lgb) + first = max(first, BeginningOfMainBody(row->par)); + int n = 0; + for (int p = first; p <= last; ++p) { // last, because the end is ignored! + if (row->par->IsHfill(p)) { + ++n; + } + } + return n; } -/* like NumberOfHfills, but only those in the manual label! */ -int LyXText::NumberOfLabelHfills(Row * row) +// like NumberOfHfills, but only those in the manual label! +int LyXText::NumberOfLabelHfills(Row const * row) const { - LyXParagraph::size_type last = RowLast(row); - LyXParagraph::size_type first = row->pos; - if (first) { /* hfill *DO* count at the beginning - * of paragraphs! */ - while(first < last && row->par->IsHfill(first)) - first++; - } - LyXParagraph::size_type main_body = - BeginningOfMainBody(row->par); - if (last > main_body) - last = main_body; - - int n = 0; - for (LyXParagraph::size_type p = first; - p < last; ++p) { // last, because the end is ignored! - if (row->par->IsHfill(p)) { - ++n; - } - } - return n; + LyXParagraph::size_type last = RowLast(row); + LyXParagraph::size_type first = row->pos; + if (first) { /* hfill *DO* count at the beginning + * of paragraphs! */ + while(first < last && row->par->IsHfill(first)) + ++first; + } + //LyXParagraph::size_type main_body = + //BeginningOfMainBody(row->par); + //if (last > main_body) + //last = main_body; + // I think this is eqvialent to the above. (Lgb) + last = min(last, BeginningOfMainBody(row->par)); + int n = 0; + for (LyXParagraph::size_type p = first; + p < last; ++p) { // last, because the end is ignored! + if (row->par->IsHfill(p)) { + ++n; + } + } + return n; } -/* returns true, if a expansion is needed. - * Rules are given by LaTeX */ -bool LyXText::HfillExpansion(Row * row_ptr, - LyXParagraph::size_type pos) +// returns true, if a expansion is needed. +// Rules are given by LaTeX +bool LyXText::HfillExpansion(Row const * row_ptr, + LyXParagraph::size_type pos) const { - /* by the way, is it a hfill? */ - if (!row_ptr->par->IsHfill(pos)) - return false; - - /* at the end of a row it does not count */ - if (pos >= RowLast(row_ptr)) - return false; - - /* at the beginning of a row it does not count, if it is not - * the first row of a paragaph */ - if (!row_ptr->pos) - return true; - - /* in some labels it does not count */ - if ( textclasslist.Style(parameters->textclass, row_ptr->par->GetLayout()).margintype != MARGIN_MANUAL && - pos < BeginningOfMainBody(row_ptr->par)) - return false; - - /* if there is anything between the first char of the row and - * the sepcified position that is not a newline and not a hfill, - * the hfill will count, otherwise not */ - LyXParagraph::size_type i = row_ptr->pos; - while (i < pos && (row_ptr->par->IsNewline(i) - || row_ptr->par->IsHfill(i))) - i++; - - return (i != pos); + // by the way, is it a hfill? + if (!row_ptr->par->IsHfill(pos)) + return false; + + // at the end of a row it does not count + if (pos >= RowLast(row_ptr)) + return false; + + // at the beginning of a row it does not count, if it is not + // the first row of a paragaph + if (!row_ptr->pos) + return true; + + // in some labels it does not count + if (textclasslist.Style(parameters->textclass, + row_ptr->par->GetLayout()).margintype + != MARGIN_MANUAL + && pos < BeginningOfMainBody(row_ptr->par)) + return false; + + // if there is anything between the first char of the row and + // the sepcified position that is not a newline and not a hfill, + // the hfill will count, otherwise not + LyXParagraph::size_type i = row_ptr->pos; + while (i < pos && (row_ptr->par->IsNewline(i) + || row_ptr->par->IsHfill(i))) + ++i; + + return i != pos; } -void LyXText::SetHeightOfRow(Row * row_ptr) +void LyXText::SetHeightOfRow(Row * row_ptr) const { /* get the maximum ascent and the maximum descent */ int asc, maxasc, desc, maxdesc, pos_end, pos, labeladdon; @@ -1192,7 +1235,7 @@ void LyXText::SetHeightOfRow(Row * row_ptr) /* Appends the implicit specified paragraph behind the specified row, * start at the implicit given position */ -void LyXText::AppendParagraph(Row * row) +void LyXText::AppendParagraph(Row * row) const { bool not_ready = true; @@ -1224,7 +1267,7 @@ void LyXText::AppendParagraph(Row * row) } -void LyXText::BreakAgain(Row * row) +void LyXText::BreakAgain(Row * row) const { bool not_ready = true; @@ -1236,8 +1279,8 @@ void LyXText::BreakAgain(Row * row) if (z < row->par->Last() ) { if (!row->next || (row->next && row->next->par != row->par)) { - /* insert a new row */ - z++; + // insert a new row + ++z; InsertRow(row, row->par, z); row = row->next; row->height = 0; @@ -1317,16 +1360,16 @@ void LyXText::BreakParagraph(char keep_layout) LyXLayout const & layout = textclasslist.Style(parameters->textclass, cursor.par->GetLayout()); - /* table stuff -- begin*/ + /* table stuff -- begin */ if (cursor.par->table) { // breaking of tables is only allowed at the beginning or the end */ if (cursor.pos && cursor.pos < cursor.par->size() && !cursor.par->table->ShouldBeVeryLastCell(NumberOfCell(cursor.par, cursor.pos))) - return; /* no breaking of tables allowed */ + return; // no breaking of tables allowed } - /* table stuff -- end*/ + /* table stuff -- end */ - /* this is only allowed, if the current paragraph is not empty or caption*/ + // this is only allowed, if the current paragraph is not empty or caption if ((cursor.par->Last() <= 0 && !cursor.par->IsDummy()) && layout.labeltype!= LABEL_SENSITIVE) @@ -1336,26 +1379,27 @@ void LyXText::BreakParagraph(char keep_layout) cursor.par->ParFromPos(cursor.pos)->previous, cursor.par->ParFromPos(cursor.pos)->next); - /* table stuff -- begin*/ + /* table stuff -- begin */ if (cursor.par->table) { int cell = NumberOfCell(cursor.par, cursor.pos); if (cursor.par->table->ShouldBeVeryLastCell(cell)) SetCursor(cursor.par, cursor.par->text.size()); } - /* table stuff -- end*/ - /* please break alway behind a space */ + /* table stuff -- end */ + + // please break always behind a space if (cursor.pos < cursor.par->Last() && cursor.par->IsLineSeparator(cursor.pos)) cursor.pos++; - /* break the paragraph */ + // break the paragraph if (keep_layout) keep_layout = 2; else keep_layout = layout.isEnvironment(); cursor.par->BreakParagraph(cursor.pos, keep_layout); - /* table stuff -- begin*/ + /* table stuff -- begin */ if (cursor.par->table){ // the table should stay with the contents if (!cursor.pos){ @@ -1363,19 +1407,18 @@ void LyXText::BreakParagraph(char keep_layout) cursor.par->table = 0; } } - /* table stuff -- end*/ + /* table stuff -- end */ - /* well this is the caption hack since one caption is really enough */ + // well this is the caption hack since one caption is really enough if (layout.labeltype == LABEL_SENSITIVE){ if (!cursor.pos) - cursor.par->SetLayout(0); /* set the new paragraph to standard-layout */ + cursor.par->SetLayout(0); // set to standard-layout else - cursor.par->Next()->SetLayout(0); /* set the new paragraph to standard-layout */ - + cursor.par->Next()->SetLayout(0); // set to standard-layout } /* if the cursor is at the beginning of a row without prior newline, - * move one row up! + * move one row up! * This touches only the screen-update. Otherwise we would may have * an empty row on the screen */ if (cursor.pos && !cursor.row->par->IsNewline(cursor.row->pos -1) && @@ -1387,7 +1430,7 @@ void LyXText::BreakParagraph(char keep_layout) refresh_row = cursor.row; refresh_y = cursor.y - cursor.row->baseline; - /* Do not forget the special right address boxes */ + // Do not forget the special right address boxes if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) { while (refresh_row->previous && refresh_row->previous->par == refresh_row->par) { @@ -1397,7 +1440,7 @@ void LyXText::BreakParagraph(char keep_layout) } RemoveParagraph(cursor.row); - /* set the dimensions of the cursor row */ + // set the dimensions of the cursor row cursor.row->fill = Fill(cursor.row, paperwidth); SetHeightOfRow(cursor.row); @@ -1410,7 +1453,7 @@ void LyXText::BreakParagraph(char keep_layout) UpdateCounters(cursor.row->previous); - /* this check is necessary. Otherwise the new empty paragraph will + /* This check is necessary. Otherwise the new empty paragraph will * be deleted automatically. And it is more friendly for the user! */ if (cursor.pos) SetCursor(cursor.par->Next(), 0); @@ -1477,32 +1520,32 @@ void LyXText::OpenFootnote() /* table stuff -- begin*/ -void LyXText::TableFeatures(int feature, string val) +void LyXText::TableFeatures(int feature, string const & val) const { - if (!cursor.par->table) - return; /* this should never happen */ + if (!cursor.par->table) + return; /* this should never happen */ - int actCell = NumberOfCell(cursor.par, cursor.pos); - SetUndo(Undo::FINISH, - cursor.par->ParFromPos(cursor.pos)->previous, - cursor.par->ParFromPos(cursor.pos)->next); - - switch (feature){ - case LyXTable::SET_PWIDTH: - cursor.par->table->SetPWidth(actCell, val); - break; - case LyXTable::SET_SPECIAL_COLUMN: - case LyXTable::SET_SPECIAL_MULTI: - cursor.par->table->SetAlignSpecial(actCell, val, feature); - break; - default: - break; - } - RedoParagraph(); + int actCell = NumberOfCell(cursor.par, cursor.pos); + SetUndo(Undo::FINISH, + cursor.par->ParFromPos(cursor.pos)->previous, + cursor.par->ParFromPos(cursor.pos)->next); + + switch (feature){ + case LyXTable::SET_PWIDTH: + cursor.par->table->SetPWidth(actCell, val); + break; + case LyXTable::SET_SPECIAL_COLUMN: + case LyXTable::SET_SPECIAL_MULTI: + cursor.par->table->SetAlignSpecial(actCell, val, feature); + break; + default: + break; + } + RedoParagraph(); } -void LyXText::TableFeatures(int feature) +void LyXText::TableFeatures(int feature) const { int setLines = 0; int setAlign = LYX_ALIGN_LEFT; @@ -2162,12 +2205,20 @@ void LyXText::BackspaceInTable() /* just a macro to make some thing easier. */ -void LyXText::RedoParagraph() +void LyXText::RedoParagraph() const { - LyXCursor tmpcursor = cursor; - ClearSelection(); - RedoParagraphs(cursor, cursor.par->Next());; - SetCursorIntern(tmpcursor.par, tmpcursor.pos); +#if 1 + // I suspect this version will work + // also. + ClearSelection(); + RedoParagraphs(cursor, cursor.par->Next()); + SetCursorIntern(cursor.par, cursor.pos); +#else + LyXCursor tmpcursor = cursor; + ClearSelection(); + RedoParagraphs(cursor, cursor.par->Next()); + SetCursorIntern(tmpcursor.par, tmpcursor.pos); +#endif } @@ -2186,7 +2237,7 @@ void LyXText::InsertChar(char c) cursor.row->par->GetLayout()).free_spacing; if (freeSpacingBo && IsLineSeparatorChar(c) - && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos-1))) + && (!cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1))) c = LyXParagraph::META_PROTECTED_SEPARATOR; /* table stuff -- begin*/ @@ -2197,11 +2248,11 @@ void LyXText::InsertChar(char c) } /* table stuff -- end*/ - /* first check, if there will be two blanks together or a blank at - * the beginning of a paragraph. - * I decided to handle blanks like normal characters, the main - * difference are the special checks when calculating the row.fill - * (blank does not count at the end of a row) and the check here */ + /* First check, if there will be two blanks together or a blank at + the beginning of a paragraph. + I decided to handle blanks like normal characters, the main + difference are the special checks when calculating the row.fill + (blank does not count at the end of a row) and the check here */ // The bug is triggered when we type in a description environment: // The current_font is not changed when we go from label to main text @@ -2224,7 +2275,7 @@ void LyXText::InsertChar(char c) bool jumped_over_space = false; if (IsLineSeparatorChar(c)) { - +#ifndef FIX_DOUBLE_SPACE if (cursor.pos < lastpos && cursor.par->IsLineSeparator(cursor.pos)) { /* the user inserted a space before a space. So we @@ -2234,22 +2285,32 @@ void LyXText::InsertChar(char c) * blank at the end of a row we have to force * a rebreak.*/ - current_view->owner()->getMiniBuffer()->Set(_("You cannot type two spaces this way. Please read the Tutorial.")); + current_view->owner()->getMiniBuffer() + ->Set(_("You cannot type two spaces this way. " + " Please read the Tutorial.")); +#if 1 + // How can this ever happen? if (cursor.pos == RowLast(cursor.row) && !IsLineSeparatorChar(c)) - cursor.row->fill = -1; /* force rebreak */ - + cursor.row->fill = -1; // force rebreak cursor.par->Erase(cursor.pos); jumped_over_space = true; - - } else if ((cursor.pos > 0 - && cursor.par->IsLineSeparator(cursor.pos - 1)) - || (cursor.pos > 0 - && cursor.par->IsNewline(cursor.pos - 1)) - || (cursor.pos == 0 - && !(cursor.par->Previous() - && cursor.par->Previous()->footnoteflag - == LyXParagraph::OPEN_FOOTNOTE))) { +#else + // Seems to me that this works just as well. + CursorRight(); + charInserted(); + return; +#endif + } else +#endif + if ((cursor.pos > 0 + && cursor.par->IsLineSeparator(cursor.pos - 1)) + || (cursor.pos > 0 + && cursor.par->IsNewline(cursor.pos - 1)) + || (cursor.pos == 0 + && !(cursor.par->Previous() + && cursor.par->Previous()->footnoteflag + == LyXParagraph::OPEN_FOOTNOTE))) { if (cursor.pos == 0 ) current_view->owner()->getMiniBuffer()->Set(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial.")); else @@ -2263,7 +2324,7 @@ void LyXText::InsertChar(char c) charInserted(); return; } - /* no newline at first position + /* No newline at first position * of a paragraph or behind labels. * TeX does not allow that. */ @@ -2273,26 +2334,22 @@ void LyXText::InsertChar(char c) cursor.row->fill = -1; // to force a new break } - /* the display inset stuff */ + // the display inset stuff if (cursor.row->par->GetChar(cursor.row->pos) == LyXParagraph::META_INSET && cursor.row->par->GetInset(cursor.row->pos) && cursor.row->par->GetInset(cursor.row->pos)->display()) cursor.row->fill = -1; // to force a new break - /* get the cursor row fist */ - /* this is a dumb solution, i will try to hold the cursor.row - in future */ - /* row = GetRow(cursor.par, cursor.pos, y);*/ - /* ok, heres a better way: */ + // get the cursor row fist Row * row = cursor.row; long y = cursor.y - row->baseline; - if (c != LyXParagraph::META_INSET) /* in this case LyXText::InsertInset - * already insertet the character */ + if (c != LyXParagraph::META_INSET) /* Here case LyXText::InsertInset + * already insertet the character */ cursor.par->InsertChar(cursor.pos, c); SetCharFont(cursor.par, cursor.pos, rawtmpfont); if (!jumped_over_space) { - /* refresh the positions */ + // refresh the positions Row * tmprow = row; while (tmprow->next && tmprow->next->par == row->par) { tmprow = tmprow->next; @@ -2300,7 +2357,7 @@ void LyXText::InsertChar(char c) } } - /* Is there a break one row above */ + // Is there a break one row above if ((cursor.par->IsLineSeparator(cursor.pos) || cursor.par->IsNewline(cursor.pos) || cursor.row->fill == -1) @@ -2310,7 +2367,7 @@ void LyXText::InsertChar(char c) if ( z >= row->pos) { row->pos = z + 1; - /* set the dimensions of the row above */ + // set the dimensions of the row above row->previous->fill = Fill(row->previous, paperwidth); SetHeightOfRow(row->previous); @@ -2419,8 +2476,10 @@ void LyXText::charInserted() } -void LyXText::PrepareToPrint(Row * row, float & x, float & fill_separator, - float & fill_hfill, float & fill_label_hfill) +void LyXText::PrepareToPrint(Row * row, float & x, + float & fill_separator, + float & fill_hfill, + float & fill_label_hfill) const { float nh, nlh, ns; @@ -2502,7 +2561,7 @@ void LyXText::PrepareToPrint(Row * row, float & x, float & fill_separator, * realize, that you left an empty paragraph, they will delete it. * They also delete the corresponding row */ -void LyXText::CursorRightOneWord() +void LyXText::CursorRightOneWord() const { // treat floats, HFills and Insets as words LyXCursor tmpcursor = cursor; @@ -2536,7 +2595,7 @@ void LyXText::CursorRightOneWord() } -void LyXText::CursorTab() +void LyXText::CursorTab() const { if (cursor.par->table) { int cell = NumberOfCell(cursor.par, cursor.pos); @@ -2588,7 +2647,7 @@ void LyXText::CursorTab() /* -------> Skip initial whitespace at end of word and move cursor to *start* of prior word, not to end of next prior word. */ -void LyXText::CursorLeftOneWord() +void LyXText::CursorLeftOneWord() const { // treat HFills, floats and Insets as words LyXCursor tmpcursor = cursor; @@ -2865,28 +2924,29 @@ void LyXText::ChangeWordCase(LyXText::TextCase action) } -void LyXText::Delete() +void LyXText::Delete() { - LyXCursor old_cursor = cursor; - /* this is a very easy implementation*/ - - /* just move to the right */ - CursorRightIntern(); - - if (cursor.par->previous == old_cursor.par->previous - && cursor.par != old_cursor.par) - return; // delete-emty-paragraph-mechanism has done it - - /* if you had success make a backspace */ - if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) { - LyXCursor tmpcursor = cursor; - cursor = old_cursor; // to make sure undo gets the right cursor position - SetUndo(Undo::DELETE, - cursor.par->ParFromPos(cursor.pos)->previous, - cursor.par->ParFromPos(cursor.pos)->next); - cursor = tmpcursor; - Backspace(); - } + // this is a very easy implementation + + LyXCursor old_cursor = cursor; + + // just move to the right + CursorRightIntern(); + + if (cursor.par->previous == old_cursor.par->previous + && cursor.par != old_cursor.par) + return; // delete-emty-paragraph-mechanism has done it + + // if you had success make a backspace + if (old_cursor.par != cursor.par || old_cursor.pos != cursor.pos) { + LyXCursor tmpcursor = cursor; + cursor = old_cursor; // to make sure undo gets the right cursor position + SetUndo(Undo::DELETE, + cursor.par->ParFromPos(cursor.pos)->previous, + cursor.par->ParFromPos(cursor.pos)->next); + cursor = tmpcursor; + Backspace(); + } } @@ -2897,13 +2957,12 @@ void LyXText::Backspace() long y; int tmpheight; - /* table stuff -- begin*/ - + /* table stuff -- begin */ if (cursor.par->table) { BackspaceInTable(); return; } - /* table stuff -- end*/ + /* table stuff -- end */ LyXFont rawtmpfont = current_font; LyXFont realtmpfont = real_current_font; @@ -2913,9 +2972,9 @@ void LyXText::Backspace() LyXFont rawparfont = cursor.par->GetFontSettings(lastpos - 1); if (cursor.pos == 0) { - /* we may paste some paragraphs */ + // we may paste some paragraphs - /* is it an empty paragraph? */ + // is it an empty paragraph? if ((lastpos == 0 || (lastpos == 1 && cursor.par->IsSeparator(0))) @@ -2938,7 +2997,7 @@ void LyXText::Backspace() CursorLeftIntern(); - /* the layout things can change the height of a row ! */ + // the layout things can change the height of a row ! tmpheight = cursor.row->height; SetHeightOfRow(cursor.row); if (cursor.row->height != tmpheight) { @@ -2950,9 +3009,9 @@ void LyXText::Backspace() } } if (cursor.par->ParFromPos(cursor.pos)->previous){ - SetUndo(Undo::DELETE, - cursor.par->ParFromPos(cursor.pos)->previous->previous, - cursor.par->ParFromPos(cursor.pos)->next); + SetUndo(Undo::DELETE, + cursor.par->ParFromPos(cursor.pos)->previous->previous, + cursor.par->ParFromPos(cursor.pos)->next); } tmppar = cursor.par; tmprow = cursor.row; @@ -2989,17 +3048,17 @@ void LyXText::Backspace() refresh_row = cursor.row; refresh_y = cursor.y - cursor.row->baseline; - /* remove the lost paragraph */ + // remove the lost paragraph RemoveParagraph(tmprow); RemoveRow(tmprow); AppendParagraph(cursor.row); UpdateCounters(cursor.row); - /* the row may have changed, block, hfills etc. */ + // the row may have changed, block, hfills etc. SetCursor(cursor.par, cursor.pos); } - } else { + } else { /* this is the code for a normal backspace, not pasting * any paragraphs */ SetUndo(Undo::DELETE, @@ -3007,12 +3066,12 @@ void LyXText::Backspace() cursor.par->ParFromPos(cursor.pos)->next); CursorLeftIntern(); - /* some insets are undeletable here */ + // some insets are undeletable here if (cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET) { if (!cursor.par->GetInset(cursor.pos)->Deletable()) return; - /* force complete redo when erasing display insets */ - /* this is a cruel mathod but save..... Matthias */ + // force complete redo when erasing display insets + // this is a cruel mathod but save..... Matthias if (cursor.par->GetInset(cursor.pos)->display()){ cursor.par->Erase(cursor.pos); RedoParagraph(); @@ -3034,7 +3093,7 @@ void LyXText::Backspace() * to the behavior when pasting paragraphs */ if (cursor.pos && cursor.par->IsNewline(cursor.pos)) { cursor.par->Erase(cursor.pos); - /* refresh the positions */ + // refresh the positions tmprow = row; while (tmprow->next && tmprow->next->par == row->par) { tmprow = tmprow->next; @@ -3045,7 +3104,7 @@ void LyXText::Backspace() if (cursor.pos < cursor.par->Last() && !cursor.par->IsSeparator(cursor.pos)) { cursor.par->InsertChar(cursor.pos, ' '); - /* refresh the positions */ + // refresh the positions tmprow = row; while (tmprow->next && tmprow->next->par == row->par) { tmprow = tmprow->next; @@ -3055,14 +3114,15 @@ void LyXText::Backspace() } else { cursor.par->Erase(cursor.pos); - /* refresh the positions */ + // refresh the positions tmprow = row; while (tmprow->next && tmprow->next->par == row->par) { tmprow = tmprow->next; tmprow->pos--; } - - /* delete superfluous blanks */ + +#ifndef FIX_DOUBLE_SPACE + // delete superfluous blanks if (cursor.pos < cursor.par->Last() - 1 && (cursor.par->IsLineSeparator(cursor.pos))) { @@ -3070,24 +3130,25 @@ void LyXText::Backspace() || !cursor.pos || cursor.par->IsLineSeparator(cursor.pos - 1)) { cursor.par->Erase(cursor.pos); - /* refresh the positions */ + // refresh the positions tmprow = row; while (tmprow->next && tmprow->next->par == row->par) { tmprow = tmprow->next; tmprow->pos--; } - if (cursor.pos) /* move one character left */ + if (cursor.pos) // move one character left cursor.pos--; } } +#endif - /* delete newlines at the beginning of paragraphs */ + // delete newlines at the beginning of paragraphs while (cursor.par->Last() && cursor.par->IsNewline(cursor.pos) && cursor.pos == BeginningOfMainBody(cursor.par)) { cursor.par->Erase(cursor.pos); - /* refresh the positions */ + // refresh the positions tmprow = row; while (tmprow->next && tmprow->next->par == row->par) { @@ -3097,7 +3158,7 @@ void LyXText::Backspace() } } - /* is there a break one row above */ + // is there a break one row above if (row->previous && row->previous->par == row->par) { z = NextBreakPoint(row->previous, paperwidth); if ( z >= row->pos) { @@ -3105,13 +3166,12 @@ void LyXText::Backspace() tmprow = row->previous; - /* maybe the current row is now empty */ + // maybe the current row is now empty if (row->pos >= row->par->Last()) { - /* remove it */ + // remove it RemoveRow(row); need_break_row = 0; - } - else { + } else { BreakAgainOneRow(row); if (row->next && row->next->par == row->par) need_break_row = row->next; @@ -3119,7 +3179,7 @@ void LyXText::Backspace() need_break_row = 0; } - /* set the dimensions of the row above */ + // set the dimensions of the row above y -= tmprow->height; tmprow->fill = Fill(tmprow, paperwidth); SetHeightOfRow(tmprow); @@ -3130,7 +3190,7 @@ void LyXText::Backspace() SetCursor(cursor.par, cursor.pos); current_font = rawtmpfont; real_current_font = realtmpfont; - /* check, whether the last character's font has changed. */ + // check, whether the last character's font has changed. rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1); if (rawparfont != rawtmpfont) RedoHeightOfParagraph(cursor); @@ -3138,12 +3198,12 @@ void LyXText::Backspace() } } - /* break the cursor row again */ + // break the cursor row again z = NextBreakPoint(row, paperwidth); - if ( z != RowLast(row) || - (row->next && row->next->par == row->par && - RowLast(row) == row->par->Last() - 1)){ + if (z != RowLast(row) || + (row->next && row->next->par == row->par && + RowLast(row) == row->par->Last() - 1)){ /* it can happen that a paragraph loses one row * without a real breakup. This is when a word @@ -3160,14 +3220,14 @@ void LyXText::Backspace() BreakAgainOneRow(row); SetCursor(cursor.par, cursor.pos); - /* cursor MUST be in row now */ + // cursor MUST be in row now if (row->next && row->next->par == row->par) need_break_row = row->next; else need_break_row = 0; } else { - /* set the dimensions of the row */ + // set the dimensions of the row row->fill = Fill(row, paperwidth); int tmpheight = row->height; SetHeightOfRow(row); @@ -3181,19 +3241,19 @@ void LyXText::Backspace() } } - /* restore the current font - * That is what a user expects! */ + // restore the current font + // That is what a user expects! current_font = rawtmpfont; real_current_font = realtmpfont; - /* check, wether the last characters font has changed. */ + // check, wether the last characters font has changed. rawtmpfont = cursor.par->GetFontSettings(cursor.par->Last() - 1); if (rawparfont != rawtmpfont) { RedoHeightOfParagraph(cursor); } else { - /* now the special right address boxes */ + // now the special right address boxes if (textclasslist.Style(parameters->textclass, - cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { + cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { RedoDrawingOfParagraph(cursor); } } @@ -3745,7 +3805,7 @@ void LyXText::GetVisibleRow(LyXScreen & scr, int offset, } } // check for FAST SELECTION - if (fast_selection || mono_video){ + if (fast_selection || mono_video) { if (selection) { /* selection code */ @@ -3773,7 +3833,7 @@ void LyXText::GetVisibleRow(LyXScreen & scr, int offset, } -int LyXText::DefaultHeight() +int LyXText::DefaultHeight() const { LyXFont font(LyXFont::ALL_SANE); return int(font.maxAscent() + font.maxDescent() * 1.5); @@ -3782,7 +3842,7 @@ int LyXText::DefaultHeight() /* returns the column near the specified x-coordinate of the row * x is set to the real beginning of this column */ -int LyXText::GetColumnNearX(Row * row, int& x) +int LyXText::GetColumnNearX(Row * row, int & x) const { float tmpx = 0.0; float fill_separator, fill_hfill, fill_label_hfill; @@ -3791,7 +3851,7 @@ int LyXText::GetColumnNearX(Row * row, int& x) PrepareToPrint(row, tmpx, fill_separator, fill_hfill, fill_label_hfill); int main_body = BeginningOfMainBody(row->par); - + int c = row->pos; int last = RowLast(row); @@ -3817,12 +3877,12 @@ int LyXText::GetColumnNearX(Row * row, int& x) x_old = tmpx; cell++; tmpx += row->par->table->GetBeginningOfTextInCell(cell); - c++; + ++c; } else ready = true; } else { tmpx += SingleWidth(row->par, c); - c++; + ++c; } } } else @@ -4011,61 +4071,62 @@ void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind) } -/* returns pointer to a specified row */ -Row * LyXText::GetRow(LyXParagraph * par, LyXParagraph::size_type pos, long &y) +// returns pointer to a specified row +Row * LyXText::GetRow(LyXParagraph * par, + LyXParagraph::size_type pos, long & y) const { - Row * tmprow; - - if (currentrow){ - if (par == currentrow->par || par == currentrow->par->Previous()){ - // do not dereference par, it may have been deleted - // already! (Matthias) - while (currentrow->previous && currentrow->previous->par != par){ - currentrow = currentrow->previous; - currentrow_y -= currentrow->height; - } - while (currentrow->previous && currentrow->previous->par == par){ - currentrow = currentrow->previous; - currentrow_y -= currentrow->height; - } - } - tmprow = currentrow; - y = currentrow_y; - /* find the first row of the specified paragraph */ - while (tmprow->next && (tmprow->par != par)) { - y += tmprow->height; - tmprow = tmprow->next; - } - - if (tmprow->par == par){ - /* now find the wanted row */ - while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par && - tmprow->next->pos <= pos) { - y += tmprow->height; - tmprow = tmprow->next; - } - currentrow = tmprow; - currentrow_y = y; - return tmprow; - } - } - tmprow = firstrow; - y = 0; - /* find the first row of the specified paragraph */ - while (tmprow->next && (tmprow->par != par)) { - y += tmprow->height; - tmprow = tmprow->next; - } - - /* now find the wanted row */ - while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par && - tmprow->next->pos <= pos) { - y += tmprow->height; - tmprow = tmprow->next; - } - - currentrow = tmprow; - currentrow_y = y; - - return tmprow; + Row * tmprow; + + if (currentrow) { + if (par == currentrow->par || par == currentrow->par->Previous()) { + // do not dereference par, it may have been deleted + // already! (Matthias) + while (currentrow->previous && currentrow->previous->par != par) { + currentrow = currentrow->previous; + currentrow_y -= currentrow->height; + } + while (currentrow->previous && currentrow->previous->par == par) { + currentrow = currentrow->previous; + currentrow_y -= currentrow->height; + } + } + tmprow = currentrow; + y = currentrow_y; + // find the first row of the specified paragraph + while (tmprow->next && (tmprow->par != par)) { + y += tmprow->height; + tmprow = tmprow->next; + } + + if (tmprow->par == par){ + // now find the wanted row + while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par && + tmprow->next->pos <= pos) { + y += tmprow->height; + tmprow = tmprow->next; + } + currentrow = tmprow; + currentrow_y = y; + return tmprow; + } + } + tmprow = firstrow; + y = 0; + // find the first row of the specified paragraph + while (tmprow->next && (tmprow->par != par)) { + y += tmprow->height; + tmprow = tmprow->next; + } + + // now find the wanted row + while (tmprow->pos < pos && tmprow->next && tmprow->next->par == par && + tmprow->next->pos <= pos) { + y += tmprow->height; + tmprow = tmprow->next; + } + + currentrow = tmprow; + currentrow_y = y; + + return tmprow; } diff --git a/src/text2.C b/src/text2.C index 7cd63f721d..1e1d0761b8 100644 --- a/src/text2.C +++ b/src/text2.C @@ -35,11 +35,12 @@ #include "BufferView.h" #include "LyXView.h" +#define FIX_DOUBLE_SPACE 1 + extern BufferView * current_view; using std::copy; -// Constructor LyXText::LyXText(int pw, Buffer * p) { firstrow = 0; @@ -61,17 +62,17 @@ LyXText::LyXText(int pw, Buffer * p) InsertParagraph(par, lastrow); par = par->Next(); } - /* set cursor at the very top position */ - selection = true; /* these setting is necessary - * because of the delete-empty- - * paragraph mechanism in - * SetCursor */ + // set cursor at the very top position + selection = true; /* these setting is necessary + because of the delete-empty- + paragraph mechanism in + SetCursor */ SetCursor(firstrow->par, 0); sel_cursor = cursor; selection = false; mark_set = false; - /* no rebreak necessary */ + // no rebreak necessary need_break_row = 0; undo_finished = true; @@ -82,7 +83,6 @@ LyXText::LyXText(int pw, Buffer * p) } -// Destructor LyXText::~LyXText() { // Delete all rows, this does not touch the paragraphs! @@ -103,7 +103,7 @@ LyXText::~LyXText() // If position is -1, we get the layout font of the paragraph. // If position is -2, we get the font of the manual label of the paragraph. LyXFont LyXText::GetFont(LyXParagraph * par, - LyXParagraph::size_type pos) + LyXParagraph::size_type pos) const { LyXLayout const & layout = textclasslist.Style(parameters->textclass, par->GetLayout()); @@ -181,8 +181,9 @@ LyXFont LyXText::GetFont(LyXParagraph * par, void LyXText::SetCharFont(LyXParagraph * par, LyXParagraph::size_type pos, - LyXFont font) + LyXFont const & fnt) { + LyXFont font(fnt); // Let the insets convert their font if (par->GetChar(pos) == LyXParagraph::META_INSET) { if (par->GetInset(pos)) @@ -229,7 +230,7 @@ void LyXText::SetCharFont(LyXParagraph * par, /* inserts a new row behind the specified row, increments * the touched counters */ void LyXText::InsertRow(Row * row, LyXParagraph * par, - LyXParagraph::size_type pos) + LyXParagraph::size_type pos) const { Row * tmprow = new Row; if (!row) { @@ -255,12 +256,12 @@ void LyXText::InsertRow(Row * row, LyXParagraph * par, if (row == lastrow) lastrow = tmprow; - number_of_rows++; /* one more row */ + number_of_rows++; // one more row } -/* removes the row and reset the touched counters */ -void LyXText::RemoveRow(Row * row) +// removes the row and reset the touched counters +void LyXText::RemoveRow(Row * row) const { /* this must not happen before the currentrow for clear reasons. so the trick is just to set the current row onto the previous @@ -284,21 +285,20 @@ void LyXText::RemoveRow(Row * row) if (row == lastrow) lastrow = row->previous; - height -= row->height; /* the text becomes smaller */ + height -= row->height; // the text becomes smaller delete row; - --number_of_rows; /* one row less */ + --number_of_rows; // one row less } -/* remove all following rows of the paragraph of the specified row. */ -void LyXText::RemoveParagraph(Row * row) +// remove all following rows of the paragraph of the specified row. +void LyXText::RemoveParagraph(Row * row) const { - Row * tmprow; - LyXParagraph * tmppar = row->par; row = row->next; + Row * tmprow; while (row && row->par == tmppar) { tmprow = row->next; RemoveRow(row); @@ -307,15 +307,15 @@ void LyXText::RemoveParagraph(Row * row) } -/* insert the specified paragraph behind the specified row */ -void LyXText::InsertParagraph(LyXParagraph * par, Row * row) +// insert the specified paragraph behind the specified row +void LyXText::InsertParagraph(LyXParagraph * par, Row * row) const { InsertRow(row, par, 0); /* insert a new row, starting * at postition 0 */ - SetCounter(par); /* set the counters */ + SetCounter(par); // set the counters - /* and now append the whole paragraph behind the new row */ + // and now append the whole paragraph behind the new row if (!row) { firstrow->height = 0; AppendParagraph(firstrow); @@ -330,11 +330,11 @@ void LyXText::InsertParagraph(LyXParagraph * par, Row * row) void LyXText::ToggleFootnote() { LyXParagraph * par = cursor.par->ParFromPos(cursor.pos); - if (par->next && par->next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE){ + if (par->next + && par->next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) { OpenFootnote(); current_view->owner()->getMiniBuffer()->Set(_("Opened float")); - } - else { + } else { current_view->owner()->getMiniBuffer()->Set(_("Closed float")); CloseFootnote(); } @@ -349,12 +349,12 @@ void LyXText::OpenStuff() else if (cursor.pos < cursor.par->Last() && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET && cursor.par->GetInset(cursor.pos)->Editable()) { - current_view->owner()->getMiniBuffer()->Set(cursor.par->GetInset(cursor.pos)->EditMessage()); + current_view->owner()->getMiniBuffer() + ->Set(cursor.par->GetInset(cursor.pos)->EditMessage()); if (cursor.par->GetInset(cursor.pos)->Editable() != 2) SetCursorParUndo(); cursor.par->GetInset(cursor.pos)->Edit(0, 0); - } - else { + } else { ToggleFootnote(); } } @@ -362,43 +362,44 @@ void LyXText::OpenStuff() void LyXText::CloseFootnote() { - LyXParagraph * endpar, * tmppar; - Row * row; - + LyXParagraph * tmppar; LyXParagraph * par = cursor.par->ParFromPos(cursor.pos); - /* if the cursor is not in an open footnote, or - * there is no open footnote in this paragraph, just return. */ + // if the cursor is not in an open footnote, or + // there is no open footnote in this paragraph, just return. if (cursor.par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE) { - if (!par->next - || par->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE) { - current_view->owner()->getMiniBuffer()->Set(_("Nothing to do")); + if (!par->next || + par->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE) { + current_view->owner()->getMiniBuffer() + ->Set(_("Nothing to do")); return; } - /* ok, move the cursor right before the footnote */ - - /* just a little faster than using CursorRight() */ - for (cursor.pos = 0; cursor.par->ParFromPos(cursor.pos)!= par; cursor.pos++); - /* now the cursor is at the beginning of the physical par */ + // ok, move the cursor right before the footnote + // just a little faster than using CursorRight() + for (cursor.pos = 0; + cursor.par->ParFromPos(cursor.pos) != par; + cursor.pos++) + {} + + // now the cursor is at the beginning of the physical par SetCursor(cursor.par, cursor.pos + cursor.par->ParFromPos(cursor.pos)->text.size()); - } - else { + } else { /* we are in a footnote, so let us move at the beginning */ /* this is just faster than using just CursorLeft() */ tmppar = cursor.par; while (tmppar->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { - /* just a little bit faster than movin the cursor */ + // just a little bit faster than movin the cursor tmppar = tmppar->Previous(); } SetCursor(tmppar, tmppar->Last()); } - /* the cursor must be exactly before the footnote */ + // the cursor must be exactly before the footnote par = cursor.par->ParFromPos(cursor.pos); status = LyXText::NEED_MORE_REFRESH; @@ -406,8 +407,8 @@ void LyXText::CloseFootnote() refresh_y = cursor.y - cursor.row->baseline; tmppar = cursor.par; - endpar = par->NextAfterFootnote()->Next(); - row = cursor.row; + LyXParagraph * endpar = par->NextAfterFootnote()->Next(); + Row * row = cursor.row; tmppar->CloseFootnote(cursor.pos); @@ -424,7 +425,7 @@ void LyXText::CloseFootnote() SetCursor(cursor.par, cursor.pos); sel_cursor = cursor; - /* just necessary */ + // just necessary if (cursor.row->next) SetHeightOfRow(cursor.row->next); } @@ -436,7 +437,8 @@ void LyXText::MakeFontEntriesLayoutSpecific(LyXParagraph * par) { LyXFont layoutfont, tmpfont; - LyXLayout const & layout = textclasslist.Style(parameters->textclass, par->GetLayout()); + LyXLayout const & layout = + textclasslist.Style(parameters->textclass, par->GetLayout()); for (LyXParagraph::size_type pos = 0; pos < par->Last(); ++pos) { @@ -452,14 +454,15 @@ void LyXText::MakeFontEntriesLayoutSpecific(LyXParagraph * par) } -/* set layout over selection and make a total rebreak of those paragraphs */ +// set layout over selection and make a total rebreak of those paragraphs void LyXText::SetLayout(char layout) { LyXCursor tmpcursor; - /* if there is no selection just set the layout of the current paragraph */ + // if there is no selection just set the layout + // of the current paragraph */ if (!selection) { - sel_start_cursor = cursor; /* dummy selection */ + sel_start_cursor = cursor; // dummy selection sel_end_cursor = cursor; } @@ -473,7 +476,7 @@ void LyXText::SetLayout(char layout) } } else if (endpar) { - endpar = endpar->Next(); /* because of parindents etc. */ + endpar = endpar->Next(); // because of parindents etc. } SetUndo(Undo::EDIT, @@ -486,7 +489,8 @@ void LyXText::SetLayout(char layout) * and sel_end cursor */ cursor = sel_start_cursor; - LyXLayout const & lyxlayout = textclasslist.Style(parameters->textclass, layout); + LyXLayout const & lyxlayout = + textclasslist.Style(parameters->textclass, layout); while (cursor.par != sel_end_cursor.par) { if (cursor.par->footnoteflag == @@ -528,8 +532,8 @@ void LyXText::SetLayout(char layout) RedoParagraphs(sel_start_cursor, endpar); - /* we have to reset the selection, because the - * geometry could have changed */ + // we have to reset the selection, because the + // geometry could have changed */ SetCursor(sel_start_cursor.par, sel_start_cursor.pos); sel_cursor = cursor; SetCursor(sel_end_cursor.par, sel_end_cursor.pos); @@ -540,13 +544,13 @@ void LyXText::SetLayout(char layout) } -/* increment depth over selection and - * make a total rebreak of those paragraphs */ +// increment depth over selection and +// make a total rebreak of those paragraphs void LyXText::IncDepth() { // If there is no selection, just use the current paragraph if (!selection) { - sel_start_cursor = cursor; /* dummy selection */ + sel_start_cursor = cursor; // dummy selection sel_end_cursor = cursor; } @@ -561,17 +565,18 @@ void LyXText::IncDepth() } } else if (endpar) { - endpar = endpar->Next(); /* because of parindents etc. */ + endpar = endpar->Next(); // because of parindents etc. } SetUndo(Undo::EDIT, - sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, + sel_start_cursor + .par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); - LyXCursor tmpcursor = cursor; /* store the current cursor */ + LyXCursor tmpcursor = cursor; // store the current cursor - /* ok we have a selection. This is always between sel_start_cursor - * and sel_end cursor */ + // ok we have a selection. This is always between sel_start_cursor + // and sel_end cursor cursor = sel_start_cursor; bool anything_changed = false; @@ -583,7 +588,8 @@ void LyXText::IncDepth() && textclasslist.Style(parameters->textclass, cursor.par->GetLayout() ).labeltype != LABEL_BIBLIO) { - LyXParagraph * prev = cursor.par->FirstPhysicalPar()->Previous(); + LyXParagraph * prev = + cursor.par->FirstPhysicalPar()->Previous(); if (prev && (prev->GetDepth() - cursor.par->GetDepth() > 0 || (prev->GetDepth() == cursor.par->GetDepth() @@ -598,7 +604,7 @@ void LyXText::IncDepth() cursor.par = cursor.par->Next(); } - /* if nothing changed set all depth to 0 */ + // if nothing changed set all depth to 0 if (!anything_changed) { cursor = sel_start_cursor; while (cursor.par != sel_end_cursor.par) { @@ -611,8 +617,8 @@ void LyXText::IncDepth() RedoParagraphs(sel_start_cursor, endpar); - /* we have to reset the selection, because the - * geometry could have changed */ + // we have to reset the selection, because the + // geometry could have changed SetCursor(sel_start_cursor.par, sel_start_cursor.pos); sel_cursor = cursor; SetCursor(sel_end_cursor.par, sel_end_cursor.pos); @@ -623,13 +629,14 @@ void LyXText::IncDepth() } -/* decrement depth over selection and - * make a total rebreak of those paragraphs */ +// decrement depth over selection and +// make a total rebreak of those paragraphs void LyXText::DecDepth() { - /* if there is no selection just set the layout of the current paragraph */ + // if there is no selection just set the layout + // of the current paragraph if (!selection) { - sel_start_cursor = cursor; /* dummy selection */ + sel_start_cursor = cursor; // dummy selection sel_end_cursor = cursor; } @@ -643,17 +650,18 @@ void LyXText::DecDepth() } } else if (endpar) { - endpar = endpar->Next(); /* because of parindents etc. */ + endpar = endpar->Next(); // because of parindents etc. } SetUndo(Undo::EDIT, - sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, + sel_start_cursor + .par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); - LyXCursor tmpcursor = cursor; /* store the current cursor */ + LyXCursor tmpcursor = cursor; // store the current cursor - /* ok we have a selection. This is always between sel_start_cursor - * and sel_end cursor */ + // ok we have a selection. This is always between sel_start_cursor + // and sel_end cursor cursor = sel_start_cursor; while (true) { @@ -669,8 +677,8 @@ void LyXText::DecDepth() RedoParagraphs(sel_start_cursor, endpar); - /* we have to reset the selection, because the - * geometry could have changed */ + // we have to reset the selection, because the + // geometry could have changed SetCursor(sel_start_cursor.par, sel_start_cursor.pos); sel_cursor = cursor; SetCursor(sel_end_cursor.par, sel_end_cursor.pos); @@ -681,10 +689,10 @@ void LyXText::DecDepth() } -/* set font over selection and make a total rebreak of those paragraphs */ -void LyXText::SetFont(LyXFont font, bool toggleall) +// set font over selection and make a total rebreak of those paragraphs +void LyXText::SetFont(LyXFont const & font, bool toggleall) { - /* if there is no selection just set the current_font */ + // if there is no selection just set the current_font if (!selection) { // Determine basis font LyXFont layoutfont; @@ -703,10 +711,10 @@ void LyXText::SetFont(LyXFont font, bool toggleall) return; } - LyXCursor tmpcursor = cursor; /* store the current cursor */ + LyXCursor tmpcursor = cursor; // store the current cursor - /* ok we have a selection. This is always between sel_start_cursor - * and sel_end cursor */ + // ok we have a selection. This is always between sel_start_cursor + // and sel_end cursor SetUndo(Undo::EDIT, sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, @@ -718,9 +726,9 @@ void LyXText::SetFont(LyXFont font, bool toggleall) { if (cursor.pos < cursor.par->Last() && cursor.par->footnoteflag - == sel_start_cursor.par->footnoteflag) { /* an open footnote - * should behave - * like a closed */ + == sel_start_cursor.par->footnoteflag) { + // an open footnote should behave + // like a closed one LyXFont newfont = GetFont(cursor.par, cursor.pos); newfont.update(font, toggleall); SetCharFont(cursor.par, cursor.pos, newfont); @@ -733,8 +741,8 @@ void LyXText::SetFont(LyXFont font, bool toggleall) RedoParagraphs(sel_start_cursor, sel_end_cursor.par->Next()); - /* we have to reset the selection, because the - * geometry could have changed */ + // we have to reset the selection, because the + // geometry could have changed SetCursor(sel_start_cursor.par, sel_start_cursor.pos); sel_cursor = cursor; SetCursor(sel_end_cursor.par, sel_end_cursor.pos); @@ -744,27 +752,28 @@ void LyXText::SetFont(LyXFont font, bool toggleall) } -void LyXText::RedoHeightOfParagraph(LyXCursor cur) +void LyXText::RedoHeightOfParagraph(LyXCursor const & cur) { Row * tmprow = cur.row; long y = cur.y - tmprow->baseline; SetHeightOfRow(tmprow); LyXParagraph * first_phys_par = tmprow->par->FirstPhysicalPar(); - /* find the first row of the paragraph */ + // find the first row of the paragraph if (first_phys_par != tmprow->par) - while (tmprow->previous && tmprow->previous->par != first_phys_par) { + while (tmprow->previous + && tmprow->previous->par != first_phys_par) { tmprow = tmprow->previous; y -= tmprow->height; SetHeightOfRow(tmprow); } - while (tmprow->previous && tmprow->previous->par == first_phys_par) { + while (tmprow->previous && tmprow->previous->par == first_phys_par) { tmprow = tmprow->previous; y -= tmprow->height; SetHeightOfRow(tmprow); } - - /* we can set the refreshing parameters now */ + + // we can set the refreshing parameters now status = LyXText::NEED_MORE_REFRESH; refresh_y = y; refresh_row = tmprow; @@ -772,14 +781,14 @@ void LyXText::RedoHeightOfParagraph(LyXCursor cur) } -void LyXText::RedoDrawingOfParagraph(LyXCursor cur) +void LyXText::RedoDrawingOfParagraph(LyXCursor const & cur) { Row * tmprow = cur.row; long y = cur.y - tmprow->baseline; SetHeightOfRow(tmprow); LyXParagraph * first_phys_par = tmprow->par->FirstPhysicalPar(); - /* find the first row of the paragraph */ + // find the first row of the paragraph if (first_phys_par != tmprow->par) while (tmprow->previous && tmprow->previous->par != first_phys_par) { tmprow = tmprow->previous; @@ -788,10 +797,9 @@ void LyXText::RedoDrawingOfParagraph(LyXCursor cur) while (tmprow->previous && tmprow->previous->par == first_phys_par) { tmprow = tmprow->previous; y -= tmprow->height; - } - /* we can set the refreshing parameters now */ + // we can set the refreshing parameters now if (status == LyXText::UNCHANGED || y < refresh_y) { refresh_y = y; refresh_row = tmprow; @@ -804,7 +812,8 @@ void LyXText::RedoDrawingOfParagraph(LyXCursor cur) /* deletes and inserts again all paragaphs between the cursor * and the specified par * This function is needed after SetLayout and SetFont etc. */ -void LyXText::RedoParagraphs(LyXCursor cur, LyXParagraph * endpar) +void LyXText::RedoParagraphs(LyXCursor const & cur, + LyXParagraph const * endpar) const { Row * tmprow2; LyXParagraph * tmppar, * first_phys_par; @@ -815,28 +824,29 @@ void LyXText::RedoParagraphs(LyXCursor cur, LyXParagraph * endpar) if (!tmprow->previous){ first_phys_par = FirstParagraph(); // a trick/hack for UNDO - } - else { + } else { first_phys_par = tmprow->par->FirstPhysicalPar(); - /* find the first row of the paragraph */ + // find the first row of the paragraph if (first_phys_par != tmprow->par) - while (tmprow->previous && tmprow->previous->par != first_phys_par) { + while (tmprow->previous + && tmprow->previous->par != first_phys_par) { tmprow = tmprow->previous; y -= tmprow->height; } - while (tmprow->previous && tmprow->previous->par == first_phys_par) { + while (tmprow->previous + && tmprow->previous->par == first_phys_par) { tmprow = tmprow->previous; y -= tmprow->height; } } - /* we can set the refreshing parameters now */ + // we can set the refreshing parameters now status = LyXText::NEED_MORE_REFRESH; refresh_y = y; - refresh_row = tmprow->previous; /* the real refresh row will - * be deleted, so I store - * the previous here */ - /* remove it */ + refresh_row = tmprow->previous; /* the real refresh row will + be deleted, so I store + the previous here */ + // remove it if (tmprow->next) tmppar = tmprow->next->par; else @@ -849,9 +859,9 @@ void LyXText::RedoParagraphs(LyXCursor cur, LyXParagraph * endpar) tmppar = 0; } - /* remove the first one */ - tmprow2 = tmprow; /* this is because tmprow->previous - * can be 0 */ + // remove the first one + tmprow2 = tmprow; /* this is because tmprow->previous + can be 0 */ tmprow = tmprow->previous; RemoveRow(tmprow2); @@ -865,17 +875,14 @@ void LyXText::RedoParagraphs(LyXCursor cur, LyXParagraph * endpar) while (tmprow->next && tmprow->next->par == tmppar) tmprow = tmprow->next; tmppar = tmppar->Next(); - } - } - while (tmppar != endpar); + } while (tmppar != endpar); - /* this is because of layout changes */ + // this is because of layout changes if (refresh_row) { refresh_y -= refresh_row->height; SetHeightOfRow(refresh_row); - } - else { + } else { refresh_row = firstrow; refresh_y = 0; SetHeightOfRow(refresh_row); @@ -904,7 +911,7 @@ int LyXText::FullRebreak() * realize, that you left an empty paragraph, they will delete it. * They also delet the corresponding row */ -/* need the selection cursor: */ +// need the selection cursor: void LyXText::SetSelection() { if (!selection) { @@ -915,7 +922,7 @@ void LyXText::SetSelection() selection = True; - /* first the toggling area */ + // first the toggling area if (cursor.y < last_sel_cursor.y || (cursor.y == last_sel_cursor.y && cursor.x < last_sel_cursor.x)) { toggle_end_cursor = last_sel_cursor; @@ -928,7 +935,7 @@ void LyXText::SetSelection() last_sel_cursor = cursor; - /* and now the whole selection */ + // and now the whole selection if (sel_cursor.y < cursor.y || (sel_cursor.y == cursor.y && sel_cursor.x < cursor.x)) { @@ -940,27 +947,27 @@ void LyXText::SetSelection() sel_start_cursor = cursor; } - /* a selection with no contents is not a selection */ + // a selection with no contents is not a selection if (sel_start_cursor.x == sel_end_cursor.x && sel_start_cursor.y == sel_end_cursor.y) selection = false; } -void LyXText::ClearSelection() +void LyXText::ClearSelection() const { selection = false; mark_set = false; } -void LyXText::CursorHome() +void LyXText::CursorHome() const { SetCursor(cursor.par, cursor.row->pos); } -void LyXText::CursorEnd() +void LyXText::CursorEnd() const { if (!cursor.row->next || cursor.row->next->par != cursor.row->par) SetCursor(cursor.par, RowLast(cursor.row) + 1); @@ -991,7 +998,7 @@ void LyXText::CursorEnd() } -void LyXText::CursorTop() +void LyXText::CursorTop() const { while (cursor.par->Previous()) cursor.par = cursor.par->Previous(); @@ -999,7 +1006,7 @@ void LyXText::CursorTop() } -void LyXText::CursorBottom() +void LyXText::CursorBottom() const { while (cursor.par->Next()) cursor.par = cursor.par->Next(); @@ -1010,21 +1017,20 @@ void LyXText::CursorBottom() /* returns a pointer to the row near the specified y-coordinate * (relative to the whole text). y is set to the real beginning * of this row */ -Row * LyXText::GetRowNearY(long & y) +Row * LyXText::GetRowNearY(long & y) const { Row * tmprow; long tmpy; - if (currentrow){ + if (currentrow) { tmprow = currentrow; tmpy = currentrow_y; - } - else { + } else { tmprow = firstrow; tmpy = 0; } - if (tmpy<= y) + if (tmpy <= y) while (tmprow->next && tmpy + tmprow->height <= y) { tmpy += tmprow->height; tmprow = tmprow->next; @@ -1038,17 +1044,18 @@ Row * LyXText::GetRowNearY(long & y) currentrow = tmprow; currentrow_y = tmpy; - y = tmpy; /* return the real y */ + y = tmpy; // return the real y return tmprow; } -void LyXText::ToggleFree(LyXFont font, bool toggleall) +void LyXText::ToggleFree(LyXFont const & font, bool toggleall) { // If the mask is completely neutral, tell user if (font == LyXFont(LyXFont::ALL_IGNORE)){ // Could only happen with user style - current_view->owner()->getMiniBuffer()->Set(_("No font change defined. Use Character under" + current_view->owner()->getMiniBuffer() + ->Set(_("No font change defined. Use Character under" " the Layout menu to define font change.")); return; } @@ -1073,7 +1080,8 @@ void LyXText::ToggleFree(LyXFont font, bool toggleall) LyXParagraph::size_type LyXText::BeginningOfMainBody(LyXParagraph * par) const { - if (textclasslist.Style(parameters->textclass, par->GetLayout()).labeltype != LABEL_MANUAL) + if (textclasslist.Style(parameters->textclass, + par->GetLayout()).labeltype != LABEL_MANUAL) return 0; else return par->BeginningOfMainBody(); @@ -1110,36 +1118,41 @@ void LyXText::MeltFootnoteEnvironment() char first_footnote_par_is_not_empty = tmppar->next->text.size(); - while (tmppar->next && tmppar->next->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { - tmppar = tmppar->next; /* I use next instead of Next(), - * because there cannot be any - * footnotes in a footnote - * environment */ + while (tmppar->next + && tmppar->next->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { + tmppar = tmppar->next; /* I use next instead of Next(), + * because there cannot be any + * footnotes in a footnote + * environment */ tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE; /* remember the captions and empty paragraphs */ if ((textclasslist.Style(parameters->textclass, - tmppar->GetLayout()).labeltype == LABEL_SENSITIVE) + tmppar->GetLayout()) + .labeltype == LABEL_SENSITIVE) || !tmppar->Last()) tmppar->SetLayout(0); } - /* now we will paste the ex-footnote, if the layouts allow it */ - /* first restore the layout of the paragraph right behind the footnote*/ + // now we will paste the ex-footnote, if the layouts allow it + // first restore the layout of the paragraph right behind + // the footnote if (tmppar->next) tmppar->next->MakeSameLayout(cursor.par); - /* first the end */ + // first the end if ((!tmppar->GetLayout() && !tmppar->table) - || (tmppar->Next() && (!tmppar->Next()->Last() - || tmppar->Next()->HasSameLayout(tmppar)))) { - if (tmppar->Next()->Last() && tmppar->Next()->IsLineSeparator(0)) + || (tmppar->Next() + && (!tmppar->Next()->Last() + || tmppar->Next()->HasSameLayout(tmppar)))) { + if (tmppar->Next()->Last() + && tmppar->Next()->IsLineSeparator(0)) tmppar->Next()->Erase(0); tmppar->PasteParagraph(); } - tmppar = tmppar->Next(); /* make shure tmppar cannot be touched - * by the pasting of the beginning */ + tmppar = tmppar->Next(); /* make sure tmppar cannot be touched + * by the pasting of the beginning */ /* then the beginning */ /* if there is no space between the text and the footnote, so we insert @@ -1179,7 +1192,8 @@ void LyXText::MeltFootnoteEnvironment() void LyXText::SetParagraph(bool line_top, bool line_bottom, bool pagebreak_top, bool pagebreak_bottom, - VSpace space_top, VSpace space_bottom, + VSpace const & space_top, + VSpace const & space_bottom, LyXAlignment align, string labelwidthstring, bool noindent) @@ -1201,16 +1215,17 @@ void LyXText::SetParagraph(bool line_top, bool line_bottom, } } else if (endpar) { - endpar = endpar->Next(); /* because of parindents etc. */ + endpar = endpar->Next(); // because of parindents etc. } SetUndo(Undo::EDIT, - sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, + sel_start_cursor + .par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); LyXParagraph * tmppar = sel_end_cursor.par; - while (tmppar != sel_start_cursor.par->FirstPhysicalPar()->Previous()){ + while (tmppar != sel_start_cursor.par->FirstPhysicalPar()->Previous()) { SetCursor(tmppar->FirstPhysicalPar(), 0); status = LyXText::NEED_MORE_REFRESH; refresh_row = cursor.row; @@ -1223,7 +1238,7 @@ void LyXText::SetParagraph(bool line_top, bool line_bottom, cursor.par->pagebreak_bottom = pagebreak_bottom; cursor.par->added_space_top = space_top; cursor.par->added_space_bottom = space_bottom; - /* does the layout allow the new alignment? */ + // does the layout allow the new alignment? if (align == LYX_ALIGN_LAYOUT) align = textclasslist .Style(parameters->textclass, @@ -1280,11 +1295,12 @@ void LyXText::SetParagraphExtraOpt(int type, } } else if (endpar) { - endpar = endpar->Next(); /* because of parindents etc. */ + endpar = endpar->Next(); // because of parindents etc. } SetUndo(Undo::EDIT, - sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, + sel_start_cursor + .par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); tmppar = sel_end_cursor.par; @@ -1319,32 +1335,31 @@ void LyXText::SetParagraphExtraOpt(int type, } -static char const * alphaCounter(int n){ - static char result[2]; - result[1] = 0; - if (n == 0) - return ""; - else { - result[0] = 64 + n; - if (n > 26) - return "??"; - } - return result; +static char const * alphaCounter(int n) { + static char result[2]; + result[1] = 0; + if (n == 0) + return ""; + else { + result[0] = 'A' + n; + if (n > 'Z') + return "??"; + } + return result; } -/* set the counter of a paragraph. This includes the labels */ -void LyXText::SetCounter(LyXParagraph * par) +// set the counter of a paragraph. This includes the labels +void LyXText::SetCounter(LyXParagraph * par) const { - int i; - - /* this is only relevant for the beginning of paragraph */ + // this is only relevant for the beginning of paragraph par = par->FirstPhysicalPar(); LyXLayout const & layout = textclasslist.Style(parameters->textclass, - par->GetLayout()); + par->GetLayout()); - LyXTextClass const & textclass = textclasslist.TextClass(parameters->textclass); + LyXTextClass const & textclass = + textclasslist.TextClass(parameters->textclass); /* copy the prev-counters to this one, unless this is the start of a footnote or of a bibliography or the very first paragraph */ @@ -1356,13 +1371,13 @@ void LyXText::SetCounter(LyXParagraph * par) par->Previous()->GetLayout() ).labeltype != LABEL_BIBLIO && layout.labeltype == LABEL_BIBLIO)) { - for (i = 0; i<10; i++) { + for (int i = 0; i<10; i++) { par->setCounter(i, par->Previous()->GetFirstCounter(i)); } par->appendix = par->Previous()->FirstPhysicalPar()->appendix; if (!par->appendix && par->start_of_appendix){ par->appendix = true; - for (i = 0; i<10; i++) { + for (int i = 0; i<10; i++) { par->setCounter(i, 0); } } @@ -1370,7 +1385,7 @@ void LyXText::SetCounter(LyXParagraph * par) par->itemdepth = par->Previous()->FirstPhysicalPar()->itemdepth; } else { - for (i = 0; i<10; i++) { + for (int i = 0; i<10; i++) { par->setCounter(i, 0); } par->appendix = par->start_of_appendix; @@ -1433,7 +1448,7 @@ void LyXText::SetCounter(LyXParagraph * par) /* reset the counters. * A depth change is like a breaking layout */ - for (i = 6 + par->enumdepth + 1; i<10;i++) + for (int i = 6 + par->enumdepth + 1; i<10;i++) par->setCounter(i, 0); } @@ -1453,7 +1468,7 @@ void LyXText::SetCounter(LyXParagraph * par) /* is it a layout that has an automatic label ? */ if (layout.labeltype >= LABEL_FIRST_COUNTER) { - i = layout.labeltype - LABEL_FIRST_COUNTER; + int i = layout.labeltype - LABEL_FIRST_COUNTER; if (i >= 0 && i<= parameters->secnumdepth) { par->incCounter(i); // increment the counter @@ -1465,8 +1480,7 @@ void LyXText::SetCounter(LyXParagraph * par) par->labelstring = layout.labelstring(); else par->labelstring.clear(); - } - else { + } else { if (!layout.labelstring_appendix().empty()) par->labelstring = layout.labelstring_appendix(); else @@ -1519,8 +1533,7 @@ void LyXText::SetCounter(LyXParagraph * par) sprintf(s, "%d.", par->getCounter(i)); break; } - } - else { + } else { switch (2 * LABEL_FIRST_COUNTER - textclass.maxcounter() + i) { case LABEL_COUNTER_CHAPTER: sprintf(s, "%s", @@ -1570,13 +1583,13 @@ void LyXText::SetCounter(LyXParagraph * par) par->labelstring += s; delete[] s; - for (i++; i<10; i++) { - /* reset the following counters */ + for (i++; i < 10; ++i) { + // reset the following counters par->setCounter(i, 0); } } else if (layout.labeltype < LABEL_COUNTER_ENUMI) { - for (i++; i<10; i++) { - /* reset the following counters */ + for (i++; i < 10; ++i) { + // reset the following counters par->setCounter(i, 0); } } else if (layout.labeltype == LABEL_COUNTER_ENUMI) { @@ -1617,34 +1630,33 @@ void LyXText::SetCounter(LyXParagraph * par) par->labelstring = s; delete[] s; - for (i += par->enumdepth + 1;i<10;i++) + for (i += par->enumdepth + 1; i < 10; ++i) par->setCounter(i, 0); /* reset the following counters */ } } else if (layout.labeltype == LABEL_BIBLIO) {// ale970302 - i = LABEL_COUNTER_ENUMI - LABEL_FIRST_COUNTER + par->enumdepth; - par->incCounter(i); - int number = par->getCounter(i); - if (!par->bibkey) - par->bibkey = new InsetBibKey(); - par->bibkey->setCounter(number); - par->labelstring = layout.labelstring(); - - // In biblio should't be following counters but... - } - else { + int i = LABEL_COUNTER_ENUMI - LABEL_FIRST_COUNTER + par->enumdepth; + par->incCounter(i); + int number = par->getCounter(i); + if (!par->bibkey) + par->bibkey = new InsetBibKey(); + par->bibkey->setCounter(number); + par->labelstring = layout.labelstring(); + + // In biblio should't be following counters but... + } else { string s = layout.labelstring(); - - /* the caption hack: */ + + // the caption hack: if (layout.labeltype == LABEL_SENSITIVE) { if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE && (par->footnotekind == LyXParagraph::FIG - || par->footnotekind == LyXParagraph::WIDE_FIG)) + || par->footnotekind == LyXParagraph::WIDE_FIG)) s = "Figure:"; else if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE && (par->footnotekind == LyXParagraph::TAB - || par->footnotekind == LyXParagraph::WIDE_TAB)) + || par->footnotekind == LyXParagraph::WIDE_TAB)) s = "Table:"; else if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE && par->footnotekind == LyXParagraph::ALGORITHM) @@ -1653,14 +1665,13 @@ void LyXText::SetCounter(LyXParagraph * par) /* par->SetLayout(0); s = layout->labelstring; */ s = "Senseless: "; - } } par->labelstring = s; - + /* reset the enumeration counter. They are always resetted * when there is any other layout between */ - for (i = 6 + par->enumdepth; i<10;i++) + for (int i = 6 + par->enumdepth; i < 10; ++i) par->setCounter(i, 0); } } @@ -1668,7 +1679,7 @@ void LyXText::SetCounter(LyXParagraph * par) /* Updates all counters BEHIND the row. Changed paragraphs * with a dynamic left margin will be rebroken. */ -void LyXText::UpdateCounters(Row * row) +void LyXText::UpdateCounters(Row * row) const { LyXParagraph * par; if (!row) { @@ -1676,7 +1687,8 @@ void LyXText::UpdateCounters(Row * row) par = row->par; } else { - if (row->par->next && row->par->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE) { + if (row->par->next + && row->par->next->footnoteflag != LyXParagraph::OPEN_FOOTNOTE) { par = row->par->LastPhysicalPar()->Next(); } else { par = row->par->next; @@ -1686,9 +1698,9 @@ void LyXText::UpdateCounters(Row * row) while (par) { while (row->par != par) row = row->next; - + SetCounter(par); - + /* now check for the headline layouts. remember that they * have a dynamic left margin */ if (!par->IsDummy() @@ -1767,37 +1779,40 @@ void LyXText::pasteEnvironmentType() void LyXText::CutSelection(bool doclear) { - /* This doesn't make sense, if there is no selection */ - if (!selection) { + // This doesn't make sense, if there is no selection + if (!selection) return; - } - /* OK, we have a selection. This is always between sel_start_cursor - * and sel_end cursor */ + // OK, we have a selection. This is always between sel_start_cursor + // and sel_end cursor LyXParagraph * tmppar; - /* Check whether there are half footnotes in the selection */ + // Check whether there are half footnotes in the selection if (sel_start_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE || sel_end_cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE){ tmppar = sel_start_cursor.par; while (tmppar != sel_end_cursor.par){ - if (tmppar->footnoteflag != sel_end_cursor.par->footnoteflag){ - WriteAlert(_("Impossible operation"), _("Don't know what to do with half floats."), _("sorry.")); + if (tmppar->footnoteflag != sel_end_cursor.par->footnoteflag) { + WriteAlert(_("Impossible operation"), + _("Don't know what to do with half floats."), + _("sorry.")); return; } tmppar = tmppar->Next(); } } - /* table stuff -- begin*/ - if (sel_start_cursor.par->table || sel_end_cursor.par->table){ - if ( sel_start_cursor.par != sel_end_cursor.par){ - WriteAlert(_("Impossible operation"), _("Don't know what to do with half tables."), _("sorry.")); + /* table stuff -- begin */ + if (sel_start_cursor.par->table || sel_end_cursor.par->table) { + if ( sel_start_cursor.par != sel_end_cursor.par) { + WriteAlert(_("Impossible operation"), + _("Don't know what to do with half tables."), + _("sorry.")); return; } sel_start_cursor.par->table->Reinit(); } - /* table stuff -- end*/ + /* table stuff -- end */ // make sure that the depth behind the selection are restored, too LyXParagraph * endpar = sel_end_cursor.par->LastPhysicalPar()->Next(); @@ -1808,136 +1823,152 @@ void LyXText::CutSelection(bool doclear) endpar = endpar->LastPhysicalPar()->Next(); undoendpar = endpar; } - } - else if (endpar) { - endpar = endpar->Next(); /* because of parindents etc. */ + } else if (endpar) { + endpar = endpar->Next(); // because of parindents etc. } SetUndo(Undo::DELETE, - sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->previous, + sel_start_cursor + .par->ParFromPos(sel_start_cursor.pos)->previous, undoendpar); - /* delete the simple_cut_buffer */ + // delete the simple_cut_buffer DeleteSimpleCutBuffer(); - /* set the textclass */ + // set the textclass simple_cut_buffer_textclass = parameters->textclass; #ifdef WITH_WARNINGS #warning Asger: Make cut more intelligent here. #endif -/* -White paper for "intelligent" cutting: - -Example: "This is our text." -Using " our " as selection, cutting will give "This istext.". -Using "our" as selection, cutting will give "This is text.". -Using " our" as selection, cutting will give "This is text.". -Using "our " as selection, cutting will give "This is text.". - -All those four selections will (however) paste identically: -Pasting with the cursor right after the "is" will give the -original text with all four selections. - -The rationale is to be intelligent such that words are copied, -cut and pasted in a functional manner. - -This is not implemented yet. -*/ - + /* + White paper for "intelligent" cutting: + + Example: "This is our text." + Using " our " as selection, cutting will give "This istext.". + Using "our" as selection, cutting will give "This is text.". + Using " our" as selection, cutting will give "This is text.". + Using "our " as selection, cutting will give "This is text.". + + All those four selections will (however) paste identically: + Pasting with the cursor right after the "is" will give the + original text with all four selections. + + The rationale is to be intelligent such that words are copied, + cut and pasted in a functional manner. + + This is not implemented yet. (Asger) + + The changes below sees to do a lot of what you want. However + I have not verified that all cases work as they should: + - cut in single row + - cut in multiple row + - cut with insets + - cut across footnotes and paragraph + My simplistic tests show that the idea are basically sound but + there are some items to fix up...we only need to find them + first. (Lgb) + */ + +#ifndef FIX_DOUBLE_SPACE bool space_wrapped = sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos); if (sel_end_cursor.pos > 0 && sel_end_cursor.par->IsLineSeparator(sel_end_cursor.pos - 1)) { - sel_end_cursor.pos--; /* please break before a space at - * the end */ + // please break before a space at the end + sel_end_cursor.pos--; space_wrapped = true; } - // cut behind a space if there is one while (sel_start_cursor.par->Last() > sel_start_cursor.pos && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos) && (sel_start_cursor.par != sel_end_cursor.par || sel_start_cursor.pos < sel_end_cursor.pos)) sel_start_cursor.pos++; - - /* there are two cases: cut only within one paragraph or - * more than one paragraph */ +#endif + // there are two cases: cut only within one paragraph or + // more than one paragraph if (sel_start_cursor.par->ParFromPos(sel_start_cursor.pos) == sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) { - /* only within one paragraph */ + // only within one paragraph simple_cut_buffer = new LyXParagraph; LyXParagraph::size_type i = sel_start_cursor.pos; - for (; i< sel_end_cursor.pos; i++){ - /* table stuff -- begin*/ + for (; i < sel_end_cursor.pos; ++i) { + /* table stuff -- begin */ if (sel_start_cursor.par->table && sel_start_cursor.par->IsNewline(sel_start_cursor.pos)){ sel_start_cursor.par->CopyIntoMinibuffer(sel_start_cursor.pos); sel_start_cursor.pos++; } else { - /* table stuff -- end*/ + /* table stuff -- end */ sel_start_cursor.par->CopyIntoMinibuffer(sel_start_cursor.pos); sel_start_cursor.par->Erase(sel_start_cursor.pos); } simple_cut_buffer->InsertFromMinibuffer(simple_cut_buffer->Last()); } - /* check for double spaces */ +#ifdef FIX_DOUBLE_SPACES + // check for double spaces if (sel_start_cursor.pos && - sel_start_cursor.par->Last()>sel_start_cursor.pos && + sel_start_cursor.par->Last() > sel_start_cursor.pos && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1) && - sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)){ + sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) { sel_start_cursor.par->Erase(sel_start_cursor.pos); } if (space_wrapped) simple_cut_buffer->InsertChar(i - sel_start_cursor.pos, ' '); +#endif endpar = sel_end_cursor.par->Next(); } else { - /* cut more than one paragraph */ + // cut more than one paragraph sel_end_cursor.par->BreakParagraphConservative(sel_end_cursor.pos); - /* insert a space at the end if there was one */ +#ifndef FIX_DOUBLE_SPACE + // insert a space at the end if there was one if (space_wrapped) sel_end_cursor.par->InsertChar(sel_end_cursor.par->Last(), ' '); - +#endif sel_end_cursor.par = sel_end_cursor.par->Next(); sel_end_cursor.pos = 0; cursor = sel_end_cursor; - - /* please break behind a space, if there is one. The space should - * be copied too */ + +#ifndef FIX_DOUBLE_SPACE + // please break behind a space, if there is one. + // The space should be copied too if (sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos)) sel_start_cursor.pos++; - sel_start_cursor.par->BreakParagraphConservative(sel_start_cursor.pos); + sel_start_cursor.par + ->BreakParagraphConservative(sel_start_cursor.pos); if (!sel_start_cursor.pos || sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1) || sel_start_cursor.par->IsNewline(sel_start_cursor.pos - 1)) { sel_start_cursor.par->Next()->InsertChar(0, ' '); } - - /* store the endparagraph for redoing later */ +#endif + // store the endparagraph for redoing later endpar = sel_end_cursor.par->Next(); /* needed because - * the sel_end_ - * cursor.par - * will be pasted!*/ + the sel_end_ + cursor.par + will be pasted! */ - /*store the selection */ - simple_cut_buffer = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->next; + // store the selection + simple_cut_buffer = sel_start_cursor.par + ->ParFromPos(sel_start_cursor.pos)->next; simple_cut_buffer->previous = 0; sel_end_cursor.par->previous->next = 0; - /* cut the selection */ + // cut the selection sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->next = sel_end_cursor.par; sel_end_cursor.par->previous = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos); - /* care about footnotes */ + // care about footnotes if (simple_cut_buffer->footnoteflag) { LyXParagraph *tmppar = simple_cut_buffer; while (tmppar){ @@ -1946,10 +1977,10 @@ This is not implemented yet. } } - /* the cut selection should begin with standard layout */ + // the cut selection should begin with standard layout simple_cut_buffer->Clear(); - /* paste the paragraphs again, if possible */ + // paste the paragraphs again, if possible if (doclear) sel_start_cursor.par->Next()->ClearParagraph(); if (sel_start_cursor.par->FirstPhysicalPar()->HasSameLayout(sel_start_cursor.par->Next()) @@ -1957,17 +1988,17 @@ This is not implemented yet. !sel_start_cursor.par->Next()->Last()) sel_start_cursor.par->ParFromPos(sel_start_cursor.pos)->PasteParagraph(); - - /* maybe a forgotten blank */ +#ifdef FIX_DOUBLE_SPACE + // maybe a forgotten blank if (sel_start_cursor.pos && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos) && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos - 1)) { sel_start_cursor.par->Erase(sel_start_cursor.pos); } +#endif } - - /* sometimes necessary */ + // sometimes necessary if (doclear) sel_start_cursor.par->ClearParagraph(); @@ -1983,14 +2014,12 @@ This is not implemented yet. void LyXText::CopySelection() { - LyXParagraph::size_type i = 0; - /* this doesnt make sense, if there is no selection */ - if (!selection) { + // this doesnt make sense, if there is no selection + if (!selection) return; - } - /* ok we have a selection. This is always between sel_start_cursor - * and sel_end cursor */ + // ok we have a selection. This is always between sel_start_cursor + // and sel_end cursor LyXParagraph * tmppar; /* check wether there are half footnotes in the selection */ @@ -1999,49 +2028,56 @@ void LyXText::CopySelection() tmppar = sel_start_cursor.par; while (tmppar != sel_end_cursor.par){ if (tmppar->footnoteflag != sel_end_cursor.par->footnoteflag){ - WriteAlert(_("Impossible operation"), _("Don't know what to do with half floats."), _("sorry.")); + WriteAlert(_("Impossible operation"), + _("Don't know what to do with half floats."), + _("sorry.")); return; } tmppar = tmppar->Next(); } } - /* table stuff -- begin*/ + /* table stuff -- begin */ if (sel_start_cursor.par->table || sel_end_cursor.par->table){ if ( sel_start_cursor.par != sel_end_cursor.par){ - WriteAlert(_("Impossible operation"), _("Don't know what to do with half tables."), _("sorry.")); + WriteAlert(_("Impossible operation"), + _("Don't know what to do with half tables."), + _("sorry.")); return; } } - /* table stuff -- end*/ + /* table stuff -- end */ - /* delete the simple_cut_buffer */ + // delete the simple_cut_buffer DeleteSimpleCutBuffer(); - /* set the textclass */ + // set the textclass simple_cut_buffer_textclass = parameters->textclass; +#ifdef FIX_DOUBLE_SPACE // copy behind a space if there is one while (sel_start_cursor.par->Last() > sel_start_cursor.pos && sel_start_cursor.par->IsLineSeparator(sel_start_cursor.pos) && (sel_start_cursor.par != sel_end_cursor.par || sel_start_cursor.pos < sel_end_cursor.pos)) sel_start_cursor.pos++; - - /* there are two cases: copy only within one paragraph or more than one paragraph */ +#endif + // there are two cases: copy only within one paragraph + // or more than one paragraph if (sel_start_cursor.par->ParFromPos(sel_start_cursor.pos) == sel_end_cursor.par->ParFromPos(sel_end_cursor.pos)) { - /* only within one paragraph */ + // only within one paragraph simple_cut_buffer = new LyXParagraph; + LyXParagraph::size_type i = 0; for (i = sel_start_cursor.pos; i < sel_end_cursor.pos; ++i){ sel_start_cursor.par->CopyIntoMinibuffer(i); simple_cut_buffer->InsertFromMinibuffer(i - sel_start_cursor.pos); } - } - else { - /* copy more than one paragraph */ - /* clone the paragraphs within the selection*/ - tmppar = sel_start_cursor.par->ParFromPos(sel_start_cursor.pos); + } else { + // copy more than one paragraph + // clone the paragraphs within the selection + tmppar = + sel_start_cursor.par->ParFromPos(sel_start_cursor.pos); simple_cut_buffer = tmppar->Clone(); LyXParagraph *tmppar2 = simple_cut_buffer; @@ -2054,22 +2090,23 @@ void LyXText::CopySelection() } tmppar2->next = 0; - /* care about footnotes */ + // care about footnotes if (simple_cut_buffer->footnoteflag) { tmppar = simple_cut_buffer; while (tmppar){ - tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE; + tmppar->footnoteflag = + LyXParagraph::NO_FOOTNOTE; tmppar = tmppar->next; } } - /* the simple_cut_buffer paragraph is too big */ + // the simple_cut_buffer paragraph is too big LyXParagraph::size_type tmpi2 = sel_start_cursor.par->PositionInParFromPos(sel_start_cursor.pos); - for (;tmpi2;tmpi2--) + for (; tmpi2; --tmpi2) simple_cut_buffer->Erase(0); - /* now tmppar 2 is too big, delete all after sel_end_cursor.pos */ + // now tmppar 2 is too big, delete all after sel_end_cursor.pos tmpi2 = sel_end_cursor.par->PositionInParFromPos(sel_end_cursor.pos); while (tmppar2->size() > tmpi2) { @@ -2081,7 +2118,7 @@ void LyXText::CopySelection() void LyXText::PasteSelection() { - /* this does not make sense, if there is nothing to paste */ + // this does not make sense, if there is nothing to paste if (!simple_cut_buffer) return; @@ -2090,22 +2127,24 @@ void LyXText::PasteSelection() LyXCursor tmpcursor; - /* be carefull with footnotes in footnotes */ + // be carefull with footnotes in footnotes if (cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE) { - /* check whether the cut_buffer includes a footnote */ + // check whether the cut_buffer includes a footnote tmppar = simple_cut_buffer; - while (tmppar && tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE) + while (tmppar + && tmppar->footnoteflag == LyXParagraph::NO_FOOTNOTE) tmppar = tmppar->next; if (tmppar) { WriteAlert(_("Impossible operation"), - _("Can't paste float into float!"), _("Sorry.")); + _("Can't paste float into float!"), + _("Sorry.")); return; } } - /* table stuff -- begin*/ + /* table stuff -- begin */ if (cursor.par->table){ if (simple_cut_buffer->next){ WriteAlert(_("Impossible operation"), @@ -2114,7 +2153,7 @@ void LyXText::PasteSelection() return; } } - /* table stuff -- end*/ + /* table stuff -- end */ SetUndo(Undo::INSERT, cursor.par->ParFromPos(cursor.pos)->previous, @@ -2122,17 +2161,18 @@ void LyXText::PasteSelection() tmpcursor = cursor; - /* There are two cases: cutbuffer only one paragraph or many */ + // There are two cases: cutbuffer only one paragraph or many if (!simple_cut_buffer->next) { - /* only within a paragraph */ - - /* please break behind a space, if there is one */ + // only within a paragraph + +#ifndef FIX_DOUBLE_SPACE + // please break behind a space, if there is one while (tmpcursor.par->Last() > tmpcursor.pos && tmpcursor.par->IsLineSeparator(tmpcursor.pos)) tmpcursor.pos++; - +#endif tmppar = simple_cut_buffer->Clone(); - /* table stuff -- begin*/ + /* table stuff -- begin */ bool table_too_small = false; if (tmpcursor.par->table) { while (simple_cut_buffer->text.size() @@ -2153,22 +2193,26 @@ void LyXText::PasteSelection() } } } else { - /* table stuff -- end*/ - while (simple_cut_buffer->text.size()){ + /* table stuff -- end */ + // Some provisions should be done here for checking if we + // are inserting at the beginning of a paragraph. If there + // are a space at the beginning of the text to insert and we are + // inserting at the beginning of the paragraph the space should + // be removed. + while (simple_cut_buffer->text.size()) { simple_cut_buffer->CutIntoMinibuffer(0); simple_cut_buffer->Erase(0); tmpcursor.par->InsertFromMinibuffer(tmpcursor.pos); tmpcursor.pos++; } } - delete simple_cut_buffer; simple_cut_buffer = tmppar; endpar = tmpcursor.par->Next(); } else { - /* many paragraphs */ + // many paragraphs - /* make a copy of the simple cut_buffer */ + // make a copy of the simple cut_buffer tmppar = simple_cut_buffer; LyXParagraph * simple_cut_clone = tmppar->Clone(); LyXParagraph * tmppar2 = simple_cut_clone; @@ -2187,51 +2231,54 @@ void LyXText::PasteSelection() } } - /* make sure there is no class difference */ + // make sure there is no class difference SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass, parameters->textclass, simple_cut_buffer); - /* make the simple_cut_buffer exactly the same layout than - the cursor paragraph */ + // make the simple_cut_buffer exactly the same layout than + // the cursor paragraph simple_cut_buffer->MakeSameLayout(cursor.par); - /* find the end of the buffer */ + // find the end of the buffer LyXParagraph *lastbuffer = simple_cut_buffer; while (lastbuffer->Next()) lastbuffer = lastbuffer->Next(); - /* find the physical end of the buffer */ + // find the physical end of the buffer lastbuffer = simple_cut_buffer; while (lastbuffer->Next()) lastbuffer = lastbuffer->Next(); - /* please break behind a space, if there is one. The space - * should be copied too */ - if (cursor.par->Last() > cursor.pos && cursor.par->IsLineSeparator(cursor.pos)) +#ifndef FIX_DOUBLE_SPACE + // Please break behind a space, if there is one. The space + // should be copied too. + if (cursor.par->Last() > cursor.pos + && cursor.par->IsLineSeparator(cursor.pos)) cursor.pos++; - +#endif bool paste_the_end = false; - /* open the paragraph for inserting the simple_cut_buffer - if necessary */ + // open the paragraph for inserting the simple_cut_buffer + // if necessary if (cursor.par->Last() > cursor.pos || !cursor.par->Next()){ cursor.par->BreakParagraphConservative(cursor.pos); paste_the_end = true; } - - /* be careful with double spaces */ + +#ifndef FIX_DOUBLE_SPACE + // be careful with double spaces if ((!cursor.par->Last() || cursor.par->IsLineSeparator(cursor.pos - 1) || cursor.par->IsNewline(cursor.pos - 1)) && simple_cut_buffer->text.size() && simple_cut_buffer->IsLineSeparator(0)) simple_cut_buffer->Erase(0); - - /* set the end for redoing later */ +#endif + // set the end for redoing later endpar = cursor.par->ParFromPos(cursor.pos)->next->Next(); - /* paste it! */ + // paste it! lastbuffer->ParFromPos(lastbuffer->Last())->next = cursor.par->ParFromPos(cursor.pos)->next; cursor.par->ParFromPos(cursor.pos)->next->previous = lastbuffer->ParFromPos(lastbuffer->Last()); @@ -2243,57 +2290,55 @@ void LyXText::PasteSelection() cursor.par->ParFromPos(cursor.pos)->PasteParagraph(); - /* store the new cursor position */ + // store the new cursor position tmpcursor.par = lastbuffer; tmpcursor.pos = lastbuffer->Last(); - /* maybe some pasting */ + // maybe some pasting if (lastbuffer->Next() && paste_the_end) { if (lastbuffer->Next()->HasSameLayout(lastbuffer)) { - - /* be careful witth double spaces */ +#ifndef FIX_DOUBLE_SPACE + // be careful with double spaces if ((!lastbuffer->Last() || lastbuffer->IsLineSeparator(lastbuffer->Last() - 1) || lastbuffer->IsNewline(lastbuffer->Last() - 1)) && lastbuffer->Next()->Last() && lastbuffer->Next()->IsLineSeparator(0)) lastbuffer->Next()->Erase(0); - +#endif lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(); - } - else if (!lastbuffer->Next()->Last()) { + } else if (!lastbuffer->Next()->Last()) { lastbuffer->Next()->MakeSameLayout(lastbuffer); - - /* be careful witth double spaces */ +#ifndef FIX_DOUBLE_SPACE + // be careful witth double spaces if ((!lastbuffer->Last() || lastbuffer->IsLineSeparator(lastbuffer->Last() - 1) || lastbuffer->IsNewline(lastbuffer->Last() - 1)) && lastbuffer->Next()->Last() && lastbuffer->Next()->IsLineSeparator(0)) lastbuffer->Next()->Erase(0); - +#endif lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(); - } - else if (!lastbuffer->Last()) { + } else if (!lastbuffer->Last()) { lastbuffer->MakeSameLayout(lastbuffer->next); - - /* be careful witth double spaces */ +#ifndef FIX_DOUBLE_SPACE + // be careful witth double spaces if ((!lastbuffer->Last() || lastbuffer->IsLineSeparator(lastbuffer->Last() - 1) || lastbuffer->IsNewline(lastbuffer->Last() - 1)) && lastbuffer->Next()->Last() && lastbuffer->Next()->IsLineSeparator(0)) lastbuffer->Next()->Erase(0); - +#endif lastbuffer->ParFromPos(lastbuffer->Last())->PasteParagraph(); } else lastbuffer->Next()->ClearParagraph(); } - /* restore the simple cut buffer */ + // restore the simple cut buffer simple_cut_buffer = simple_cut_clone; } @@ -2309,17 +2354,17 @@ void LyXText::PasteSelection() } -/* returns a pointer to the very first LyXParagraph */ -LyXParagraph * LyXText::FirstParagraph() +// returns a pointer to the very first LyXParagraph +LyXParagraph * LyXText::FirstParagraph() const { return params->paragraph; } -/* returns true if the specified string is at the specified position */ +// returns true if the specified string is at the specified position bool LyXText::IsStringInText(LyXParagraph * par, LyXParagraph::size_type pos, - char const * str) + char const * str) const { if (par) { int i = 0; @@ -2334,7 +2379,7 @@ bool LyXText::IsStringInText(LyXParagraph * par, } -/* sets the selection over the number of characters of string, no check!! */ +// sets the selection over the number of characters of string, no check!! void LyXText::SetSelectionOverString(char const * string) { sel_cursor = cursor; @@ -2344,13 +2389,13 @@ void LyXText::SetSelectionOverString(char const * string) } -/* simple replacing. The font of the first selected character is used */ +// simple replacing. The font of the first selected character is used void LyXText::ReplaceSelectionWithString(char const * str) { SetCursorParUndo(); FreezeUndo(); - if (!selection) { /* create a dummy selection */ + if (!selection) { // create a dummy selection sel_end_cursor = cursor; sel_start_cursor = cursor; } @@ -2373,9 +2418,9 @@ void LyXText::ReplaceSelectionWithString(char const * str) } -/* if the string can be found: return true and set the cursor to - * the new position */ -bool LyXText::SearchForward(char const * str) +// if the string can be found: return true and set the cursor to +// the new position +bool LyXText::SearchForward(char const * str) const { LyXParagraph * par = cursor.par; LyXParagraph::size_type pos = cursor.pos; @@ -2396,29 +2441,28 @@ bool LyXText::SearchForward(char const * str) } -bool LyXText::SearchBackward(char const * string) +bool LyXText::SearchBackward(char const * string) const { LyXParagraph * par = cursor.par; int pos = cursor.pos; do { - if (pos>0) - pos--; + if (pos > 0) + --pos; else { // We skip empty paragraphs (Asger) do { par = par->Previous(); if (par) - pos = par->Last()-1; - } while (par && pos<0); + pos = par->Last() - 1; + } while (par && pos < 0); } } while (par && !IsStringInText(par, pos, string)); if (par) { SetCursor(par, pos); return true; - } - else + } else return false; } @@ -2433,7 +2477,7 @@ void LyXText::InsertStringA(LyXParagraph::TextContainer const & text) } -/* needed to insert the selection */ +// needed to insert the selection void LyXText::InsertStringA(char const * s) { string str(s); @@ -2442,65 +2486,62 @@ void LyXText::InsertStringA(char const * s) LyXParagraph::size_type a = 0; int cell = 0; LyXParagraph * endpar = cursor.par->Next(); - + SetCursorParUndo(); - - char flag = textclasslist.Style(parameters->textclass, - cursor.par->GetLayout()).isEnvironment(); - /* only to be sure, should not be neccessary */ + + char flag = + textclasslist.Style(parameters->textclass, + cursor.par->GetLayout()).isEnvironment(); + // only to be sure, should not be neccessary ClearSelection(); - - /* insert the string, don't insert doublespace */ + + // insert the string, don't insert doublespace string::size_type i = 0; while (i < str.length()) { if (str[i] != '\n') { if (str[i] == ' ' - && i+1GetChar(pos-1)!= ' ') { + && i + 1 < str.length() && str[i + 1] != ' ' + && pos && par->GetChar(pos - 1)!= ' ') { par->InsertChar(pos,' '); - pos++; - } - else if (par->table) { - if (str[i] == '\t') { - while((pos < par->size()) && - (par->GetChar(pos) != LyXParagraph::META_NEWLINE)) - ++pos; - if (pos < par->size()) - ++pos; - else // no more fields to fill skip the rest - break; - } else if ((str[i] != 13) && - ((str[i] & 127) >= ' ')) { - par->InsertChar(pos, str[i]); - pos++; - } - } - else if (str[i] == ' ') { + ++pos; + } else if (par->table) { + if (str[i] == '\t') { + while((pos < par->size()) && + (par->GetChar(pos) != LyXParagraph::META_NEWLINE)) + ++pos; + if (pos < par->size()) + ++pos; + else // no more fields to fill skip the rest + break; + } else if ((str[i] != 13) && + ((str[i] & 127) >= ' ')) { + par->InsertChar(pos, str[i]); + ++pos; + } + } else if (str[i] == ' ') { par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR); - pos++; - } - else if (str[i] == '\t') { - for (a = pos; a < (pos/8 + 1) * 8 ; ++a) { + ++pos; + } else if (str[i] == '\t') { + for (a = pos; a < (pos / 8 + 1) * 8 ; ++a) { par->InsertChar(a, LyXParagraph::META_PROTECTED_SEPARATOR); } pos = a; - } - else if (str[i]!= 13 && - // Ignore unprintables - (str[i] & 127) >= ' ') { + } else if (str[i]!= 13 && + // Ignore unprintables + (str[i] & 127) >= ' ') { par->InsertChar(pos, str[i]); - pos++; + ++pos; } } else { if (par->table) { - if (i+1>=str.length()) { - pos++; + if (i + 1 >= str.length()) { + ++pos; break; } while((pos < par->size()) && (par->GetChar(pos) != LyXParagraph::META_NEWLINE)) - pos++; - pos++; + ++pos; + ++pos; cell = NumberOfCell(par, pos); while((pos < par->size()) && !(par->table->IsFirstCell(cell))) { @@ -2516,17 +2557,16 @@ void LyXText::InsertStringA(char const * s) } else { if (!par->text.size()) { par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR); - pos++; + ++pos; } par->BreakParagraph(pos, flag); par = par->Next(); pos = 0; } } - - i++; + ++i; } - + RedoParagraphs(cursor, endpar); SetCursor(cursor.par, cursor.pos); sel_cursor = cursor; @@ -2557,16 +2597,16 @@ void LyXText::InsertStringB(char const * s) while (i < str.length()) { if (str[i] == '\t' && !par->table) str[i] = ' '; - if (str[i] == ' ' && i+1 < str.length() && str[i + 1] == ' ') + if (str[i] == ' ' && i + 1 < str.length() && str[i + 1] == ' ') str[i] = 13; - if (str[i] == '\n' && i+1 < str.length() && !par->table){ + if (str[i] == '\n' && i + 1 < str.length() && !par->table){ if (str[i + 1] != '\n') { if (str[i - 1] != ' ') str[i] = ' '; else str[i] = 13; } - while (i+1 < str.length() + while (i + 1 < str.length() && (str[i + 1] == ' ' || str[i + 1] == '\t' || str[i + 1] == '\n' @@ -2581,7 +2621,7 @@ void LyXText::InsertStringB(char const * s) } -bool LyXText::GotoNextError() +bool LyXText::GotoNextError() const { LyXCursor res = cursor; do { @@ -2601,19 +2641,17 @@ bool LyXText::GotoNextError() SetCursor(res.par, res.pos); return true; } - return false; } -bool LyXText::GotoNextNote() +bool LyXText::GotoNextNote() const { LyXCursor res = cursor; do { - if (res.pos < res.par->Last()-1) { + if (res.pos < res.par->Last() - 1) { res.pos++; - } - else { + } else { res.par = res.par->Next(); res.pos = 0; } @@ -2626,7 +2664,6 @@ bool LyXText::GotoNextNote() SetCursor(res.par, res.pos); return true; } - return false; } @@ -2687,11 +2724,11 @@ void LyXText::CheckParagraph(LyXParagraph * par, LyXParagraph::size_type z; Row * row = GetRow(par, pos, y); - /* is there a break one row above */ + // is there a break one row above if (row->previous && row->previous->par == row->par) { z = NextBreakPoint(row->previous, paperwidth); if ( z >= row->pos) { - /* set the dimensions of the row above */ + // set the dimensions of the row above y -= row->previous->height; refresh_y = y; refresh_row = row->previous; @@ -2699,7 +2736,8 @@ void LyXText::CheckParagraph(LyXParagraph * par, BreakAgain(row->previous); - /* set the cursor again. Otherwise dungling pointers are possible */ + // set the cursor again. Otherwise + // dangling pointers are possible SetCursor(cursor.par, cursor.pos); sel_cursor = cursor; return; @@ -2717,8 +2755,10 @@ void LyXText::CheckParagraph(LyXParagraph * par, else status = LyXText::NEED_MORE_REFRESH; - /* check the special right address boxes */ - if (textclasslist.Style(parameters->textclass, par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { + // check the special right address boxes + if (textclasslist.Style(parameters->textclass, + par->GetLayout()).margintype + == MARGIN_RIGHT_ADDRESS_BOX) { tmpcursor.par = par; tmpcursor.row = row; tmpcursor.y = y; @@ -2730,10 +2770,10 @@ void LyXText::CheckParagraph(LyXParagraph * par, } - /* set the cursor again. Otherwise dangling pointers are possible */ + // set the cursor again. Otherwise dangling pointers are possible // also set the selection - if (selection){ + if (selection) { tmpcursor = cursor; SetCursorIntern(sel_cursor.par, sel_cursor.pos); sel_cursor = cursor; @@ -2749,21 +2789,21 @@ void LyXText::CheckParagraph(LyXParagraph * par, } -/* returns 0 if inset wasn't found */ +// returns 0 if inset wasn't found int LyXText::UpdateInset(Inset * inset) { - /* first check the current paragraph */ + // first check the current paragraph int pos = cursor.par->GetPositionOfInset(inset); if (pos != -1){ CheckParagraph(cursor.par, pos); return 1; } - /* check every paragraph */ + // check every paragraph LyXParagraph * par = FirstParagraph(); do { - /* make sure the paragraph is open */ + // make sure the paragraph is open if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){ pos = par->GetPositionOfInset(inset); if (pos != -1){ @@ -2779,7 +2819,7 @@ int LyXText::UpdateInset(Inset * inset) void LyXText::SetCursor(LyXParagraph * par, - LyXParagraph::size_type pos) + LyXParagraph::size_type pos) const { LyXCursor old_cursor = cursor; SetCursorIntern(par, pos); @@ -2787,14 +2827,15 @@ void LyXText::SetCursor(LyXParagraph * par, } -void LyXText::SetCursorIntern(LyXParagraph * par, LyXParagraph::size_type pos) +void LyXText::SetCursorIntern(LyXParagraph * par, + LyXParagraph::size_type pos) const { long y; Row * row; int left_margin; LyXParagraph * tmppar; - /* correct the cursor position if impossible */ + // correct the cursor position if impossible if (pos > par->Last()){ tmppar = par->ParFromPos(pos); pos = par->PositionInParFromPos(pos); @@ -2902,7 +2943,7 @@ void LyXText::SetCursorIntern(LyXParagraph * par, LyXParagraph::size_type pos) } -void LyXText::SetCursorFromCoordinates(int x, long y) +void LyXText::SetCursorFromCoordinates(int x, long y) const { LyXCursor old_cursor = cursor; @@ -2935,7 +2976,7 @@ void LyXText::SetCursorFromCoordinates(int x, long y) } -void LyXText::CursorLeft() +void LyXText::CursorLeft() const { CursorLeftIntern(); if (cursor.par->table) { @@ -2948,7 +2989,7 @@ void LyXText::CursorLeft() } -void LyXText::CursorLeftIntern() +void LyXText::CursorLeftIntern() const { if (cursor.pos > 0) { SetCursor(cursor.par, cursor.pos - 1); @@ -2959,7 +3000,7 @@ void LyXText::CursorLeftIntern() } -void LyXText::CursorRight() +void LyXText::CursorRight() const { CursorRightIntern(); if (cursor.par->table) { @@ -2972,7 +3013,7 @@ void LyXText::CursorRight() } -void LyXText::CursorRightIntern() +void LyXText::CursorRightIntern() const { if (cursor.pos < cursor.par->Last()) { SetCursor(cursor.par, cursor.pos + 1); @@ -2983,7 +3024,7 @@ void LyXText::CursorRightIntern() } -void LyXText::CursorUp() +void LyXText::CursorUp() const { SetCursorFromCoordinates(cursor.x_fix, cursor.y - cursor.row->baseline - 1); @@ -2997,7 +3038,7 @@ void LyXText::CursorUp() } -void LyXText::CursorDown() +void LyXText::CursorDown() const { if (cursor.par->table && cursor.par->table->ShouldBeVeryLastRow(NumberOfCell(cursor.par, cursor.pos)) && @@ -3024,7 +3065,7 @@ void LyXText::CursorDown() } -void LyXText::CursorUpParagraph() +void LyXText::CursorUpParagraph() const { if (cursor.pos > 0) { SetCursor(cursor.par, 0); @@ -3035,7 +3076,7 @@ void LyXText::CursorUpParagraph() } -void LyXText::CursorDownParagraph() +void LyXText::CursorDownParagraph() const { if (cursor.par->Next()) { SetCursor(cursor.par->Next(), 0); @@ -3046,147 +3087,192 @@ void LyXText::CursorDownParagraph() -void LyXText::DeleteEmptyParagraphMechanism(LyXCursor old_cursor) +void LyXText::DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const { - bool deleted = false; + bool deleted = false; - /* this is the delete-empty-paragraph-mechanism. */ - if (selection) - return; - - // Paragraph should not be deleted if empty - if ((textclasslist.Style(parameters->textclass, - old_cursor.par->GetLayout())).keepempty) - return; - - LyXCursor tmpcursor; - - if (old_cursor.par != cursor.par) { - if ( (old_cursor.par->Last() == 0 - || (old_cursor.par->Last() == 1 - && (old_cursor.par->IsLineSeparator(0)))) - && old_cursor.par->FirstPhysicalPar() - == old_cursor.par->LastPhysicalPar()) { + // this is the delete-empty-paragraph-mechanism. + if (selection) return; + +#ifdef FIX_DOUBLE_SPACE + /* Ok I'll put some comments here about what is missing. + I have fixed BackSpace (and thus Delete) to not delete + double-spaces automagically. I have also changed Cut, + Copy and Paste to hopefully do some sensible things. + There are still some small problems that can lead to + double spaces stored in the document file or space at + the beginning of paragraphs. This happens if you have + the cursor betwenn to spaces and then save. Or if you + cut and paste and the selection have a space at the + beginning and then save right after the paste. I am + sure none of these are very hard to fix, but I will + put out 1.1.4pre2 with FIX_DOUBLE_SPACE defined so + that I can get some feedback. (Lgb) + */ + + // If old_cursor.pos == 0 and old_cursor.pos(1) == LineSeparator + // delete the LineSeparator. + // MISSING + + // If old_cursor.pos == 1 and old_cursor.pos(0) == LineSeparator + // delete the LineSeparator. + // MISSING + + // If the pos around the old_cursor were spaces, delete one of them. + if (!(old_cursor.par == cursor.par && old_cursor.pos == cursor.pos) + && old_cursor.pos > 0 + && old_cursor.pos < old_cursor.par->Last() + && old_cursor.par->IsLineSeparator(old_cursor.pos) + && old_cursor.par->IsLineSeparator(old_cursor.pos - 1)) { + old_cursor.par->Erase(old_cursor.pos - 1); + RedoParagraphs(old_cursor, old_cursor.par->Next()); + // or RedoDrawingOfParagraph(old_cursor); + // correct cursor + if (old_cursor.par == cursor.par && + cursor.pos > old_cursor.pos) + SetCursor(cursor.par, cursor.pos - 1); + else + SetCursor(cursor.par, cursor.pos); + return; + } +#endif + // + // Paragraph should not be deleted if empty + if ((textclasslist.Style(parameters->textclass, + old_cursor.par->GetLayout())).keepempty) + return; + + LyXCursor tmpcursor; + + if (old_cursor.par != cursor.par) { + if ( (old_cursor.par->Last() == 0 + || (old_cursor.par->Last() == 1 + && (old_cursor.par->IsLineSeparator(0)))) + && old_cursor.par->FirstPhysicalPar() + == old_cursor.par->LastPhysicalPar()) { - /* ok, we will delete anything */ + // ok, we will delete anything - // make sure that you do not delete any environments - if ((old_cursor.par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE && - !(old_cursor.row->previous - && old_cursor.row->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) - && !(old_cursor.row->next - && old_cursor.row->next->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) - || - (old_cursor.par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE && - ((old_cursor.row->previous - && old_cursor.row->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) - || - (old_cursor.row->next - && old_cursor.row->next->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) - )){ - status = LyXText::NEED_MORE_REFRESH; - deleted = true; + // make sure that you do not delete any environments + if ((old_cursor.par->footnoteflag != LyXParagraph::OPEN_FOOTNOTE && + !(old_cursor.row->previous + && old_cursor.row->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) + && !(old_cursor.row->next + && old_cursor.row->next->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) + || + (old_cursor.par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE && + ((old_cursor.row->previous + && old_cursor.row->previous->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) + || + (old_cursor.row->next + && old_cursor.row->next->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE)) + )) { + status = LyXText::NEED_MORE_REFRESH; + deleted = true; - if (old_cursor.row->previous) { - refresh_row = old_cursor.row->previous; - refresh_y = old_cursor.y - old_cursor.row->baseline - refresh_row->height; - tmpcursor = cursor; - cursor = old_cursor; // that undo can restore the right cursor position - LyXParagraph *endpar = old_cursor.par->next; - if (endpar && endpar->GetDepth()) { - while (endpar && endpar->GetDepth()) { - endpar = endpar->LastPhysicalPar()->Next(); - } - } - SetUndo(Undo::DELETE, - old_cursor.par->previous, - endpar); - cursor = tmpcursor; - - /* delete old row */ - RemoveRow(old_cursor.row); - if (params->paragraph == old_cursor.par) { - params->paragraph = params->paragraph->next; - } - /* delete old par */ - delete old_cursor.par; + if (old_cursor.row->previous) { + refresh_row = old_cursor.row->previous; + refresh_y = old_cursor.y - old_cursor.row->baseline - refresh_row->height; + tmpcursor = cursor; + cursor = old_cursor; // that undo can restore the right cursor position + LyXParagraph * endpar = old_cursor.par->next; + if (endpar && endpar->GetDepth()) { + while (endpar && endpar->GetDepth()) { + endpar = endpar->LastPhysicalPar()->Next(); + } + } + SetUndo(Undo::DELETE, + old_cursor.par->previous, + endpar); + cursor = tmpcursor; + + // delete old row + RemoveRow(old_cursor.row); + if (params->paragraph == old_cursor.par) { + params->paragraph = params->paragraph->next; + } + // delete old par + delete old_cursor.par; - /* Breakagain the next par. Needed - * because of the parindent that - * can occur or dissappear. The - * next row can change its height, - * if there is another layout before */ - if (refresh_row->next) { - BreakAgain(refresh_row->next); - UpdateCounters(refresh_row); - } - SetHeightOfRow(refresh_row); - } - else { - refresh_row = old_cursor.row->next; - refresh_y = old_cursor.y - old_cursor.row->baseline; + /* Breakagain the next par. Needed + * because of the parindent that + * can occur or dissappear. The + * next row can change its height, + * if there is another layout before */ + if (refresh_row->next) { + BreakAgain(refresh_row->next); + UpdateCounters(refresh_row); + } + SetHeightOfRow(refresh_row); + } else { + refresh_row = old_cursor.row->next; + refresh_y = old_cursor.y - old_cursor.row->baseline; - tmpcursor = cursor; - cursor = old_cursor; // that undo can restore the right cursor position - LyXParagraph *endpar = old_cursor.par->next; - if (endpar && endpar->GetDepth()) { - while (endpar && endpar->GetDepth()) { - endpar = endpar->LastPhysicalPar()->Next(); - } - } - SetUndo(Undo::DELETE, - old_cursor.par->previous, - endpar); - cursor = tmpcursor; - - /* delete old row */ - RemoveRow(old_cursor.row); - /* delete old par */ - if (params->paragraph == old_cursor.par) { - params->paragraph = params->paragraph->next; - } - delete old_cursor.par; + tmpcursor = cursor; + cursor = old_cursor; // that undo can restore the right cursor position + LyXParagraph *endpar = old_cursor.par->next; + if (endpar && endpar->GetDepth()) { + while (endpar && endpar->GetDepth()) { + endpar = endpar->LastPhysicalPar()->Next(); + } + } + SetUndo(Undo::DELETE, + old_cursor.par->previous, + endpar); + cursor = tmpcursor; + + // delete old row + RemoveRow(old_cursor.row); + // delete old par + if (params->paragraph == old_cursor.par) { + params->paragraph = params->paragraph->next; + } + delete old_cursor.par; - /* Breakagain the next par. Needed because of - * the parindent that can occur or dissappear. - * The next row can change its height, if there - * is another layout before */ - if (refresh_row) { - BreakAgain(refresh_row); - UpdateCounters(refresh_row->previous); - } - } + /* Breakagain the next par. Needed + because of the parindent that can + occur or dissappear. + The next row can change its height, + if there is another layout before + */ + if (refresh_row) { + BreakAgain(refresh_row); + UpdateCounters(refresh_row->previous); + } + } + + // correct cursor y + SetCursor(cursor.par, cursor.pos); - /* correct cursor y */ - SetCursor(cursor.par, cursor.pos); - /* if (cursor.y > old_cursor.y) cursor.y -= old_cursor.row->height; */ - if (sel_cursor.par == old_cursor.par - && sel_cursor.pos == sel_cursor.pos) { - /* correct selection*/ - sel_cursor = cursor; - } - } - - } - if (!deleted){ - if (old_cursor.par->ClearParagraph()){ - RedoParagraphs(old_cursor, old_cursor.par->Next()); - /* correct cursor y */ - SetCursor(cursor.par, cursor.pos); - sel_cursor = cursor; - } - } - } else if (cursor.par->table && (cursor.row != old_cursor.row)) { - int cell = NumberOfCell(old_cursor.par, old_cursor.pos); - if (old_cursor.par->table->IsContRow(cell) && - IsEmptyTableRow(&old_cursor)) { - RemoveTableRow(&old_cursor); - RedoParagraph(); - } - } + if (sel_cursor.par == old_cursor.par + && sel_cursor.pos == sel_cursor.pos) { + // correct selection + sel_cursor = cursor; + } + } + } + if (!deleted) { + if (old_cursor.par->ClearParagraph()){ + RedoParagraphs(old_cursor, old_cursor.par->Next()); + // correct cursor y + SetCursor(cursor.par, cursor.pos); + sel_cursor = cursor; + } + } + } +#if 0 + else if (cursor.par->table && (cursor.row != old_cursor.row)) { + int cell = NumberOfCell(old_cursor.par, old_cursor.pos); + if (old_cursor.par->table->IsContRow(cell) && + IsEmptyTableRow(old_cursor)) { + RemoveTableRow(const_cast(&old_cursor)); + RedoParagraph(); + } + } +#endif } @@ -3200,39 +3286,47 @@ LyXParagraph * LyXText::GetParFromID(int id) // undo functions -bool LyXText::TextUndo() -{ // returns false if no undo possible +bool LyXText::TextUndo() +{ + // returns false if no undo possible Undo * undo = params->undostack.pop(); - if (undo){ + if (undo) { FinishUndo(); if (!undo_frozen) - params->redostack.push(CreateUndo(undo->kind, - GetParFromID(undo->number_of_before_par), - GetParFromID(undo->number_of_behind_par))); + params->redostack + .push(CreateUndo(undo->kind, + GetParFromID(undo->number_of_before_par), + GetParFromID(undo->number_of_behind_par))); } return TextHandleUndo(undo); } bool LyXText::TextRedo() -{ // returns false if no redo possible +{ + // returns false if no redo possible Undo * undo = params->redostack.pop(); - if (undo){ + if (undo) { FinishUndo(); if (!undo_frozen) - params->undostack.push(CreateUndo(undo->kind, - GetParFromID(undo->number_of_before_par), - GetParFromID(undo->number_of_behind_par))); + params->undostack + .push(CreateUndo(undo->kind, + GetParFromID(undo->number_of_before_par), + GetParFromID(undo->number_of_behind_par))); } return TextHandleUndo(undo); } -bool LyXText::TextHandleUndo(Undo * undo){ // returns false if no undo possible +bool LyXText::TextHandleUndo(Undo * undo) +{ + // returns false if no undo possible bool result = false; - if (undo){ - LyXParagraph * before = GetParFromID(undo->number_of_before_par); - LyXParagraph * behind = GetParFromID(undo->number_of_behind_par); + if (undo) { + LyXParagraph * before = + GetParFromID(undo->number_of_before_par); + LyXParagraph * behind = + GetParFromID(undo->number_of_behind_par); LyXParagraph * tmppar; LyXParagraph * tmppar2; LyXParagraph * tmppar3; @@ -3240,7 +3334,8 @@ bool LyXText::TextHandleUndo(Undo * undo){ // returns false if no undo possible LyXParagraph * endpar; LyXParagraph * tmppar5; - // if there's no before take the beginning of the document for redoing + // if there's no before take the beginning + // of the document for redoing if (!before) SetCursorIntern(FirstParagraph(), 0); @@ -3350,25 +3445,28 @@ bool LyXText::TextHandleUndo(Undo * undo){ // returns false if no undo possible void LyXText::FinishUndo() -{ // makes sure the next operation will be stored +{ + // makes sure the next operation will be stored undo_finished = True; } void LyXText::FreezeUndo() -{ // this is dangerous and for internal use only +{ + // this is dangerous and for internal use only undo_frozen = True; } void LyXText::UnFreezeUndo() -{ // this is dangerous and for internal use only +{ + // this is dangerous and for internal use only undo_frozen = false; } -void LyXText::SetUndo(Undo::undo_kind kind, LyXParagraph * before, - LyXParagraph * behind) +void LyXText::SetUndo(Undo::undo_kind kind, LyXParagraph const * before, + LyXParagraph const * behind) const { if (!undo_frozen) params->undostack.push(CreateUndo(kind, before, behind)); @@ -3376,15 +3474,15 @@ void LyXText::SetUndo(Undo::undo_kind kind, LyXParagraph * before, } -void LyXText::SetRedo(Undo::undo_kind kind, LyXParagraph * before, - LyXParagraph * behind) +void LyXText::SetRedo(Undo::undo_kind kind, LyXParagraph const * before, + LyXParagraph const * behind) { params->redostack.push(CreateUndo(kind, before, behind)); } -Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph * before, - LyXParagraph * behind) +Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph const * before, + LyXParagraph const * behind) const { int before_number = -1; int behind_number = -1; @@ -3430,16 +3528,17 @@ Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph * before, end = end->next; } - if (start && end && start != end->next && (before != behind || (!before && !behind))) { + if (start && end + && start != end->next + && (before != behind || (!before && !behind))) { tmppar = start; tmppar2 = tmppar->Clone(); tmppar2->id(tmppar->id()); - // a memory optimization: Just store the layout information when only edit + // a memory optimization: Just store the layout information + // when only edit if (kind == Undo::EDIT){ tmppar2->text.clear(); - //tmppar2->text.erase(tmppar2->text.begin(), - // tmppar2->text.end()); } undopar = tmppar2; @@ -3448,26 +3547,25 @@ Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph * before, tmppar = tmppar->next; tmppar2->next = tmppar->Clone(); tmppar2->next->id(tmppar->id()); - // a memory optimization: Just store the layout information when only edit + // a memory optimization: Just store the layout + // information when only edit if (kind == Undo::EDIT){ tmppar2->next->text.clear(); - //tmppar2->next->text.erase(tmppar2->next->text.begin(), tmppar2->next->text.end()); } tmppar2->next->previous = tmppar2; tmppar2 = tmppar2->next; } tmppar2->next = 0; - } - else + } else undopar = 0; // nothing to replace (undo of delete maybe) int cursor_par = cursor.par->ParFromPos(cursor.pos)->id(); int cursor_pos = cursor.par->PositionInParFromPos(cursor.pos); Undo * undo = new Undo(kind, - before_number, behind_number, - cursor_par, cursor_pos, - undopar); + before_number, behind_number, + cursor_par, cursor_pos, + undopar); undo_finished = false; return undo; @@ -3481,86 +3579,89 @@ void LyXText::SetCursorParUndo() cursor.par->ParFromPos(cursor.pos)->next); } -void LyXText::RemoveTableRow(LyXCursor * cur) + +void LyXText::RemoveTableRow(LyXCursor * cur) const { int cell = -1; int cell_org = 0; int ocell = 0; - /* move to the previous row */ - int cell_act = NumberOfCell(cur->par, cur->pos); - if (cell < 0) - cell = cell_act; - while (cur->pos && !cur->par->IsNewline(cur->pos - 1)) - cur->pos--; - while (cur->pos && - !cur->par->table->IsFirstCell(cell_act)) { - cur->pos--; - while (cur->pos && !cur->par->IsNewline(cur->pos - 1)) - cur->pos--; - --cell; - --cell_act; - } - /* now we have to pay attention if the actual table is the - main row of TableContRows and if yes to delete all of them */ - if (!cell_org) - cell_org = cell; - do { - ocell = cell; - /* delete up to the next row */ - while (cur->pos < cur->par->Last() && - (cell_act == ocell - || !cur->par->table->IsFirstCell(cell_act))) { - while (cur->pos < cur->par->Last() && - !cur->par->IsNewline(cur->pos)) - cur->par->Erase(cur->pos); - ++cell; - ++cell_act; - if (cur->pos < cur->par->Last()) - cur->par->Erase(cur->pos); - } - if (cur->pos && cur->pos == cur->par->Last()) { - cur->pos--; - cur->par->Erase(cur->pos); // no newline at the very end! - } - } while (((cell + 1) < cur->par->table->GetNumberOfCells()) && - !cur->par->table->IsContRow(cell_org) && - cur->par->table->IsContRow(cell)); - cur->par->table->DeleteRow(cell_org); - return; -} - - -bool LyXText::IsEmptyTableRow(LyXCursor * old_cursor) const -{ - if (!old_cursor->par->table) + // move to the previous row + int cell_act = NumberOfCell(cur->par, cur->pos); + if (cell < 0) + cell = cell_act; + while (cur->pos && !cur->par->IsNewline(cur->pos - 1)) + cur->pos--; + while (cur->pos && + !cur->par->table->IsFirstCell(cell_act)) { + cur->pos--; + while (cur->pos && !cur->par->IsNewline(cur->pos - 1)) + cur->pos--; + --cell; + --cell_act; + } + // now we have to pay attention if the actual table is the + // main row of TableContRows and if yes to delete all of them + if (!cell_org) + cell_org = cell; + do { + ocell = cell; + // delete up to the next row + while (cur->pos < cur->par->Last() && + (cell_act == ocell + || !cur->par->table->IsFirstCell(cell_act))) { + while (cur->pos < cur->par->Last() && + !cur->par->IsNewline(cur->pos)) + cur->par->Erase(cur->pos); + ++cell; + ++cell_act; + if (cur->pos < cur->par->Last()) + cur->par->Erase(cur->pos); + } + if (cur->pos && cur->pos == cur->par->Last()) { + cur->pos--; + cur->par->Erase(cur->pos); // no newline at very end! + } + } while (((cell + 1) < cur->par->table->GetNumberOfCells()) && + !cur->par->table->IsContRow(cell_org) && + cur->par->table->IsContRow(cell)); + cur->par->table->DeleteRow(cell_org); + return; +} + + +#if 0 +bool LyXText::IsEmptyTableRow(LyXCursor const & old_cursor) const +{ + if (!old_cursor.par->table) return false; #ifdef I_DONT_KNOW_IF_I_SHOULD_DO_THIS - int pos = old_cursor->pos; - int cell = NumberOfCell(old_cursor->par, pos); - + int pos = old_cursor.pos; + int cell = NumberOfCell(old_cursor.par, pos); + // search first charater of this table row - while (pos && !old_cursor->par->table->IsFirstCell(cell)) { - pos--; - while (pos && !old_cursor->par->IsNewline(pos-1)) - pos--; - cell--; + while (pos && !old_cursor.par->table->IsFirstCell(cell)) { + --pos; + while (pos && !old_cursor.par->IsNewline(pos-1)) + --pos; + --cell; } - if (!old_cursor->par->IsNewline(pos)) + if (!old_cursor.par->IsNewline(pos)) return false; - cell++; - pos++; - while ((pos < old_cursor->par->Last()) && - !old_cursor->par->table->IsFirstCell(cell)) { - if (!old_cursor->par->IsNewline(pos)) + ++cell; + ++pos; + while ((pos < old_cursor.par->Last()) && + !old_cursor.par->table->IsFirstCell(cell)) { + if (!old_cursor.par->IsNewline(pos)) return false; - pos++; - cell++; + ++pos; + ++cell; } return true; #endif return false; } +#endif bool LyXText::IsEmptyTableCell() const @@ -3574,20 +3675,20 @@ bool LyXText::IsEmptyTableCell() const void LyXText::toggleAppendix(){ - LyXParagraph * par = cursor.par->FirstPhysicalPar(); - bool start = !par->start_of_appendix; - - /* ensure that we have only one start_of_appendix in this document */ - LyXParagraph * tmp = FirstParagraph(); - for (;tmp;tmp = tmp->next) - tmp->start_of_appendix = 0; - par->start_of_appendix = start; - - /* we can set the refreshing parameters now */ - status = LyXText::NEED_MORE_REFRESH; - refresh_y = 0; - refresh_row = 0; // not needed for full update - UpdateCounters(0); - SetCursor(cursor.par, cursor.pos); + LyXParagraph * par = cursor.par->FirstPhysicalPar(); + bool start = !par->start_of_appendix; + + // ensure that we have only one start_of_appendix in this document + LyXParagraph * tmp = FirstParagraph(); + for (; tmp; tmp = tmp->next) + tmp->start_of_appendix = 0; + par->start_of_appendix = start; + + // we can set the refreshing parameters now + status = LyXText::NEED_MORE_REFRESH; + refresh_y = 0; + refresh_row = 0; // not needed for full update + UpdateCounters(0); + SetCursor(cursor.par, cursor.pos); } -- 2.39.2