From fa4bef2dd25a3e8fa9356e638190c6eba7bc890a Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 8 Dec 2000 16:10:37 +0000 Subject: [PATCH] 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 --- ChangeLog | 34 ++++++++++++++++++++++++++ src/BufferView.h | 2 ++ src/BufferView2.C | 11 +++++++++ src/BufferView_pimpl.C | 37 ++++++++++++---------------- src/insets/insetlabel.C | 3 ++- src/mathed/formula.C | 53 +++++++++++++++++++++++++--------------- src/mathed/math_cursor.h | 4 +++ src/mathed/math_iter.h | 4 +++ src/spellchecker.C | 6 +++++ src/text.C | 34 ++++++++++++-------------- 10 files changed, 128 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index bfb872ba73..53ffd51952 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2000-12-02 Dekel Tsur + + * 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 + + * 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 * src/lyx_cb.C (InsertAsciiFile): use a vector to temporary store diff --git a/src/BufferView.h b/src/BufferView.h index b1e1e11b8b..e81f84a167 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -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); diff --git a/src/BufferView2.C b/src/BufferView2.C index d3a61c3ac6..7f4da5b323 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -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 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) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 21f8ef04fe..fbdfe058c8 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -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)) { diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index ea7b8e6e1e..922b8d9626 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -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) { diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 4b8ea30a6f..d6c3476e76 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -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 - 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 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; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index e019208b51..228d7ecf94 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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); diff --git a/src/mathed/math_iter.h b/src/mathed/math_iter.h index a34738eb32..259dbfec0d 100644 --- a/src/mathed/math_iter.h +++ b/src/mathed/math_iter.h @@ -219,6 +219,10 @@ class MathedXIter: public MathedIter { //@{ /// bool setLabel(char* label); + /// + char const * getLabel() const { + return crow->getLabel(); + } /// bool setNumbered(bool); //@} diff --git a/src/spellchecker.C b/src/spellchecker.C index 14b51e9227..3b7c8118c0 100644 --- a/src/spellchecker.C +++ b/src/spellchecker.C @@ -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"; diff --git a/src/text.C b/src/text.C index b3275c0876..81c2337080 100644 --- a/src/text.C +++ b/src/text.C @@ -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 !=