From 7a0b5603e516f90b64e7385600b7ae5f6f0a95f7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 13 Feb 2004 13:51:12 +0000 Subject: [PATCH] more IU as advertised git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8431 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 17 ++---- src/cursor.C | 13 ++--- src/cursor.h | 3 +- src/cursor_slice.h | 2 +- src/insets/insetbase.C | 5 +- src/insets/insetbase.h | 2 +- src/insets/insetcollapsable.C | 16 +++--- src/insets/insetcollapsable.h | 2 +- src/insets/insetexternal.h | 3 +- src/insets/insetgraphics.h | 6 +- src/insets/insettabular.C | 33 ++++++----- src/insets/insettabular.h | 8 +-- src/insets/insettext.C | 4 +- src/insets/insettext.h | 2 +- src/lyx_cb.C | 43 --------------- src/lyx_cb.h | 2 - src/lyxrow_funcs.C | 71 ------------------------ src/lyxrow_funcs.h | 6 -- src/lyxtext.h | 12 ++-- src/mathed/math_hullinset.C | 1 - src/mathed/math_nestinset.C | 6 +- src/mathed/math_nestinset.h | 2 +- src/text.C | 101 ++++++++++++++++++++++++++++++++++ src/text2.C | 75 ++++++++++++------------- src/text3.C | 11 ++-- 25 files changed, 207 insertions(+), 239 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index e36a500bbf..5880205469 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -474,13 +474,14 @@ void BufferView::Pimpl::scrollDocView(int value) int const first = top_y() + height; int const last = top_y() + workarea().workHeight() - height; + bv_->cursor().reset(); LyXText * text = bv_->text(); CursorSlice & cur = bv_->cursor().cursor_.front(); int y = text->cursorY(cur); if (y < first) - text->setCursorFromCoordinates(cur, 0, first); + text->setCursorFromCoordinates(bv_->cursor(), 0, first); else if (y > last) - text->setCursorFromCoordinates(cur, 0, last); + text->setCursorFromCoordinates(bv_->cursor(), 0, last); owner_->updateLayoutChoice(); } @@ -922,18 +923,12 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) // surrounding LyXText will handle this event. // built temporary path to inset - LyXText * text = bv_->text(); - InsetBase * const inset_hit = text->checkInsetHit(cmd.x, cmd.y); - if (inset_hit) - inset_hit->edit(cur, cmd.x, cmd.y); - else - text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y); + InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y); + lyxerr << "hit inset at tip: " << inset << endl; lyxerr << "created temp cursor: " << cur << endl; // Try to dispatch to an non-editable inset near this position DispatchResult res; - InsetBase * inset = cur.nextInset(); - lyxerr << "next inset: " << inset << endl; if (inset) res = inset->dispatch(cur, cmd); @@ -1027,7 +1022,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd) case LFUN_INSERT_LABEL: { // Try and generate a valid label string const contents = cmd.argument.empty() ? - getPossibleLabel(*bv_) : cmd.argument; + cur.getPossibleLabel() : cmd.argument; InsetCommandParams icp("label", contents); string data = InsetCommandMailer::params2string("label", icp); owner_->getDialogs().show("label", data, 0); diff --git a/src/cursor.C b/src/cursor.C index 1902a16f23..49859013e3 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -1810,13 +1810,6 @@ void LCursor::handleFont(string const & font) } -void LCursor::releaseMathCursor() -{ - if (inMathed()) - formula()->insetUnlock(bv()); -} - - bool LCursor::inMathed() const { return formula(); @@ -1937,3 +1930,9 @@ void LCursor::update() { bv().update(); } + + +string LCursor::getPossibleLabel() +{ + return inMathed() ? "eq:" : text()->getPossibleLabel(*this); +} diff --git a/src/cursor.h b/src/cursor.h index 5071dcec84..842ff17c63 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -426,7 +426,6 @@ public: /// split font inset etc void handleFont(std::string const & font); - void releaseMathCursor(); /// are we in mathed? bool inMathed() const; /// are we in texted? @@ -436,6 +435,8 @@ public: void message(std::string const & msg) const; /// display an error message void errorMessage(std::string const & msg) const; + /// + std::string getPossibleLabel(); private: /// moves cursor index one cell to the left diff --git a/src/cursor_slice.h b/src/cursor_slice.h index a06a374222..3bf2e31dbe 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -120,7 +120,7 @@ public: /// friend std::ostream & operator<<(std::ostream &, CursorSlice const &); public: - /// pointer to an inset + /// pointer to 'owning' inset InsetBase * inset_; /// cell index of a position in this inset idx_type idx_; diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 4a03ba7327..b8ebb5757f 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -35,6 +35,7 @@ DispatchResult InsetBase::dispatch(LCursor & cur, FuncRequest const & cmd) DispatchResult InsetBase::priv_dispatch(LCursor &, FuncRequest const &) { + lyxerr << "InsetBase::priv_dispatch" << std::endl; return DispatchResult(false); } @@ -45,10 +46,10 @@ void InsetBase::edit(LCursor &, bool) } -void InsetBase::edit(LCursor & cur, int, int) +InsetBase * InsetBase::editXY(LCursor & cur, int, int) { lyxerr << "InsetBase: edit xy" << std::endl; - edit(cur, true); + return this; } diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index a8d458fa34..607230c532 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -73,7 +73,7 @@ public: /// cursor enters virtual void edit(LCursor & cur, bool left); /// cursor enters - virtual void edit(LCursor & cur, int x, int y); + virtual InsetBase * editXY(LCursor & cur, int x, int y); /// compute the size of the object returned in dim virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 7480b7bb25..97f34812d9 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -299,7 +299,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left) } -void InsetCollapsable::edit(LCursor & cur, int x, int y) +InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) { cur.push(this); //lyxerr << "InsetCollapsable: edit xy" << endl; @@ -309,14 +309,14 @@ void InsetCollapsable::edit(LCursor & cur, int x, int y) #warning look here //we are not calling edit(x,y) because there are no coordinates in the //inset yet. I personally think it's ok. (ab) - } else { -// if (y <= yo() + inset.ascent() + button_dim.y2) -// y = yo(); -// else -// y += inset.ascent() - height_collapsed(); - - inset.edit(cur, x, y); + return this; } + +//if (y <= yo() + inset.ascent() + button_dim.y2) +// y = yo(); +//else +// y += inset.ascent() - height_collapsed(); + return inset.editXY(cur, x, y); } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 761faa9c90..e2785d82f3 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -137,7 +137,7 @@ protected: /// void edit(LCursor & cur, bool left); /// - void edit(LCursor & cur, int x, int y); + InsetBase * editXY(LCursor & cur, int x, int y); private: /// diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index 37114c33af..5afe94dca0 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -142,11 +142,12 @@ public: /// InsetExternalParams const & params() const; + /// void setParams(InsetExternalParams const &, Buffer const &); /// void addPreview(lyx::graphics::PreviewLoader &) const; /// - void edit(LCursor & cur, bool); + void edit(LCursor & cur, bool left); protected: /// diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 7c99e11dbd..a51ca6e2e7 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -78,12 +78,10 @@ public: /// void draw(PainterInfo & pi, int x, int y) const; /// - void edit(LCursor & cur, bool); + void edit(LCursor & cur, bool left); protected: /// - virtual - DispatchResult - priv_dispatch(LCursor & cur, FuncRequest const & cmd); + DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd); private: /// friend class InsetGraphicsMailer; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index b904da7049..408615b274 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -461,19 +461,18 @@ void InsetTabular::edit(LCursor & cur, bool left) } -void InsetTabular::edit(LCursor & cur, int x, int y) +InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) { lyxerr << "InsetTabular::edit: " << this << " first cell " << &tabular.cell_info[0][0].inset << endl; - - finishUndo(); - setPos(cur, x, y); clearSelection(); - finishUndo(); - //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell); cur.push(this); + setPos(cur, x, y); + //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell); //if (x > xx) // activateCellInset(bv, cell, x - xx, y - cursory_); +#warning wrong! + return this; } @@ -977,7 +976,7 @@ void InsetTabular::setPos(LCursor & cur, int x, int y) const //lyxerr << "# InsetTabular::setPos() cursor: " << cur << endl; int const cell = getCell(x + xo_, y + yo_); InsetText const & inset = tabular.getCellInset(cell); - inset.text_.setCursorFromCoordinates(cur.current(), x, y); + inset.text_.setCursorFromCoordinates(cur, x, y); cursory_ = 0; int actcell = 0; int actrow = 0; @@ -1023,7 +1022,7 @@ int InsetTabular::getCellXPos(int cell) const void InsetTabular::resetPos(LCursor & cur) const { -#if 0 +#if 1 #ifdef WITH_WARNINGS #warning This should be fixed in the right manner (20011128 Jug) #endif @@ -1033,7 +1032,7 @@ void InsetTabular::resetPos(LCursor & cur) const BufferView & bv = cur.bv(); int cell = 0; - int actcell = cur.cell(); + int actcell = cur.idx(); int actcol = tabular.column_of_cell(actcell); int actrow = 0; cursory_ = 0; @@ -1054,24 +1053,24 @@ void InsetTabular::resetPos(LCursor & cur) const cursorx_ = new_x; // cursor.x(getCellXPos(actcell) + offset); if (actcol < tabular.columns() - 1 && scroll(false) && - tabular.getWidthOfTabular() < bv->workWidth()-20) + tabular.getWidthOfTabular() < bv.workWidth()-20) { scroll(bv, 0.0F); updateLocal(cur); } else if (cursorx_ - offset > 20 && cursorx_ - offset + tabular.getWidthOfColumn(actcell) > bv.workWidth() - 20) { - scroll(&bv, - tabular.getWidthOfColumn(actcell) - 20); + scroll(bv, - tabular.getWidthOfColumn(actcell) - 20); updateLocal(cur); } else if (cursorx_ - offset < 20) { - scroll(&bv, 20 - cursorx_ + offset); + scroll(bv, 20 - cursorx_ + offset); updateLocal(cur); } else if (scroll() && xo_ > 20 && - xo_ + tabular.getWidthOfTabular() > bv->workWidth() - 20) { - scroll(&bv, old_x - cursorx_); + xo_ + tabular.getWidthOfTabular() > bv.workWidth() - 20) { + scroll(bv, old_x - cursorx_); updateLocal(cur); } - InsetTabularMailer(*this).updateDialog(bv); + InsetTabularMailer(*this).updateDialog(&bv); in_reset_pos = 0; #endif } @@ -1595,16 +1594,16 @@ void InsetTabular::tabularFeatures(LCursor & cur, void InsetTabular::activateCellInset(LCursor & cur, int cell, int x, int y) { - tabular.getCellInset(cell).edit(cur, x, y); cur.idx() = cell; + tabular.getCellInset(cell).editXY(cur, x, y); updateLocal(cur); } void InsetTabular::activateCellInset(LCursor & cur, int cell, bool behind) { - tabular.getCellInset(cell).edit(cur, behind); cur.idx() = cell; + tabular.getCellInset(cell).edit(cur, behind); updateLocal(cur); } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 8214f0a126..4f3647f9bc 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -147,9 +147,9 @@ public: /// set the owning buffer void buffer(Buffer * buf); /// lock cell with given index - void edit(LCursor & cur, bool); + void edit(LCursor & cur, bool left); /// - void edit(LCursor & cur, int, int); + InsetBase * editXY(LCursor & cur, int x, int y); /// can we go further down on mouse click? bool descendable() const { return true; } @@ -160,9 +160,7 @@ public: protected: /// - virtual - DispatchResult - priv_dispatch(LCursor & cur, FuncRequest const & cmd); + DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd); private: /// void lfunMousePress(LCursor & cur, FuncRequest const & cmd); diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 374736f4c2..5a61957705 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -298,11 +298,11 @@ void InsetText::edit(LCursor & cur, bool left) } -void InsetText::edit(LCursor & cur, int x, int y) +InsetBase * InsetText::editXY(LCursor & cur, int x, int y) { lyxerr << "InsetText::edit xy" << endl; old_par = -1; - text_.edit(cur, x, y); + return text_.editXY(cur, x, y); //sanitizeEmptyText(cur.bv()); //updateLocal(cur); //dispatch(cur, FuncRequest(LFUN_PARAGRAPH_UPDATE)); diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 5ede34ee13..ed99e024df 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -148,7 +148,7 @@ public: /// void edit(LCursor & cur, bool left); /// - void edit(LCursor & cur, int x, int y); + InsetBase * editXY(LCursor & cur, int x, int y); /// int numParagraphs() const { return 1; } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 5838b29e14..bdfe5e83f8 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -432,49 +432,6 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap } -string const getPossibleLabel(BufferView const & bv) -{ - ParagraphList::iterator pit = bv.getLyXText()->cursorPar(); - ParagraphList & plist = bv.getLyXText()->paragraphs(); - - LyXLayout_ptr layout = pit->layout(); - - if (layout->latextype == LATEX_PARAGRAPH && pit != plist.begin()) { - ParagraphList::iterator pit2 = boost::prior(pit); - - LyXLayout_ptr const & layout2 = pit2->layout(); - - if (layout2->latextype != LATEX_PARAGRAPH) { - pit = pit2; - layout = layout2; - } - } - - string text = layout->latexname().substr(0, 3); - if (layout->latexname() == "theorem") - text = "thm"; // Create a correct prefix for prettyref - - text += ':'; - if (layout->latextype == LATEX_PARAGRAPH || - lyxrc.label_init_length < 0) - text.erase(); - - string par_text = pit->asString(*bv.buffer(), false); - for (int i = 0; i < lyxrc.label_init_length; ++i) { - if (par_text.empty()) - break; - string head; - par_text = split(par_text, head, ' '); - // Is it legal to use spaces in labels ? - if (i > 0) - text += '-'; - text += head; - } - - return text; -} - - // This function runs "configure" and then rereads lyx.defaults to // reconfigure the automatic settings. void Reconfigure(BufferView * bv) diff --git a/src/lyx_cb.h b/src/lyx_cb.h index 949f695295..67bc2bddd8 100644 --- a/src/lyx_cb.h +++ b/src/lyx_cb.h @@ -35,7 +35,5 @@ void InsertAsciiFile(BufferView * bv, std::string const & f, bool asParagraph); /// std::string getContentsOfAsciiFile(BufferView * bv, std::string const & f, bool asParagraph); /// -std::string const getPossibleLabel(BufferView const & bv); -/// void Reconfigure(BufferView * bv); #endif diff --git a/src/lyxrow_funcs.C b/src/lyxrow_funcs.C index e4cd8c26dd..ec805f892e 100644 --- a/src/lyxrow_funcs.C +++ b/src/lyxrow_funcs.C @@ -19,77 +19,6 @@ using lyx::pos_type; -using std::max; -using std::min; -using std::endl; - - -int numberOfSeparators(Paragraph const & par, Row const & row) -{ - pos_type const first = max(row.pos(), par.beginOfBody()); - pos_type const last = row.endpos() - 1; - int n = 0; - for (pos_type p = first; p < last; ++p) { - if (par.isSeparator(p)) - ++n; - } - - return n; -} - - -// This is called _once_ from LyXText and should at least be moved into -// an anonymous namespace there. (Lgb) -int numberOfHfills(Paragraph const & par, Row const & row) -{ - pos_type const last = row.endpos() - 1; - pos_type first = row.pos(); - - // hfill *DO* count at the beginning of paragraphs! - if (first) { - while (first < last && par.isHfill(first)) - ++first; - } - - first = max(first, par.beginOfBody()); - - int n = 0; - - // last, because the end is ignored! - for (pos_type p = first; p < last; ++p) { - if (par.isHfill(p)) - ++n; - } - - return n; -} - - -// This is called _once_ from LyXText and should at least be moved into -// an anonymous namespace there. (Lgb) -int numberOfLabelHfills(Paragraph const & par, Row const & row) -{ - pos_type last = row.endpos() - 1; - pos_type first = row.pos(); - - // hfill *DO* count at the beginning of paragraphs! - if (first) { - while (first < last && par.isHfill(first)) - ++first; - } - - last = min(last, par.beginOfBody()); - int n = 0; - - // last, because the end is ignored - for (pos_type p = first; p < last; ++p) { - if (par.isHfill(p)) - ++n; - } - - return n; -} - bool hfillExpansion(Paragraph const & par, Row const & row, pos_type pos) { diff --git a/src/lyxrow_funcs.h b/src/lyxrow_funcs.h index 66b0288615..2eee7cf282 100644 --- a/src/lyxrow_funcs.h +++ b/src/lyxrow_funcs.h @@ -18,12 +18,6 @@ class Paragraph; class Row; -int numberOfSeparators(Paragraph const & par, Row const & row); - -int numberOfHfills(Paragraph const & par, Row const & row); - -int numberOfLabelHfills(Paragraph const & par, Row const & row); - bool hfillExpansion(Paragraph const & par, Row const & row, lyx::pos_type pos); diff --git a/src/lyxtext.h b/src/lyxtext.h index 4e25e90dc9..77ed1ee2b9 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -187,9 +187,9 @@ public: /// void recUndo(par_type first) const; /// - void setCursorFromCoordinates(CursorSlice &, int x, int y); + void setCursorFromCoordinates(LCursor & cur, int x, int y); /// - void edit(LCursor & cur, int x, int y); + InsetBase * editXY(LCursor & cur, int x, int y); /// void cursorUp(LCursor & cur, bool selecting = false); /// @@ -339,7 +339,9 @@ public: bool isFirstRow(ParagraphList::iterator pit, Row const & row) const; /// - double spacing(Paragraph const &) const; + double spacing(Paragraph const & par) const; + /// make a suggestion for a label + std::string getPossibleLabel(LCursor & cur) const; /// DispatchResult moveRight(LCursor & cur); @@ -431,7 +433,9 @@ private: void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where); /// delete double space (false) or empty paragraphs (true) around old_cursor - bool deleteEmptyParagraphMechanism(CursorSlice const & old_cursor); + bool deleteEmptyParagraphMechanism( + CursorSlice & cur, + CursorSlice const & old_cursor); /// void setCounter(Buffer const &, ParagraphList::iterator pit); diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 443240e921..19a1f94e7a 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -993,7 +993,6 @@ void MathHullInset::insetUnlock(BufferView & bv) if (bv.cursor().inMathed()) { if (bv.cursor().inMacroMode()) bv.cursor().macroModeClose(); - bv.cursor().releaseMathCursor(); } if (bv.buffer()) generatePreview(*bv.buffer()); diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index f489193b82..99d2b8f4e8 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -744,7 +744,6 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd) revealCodes(cur); cur.bv().stuffClipboard(cur.grabSelection()); } else { - cur.releaseMathCursor(); if (remove_inset) cur.bv().owner()->dispatch(FuncRequest(LFUN_DELETE)); } @@ -767,7 +766,7 @@ void MathNestInset::edit(LCursor & cur, bool left) } -void MathNestInset::edit(LCursor & cur, int x, int y) +InsetBase * MathNestInset::editXY(LCursor & cur, int x, int y) { int idx_min = 0; int dist_min = 1000000; @@ -787,8 +786,9 @@ void MathNestInset::edit(LCursor & cur, int x, int y) // hit inside cell for (pos_type i = 0, n = ar.size(); i < n; ++i) if (ar[i]->covers(x, y)) - ar[i].nucleus()->edit(cur, x, y); + return ar[i].nucleus()->editXY(cur, x, y); } + return this; } diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 471e0bb282..58532f31ba 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -43,7 +43,7 @@ public: /// void edit(LCursor & cur, bool left); /// - void edit(LCursor & cur, int x, int y); + InsetBase * editXY(LCursor & cur, int x, int y); /// order of movement through the cells when pressing the left key bool idxLeft(LCursor &) const; diff --git a/src/text.C b/src/text.C index 26b682bb1c..de104b34ca 100644 --- a/src/text.C +++ b/src/text.C @@ -60,11 +60,13 @@ using lyx::word_location; using lyx::support::bformat; using lyx::support::contains; using lyx::support::lowercase; +using lyx::support::split; using lyx::support::uppercase; using std::advance; using std::distance; using std::max; +using std::min; using std::endl; using std::string; @@ -79,6 +81,19 @@ extern int const RIGHT_MARGIN = 10; namespace { +int numberOfSeparators(Paragraph const & par, Row const & row) +{ + pos_type const first = max(row.pos(), par.beginOfBody()); + pos_type const last = row.endpos() - 1; + int n = 0; + for (pos_type p = first; p < last; ++p) { + if (par.isSeparator(p)) + ++n; + } + return n; +} + + unsigned int maxParagraphWidth(ParagraphList const & plist) { unsigned int width = 0; @@ -89,6 +104,49 @@ unsigned int maxParagraphWidth(ParagraphList const & plist) return width; } + +int numberOfLabelHfills(Paragraph const & par, Row const & row) +{ + pos_type last = row.endpos() - 1; + pos_type first = row.pos(); + + // hfill *DO* count at the beginning of paragraphs! + if (first) { + while (first < last && par.isHfill(first)) + ++first; + } + + last = min(last, par.beginOfBody()); + int n = 0; + for (pos_type p = first; p < last; ++p) { + if (par.isHfill(p)) + ++n; + } + return n; +} + + +int numberOfHfills(Paragraph const & par, Row const & row) +{ + pos_type const last = row.endpos() - 1; + pos_type first = row.pos(); + + // hfill *DO* count at the beginning of paragraphs! + if (first) { + while (first < last && par.isHfill(first)) + ++first; + } + + first = max(first, par.beginOfBody()); + + int n = 0; + for (pos_type p = first; p < last; ++p) { + if (par.isHfill(p)) + ++n; + } + return n; +} + } // namespace anon @@ -1955,3 +2013,46 @@ string LyXText::currentState(LCursor & cur) #endif return os.str(); } + + +string LyXText::getPossibleLabel(LCursor & cur) const +{ + ParagraphList & plist = paragraphs(); + ParagraphList::iterator pit = getPar(cur.par()); + + LyXLayout_ptr layout = pit->layout(); + + if (layout->latextype == LATEX_PARAGRAPH && pit != plist.begin()) { + ParagraphList::iterator pit2 = boost::prior(pit); + + LyXLayout_ptr const & layout2 = pit2->layout(); + + if (layout2->latextype != LATEX_PARAGRAPH) { + pit = pit2; + layout = layout2; + } + } + + string text = layout->latexname().substr(0, 3); + if (layout->latexname() == "theorem") + text = "thm"; // Create a correct prefix for prettyref + + text += ':'; + if (layout->latextype == LATEX_PARAGRAPH || + lyxrc.label_init_length < 0) + text.erase(); + + string par_text = pit->asString(*cur.bv().buffer(), false); + for (int i = 0; i < lyxrc.label_init_length; ++i) { + if (par_text.empty()) + break; + string head; + par_text = split(par_text, head, ' '); + // Is it legal to use spaces in labels ? + if (i > 0) + text += '-'; + text += head; + } + + return text; +} diff --git a/src/text2.C b/src/text2.C index ba9912e9b0..de12a7051f 100644 --- a/src/text2.C +++ b/src/text2.C @@ -292,7 +292,7 @@ void LyXText::setLayout(LCursor & cur, string const & layout) bv()->owner()->dispatch(FuncRequest(LFUN_CUT)); InsetBase * inset = new InsetEnvironment(params, layout); insertInset(cur, inset); - //inset->edit(bv()); + //inset->edit(cur, true); //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); return; } @@ -1089,7 +1089,7 @@ bool LyXText::setCursor(LCursor & cur, par_type par, pos_type pos, { CursorSlice old_cursor = cur.current(); setCursorIntern(cur, par, pos, setfont, boundary); - return deleteEmptyParagraphMechanism(old_cursor); + return deleteEmptyParagraphMechanism(cur.current(), old_cursor); } @@ -1298,23 +1298,24 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, // x,y are coordinates relative to this LyXText -void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y) +void LyXText::setCursorFromCoordinates(LCursor & cur, int x, int y) { - CursorSlice old_cursor = cur; + CursorSlice old_cursor = cur.current(); ParagraphList::iterator pit; Row const & row = *getRowNearY(y, pit); + lyxerr << "hit row at: " << row.pos() << endl; bool bound = false; int xx = x + xo_; // getRowNearX get absolute x coords pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound); cur.par() = parOffset(pit); cur.pos() = pos; cur.boundary() = bound; - deleteEmptyParagraphMechanism(old_cursor); + deleteEmptyParagraphMechanism(cur.current(), old_cursor); } // x,y are absolute screen coordinates -void LyXText::edit(LCursor & cur, int x, int y) +InsetBase * LyXText::editXY(LCursor & cur, int x, int y) { ParagraphList::iterator pit; Row const & row = *getRowNearY(y - yo_, pit); @@ -1328,17 +1329,18 @@ void LyXText::edit(LCursor & cur, int x, int y) // try to descend into nested insets InsetBase * inset = checkInsetHit(x, y); - if (inset) { - // This should be just before or just behind the - // cursor position set above. - BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1)) - || inset == pit->getInset(pos)); - // Make sure the cursor points to the position before - // this inset. - if (inset == pit->getInset(pos - 1)) - --cur.pos(); - inset->edit(cur, x, y); - } + if (!inset) + return 0; + + // This should be just before or just behind the + // cursor position set above. + BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1)) + || inset == pit->getInset(pos)); + // Make sure the cursor points to the position before + // this inset. + if (inset == pit->getInset(pos - 1)) + --cur.pos(); + return inset->editXY(cur, x, y); } @@ -1433,7 +1435,7 @@ bool LyXText::cursorLeft(LCursor & cur, bool internal) if (cur.par() != 0) { // steps into the paragraph above - setCursor(cur, cur.par() - 1, boost::prior(cursorPar())->size()); + setCursor(cur, cur.par() - 1, getPar(cur.par() - 1)->size()); return true; } @@ -1470,12 +1472,12 @@ void LyXText::cursorUp(LCursor & cur, bool selecting) Row const & row = cur.textRow(); int x = cur.x_target(); int y = cursorY(cur.current()) - row.baseline() - 1; - setCursorFromCoordinates(cur.current(), x - xo_, y - yo_); + setCursorFromCoordinates(cur, x - xo_, y - yo_); if (!selecting) { InsetBase * inset_hit = checkInsetHit(cur.x_target(), y); if (inset_hit && isHighlyEditableInset(inset_hit)) - inset_hit->edit(cur, cur.x_target(), y); + inset_hit->editXY(cur, cur.x_target(), y); } } @@ -1485,12 +1487,12 @@ void LyXText::cursorDown(LCursor & cur, bool selecting) Row const & row = cur.textRow(); int x = cur.x_target(); int y = cursorY(cur.current()) - row.baseline() + row.height() + 1; - setCursorFromCoordinates(cur.current(), x - xo_, y - yo_); + setCursorFromCoordinates(cur, x - xo_, y - yo_); if (!selecting) { InsetBase * inset_hit = checkInsetHit(cur.x_target(), y); if (inset_hit && isHighlyEditableInset(inset_hit)) - inset_hit->edit(cur, cur.x_target(), y); + inset_hit->editXY(cur, cur.x_target(), y); } } @@ -1517,13 +1519,12 @@ void LyXText::cursorDownParagraph(LCursor & cur) // position. Called by deleteEmptyParagraphMechanism void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where) { - // if cursor is not in the paragraph where the delete occured, - // do nothing + // do notheing if cursor is not in the paragraph where the + // deletion occured, if (cur.par() != where.par()) return; - // if cursor position is after the place where the delete occured, - // update it + // if cursor position is after the deletion place update it if (cur.pos() > where.pos()) --cur.pos(); @@ -1534,22 +1535,19 @@ void LyXText::fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where) } -bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor) +bool LyXText::deleteEmptyParagraphMechanism(CursorSlice & cur, + CursorSlice const & old_cursor) { #warning Disabled as it crashes after the cursor data shift... (Andre) return false; // Would be wrong to delete anything if we have a selection. - if (bv()->cursor().selection()) - return false; - - // Don't do anything if the cursor is invalid - if (old_cursor.par() == -1) - return false; + //if (cur.selection()) + // return false; #if 0 // We allow all kinds of "mumbo-jumbo" when freespacing. - ParagraphList::iterator const old_pit = getPar(old_cursor); + ParagraphList::iterator const old_pit = getPar(old_cursor.par()); if (old_pit->isFreeSpacing()) return false; @@ -1577,8 +1575,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor) // 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()) { + if (old_cursor.par() != cur.par() || old_cursor.pos() != cur.pos()) { // Only if the cursor has really moved if (old_cursor.pos() > 0 @@ -1612,7 +1609,7 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor) return false; // only do our magic if we changed paragraph - if (old_cursor.par() == cursor().par()) + if (old_cursor.par() == cur.par()) return false; // record if we have deleted a paragraph @@ -1640,12 +1637,10 @@ bool LyXText::deleteEmptyParagraphMechanism(CursorSlice const & old_cursor) recUndo(parOffset(old_pit), parOffset(endpit) - 1); cursor() = tmpcursor; - // cache cursor pit - ParagraphList::iterator tmppit = cursorPar(); // delete old par paragraphs().erase(old_pit); // update cursor par offset - cursor().par(parOffset(tmppit)); + --cur.par(); redoParagraph(); if (selection_position_was_oldcursor_position) { diff --git a/src/text3.C b/src/text3.C index ffccff2353..679b1190ed 100644 --- a/src/text3.C +++ b/src/text3.C @@ -293,7 +293,7 @@ void LyXText::cursorPrevious(LCursor & cur) int x = cur.x_target(); int y = bv()->top_y(); - setCursorFromCoordinates(cur.current(), x, y); + setCursorFromCoordinates(cur, x, y); if (cpar == cur.par() && cpos == cur.pos()) { // we have a row which is taller than the workarea. The @@ -313,7 +313,7 @@ void LyXText::cursorNext(LCursor & cur) int x = cur.x_target(); int y = bv()->top_y() + bv()->workHeight(); - setCursorFromCoordinates(cur.current(), x, y); + setCursorFromCoordinates(cur, x, y); if (cpar == cur.par() && cpos == cur.pos()) { // we have a row which is taller than the workarea. The @@ -910,7 +910,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) lyxerr << "SETXY: Could not parse coordinates in '" << cmd.argument << std::endl; else - setCursorFromCoordinates(cur.current(), x, y); + setCursorFromCoordinates(cur, x, y); break; } @@ -1092,7 +1092,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) break; } CursorSlice old = cur.current(); - setCursorFromCoordinates(cur.current(), cmd.x, cmd.y); + setCursorFromCoordinates(cur, cmd.x, cmd.y); // This is to allow jumping over large insets // FIXME: shouldn't be top-text-specific @@ -1147,8 +1147,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd) // Clear the selection cur.clearSelection(); - setCursorFromCoordinates(cur.current(), cmd.x - xo_, - cmd.y - yo_); + setCursorFromCoordinates(cur, cmd.x - xo_, cmd.y - yo_); cur.resetAnchor(); finishUndo(); cur.x_target() = cursorX(cur.current()); -- 2.39.2