#include "BufferView.h"
#include "language.h"
#include "ParagraphParameters.h"
+#include "undo_funcs.h"
using std::max;
using std::min;
tmpinset->draw(bview, font, offset+row->baseline(), x,
cleared);
#ifdef SEEMS_TO_BE_NOT_NEEDED
- if (status == CHANGED_IN_DRAW) {
+ if (status_ == CHANGED_IN_DRAW) {
UpdateInset(bview, tmpinset);
- status = CHANGED_IN_DRAW;
+ status(bview, CHANGED_IN_DRAW);
}
#endif
}
last_separator = i - 1;
x = width; // this means break
} else {
-#if 0
- last_separator = i;
- x += width;
-#else
x += singleWidth(bview, par, i, c);
-#endif
}
} else {
if (IsLineSeparatorChar(c))
not_ready = false;
// Set the dimensions of the row
+#ifdef WITH_WARNINGS
+#warning Something is rotten here! (Jug)
+#endif
tmprow->fill(fill(bview, tmprow, workWidth(bview)));
setHeightOfRow(bview, tmprow);
&& layout.labeltype!= LABEL_SENSITIVE)
return;
- setUndo(bview->buffer(), Undo::INSERT,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::INSERT,cursor.par(),cursor.par()->next());
// Always break behind a space
//
cursorLeft(bview);
}
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_row = cursor.row();
refresh_y = cursor.y() - cursor.row()->baseline();
* same Paragraph one to the right and make a rebreak */
void LyXText::insertChar(BufferView * bview, char c)
{
- setUndo(bview->buffer(), Undo::INSERT,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::INSERT,
+ cursor.par(), cursor.par()->next());
// When the free-spacing option is set for the current layout,
// disable the double-space checking
y -= row->previous()->height();
refresh_y = y;
refresh_row = row->previous();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgainOneRow(bview, row);
refresh_row = row;
refresh_x = cursor.x();
refresh_pos = cursor.pos();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgainOneRow(bview, row);
// will the cursor be in another row now?
if (rowLast(row) <= cursor.pos() + 1 && row->next()) {
int const tmpheight = row->height();
setHeightOfRow(bview, row);
if (tmpheight == row->height())
- status = LyXText::NEED_VERY_LITTLE_REFRESH;
+ status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
else
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
current_font = rawtmpfont;
real_current_font = realtmpfont;
if (row->par()->getChar(row->pos()) == Paragraph::META_INSET
&& (inset=row->par()->getInset(row->pos()))
&& (inset->display())) // || (inset->scroll() < 0)))
- align = (inset->LyxCode() == Inset::MATHMACRO_CODE)
+ align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
switch (align) {
void LyXText::cursorLeftOneWord(BufferView * bview) const
{
- // treat HFills, floats and Insets as words
LyXCursor tmpcursor = cursor;
- while (tmpcursor.pos()
- && (tmpcursor.par()->isSeparator(tmpcursor.pos() - 1)
- || tmpcursor.par()->isKomma(tmpcursor.pos() - 1))
- && !(tmpcursor.par()->isHfill(tmpcursor.pos() - 1)
- || tmpcursor.par()->isInset(tmpcursor.pos() - 1)))
- tmpcursor.pos(tmpcursor.pos() - 1);
-
- if (tmpcursor.pos()
- && (tmpcursor.par()->isInset(tmpcursor.pos() - 1)
- || tmpcursor.par()->isHfill(tmpcursor.pos() - 1))) {
- tmpcursor.pos(tmpcursor.pos() - 1);
- } else if (!tmpcursor.pos()) {
- if (tmpcursor.par()->previous()){
- tmpcursor.par(tmpcursor.par()->previous());
- tmpcursor.pos(tmpcursor.par()->size());
- }
- } else { // Here, tmpcursor != 0
- while (tmpcursor.pos() > 0 &&
- tmpcursor.par()->isWord(tmpcursor.pos()-1) )
- tmpcursor.pos(tmpcursor.pos() - 1);
- }
+ cursorLeftOneWord(tmpcursor);
setCursor(bview, tmpcursor.par(), tmpcursor.pos());
}
+void LyXText::cursorLeftOneWord(LyXCursor & cur) const
+{
+ // treat HFills, floats and Insets as words
+ cur = cursor;
+ while (cur.pos()
+ && (cur.par()->isSeparator(cur.pos() - 1)
+ || cur.par()->isKomma(cur.pos() - 1))
+ && !(cur.par()->isHfill(cur.pos() - 1)
+ || cur.par()->isInset(cur.pos() - 1)))
+ cur.pos(cur.pos() - 1);
+
+ if (cur.pos()
+ && (cur.par()->isInset(cur.pos() - 1)
+ || cur.par()->isHfill(cur.pos() - 1))) {
+ cur.pos(cur.pos() - 1);
+ } else if (!cur.pos()) {
+ if (cur.par()->previous()){
+ cur.par(cur.par()->previous());
+ cur.pos(cur.par()->size());
+ }
+ } else { // Here, cur != 0
+ while (cur.pos() > 0 &&
+ cur.par()->isWord(cur.pos()-1) )
+ cur.pos(cur.pos() - 1);
+ }
+}
+
/* -------> Select current word. This depends on behaviour of CursorLeftOneWord(), so it is
patched as well. */
-void LyXText::selectWord(BufferView * bview)
+void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location loc) const
{
- // Move cursor to the beginning, when not already there.
- if (cursor.pos()
- && !cursor.par()->isSeparator(cursor.pos() - 1)
- && !cursor.par()->isKomma(cursor.pos() - 1))
- cursorLeftOneWord(bview);
+ // first put the cursor where we wana start to select the word
+ from = cursor;
+ switch(loc) {
+ case WHOLE_WORD:
+ // Move cursor to the beginning, when not already there.
+ if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
+ && !from.par()->isKomma(from.pos() - 1))
+ cursorLeftOneWord(from);
+ break;
+ case NEXT_WORD:
+ lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet\n";
+ break;
+ case PARTIAL_WORD:
+ break;
+ }
+ to = from;
+ while (to.pos() < to.par()->size()
+ && !to.par()->isSeparator(to.pos())
+ && !to.par()->isKomma(to.pos())
+ && !to.par()->isHfill(to.pos()) )
+ {
+ to.pos(to.pos() + 1);
+ }
+}
- // set the sel cursor
-#if 0
- sel_cursor = cursor;
-#else
+
+void LyXText::selectWord(BufferView * bview)
+{
+ LyXCursor from;
+ LyXCursor to;
+ getWord(from, to, WHOLE_WORD);
+ if (cursor != from)
+ setCursor(bview, from.par(), from.pos());
selection.cursor = cursor;
-#endif
-
- while (cursor.pos() < cursor.par()->size()
- && !cursor.par()->isSeparator(cursor.pos())
- && !cursor.par()->isKomma(cursor.pos()) )
- cursor.pos(cursor.pos() + 1);
- setCursor(bview, cursor.par(), cursor.pos() );
-
- // finally set the selection
+ setCursor(bview, to.par(), to.pos() );
setSelection(bview);
}
-
/* -------> Select the word currently under the cursor when:
1: no selection is currently set,
2: the cursor is not at the borders of the word. */
bool LyXText::selectWordWhenUnderCursor(BufferView * bview)
{
-#if 0
- if (!selection &&
-#else
- if (!selection.set() &&
-#endif
+ if (!selection.set() &&
cursor.pos() > 0 && cursor.pos() < cursor.par()->size()
&& !cursor.par()->isSeparator(cursor.pos())
&& !cursor.par()->isKomma(cursor.pos())
// Now, skip until we have real text (will jump paragraphs)
while ((cursor.par()->size() > cursor.pos()
&& (!cursor.par()->isLetter(cursor.pos())
+#ifndef NO_LATEX
|| cursor.par()->getFont(bview->buffer()->params, cursor.pos())
- .latex() == LyXFont::ON))
+ .latex() == LyXFont::ON
+#endif
+ ))
|| (cursor.par()->size() == cursor.pos()
&& cursor.par()->next())){
if (cursor.pos() == cursor.par()->size()) {
}
// Start the selection from here
-#if 0
- sel_cursor = cursor;
-#else
selection.cursor = cursor;
-#endif
- std::ostringstream latex;
+ ostringstream latex;
// and find the end of the word
// (optional hyphens are part of a word)
&& (cursor.par()->isLetter(cursor.pos()))
|| (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
&& cursor.par()->getInset(cursor.pos()) != 0
- && cursor.par()->getInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
+ && cursor.par()->getInset(cursor.pos())->latex(bview->buffer(), latex, false, false) == 0
&& latex.str() == "\\-"
))
cursor.pos(cursor.pos() + 1);
// Finally, we copy the word to a string and return it
string str;
-#if 0
- if (sel_cursor.pos() < cursor.pos()) {
- Paragraph::size_type i;
- for (i = sel_cursor.pos(); i < cursor.pos(); ++i) {
- if (cursor.par()->getChar(i) != Paragraph::META_INSET)
- str += cursor.par()->getChar(i);
- }
- }
-#else
if (selection.cursor.pos() < cursor.pos()) {
Paragraph::size_type i;
for (i = selection.cursor.pos(); i < cursor.pos(); ++i) {
str += cursor.par()->getChar(i);
}
}
-#endif
return str;
}
// This one is also only for the spellchecker
void LyXText::selectSelectedWord(BufferView * bview)
{
-#if 0
- // move cursor to the beginning
- setCursor(bview, sel_cursor.par(), sel_cursor.pos());
-
- // set the sel cursor
- sel_cursor = cursor;
-#else
// move cursor to the beginning
setCursor(bview, selection.cursor.par(), selection.cursor.pos());
// set the sel cursor
selection.cursor = cursor;
-#endif
- std::ostringstream latex;
+ ostringstream latex;
// now find the end of the word
while (cursor.pos() < cursor.par()->size()
&& (cursor.par()->isLetter(cursor.pos())
|| (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET
&& cursor.par()->getInset(cursor.pos()) != 0
- && cursor.par()->getInset(cursor.pos())->Latex(bview->buffer(), latex, false, false) == 0
+ && cursor.par()->getInset(cursor.pos())->latex(bview->buffer(), latex, false, false) == 0
&& latex.str() == "\\-"
)))
cursor.pos(cursor.pos() + 1);
else {
LyXCursor tmpcursor = cursor;
tmpcursor.row(0); // ??
-#if 0
- selection = true; // to avoid deletion
-#else
selection.set(true); // to avoid deletion
-#endif
cursorRightOneWord(bview);
setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
-#if 0
- sel_cursor = cursor;
-#else
selection.cursor = cursor;
-#endif
cursor = tmpcursor;
setSelection(bview);
else {
LyXCursor tmpcursor = cursor;
tmpcursor.row(0); // ??
-#if 0
- selection = true; // to avoid deletion
-#else
selection.set(true); // to avoid deletion
-#endif
cursorLeftOneWord(bview);
setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
-#if 0
- sel_cursor = cursor;
-#else
selection.cursor = cursor;
-#endif
cursor = tmpcursor;
setSelection(bview);
cutSelection(bview);
// We can't store the row over a regular setCursor
// so we set it to 0 and reset it afterwards.
tmpcursor.row(0); // ??
-#if 0
- selection = true; // to avoid deletion
-#else
selection.set(true); // to avoid deletion
-#endif
cursorEnd(bview);
setCursor(bview, tmpcursor, tmpcursor.par(), tmpcursor.pos());
-#if 0
- sel_cursor = cursor;
-#else
selection.cursor = cursor;
-#endif
cursor = tmpcursor;
setSelection(bview);
// What is this test for ??? (JMarc)
-#if 0
- if (!selection) {
-#else
- if (!selection.set()) {
-#endif
+ if (!selection.set()) {
deleteWordForward(bview);
} else {
cutSelection(bview);
// Paragraph, but it will have to change for 1.1 anyway. At least
// it does not access outside of the allocated array as the older
// version did. (JMarc)
-void LyXText::changeWordCase(BufferView * bview, LyXText::TextCase action)
+void LyXText::changeCase(BufferView * bview, LyXText::TextCase action)
{
- Paragraph * tmppar = cursor.par();
+ LyXCursor from;
+ LyXCursor to;
- setUndo(bview->buffer(),Undo::FINISH,
- tmppar->previous(), tmppar->next());
+ if (selection.set()) {
+ from = selection.start;
+ to = selection.end;
+ } else {
+ getWord(from, to, PARTIAL_WORD);
+ setCursor(bview, to.par(), to.pos() + 1);
+ }
- Paragraph::size_type tmppos = cursor.pos();
+ changeRegionCase(bview, from, to, action);
+}
- while (tmppos < tmppar->size()) {
- unsigned char c = tmppar->getChar(tmppos);
- if (IsKommaChar(c) || IsLineSeparatorChar(c))
- break;
- if (c != Paragraph::META_INSET) {
+
+void LyXText::changeRegionCase(BufferView * bview,
+ LyXCursor const & from,
+ LyXCursor const & to,
+ LyXText::TextCase action)
+{
+ lyx::Assert(from <= to);
+
+ setUndo(bview, Undo::FINISH,
+ from.par(), to.par()->next());
+
+ Paragraph::size_type pos = from.pos();
+ Paragraph * par = from.par();
+
+ while (par && (pos != to.pos() || par != to.par())) {
+ unsigned char c = par->getChar(pos);
+ if (!IsInsetChar(c) && !IsHfillChar(c)) {
switch (action) {
case text_lowercase:
c = tolower(c);
break;
}
}
-
- //tmppar->text[tmppos] = c;
- tmppar->setChar(tmppos, c);
- ++tmppos;
+ par->setChar(pos, c);
+ checkParagraph(bview, par, pos);
+
+ ++pos;
+ if (pos == par->size()) {
+ par = par->next();
+ pos = 0;
+ }
+ }
+ if (to.row() != from.row()) {
+ refresh_y = from.y() - from.row()->baseline();
+ refresh_row = from.row();
+ status(bview, LyXText::NEED_MORE_REFRESH);
}
- checkParagraph(bview, tmppar, tmppos);
- cursorRightOneWord(bview);
}
-void LyXText::transposeChars(BufferView const & bview)
+void LyXText::transposeChars(BufferView & bview)
{
Paragraph * tmppar = cursor.par();
- setUndo(bview.buffer(), Undo::FINISH,
- tmppar->previous(), tmppar->next());
+ setUndo(&bview, Undo::FINISH,
+ tmppar, tmppar->next());
Paragraph::size_type tmppos = cursor.pos();
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(bview->buffer(), Undo::DELETE,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::DELETE,
+ cursor.par(), cursor.par()->next());
cursor = tmpcursor;
backspace(bview);
}
if (cursor.row()->height() != tmpheight) {
refresh_y = cursor.y() - cursor.row()->baseline();
refresh_row = cursor.row();
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
}
return;
}
}
if (cursor.par()->previous()) {
- setUndo(bview->buffer(), Undo::DELETE,
- cursor.par()->previous()->previous(),
+ setUndo(bview, Undo::DELETE,
+ cursor.par()->previous(),
cursor.par()->next());
}
if (cursor.pos())
cursor.pos(cursor.pos() - 1);
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_row = cursor.row();
refresh_y = cursor.y() - cursor.row()->baseline();
} else {
/* this is the code for a normal backspace, not pasting
* any paragraphs */
- setUndo(bview->buffer(), Undo::DELETE,
- cursor.par()->previous(),
- cursor.par()->next());
+ setUndo(bview, Undo::DELETE,
+ cursor.par(), cursor.par()->next());
// We used to do cursorLeftIntern() here, but it is
// not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite,
// some insets are undeletable here
if (cursor.par()->getChar(cursor.pos()) == Paragraph::META_INSET) {
- if (!cursor.par()->getInset(cursor.pos())->Deletable())
+ if (!cursor.par()->getInset(cursor.pos())->deletable())
return;
// force complete redo when erasing display insets
// this is a cruel method but safe..... Matthias
refresh_y = y;
refresh_row = tmprow;
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
setCursor(bview, cursor.par(), cursor.pos(),
false, cursor.boundary());
//current_font = rawtmpfont;
refresh_y = y;
refresh_row = row;
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
breakAgainOneRow(bview, row);
// will the cursor be in another row now?
int const tmpheight = row->height();
setHeightOfRow(bview, row);
if (tmpheight == row->height())
- status = LyXText::NEED_VERY_LITTLE_REFRESH;
+ status(bview, LyXText::NEED_VERY_LITTLE_REFRESH);
else
- status = LyXText::NEED_MORE_REFRESH;
+ status(bview, LyXText::NEED_MORE_REFRESH);
refresh_y = y;
refresh_row = row;
setCursor(bview, cursor.par(), cursor.pos(), false, cursor.boundary());
float last_tmpx = tmpx;
if (main_body > 0 &&
- (main_body-1 > last ||
+ (main_body - 1 > last ||
!row->par()->isLineSeparator(main_body - 1)))
main_body = 0;
++vc;
}
- if (1 || (tmpx + last_tmpx) / 2 > x) {
+ if ((tmpx + last_tmpx) / 2 > x) {
tmpx = last_tmpx;
left_side = true;
}