Bugfix patch from Dekel

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/lyx-1_1_5@1270 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2000-12-08 16:10:37 +00:00
parent 13394206d1
commit fa4bef2dd2
10 changed files with 128 additions and 60 deletions

View File

@ -1,3 +1,37 @@
2000-12-02 Dekel Tsur <dekelts@tau.ac.il>
* src/BufferView_pimpl.C (workAreaMotionNotify): Fixed mouse
movement in inset in RTL text.
(checkInsetHit): Fixed mouse movement in scrolled inset in RTL text.
(workAreaButtonRelease): Do not open a float when there is a selection.
* src/spellchecker.C (RunSpellChecker): Open all floats before
spellchecking.
* src/text.C (InsertChar): Consider "," as a part of a number
(for LTR numbers in RTL text code).
(IsBoundary): Fixed (and simplified).
(InsertChar): Recalculate cursor boundary.
(Backspace): Ditto.
2000-11-23 Dekel Tsur <dekelts@tau.ac.il>
* mathed/formula.C (LocalDispatch): Preserve the label when
changing from display math to eqnarray (however, the label
do not appear at the first line, as one might expects, but at the
second line).
(LocalDispatch): When inserting a label to a formula which already
have a label, the old label is used as default value.
Also, if the label is changed, then all references to the label
are changed.
* src/mathed/math_iter.C (setLabel): Allow to set the label
even if it is empty. This is needed to allow deletion of a label
in an eqnarray.
* src/BufferView2.C (ChangeRefsIfUnique): New method. Changes the
refernces only if the old label appears once in the document.
2000-12-06 Lars Gullik Bjønnes <larsbj@lyx.org>
* src/lyx_cb.C (InsertAsciiFile): use a vector to temporary store

View File

@ -226,6 +226,8 @@ public:
#endif
///
bool ChangeRefs(string const & from, string const & to);
///
bool ChangeRefsIfUnique(string const & from, string const & to);
#ifdef XFORMS_CLIPBOARD
///
void pasteClipboard(bool asPara);

View File

@ -39,6 +39,7 @@ using std::endl;
using std::ifstream;
using std::vector;
using std::find;
using std::count;
// Inserts a file into current document
bool BufferView::insertLyXFile(string const & filen)
@ -795,6 +796,16 @@ void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
}
bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
{
// Check if the label 'from' appears more than once
vector<string> labels = buffer()->getLabelList();
if (count(labels.begin(), labels.end(), from) > 1)
return false;
return ChangeRefs(from, to);
}
void BufferView::updateInset(Inset * inset, bool mark_dirty)
{
if (!inset)

View File

@ -505,9 +505,13 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
// Check for inset locking
if (bv_->the_locking_inset) {
LyXCursor cursor = bv_->text->cursor;
LyXFont font = bv_->text->GetFont(cursor.par, cursor.pos);
int width = bv_->the_locking_inset->width(bv_->painter(), font);
int start_x = font.isVisibleRightToLeft()
? cursor.x - width : cursor.x;
bv_->the_locking_inset->
InsetMotionNotify(bv_,
x - cursor.x,
x - start_x,
y - cursor.y + screen->first,
state);
return;
@ -810,6 +814,7 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
c = bv_->text->cursor.par->
GetChar(bv_->text->cursor.pos);
}
if(!bv_->text->selection)
if (c == LyXParagraph::META_FOOTNOTE
|| c == LyXParagraph::META_MARGIN
|| c == LyXParagraph::META_FIG
@ -906,17 +911,11 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
// Check whether the inset really was hit
Inset * tmpinset = cursor.par->GetInset(cursor.pos);
LyXFont font = bv_->text->GetFont(cursor.par, cursor.pos);
bool is_rtl = font.isVisibleRightToLeft();
int start_x, end_x;
if (is_rtl) {
start_x = cursor.x - tmpinset->width(bv_->painter(), font);
end_x = cursor.x;
} else {
start_x = cursor.x;
end_x = cursor.x + tmpinset->width(bv_->painter(), font);
}
int width = tmpinset->width(bv_->painter(), font);
int start_x = font.isVisibleRightToLeft()
? cursor.x - width : cursor.x;
int end_x = start_x + width;
if (x > start_x && x < end_x
&& y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
&& y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {
@ -937,16 +936,12 @@ Inset * BufferView::Pimpl::checkInsetHit(int & x, int & y,
(cursor.par->GetInset(cursor.pos - 1)->Editable())) {
Inset * tmpinset = cursor.par->GetInset(cursor.pos-1);
LyXFont font = bv_->text->GetFont(cursor.par, cursor.pos-1);
bool is_rtl = font.isVisibleRightToLeft();
int start_x, end_x;
if (!is_rtl) {
start_x = cursor.x - tmpinset->width(bv_->painter(), font);
end_x = cursor.x;
} else {
start_x = cursor.x;
end_x = cursor.x + tmpinset->width(bv_->painter(), font);
}
int width = tmpinset->width(bv_->painter(), font);
int start_x = font.isVisibleRightToLeft()
? cursor.x : cursor.x - width;
int end_x = start_x + width;
if (x > start_x && x < end_x
&& y_tmp > cursor.y - tmpinset->ascent(bv_->painter(), font)
&& y_tmp < cursor.y + tmpinset->descent(bv_->painter(), font)) {

View File

@ -60,7 +60,8 @@ void InsetLabel::Edit(BufferView * bv, int, int, unsigned int)
if (!new_contents.empty() &&
contents != new_contents) {
bv->buffer()->markDirty();
bool flag = bv->ChangeRefs(contents,new_contents);
bool flag = bv->ChangeRefsIfUnique(contents,
new_contents);
contents = new_contents;
bv->text->RedoParagraph();
if (flag) {

View File

@ -765,6 +765,10 @@ InsetFormula::LocalDispatch(BufferView * bv,
case LFUN_BREAKLINE:
bv->lockedInsetStoreUndo(Undo::INSERT);
mathcursor->Insert(' ', LM_TC_CR);
if (!label.empty()) {
mathcursor->setLabel(label.c_str());
label.erase();
}
par = mathcursor->GetPar();
UpdateLocal(bv);
break;
@ -1020,28 +1024,37 @@ InsetFormula::LocalDispatch(BufferView * bv,
case LFUN_INSERT_LABEL:
{
bv->lockedInsetStoreUndo(Undo::INSERT);
if (par->GetType() < LM_OT_PAR) break;
string lb = arg;
if (lb.empty()) {
pair<bool, string>
res = askForText(_("Enter new label to insert:"));
if (res.first) {
lb = res.second;
}
if (par->GetType() < LM_OT_PAR)
break;
string old_label = (par->GetType() == LM_OT_MPARN)
? mathcursor->getLabel() : label;
string new_label = arg;
if (new_label.empty()) {
pair<bool, string> res = old_label.empty()
? askForText(_("Enter new label to insert:"))
: askForText(_("Enter label:"), old_label);
if (!res.first)
break;
new_label = frontStrip(strip(res.second));
}
if (!lb.empty() && lb[0] > ' ') {
if (new_label == old_label)
break; // Nothing to do
if (!new_label.empty())
SetNumber(true);
if (par->GetType() == LM_OT_MPARN) {
mathcursor->setLabel(lb.c_str());
// MathMatrixInset *mt = (MathMatrixInset*)par;
// mt->SetLabel(lb);
} else {
//if (label.notEmpty()) delete label;
label = lb;
}
UpdateLocal(bv);
} else
label.erase();
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw();
if (par->GetType() == LM_OT_MPARN)
mathcursor->setLabel(new_label.c_str());
// MathMatrixInset *mt = (MathMatrixInset*)par;
// mt->SetLabel(new_label);
else
label = new_label;
UpdateLocal(bv);
break;
}

View File

@ -85,6 +85,10 @@ class MathedCursor {
void setNumbered();
void setLabel(char const *);
///
char const * getLabel() const {
return cursor->getLabel();
}
///
bool Limits();
/// Set accent: if argument = 0 it's considered consumed
void setAccent(int ac = 0);

View File

@ -219,6 +219,10 @@ class MathedXIter: public MathedIter {
//@{
///
bool setLabel(char* label);
///
char const * getLabel() const {
return crow->getLabel();
}
///
bool setNumbered(bool);
//@}

View File

@ -651,6 +651,12 @@ bool RunSpellChecker(BufferView * bv)
int i, newvalue;
FL_OBJECT * obj;
#ifndef NEW_INSETS
// Open all floats
bv->allFloats(1, 0);
bv->allFloats(1, 1);
#endif
string tmp = (lyxrc.isp_use_alt_lang) ? lyxrc.isp_alt_lang : bv->buffer()->GetLanguage();
bool rtl = tmp == "hebrew" || tmp == "arabic";

View File

@ -434,12 +434,9 @@ bool LyXText::IsBoundary(LyXParagraph * par, LyXParagraph::size_type pos) const
return false;
bool rtl = bidi_level(pos - 1) % 2;
bool rtl2 = rtl;
if (pos == par->Last() ||
(par->table && par->IsNewline(pos)))
rtl2 = par->isRightToLeftPar();
else if (bidi_InRange(pos))
rtl2 = bidi_level(pos) % 2;
bool rtl2 = bidi_InRange(pos)
? bidi_level(pos) % 2
: par->isRightToLeftPar();
return rtl != rtl2;
}
@ -450,12 +447,9 @@ bool LyXText::IsBoundary(LyXParagraph * par, LyXParagraph::size_type pos,
return false; // This is just for speedup
bool rtl = font.isVisibleRightToLeft();
bool rtl2 = rtl;
if (pos == par->Last() ||
(par->table && par->IsNewline(pos)))
rtl2 = par->isRightToLeftPar();
else if (bidi_InRange(pos))
rtl2 = bidi_level(pos) % 2;
bool rtl2 = bidi_InRange(pos)
? bidi_level(pos) % 2
: par->isRightToLeftPar();
return rtl != rtl2;
}
@ -2666,7 +2660,7 @@ void LyXText::InsertChar(char c)
if (lyxrc.auto_number) {
if (current_font.number() == LyXFont::ON) {
if (!isdigit(c) && !strchr("+-/*", c) &&
!(strchr(".",c) &&
!(strchr(".,",c) &&
cursor.pos >= 1 && cursor.pos < cursor.par->size() &&
GetFont(cursor.par, cursor.pos).number() == LyXFont::ON &&
GetFont(cursor.par, cursor.pos-1).number() == LyXFont::ON)
@ -2685,7 +2679,7 @@ void LyXText::InsertChar(char c)
) {
SetCharFont(cursor.par, cursor.pos - 1,
current_font);
} else if (strchr(".", c) &&
} else if (strchr(".,", c) &&
cursor.pos >= 2 &&
GetFont(cursor.par, cursor.pos-2).number() == LyXFont::ON) {
SetCharFont(cursor.par, cursor.pos - 1,
@ -2847,6 +2841,10 @@ void LyXText::InsertChar(char c)
current_font = rawtmpfont;
real_current_font = realtmpfont;
SetCursor(cursor.par, cursor.pos + 1, false, cursor.boundary);
if (IsBoundary(cursor.par, cursor.pos) != cursor.boundary)
SetCursor(cursor.par, cursor.pos, false,
!cursor.boundary);
if (row->next && row->next->par == row->par)
need_break_row = row->next;
else
@ -3734,12 +3732,12 @@ void LyXText::Backspace()
// current_font = rawtmpfont;
// real_current_font = realtmpfont;
if (IsBoundary(cursor.par, cursor.pos) != cursor.boundary)
SetCursor(cursor.par, cursor.pos, false, !cursor.boundary);
lastpos = cursor.par->Last();
if (cursor.pos == lastpos) {
if (IsBoundary(cursor.par, cursor.pos) != cursor.boundary)
SetCursor(cursor.par, cursor.pos, false, !cursor.boundary);
if (cursor.pos == lastpos)
SetCurrentFont();
}
// check, wether the last characters font has changed.
if (rawparfont !=