]> git.lyx.org Git - features.git/commitdiff
more IU as advertised
authorAndré Pönitz <poenitz@gmx.net>
Fri, 13 Feb 2004 13:51:12 +0000 (13:51 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 13 Feb 2004 13:51:12 +0000 (13:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8431 a592a061-630c-0410-9148-cb99ea01b6c8

25 files changed:
src/BufferView_pimpl.C
src/cursor.C
src/cursor.h
src/cursor_slice.h
src/insets/insetbase.C
src/insets/insetbase.h
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insetexternal.h
src/insets/insetgraphics.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/lyx_cb.C
src/lyx_cb.h
src/lyxrow_funcs.C
src/lyxrow_funcs.h
src/lyxtext.h
src/mathed/math_hullinset.C
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/text.C
src/text2.C
src/text3.C

index e36a500bbf37a62cdebf56c36cd63568302c4269..5880205469c9d0af6debe5f5abfe765fcbbdce08 100644 (file)
@@ -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);
index 1902a16f231ab8cc2424f889a6588912820bfaa0..49859013e3fde7b304c8c94591c643b729be9f77 100644 (file)
@@ -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);
+}
index 5071dcec846db01a2c3e66829ac11137626c5caa..842ff17c63b9aae0797c469dbc8f38c9905be347 100644 (file)
@@ -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
index a06a374222015d7864e1ebbcd2a837358a9c2733..3bf2e31dbe5ea97d02fda4a2bdeecc9e7c868675 100644 (file)
@@ -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_;
index 4a03ba732791c551156ad09e9c37c2fc9534edf6..b8ebb5757fcb6fe150d96fb2aa6717223ac58e86 100644 (file)
@@ -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;
 }
 
 
index a8d458fa346c94a8ec99bcdead58bb176d372cab..607230c532445a2295a48589f967de9636ce042c 100644 (file)
@@ -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;
index 7480b7bb2512a359dc5d8f8cb9e0c588c5b7f585..97f34812d9bdcc82cc33921c1ead4b843c6c10d1 100644 (file)
@@ -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);
 }
 
 
index 761faa9c901a6b8c02a54bfc5bd608884cc71701..e2785d82f338c4688d323f8be37d151c1c92d7d7 100644 (file)
@@ -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:
        ///
index 37114c33af319c99e50097dd616f87d1a92c43b1..5afe94dca027912875c1491208dbf8553da93bbe 100644 (file)
@@ -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:
        ///
index 7c99e11dbdc837d342d391c466fa7dd33a2e2427..a51ca6e2e7953b6f73bf4ce057e6eeee8850d338 100644 (file)
@@ -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;
index b904da704986cdbc038cad3bcc88b6e3b8dc8313..408615b274b2896b482b1734bdef242a59ead703 100644 (file)
@@ -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);
 }
 
index 8214f0a1261c7e24f469310afd852c2d19359a99..4f3647f9bc4a18b6401d1487bc6f8ba4fd8db0b6 100644 (file)
@@ -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);
index 374736f4c21d9e97c4fb3f5c0a281285fd97ec9a..5a619577054556d7ba75b088370a76159c3903b5 100644 (file)
@@ -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));
index 5ede34ee13c23cddaaeada15219c6fad8dffdf8d..ed99e024dfad23c265d9f0eb18cced6a480bf62a 100644 (file)
@@ -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; }
index 5838b29e143b55fd14839a4288a0737d252f8cf8..bdfe5e83f86ef72a3ae719976d93fb78fbad6627 100644 (file)
@@ -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)
index 949f695295cc336553847012e6c252b133e6bf55..67bc2bddd82c954dc8404e6cdb3718bd806bf701 100644 (file)
@@ -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
index e4cd8c26ddd1cd767e0b52edb5716cb9ee24f8a9..ec805f892e415e120dc6af884323568c91fb86e2 100644 (file)
 
 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)
 {
index 66b0288615cf06f942a4f1846843453e921f5b12..2eee7cf2821be054b002d203c91ef592bbf5c8b3 100644 (file)
 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);
 
index 4e25e90dc9ce4442496eecdd3ed9b140b3d96d9b..77ed1ee2b99b93d036f615cdfd1a9def1dee2644 100644 (file)
@@ -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);
index 443240e921db7a051ee1af0ae78c937a5f3590d6..19a1f94e7a614200209b951e53d0a58a90ae9f42 100644 (file)
@@ -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());
index f489193b8221056a84fce4136d1f49495cea0133..99d2b8f4e80c4d5ff471765ccfece32763de0e68 100644 (file)
@@ -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;
 }
 
 
index 471e0bb2829c3d02a9d39a8a904c332bee26002b..58532f31ba0b12500bf6a5bea7e64fe0d66e37a2 100644 (file)
@@ -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;
index 26b682bb1c43126c11efa00b33cc5c4943a6854c..de104b34ca7f197b3088ed842489509e7851956a 100644 (file)
@@ -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;
+}
index ba9912e9b06b52d15236c58a29914befe339c986..de12a7051f435f260881449ed28ea4e69025c162 100644 (file)
@@ -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) {
index ffccff2353d54997140d605919651e2e86425e14..679b1190ed69cd5b26fcc3f7eb81f4beb561d856 100644 (file)
@@ -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());