where a "struct utimbuf" is allocated with "new" and deleted with
"delete[]".
+2000-01-13 Lars Gullik Bjønnes <larsbj@lyx.org>
+
+ * 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 <larsbj@lyx.org>
+
+ * 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 <Jean-Marc.Lasgouttes@inria.fr>
* config/lyxinclude.m4 (LYX_FUNC_PUTENV_ARGTYPE): fix the macro,
(May 19 1996, 12:04, RvdK)
*/
-
// These are globals.
LyXAction lyxaction;
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());
#include "lyx_gui_misc.h" // CancelCloseBoxCB + WriteAlert
extern int mono_video;
+
extern BufferView * current_view;
FD_form_bullet * fd_form_bullet;
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."),
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());
val.foreground= WhitePixel(fl_display,
DefaultScreen(fl_display));
}
-
val.function= GXcopy;
val.graphics_exposures = false;
if (!fast_selection && selection_color[0] != 0) {
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;
}
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;
}
if (status) return true;
- status = is.eof() ? LEX_FEOF: LEX_UNDEF;
+ status = is.eof() ? LEX_FEOF : LEX_UNDEF;
buff[0] = '\0';
return false;
}
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();
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;
///
/// 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 *);
///
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 <enter> at cursor position
void BreakParagraph(char keep_layout = 0);
/** 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
///
Row * need_break_row;
///
- long refresh_y;
+ mutable long refresh_y;
///
int refresh_height;
///
///
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
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;
///
/// need the selection cursor:
void SetSelection();
///
- void ClearSelection();
+ void ClearSelection() const;
/// just selects the word the cursor is in
void SelectWord();
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();
///
*/
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);
*/
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!!
*/
/** 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
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);
///
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
/// 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
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
///
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;
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();
};
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
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<int>(pos)
- << ")\n";
+ << ")" << endl;
}
} else if (pos) {
return GetFontSettings(pos - 1);
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();
"position does not exist."
<< pos << " (" << static_cast<int>(pos)
<< ")\n";
+ Assert(false);
}
return '\0';
} else {
return NextAfterFootnote()
->GetChar(pos - text.size() - 1);
else {
- lyxerr << "ERROR (LyXParagraph::GetChar): "
+ lyxerr << "ERROR (LyXParagraph::GetChar const): "
"position does not exist."
<< pos << " (" << static_cast<int>(pos)
<< ")\n";
+ Assert(false);
}
return '\0';
} else {
{
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;
// 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
while (IsLetter(lastpos)) theword += GetChar(lastpos++);
- return theword;
+ return theword;
}
lyxerr << "ERROR (LyXParagraph::ParFromPos): "
"position does not exist." << endl;
return this;
- }
- else
+ } else
return this;
}
// > 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 {
paragraph */
else
return next; // This should never happen!
- }
- else
+ } else
return next;
}
in a logical paragraph */
else
return next; // This should never happen!
- }
- else
+ } else
return next;
}
in a logical paragraph */
else
return next; // This should never happen!
- }
- else
+ } else
return next;
}
in a logical paragraph */
else
return previous; // This should never happen!
- }
- else
+ } else
return previous;
}
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;
}
|| 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;
}
else
return previous;
- }
- else
+ } else
return previous;
}
else
return previous;
- }
- else
+ } else
return previous;
}
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) {
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);
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());
{
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())
extern int mono_video;
extern int fast_selection;
-
// Constructor
LyXScreen::LyXScreen(Window window,
Dimension width,
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),
{
if (!cursor_visible) return;
- if (fast_selection || mono_video){
+ if (fast_selection || mono_video) {
cursor_visible = false;
ShowCursor();
cursor_visible = false;
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) {
#ifdef HAVE_PARTIAL_SPECIALIZATION
// Not too sure if this is the correct way to specialize
template<class A> inline void Assert(A * ptr)
+{
+ Assert<void const *>(ptr);
+}
+template<> inline void Assert(void const * ptr)
{
if (!ptr) {
abort();
int j = i;
while (j < baselen) {
if (basepath[j] == '/') {
- if (j+1 == baselen) break;
+ if (j + 1 == baselen) break;
buf += "../";
}
++j;
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
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);
int LyXText::SingleWidth(LyXParagraph * par,
- LyXParagraph::size_type pos, char c)
+ LyXParagraph::size_type pos, char c) const
{
LyXFont font = GetFont(par, pos);
// 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);
Inset * tmpinset = row->par->GetInset(pos);
if (tmpinset)
tmpinset->Draw(font, scr, offset + row->baseline, x);
- pos++;
+ ++pos;
return;
}
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,
}
-/* 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;
}
-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)) {
}
-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);
/* 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*/
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;
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))
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;
}
-/* 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;
/* 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;
}
-void LyXText::BreakAgain(Row * row)
+void LyXText::BreakAgain(Row * row) const
{
bool not_ready = true;
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;
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)
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){
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) &&
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) {
}
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);
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);
/* 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;
/* 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
}
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*/
}
/* 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
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
* 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
charInserted();
return;
}
- /* no newline at first position
+ /* No newline at first position
* of a paragraph or behind labels.
* TeX does not allow that. */
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;
}
}
- /* 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)
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);
}
-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;
* 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;
}
-void LyXText::CursorTab()
+void LyXText::CursorTab() const
{
if (cursor.par->table) {
int cell = NumberOfCell(cursor.par, cursor.pos);
/* -------> 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;
}
-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();
+ }
}
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;
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)))
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) {
}
}
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;
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,
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();
* 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;
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;
} 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))) {
|| !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) {
}
}
- /* 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) {
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;
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);
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);
}
}
- /* 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
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);
}
}
- /* 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);
}
}
}
}
// check for FAST SELECTION
- if (fast_selection || mono_video){
+ if (fast_selection || mono_video) {
if (selection) {
/* selection code */
}
-int LyXText::DefaultHeight()
+int LyXText::DefaultHeight() const
{
LyXFont font(LyXFont::ALL_SANE);
return int(font.maxAscent() + font.maxDescent() * 1.5);
/* 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;
PrepareToPrint(row, tmpx, fill_separator,
fill_hfill, fill_label_hfill);
int main_body = BeginningOfMainBody(row->par);
-
+
int c = row->pos;
int last = RowLast(row);
x_old = tmpx;
cell++;
tmpx += row->par->table->GetBeginningOfTextInCell(cell);
- c++;
+ ++c;
} else
ready = true;
} else {
tmpx += SingleWidth(row->par, c);
- c++;
+ ++c;
}
}
} else
}
-/* 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;
}
#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;
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;
}
-// Destructor
LyXText::~LyXText()
{
// Delete all rows, this does not touch the paragraphs!
// 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());
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))
/* 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) {
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
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);
}
-/* 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);
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();
}
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();
}
}
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;
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);
SetCursor(cursor.par, cursor.pos);
sel_cursor = cursor;
- /* just necessary */
+ // just necessary
if (cursor.row->next)
SetHeightOfRow(cursor.row->next);
}
{
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) {
}
-/* 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;
}
}
}
else if (endpar) {
- endpar = endpar->Next(); /* because of parindents etc. */
+ endpar = endpar->Next(); // because of parindents etc.
}
SetUndo(Undo::EDIT,
* 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 ==
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);
}
-/* 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;
}
}
}
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;
&& 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()
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) {
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);
}
-/* 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;
}
}
}
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) {
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);
}
-/* 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;
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,
{
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);
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);
}
-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;
}
-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;
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;
/* 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;
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
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);
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);
* 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) {
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;
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)) {
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);
}
-void LyXText::CursorTop()
+void LyXText::CursorTop() const
{
while (cursor.par->Previous())
cursor.par = cursor.par->Previous();
}
-void LyXText::CursorBottom()
+void LyXText::CursorBottom() const
{
while (cursor.par->Next())
cursor.par = cursor.par->Next();
/* 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;
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;
}
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();
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
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)
}
}
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;
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,
}
}
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;
}
-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 */
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);
}
}
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;
/* 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);
}
/* 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
par->labelstring = layout.labelstring();
else
par->labelstring.clear();
- }
- else {
+ } else {
if (!layout.labelstring_appendix().empty())
par->labelstring = layout.labelstring_appendix();
else
sprintf(s, "%d.", par->getCounter(i));
break;
}
- }
- else {
+ } else {
switch (2 * LABEL_FIRST_COUNTER - textclass.maxcounter() + i) {
case LABEL_COUNTER_CHAPTER:
sprintf(s, "%s",
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) {
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)
/* 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);
}
}
/* 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) {
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;
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()
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();
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){
}
}
- /* 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())
!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();
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 */
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;
}
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) {
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;
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"),
return;
}
}
- /* table stuff -- end*/
+ /* table stuff -- end */
SetUndo(Undo::INSERT,
cursor.par->ParFromPos(cursor.pos)->previous,
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()
}
}
} 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;
}
}
- /* 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());
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;
}
}
-/* 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;
}
-/* 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;
}
-/* 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;
}
}
-/* 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;
}
-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;
}
}
-/* needed to insert the selection */
+// needed to insert the selection
void LyXText::InsertStringA(char const * s)
{
string str(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+1<str.length() && str[i+1]!= ' '
- && pos && par->GetChar(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))) {
} 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;
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'
}
-bool LyXText::GotoNextError()
+bool LyXText::GotoNextError() const
{
LyXCursor res = cursor;
do {
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;
}
SetCursor(res.par, res.pos);
return true;
}
-
return false;
}
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;
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;
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;
}
- /* 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;
}
-/* 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){
void LyXText::SetCursor(LyXParagraph * par,
- LyXParagraph::size_type pos)
+ LyXParagraph::size_type pos) const
{
LyXCursor old_cursor = cursor;
SetCursorIntern(par, pos);
}
-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);
}
-void LyXText::SetCursorFromCoordinates(int x, long y)
+void LyXText::SetCursorFromCoordinates(int x, long y) const
{
LyXCursor old_cursor = cursor;
}
-void LyXText::CursorLeft()
+void LyXText::CursorLeft() const
{
CursorLeftIntern();
if (cursor.par->table) {
}
-void LyXText::CursorLeftIntern()
+void LyXText::CursorLeftIntern() const
{
if (cursor.pos > 0) {
SetCursor(cursor.par, cursor.pos - 1);
}
-void LyXText::CursorRight()
+void LyXText::CursorRight() const
{
CursorRightIntern();
if (cursor.par->table) {
}
-void LyXText::CursorRightIntern()
+void LyXText::CursorRightIntern() const
{
if (cursor.pos < cursor.par->Last()) {
SetCursor(cursor.par, cursor.pos + 1);
}
-void LyXText::CursorUp()
+void LyXText::CursorUp() const
{
SetCursorFromCoordinates(cursor.x_fix,
cursor.y - cursor.row->baseline - 1);
}
-void LyXText::CursorDown()
+void LyXText::CursorDown() const
{
if (cursor.par->table &&
cursor.par->table->ShouldBeVeryLastRow(NumberOfCell(cursor.par, cursor.pos)) &&
}
-void LyXText::CursorUpParagraph()
+void LyXText::CursorUpParagraph() const
{
if (cursor.pos > 0) {
SetCursor(cursor.par, 0);
}
-void LyXText::CursorDownParagraph()
+void LyXText::CursorDownParagraph() const
{
if (cursor.par->Next()) {
SetCursor(cursor.par->Next(), 0);
-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<LyXCursor*>(&old_cursor));
+ RedoParagraph();
+ }
+ }
+#endif
}
// 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;
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);
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));
}
-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;
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;
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;
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
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);
}