]> git.lyx.org Git - lyx.git/commitdiff
cursor.diff, bug 1095
authorJohn Levon <levon@movementarian.org>
Sat, 3 May 2003 18:05:53 +0000 (18:05 +0000)
committerJohn Levon <levon@movementarian.org>
Sat, 3 May 2003 18:05:53 +0000 (18:05 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6930 a592a061-630c-0410-9148-cb99ea01b6c8

35 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/ChangeLog
src/bufferview_funcs.C
src/frontends/ChangeLog
src/frontends/qt2/ChangeLog
src/frontends/qt2/qscreen.C
src/frontends/qt2/qscreen.h
src/frontends/screen.C
src/frontends/screen.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/xscreen.C
src/frontends/xforms/xscreen.h
src/insets/ChangeLog
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/insets/insettabular.C
src/insets/insettabular.h
src/insets/insettext.C
src/insets/insettext.h
src/insets/updatableinset.C
src/insets/updatableinset.h
src/lyx_cb.C
src/lyxfind.C
src/lyxfunc.C
src/mathed/ChangeLog
src/mathed/formula.C
src/mathed/formulabase.C
src/mathed/formulabase.h
src/mathed/formulamacro.C
src/mathed/math_cursor.C
src/text.C
src/text3.C

index b6e81d75690bf7a742ac795f3b77de21f3b6c515..914e9abb59bc8852d1d3c1673b84a6a70325fed2 100644 (file)
@@ -223,18 +223,6 @@ int BufferView::workWidth() const
 }
 
 
-void BufferView::showCursor()
-{
-       pimpl_->showCursor();
-}
-
-
-void BufferView::hideCursor()
-{
-       pimpl_->hideCursor();
-}
-
-
 void BufferView::toggleSelection(bool b)
 {
        pimpl_->toggleSelection(b);
@@ -585,7 +573,6 @@ void BufferView::undo()
                return;
 
        owner()->message(_("Undo"));
-       hideCursor();
        beforeChange(text);
        update(text, BufferView::SELECT);
        if (!textUndo(this))
@@ -602,7 +589,6 @@ void BufferView::redo()
                return;
 
        owner()->message(_("Redo"));
-       hideCursor();
        beforeChange(text);
        update(text, BufferView::SELECT);
        if (!textRedo(this))
@@ -631,7 +617,6 @@ void BufferView::selectLastWord()
                return;
 
        LyXCursor cur = text->selection.cursor;
-       hideCursor();
        beforeChange(text);
        text->selection.cursor = cur;
        text->selectSelectedWord();
@@ -644,7 +629,6 @@ void BufferView::endOfSpellCheck()
 {
        if (!available()) return;
 
-       hideCursor();
        beforeChange(text);
        text->selectSelectedWord();
        text->clearSelection();
@@ -658,7 +642,6 @@ void BufferView::replaceWord(string const & replacestring)
                return;
 
        LyXText * tt = getLyXText();
-       hideCursor();
        update(tt, BufferView::SELECT);
 
        // clear the selection (if there is any)
@@ -729,44 +712,6 @@ bool BufferView::lockInset(UpdatableInset * inset)
 }
 
 
-void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
-{
-       if (available() && theLockingInset() && !theLockingInset()->nodraw()) {
-               LyXCursor cursor = text->cursor;
-               Inset * locking_inset = theLockingInset()->getLockingInset();
-
-               if ((cursor.pos() - 1 >= 0) &&
-                   cursor.par()->isInset(cursor.pos() - 1) &&
-                   (cursor.par()->getInset(cursor.pos() - 1) ==
-                    locking_inset))
-                       text->setCursor(cursor,
-                                       cursor.par(), cursor.pos() - 1);
-               LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
-               LyXText * txt = getLyXText();
-               if (locking_inset->isTextInset() &&
-                   locking_inset->lyxCode() != Inset::ERT_CODE &&
-                   (txt->real_current_font.language() !=
-                    buffer()->params.language
-                    || txt->real_current_font.isVisibleRightToLeft()
-                    != buffer()->params.language->RightToLeft()))
-                       shape = (txt->real_current_font.isVisibleRightToLeft())
-                               ? LyXScreen::REVERSED_L_SHAPE
-                               : LyXScreen::L_SHAPE;
-               y += cursor.iy() + theLockingInset()->insetInInsetY();
-               screen().showManualCursor(text, x, y, asc, desc,
-                                                 shape);
-       }
-}
-
-
-void BufferView::hideLockedInsetCursor()
-{
-       if (theLockingInset() && available()) {
-               screen().hideCursor();
-       }
-}
-
-
 bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 {
        if (theLockingInset() && available()) {
@@ -780,6 +725,12 @@ bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
 }
 
 
+void BufferView::hideCursor()
+{
+       screen().hideCursor();
+}
+
+
 int BufferView::unlockInset(UpdatableInset * inset)
 {
        if (!inset)
index 13053325051f971203d4c7dc636cfc18ea9dd69b..9a586251083ef43b4ecd560154051a44983d897a 100644 (file)
@@ -167,14 +167,6 @@ public:
        /// Inserts a lyx file at cursor position. return false if it fails
        bool insertLyXFile(string const & file);
 
-       /// show the user cursor
-       void showCursor();
-       /// hide the user cursor
-       void hideCursor();
-       /// FIXME
-       void showLockedInsetCursor(int x, int y, int asc, int desc);
-       /// FIXME
-       void hideLockedInsetCursor();
        /// FIXME
        bool fitLockedInsetCursor(int x, int y, int asc, int desc);
        /// FIXME
@@ -184,6 +176,9 @@ public:
        /// FIXME: my word !
        void toggleToggle();
 
+       /// hide the cursor if it is visible
+       void hideCursor();
+
        /// center the document view around the cursor
        void center();
        /// scroll document by the given number of lines of default height
index a2f74e21a1a8148baacdd20a54010cc0e0d176cd..d78862cb72535527d68fb1ee440710ec794fb7d2 100644 (file)
@@ -377,6 +377,8 @@ void BufferView::Pimpl::scrollDocView(int value)
        if (!buffer_)
                return;
 
+       screen().hideCursor();
+
        screen().draw(bv_->text, bv_, value);
 
        if (!lyxrc.cursor_follows_scrollbar)
@@ -424,6 +426,18 @@ void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key,
                                         key_modifier::state state)
 {
        bv_->owner()->getLyXFunc().processKeySym(key, state);
+
+       /* This is perhaps a bit of a hack. When we move
+        * around, or type, it's nice to be able to see
+        * the cursor immediately after the keypress. So
+        * we reset the toggle timeout and force the visibility
+        * of the cursor. Note we cannot do this inside
+        * dispatch() itself, because that's called recursively.
+        */
+       if (available()) {
+               cursor_timeout.restart();
+               screen().showCursor(*bv_);
+       }
 }
 
 
@@ -456,10 +470,9 @@ void BufferView::Pimpl::selectionRequested()
 void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
-               hideCursor();
+               screen().hideCursor();
                toggleSelection();
                bv_->getLyXText()->clearSelection();
-               showCursor();
                bv_->text->xsel_cache.set(false);
        }
 }
@@ -565,11 +578,7 @@ void BufferView::Pimpl::cursorToggle()
                return;
        }
 
-       if (!bv_->theLockingInset()) {
-               screen().cursorToggle(bv_);
-       } else {
-               bv_->theLockingInset()->toggleInsetCursor(bv_);
-       }
+       screen().toggleCursor(*bv_);
 
        cursor_timeout.restart();
 }
@@ -698,22 +707,6 @@ void BufferView::Pimpl::insetUnlock()
 }
 
 
-void BufferView::Pimpl::showCursor()
-{
-       if (bv_->theLockingInset())
-               bv_->theLockingInset()->showInsetCursor(bv_);
-       else
-               screen().showCursor(bv_->text, bv_);
-}
-
-
-void BufferView::Pimpl::hideCursor()
-{
-       if (!bv_->theLockingInset())
-               screen().hideCursor();
-}
-
-
 void BufferView::Pimpl::toggleSelection(bool b)
 {
        if (bv_->theLockingInset())
@@ -935,8 +928,14 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & ev_in)
        if (!available())
                return false;
 
+       screen().hideCursor();
+
        bool const res = dispatch(ev_in);
 
+       // see workAreaKeyPress
+       cursor_timeout.restart();
+       screen().showCursor(*bv_);
+
        // FIXME: we should skip these when selecting
        bv_->owner()->updateLayoutChoice();
        bv_->owner()->updateToolbar();
@@ -1367,7 +1366,6 @@ void BufferView::Pimpl::updateInset(Inset * inset)
        Inset * tl_inset = inset;
        while (tl_inset->owner())
                tl_inset = tl_inset->owner();
-       hideCursor();
        if (tl_inset == inset) {
                update(BufferView::UPDATE);
                if (bv_->text->updateInset(inset)) {
index 761d1911dcc66306ebe973eaf8eb5bc2efabf190..0f2ad9f51b28c0c3df7dfea9d662f310892c6073 100644 (file)
@@ -89,10 +89,6 @@ struct BufferView::Pimpl : public boost::signals::trackable {
        ///
        void insetUnlock();
        ///
-       void showCursor();
-       ///
-       void hideCursor();
-       ///
        void toggleSelection(bool = true);
        ///
        void toggleToggle();
index 523559305d1138b797dad003c5474e1851677c3a..1083c2906a36940009cdf02fd6d6555d07ca81bf 100644 (file)
@@ -1,3 +1,19 @@
+2003-05-03  John Levon  <levon@movementarian.org>
+
+       * BufferView.h:
+       * BufferView.C: remove showLockedInsetCursor(), showCursor(),
+       explicit cursor show/hide
+
+       * BufferView_pimpl.h:
+       * BufferView_pimpl.C: hide cursor before dispatching. Show cursor
+       after a cursor move lfun. Simplify cursorToggle(). Remove show/hideCursor().
+
+       * lyxfunc.C: hide cursor before dispatching.
+
+       * lyx_cb.C:
+       * lyxfind.C:
+       * text.C:
+       * text3.C: remove explicit cursor hides
 
 2003-05-02 André Pönitz <poenitz@gmx.net>
 
index c7f640a03a8e38dd2c5d7e2ab5517a07ddf43d09..a1782c0121d351f5c3f5fbe9a0a80bb5c7c0155e 100644 (file)
@@ -226,7 +226,6 @@ bool changeDepth(BufferView * bv, LyXText * text, DEPTH_CHANGE type, bool test_o
        if (test_only)
                return text->changeDepth(type, true);
 
-       bv->hideCursor();
        bv->update(BufferView::SELECT);
        bool const changed = text->changeDepth(type, false);
        if (text->inset_owner)
@@ -390,7 +389,6 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
        if (!text)
                return;
 
-       bv->hideCursor();
        bv->update(text, BufferView::SELECT);
        text->toggleFree(font, toggleall);
        bv->update(text, BufferView::SELECT);
index b8f3e1c6ed7b11f592a36ce6e0eac3decaf508b9..82a4c841927590e34d1a193552143a1935b26f74 100644 (file)
@@ -1,3 +1,10 @@
+2003-05-03  John Levon  <levon@movementarian.org>
+
+       * screen.h:
+       * screen.C: replace cursor code with simpler variant
+       that calculates the cursor pos via inset inspector. Hide
+       the cursor before a paint. Make Cursor_Shape protected.
+
 2003-04-27  John Levon  <levon@movementarian.org>
 
        * Alert.h:
index d3fbc805decd58e439a9cda0637d7637a2279275..d9bf35f2eaadc019c7b79682f84fd10085ec1930 100644 (file)
@@ -1,3 +1,8 @@
+2003-05-03  John Levon  <levon@movementarian.org>
+
+       * qscreen.h:
+       * qscreen.C: implement new cursor API
+
 2003-04-29  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * QPrefs.C (apply): only set colors if they are different from
index 185007700b60f62759738ddee439aff8b3652aef..55c873413dbdc2d64453049c4b619225305e0a54 100644 (file)
@@ -52,90 +52,6 @@ QScreen::~QScreen()
 }
 
 
-void QScreen::showManualCursor(LyXText const * text, int x, int y,
-                                int asc, int desc, Cursor_Shape shape)
-{
-       if (!qApp->focusWidget())
-               return;
-
-       int const y1 = max(y - text->top_y() - asc, 0);
-       int const y_tmp = min(y - text->top_y() + desc, owner_.height());
-
-       // secure against very strange situations
-       // which would be when .... ?
-       int const y2 = max(y_tmp, y1);
-
-       if (y2 > 0 && y1 < owner_.height()) {
-               cursor_h_ = y2 - y1 + 1;
-               cursor_y_ = y1;
-
-               switch (shape) {
-               case BAR_SHAPE:
-                       cursor_w_ = 1;
-                       cursor_x_ = x;
-                       break;
-               case L_SHAPE:
-                       cursor_w_ = cursor_h_ / 3;
-                       cursor_x_ = x;
-                       break;
-               case REVERSED_L_SHAPE:
-                       cursor_w_ = cursor_h_ / 3;
-                       cursor_x_ = x - cursor_w_ + 1;
-                       break;
-               }
-
-               if (!nocursor_pixmap_.get()
-                       || cursor_w_ != nocursor_pixmap_->width()
-                       || cursor_h_ != nocursor_pixmap_->height()) {
-                       nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
-               }
-
-               owner_.getPainter().start();
-
-               // save old area
-               bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
-                       cursor_x_, cursor_y_, cursor_w_, cursor_h_);
-
-               owner_.getPainter().line(x, y1, x, y2, LColor::cursor);
-               switch (shape) {
-               case BAR_SHAPE:
-                       break;
-               case L_SHAPE:
-               case REVERSED_L_SHAPE:
-                       int const rectangle_h = (cursor_h_ + 10) / 20;
-                       owner_.getPainter().fillRectangle(
-                               cursor_x_, y2 - rectangle_h + 1,
-                               cursor_w_ - 1, rectangle_h, LColor::cursor);
-                       break;
-               }
-
-               owner_.getPainter().end();
-
-               owner_.getContent()->repaint(
-                       cursor_x_, cursor_y_,
-                       cursor_w_, cursor_h_);
-
-       }
-       cursor_visible_ = true;
-}
-
-
-void QScreen::hideCursor()
-{
-       if (!cursor_visible_)
-               return;
-
-       bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
-               nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
-
-       owner_.getContent()->repaint(
-               cursor_x_, cursor_y_,
-               cursor_w_, cursor_h_);
-
-       cursor_visible_ = false;
-}
-
-
 void QScreen::repaint()
 {
        QWidget * content(owner_.getContent());
@@ -158,8 +74,6 @@ void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
 
        owner_.getPainter().start();
 
-       if (cursor_visible_) hideCursor();
-
        int const old_first = text->top_y();
        text->top_y(y);
 
@@ -188,3 +102,72 @@ void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
 
        owner_.getPainter().end();
 }
+
+
+void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
+{
+       cursor_x_ = x;
+       cursor_y_ = y;
+       cursor_h_ = h;
+
+       switch (shape) {
+               case BAR_SHAPE:
+                       cursor_w_ = 1;
+                       break;
+               case L_SHAPE:
+                       cursor_w_ = cursor_h_ / 3;
+                       break;
+               case REVERSED_L_SHAPE:
+                       cursor_w_ = cursor_h_ / 3;
+                       cursor_x_ = x - cursor_w_ + 1;
+                       break;
+       }
+
+       if (!nocursor_pixmap_.get()
+               || cursor_w_ != nocursor_pixmap_->width()
+               || cursor_h_ != nocursor_pixmap_->height()) {
+               nocursor_pixmap_.reset(new QPixmap(cursor_w_, cursor_h_));
+       }
+
+       // save old area
+       bitBlt(nocursor_pixmap_.get(), 0, 0, owner_.getPixmap(),
+               cursor_x_, cursor_y_, cursor_w_, cursor_h_);
+
+       if (!qApp->focusWidget())
+               return;
+
+       Painter & pain(owner_.getPainter());
+       pain.start();
+       pain.line(x, y, x, y + h - 1, LColor::cursor);
+
+       switch (shape) {
+               case BAR_SHAPE:
+                       break;
+               case REVERSED_L_SHAPE:
+               case L_SHAPE:
+                       pain.line(cursor_x_, y + h - 1, cursor_x_ + cursor_w_ - 1,
+                               y + h - 1, LColor::cursor);
+                       break;
+       }
+
+       pain.end();
+
+       owner_.getContent()->repaint(
+               cursor_x_, cursor_y_,
+               cursor_w_, cursor_h_);
+}
+
+
+void QScreen::removeCursor()
+{
+       // before first showCursor
+       if (!nocursor_pixmap_.get())
+               return;
+
+       bitBlt(owner_.getPixmap(), cursor_x_, cursor_y_,
+               nocursor_pixmap_.get(), 0, 0, cursor_w_, cursor_h_);
+
+       owner_.getContent()->repaint(
+               cursor_x_, cursor_y_,
+               cursor_w_, cursor_h_);
+}
index 22e8ee3160f94c70d6fe47a349f9a0c1527114f3..0ec97f94a94b7a9e0a3f02d884b87578e4a85338 100644 (file)
@@ -37,22 +37,6 @@ public:
         */
        virtual void draw(LyXText *, BufferView *, unsigned int y);
 
-       /**
-        * showManualCursor - display the caret on the work area
-        * @param text the lyx text containing the cursor
-        * @param x the x position of the cursor
-        * @param y the y position of the row's baseline
-        * @param asc ascent of the row
-        * @param desc descent of the row
-        * @param shape the current shape
-        */
-       virtual void showManualCursor(LyXText const *, int x, int y,
-                             int asc, int desc,
-                             Cursor_Shape shape);
-
-       /// unpaint the cursor painted by showManualCursor()
-       virtual void hideCursor();
-
 protected:
        /// get the work area
        virtual WorkArea & workarea() const { return owner_; }
@@ -63,11 +47,16 @@ protected:
        /// copies specified area of pixmap to screen
        virtual void expose(int x, int y, int exp_width, int exp_height);
 
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
+
+       /// hide the cursor
+       virtual void removeCursor();
+
 private:
        /// our owning widget
        QWorkArea & owner_;
 
-       /// the mini-pixmap used for backing store for the blinking cursor
        boost::scoped_ptr<QPixmap> nocursor_pixmap_;
 
        //@{ the cursor pixmap position/size
index 2e98ad9cba26e2c045f3d2971273855f61cc71af..0ec0a0daee28bb867f5362bd379ae41b176baaf0 100644 (file)
@@ -25,6 +25,8 @@
 #include "language.h"
 #include "debug.h"
 #include "rowpainter.h"
+#include "insets/updatableinset.h"
+#include "mathed/formulabase.h"
 
 // Splash screen-specific stuff
 #include "lyxfont.h"
@@ -126,33 +128,89 @@ LyXScreen::~LyXScreen()
 {
 }
 
-// FIXME: GUII these cursor methods need to decide
-// whether the workarea is focused or not
 
-void LyXScreen::showCursor(LyXText const * text, BufferView const * bv)
+void LyXScreen::showCursor(BufferView & bv)
 {
        if (cursor_visible_)
                return;
 
-       workarea().getPainter().start();
+       if (!bv.available())
+               return;
 
        Cursor_Shape shape = BAR_SHAPE;
-       BufferParams const & bp(bv->buffer()->params);
-       LyXFont const & realfont(text->real_current_font);
-
-       if (realfont.language() != bp.language
-               || realfont.isVisibleRightToLeft()
-               != bp.language->RightToLeft()) {
-               shape = (realfont.isVisibleRightToLeft())
-                       ? REVERSED_L_SHAPE : L_SHAPE;
+
+       LyXText const & text = *bv.getLyXText();
+       LyXFont const & realfont(text.real_current_font);
+       BufferParams const & bp(bv.buffer()->params);
+       bool const samelang = realfont.language() == bp.language;
+       bool const isrtl = realfont.isVisibleRightToLeft();
+
+       if (!samelang || isrtl != bp.language->RightToLeft()) {
+               shape = L_SHAPE;
+               if (isrtl)
+                       shape = REVERSED_L_SHAPE;
        }
 
-       showManualCursor(text, text->cursor.x(), text->cursor.y(),
-               font_metrics::maxAscent(realfont),
-               font_metrics::maxDescent(realfont),
-               shape);
+       int ascent = font_metrics::maxAscent(realfont);
+       int descent = font_metrics::maxDescent(realfont);
+       int h = ascent + descent;
+       int x = 0;
+       int y = 0;
+       int const top_y = bv.text->top_y();
+
+       if (bv.theLockingInset()) {
+               // Would be nice to clean this up to make some understandable sense...
+               UpdatableInset * inset = bv.theLockingInset();
+               inset->getCursor(bv, x, y);
+
+               // Non-obvious. The reason we have to have these
+               // extra checks is that the ->getCursor() calls rely
+               // on the inset's own knowledge of its screen position.
+               // If we scroll up or down in a big enough increment, the
+               // inset->draw() is not called: this doesn't update
+               // inset.top_baseline, so getCursor() returns an old value.
+               // Ugly as you like.
+               int bx, by;
+               inset->getCursorPos(&bv, bx, by);
+               by += inset->insetInInsetY() + bv.text->cursor.iy();
+               if (by < top_y)
+                       return;
+               if (by > top_y + workarea().workHeight())
+                       return;
+       } else {
+               x = bv.text->cursor.x();
+               y = bv.text->cursor.y();
+               y -= top_y;
+       }
 
-       workarea().getPainter().end();
+       y -= ascent;
+
+       // if it doesn't fit entirely on the screen, don't try to show it
+       if (y < 0 || y + h > workarea().workHeight())
+               return;
+
+       showCursor(x, y, h, shape);
+
+       cursor_visible_ = true;
+}
+
+
+void LyXScreen::hideCursor()
+{
+       if (!cursor_visible_)
+               return;
+
+       removeCursor();
+       cursor_visible_ = false;
+}
+
+
+void LyXScreen::toggleCursor(BufferView & bv)
+{
+       if (cursor_visible_)
+               hideCursor();
+       else
+               showCursor(bv);
 }
 
 
@@ -181,15 +239,6 @@ bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text,
 }
 
 
-void LyXScreen::cursorToggle(BufferView * bv) const
-{
-       if (cursor_visible_)
-               bv->hideCursor();
-       else
-               bv->showCursor();
-}
-
-
 unsigned int LyXScreen::topCursorVisible(LyXCursor const & cursor, int top_y)
 {
        int const vheight = workarea().workHeight();
@@ -365,11 +414,6 @@ void LyXScreen::redraw(LyXText * text, BufferView * bv)
        expose(0, 0, workarea().workWidth(), workarea().workHeight());
 
        workarea().getPainter().end();
-
-       if (cursor_visible_) {
-               cursor_visible_ = false;
-               bv->showCursor();
-       }
 }
 
 
@@ -421,6 +465,8 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
        int y = y_text - topy;
        // y1 is now the real beginning of row on the screen
 
+       hideCursor();
+
        RowList::iterator const rend = text->rows().end();
        while (rit != rend && y < y2) {
                RowPainter rp(*bv, *text, rit);
@@ -450,6 +496,8 @@ void LyXScreen::drawOneRow(LyXText * text, BufferView * bv,
        if (y - row->height() > workarea().workHeight())
                return;
 
+       hideCursor();
+
        RowPainter rp(*bv, *text, row);
        rp.paint(y, xo, y + text->top_y());
 }
index 0c9c1b42336df49d785d4e8ed8bc43abbf212bbd..282dfc474691eede5a390270f7762725d5b168f0 100644 (file)
@@ -34,16 +34,6 @@ class BufferView;
  */
 class LyXScreen {
 public:
-       /// types of cursor in work area
-       enum Cursor_Shape {
-               /// normal I-beam
-               BAR_SHAPE,
-               /// L-shape for locked insets of a different language
-               L_SHAPE,
-               /// reverse L-shape for RTL text
-               REVERSED_L_SHAPE
-       };
-
        LyXScreen();
 
        virtual ~LyXScreen();
@@ -56,22 +46,6 @@ public:
         */
        virtual void draw(LyXText *, BufferView *, unsigned int y) = 0;
 
-       /**
-        * showManualCursor - display the cursor on the work area
-        * @param text the lyx text containing the cursor
-        * @param x the x position of the cursor
-        * @param y the y position of the row's baseline
-        * @param asc ascent of the row
-        * @param desc descent of the row
-        * @param shape the current shape
-        */
-       virtual void showManualCursor(LyXText const *, int x, int y,
-                             int asc, int desc,
-                             Cursor_Shape shape) = 0;
-
-       /// unpaint the cursor painted by showManualCursor()
-       virtual void hideCursor() = 0;
-
        /**
         * fit the cursor onto the visible work area, scrolling if necessary
         * @param bv the buffer view
@@ -89,9 +63,6 @@ public:
        /// redraw the screen, without using existing pixmap
        virtual void redraw(LyXText *, BufferView *);
 
-       /// draw the cursor if it's not already shown
-       virtual void showCursor(LyXText const *, BufferView const *);
-
        /**
         * topCursorVisible - get a new "top" to make the cursor visible
         * @param c the cursor
@@ -113,9 +84,6 @@ public:
         */
        virtual bool fitCursor(LyXText *, BufferView *);
 
-       /// show the cursor if it's not, and vice versa
-       virtual void cursorToggle(BufferView *) const;
-
        /**
         * update - update part of the screen rendering
         * @param bv the bufferview
@@ -130,6 +98,15 @@ public:
         */
        virtual void update(BufferView & bv, int yo = 0, int xo = 0);
 
+       /// hide the visible cursor, if it is visible
+       void hideCursor();
+       
+       /// show the cursor if it is not visible
+       void showCursor(BufferView & bv);
+
+       /// toggle the cursor's visibility
+       void toggleCursor(BufferView & bv);
+
        /// FIXME
        virtual void toggleSelection(LyXText *, BufferView *, bool = true,
                             int y_offset = 0, int x_offset = 0);
@@ -145,6 +122,22 @@ protected:
        /// get the work area
        virtual WorkArea & workarea() const = 0;
 
+       /// types of cursor in work area
+       enum Cursor_Shape {
+               /// normal I-beam
+               BAR_SHAPE,
+               /// L-shape for locked insets of a different language
+               L_SHAPE,
+               /// reverse L-shape for RTL text
+               REVERSED_L_SHAPE
+       };
+
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape) = 0;
+
+       /// hide the cursor
+       virtual void removeCursor() = 0;
+
        /// y1 and y2 are coordinates of the screen
        void drawFromTo(LyXText *, BufferView *, int y1, int y2,
                        int y_offset = 0, int x_offset = 0);
@@ -154,13 +147,13 @@ protected:
                        RowList::iterator row,
                        int y_text, int y_offset = 0, int x_offset = 0);
 
-       /// is the blinking cursor currently drawn
-       bool cursor_visible_;
-
 private:
        /// grey out (no buffer)
        void greyOut();
 
+       /// is the cursor currently displayed
+       bool cursor_visible_;
+
        /// is the screen displaying text or the splash screen?
        bool greyed_out_;
 };
index ab0d8d2e42c2864b0536eb9ec47d1043ab68e33b..34ac8d45e5435eea72e727c859765ba0fd6e6c5f 100644 (file)
@@ -1,3 +1,8 @@
+2003-05-03  John Levon  <levon@movementarian.org>
+
+       * xscreen.h:
+       * xscreen.C: implement new cursor API
+
 2003-04-30  John Levon  <levon@movementarian.org>
 
        * Form<Various>: fix dialog titles to match new menus
index 5e90484300657acf86c57d89fe26826687c3db09..c8ca235ce2e0643016314e2a30f59a369f554e3f 100644 (file)
@@ -55,15 +55,9 @@ GC createGC()
 
 
 XScreen::XScreen(XWorkArea & o)
-       : LyXScreen(), owner_(o)
+       : LyXScreen(), owner_(o), nocursor_pixmap_(0),
+       cursor_x_(0), cursor_y_(0), cursor_w_(0), cursor_h_(0)
 {
-       // the cursor isnt yet visible
-       cursor_pixmap = 0;
-       cursor_pixmap_x = 0;
-       cursor_pixmap_y = 0;
-       cursor_pixmap_w = 0;
-       cursor_pixmap_h = 0;
-
        // We need this GC
        gc_copy = createGC();
 }
@@ -89,100 +83,77 @@ void XScreen::setCursorColor()
 }
 
 
-void XScreen::showManualCursor(LyXText const * text, int x, int y,
-                                int asc, int desc, Cursor_Shape shape)
+void XScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
 {
-       // Update the cursor color.
+       // Update the cursor color. (a little slow dooing it like this ??)
        setCursorColor();
 
-       int const y1 = max(y - text->top_y() - asc, 0);
-       int const y_tmp = min(y - text->top_y() + desc,
-                             static_cast<int>(owner_.workHeight()));
-
-       // Secure against very strange situations
-       int const y2 = max(y_tmp, y1);
-
-       if (cursor_pixmap) {
-               XFreePixmap(fl_get_display(), cursor_pixmap);
-               cursor_pixmap = 0;
-       }
-
-       if (y2 > 0 && y1 < int(owner_.workHeight())) {
-               cursor_pixmap_h = y2 - y1 + 1;
-               cursor_pixmap_y = y1;
+       cursor_x_ = x;
+       cursor_y_ = y;
+       cursor_h_ = h;
 
-               switch (shape) {
+       switch (shape) {
                case BAR_SHAPE:
-                       cursor_pixmap_w = 1;
-                       cursor_pixmap_x = x;
+                       cursor_w_ = 1;
                        break;
                case L_SHAPE:
-                       cursor_pixmap_w = cursor_pixmap_h/3;
-                       cursor_pixmap_x = x;
+                       cursor_w_ = cursor_h_ / 3;
                        break;
                case REVERSED_L_SHAPE:
-                       cursor_pixmap_w = cursor_pixmap_h/3;
-                       cursor_pixmap_x = x - cursor_pixmap_w + 1;
+                       cursor_w_ = cursor_h_ / 3;
+                       cursor_x_ = x - cursor_w_ + 1;
                        break;
-               }
+       }
+
+       if (nocursor_pixmap_) {
+               XFreePixmap(fl_get_display(), nocursor_pixmap_);
+               nocursor_pixmap_ = 0;
+       }
+       nocursor_pixmap_ = XCreatePixmap(fl_get_display(),
+               fl_root, cursor_w_, cursor_h_, fl_get_visual_depth());
 
-               cursor_pixmap =
-                       XCreatePixmap (fl_get_display(),
-                                      fl_root,
-                                      cursor_pixmap_w,
-                                      cursor_pixmap_h,
-                                      fl_get_visual_depth());
-               XCopyArea (fl_get_display(),
-                          owner_.getWin(),
-                          cursor_pixmap,
-                          gc_copy,
-                          owner_.xpos() + cursor_pixmap_x,
-                          owner_.ypos() + cursor_pixmap_y,
-                          cursor_pixmap_w,
-                          cursor_pixmap_h,
-                          0, 0);
-               XDrawLine(fl_get_display(),
-                         owner_.getWin(),
-                         gc_copy,
-                         x + owner_.xpos(),
-                         y1 + owner_.ypos(),
-                         x + owner_.xpos(),
-                         y2 + owner_.ypos());
-               switch (shape) {
+       // save old area
+       XCopyArea(fl_get_display(),
+               owner_.getWin(), nocursor_pixmap_, gc_copy,
+               owner_.xpos() + cursor_x_,
+               owner_.ypos() + cursor_y_,
+               cursor_w_, cursor_h_, 0, 0);
+
+// xforms equivalent needed here
+#if 0
+       if (!qApp->focusWidget())
+               return;
+#endif
+
+       XDrawLine(fl_get_display(), owner_.getWin(), gc_copy,
+               owner_.xpos() + x, owner_.ypos() + y,
+               owner_.xpos() + x, owner_.ypos() + y + h - 1);
+
+       switch (shape) {
                case BAR_SHAPE:
                        break;
-               case L_SHAPE:
                case REVERSED_L_SHAPE:
-                       int const rectangle_h = (cursor_pixmap_h + 10) / 20;
-                       XFillRectangle(fl_get_display(),
-                                      owner_.getWin(),
-                                      gc_copy,
-                                      cursor_pixmap_x + owner_.xpos(),
-                                      y2 - rectangle_h + 1 + owner_.ypos(),
-                                      cursor_pixmap_w - 1, rectangle_h);
+               case L_SHAPE:
+                       XDrawLine(fl_get_display(), owner_.getWin(), gc_copy,
+                               owner_.xpos() + cursor_x_,
+                               owner_.ypos() + y + h - 1,
+                               owner_.xpos() + cursor_x_ + cursor_w_ - 1,
+                               owner_.ypos() + y + h - 1);
                        break;
-               }
-
        }
-       cursor_visible_ = true;
 }
 
 
-void XScreen::hideCursor()
+void XScreen::removeCursor()
 {
-       if (!cursor_visible_) return;
-
-       if (cursor_pixmap) {
-               XCopyArea (fl_get_display(),
-                          cursor_pixmap,
-                          owner_.getWin(),
-                          gc_copy,
-                          0, 0,
-                          cursor_pixmap_w, cursor_pixmap_h,
-                          cursor_pixmap_x + owner_.xpos(),
-                          cursor_pixmap_y + owner_.ypos());
-       }
-       cursor_visible_ = false;
+       // before first showCursor
+       if (!nocursor_pixmap_)
+               return;
+
+       XCopyArea(fl_get_display(), nocursor_pixmap_, owner_.getWin(),
+               gc_copy, 0, 0, cursor_w_, cursor_h_,
+               owner_.xpos() + cursor_x_,
+               owner_.ypos() + cursor_y_);
 }
 
 
@@ -202,9 +173,6 @@ void XScreen::expose(int x, int y, int w, int h)
 
 void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
 {
-       if (cursor_visible_)
-               hideCursor();
-
        int const old_first = text->top_y();
        text->top_y(y);
 
index 584c4f2d5b49a7092ff368d0363cc44895b89f70..dbae69a21dc0a16f35b308f6a06776ef27bc97a6 100644 (file)
@@ -34,12 +34,6 @@ public:
 
        /// Sets the cursor color to LColor::cursor.
        virtual void setCursorColor();
-       ///
-       virtual void hideCursor();
-       ///
-       virtual void showManualCursor(LyXText const *, int x, int y,
-                             int asc, int desc,
-                             Cursor_Shape shape);
 
        /** Draws the screen form textposition y. Uses as much of
            the already printed pixmap as possible */
@@ -52,21 +46,27 @@ protected:
        /// Copies specified area of pixmap to screen
        virtual void expose(int x, int y, int w, int h);
 
+       /// paint the cursor and store the background
+       virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
+
+       /// hide the cursor
+       virtual void removeCursor();
+
 private:
        /// our owning widget
        XWorkArea & owner_;
 
-       ///
-       Pixmap cursor_pixmap;
-       ///
-       int cursor_pixmap_x;
-       ///
-       int cursor_pixmap_y;
-       ///
-       int cursor_pixmap_w;
-       ///
-       int cursor_pixmap_h;
-       ///
+       /// backing pixmap for cursor
+       Pixmap nocursor_pixmap_;
+       /// x of backing pixmap
+       int cursor_x_;
+       /// y of backing pixmap
+       int cursor_y_;
+       /// width of backing pixmap
+       int cursor_w_;
+       /// height of backing pixmap
+       int cursor_h_;
+       /// cursor cs
        GC gc_copy;
 };
 
index 6dc4d6d5183cf79e61983159d680a9dbded0dfa0..f5cbd637a209a8690ebb0a291ef4a3e6383ee68c 100644 (file)
@@ -1,3 +1,16 @@
+2003-05-03  John Levon  <levon@movementarian.org>
+
+       * insetcollapsable.h:
+       * insetcollapsable.C:
+       * insettabular.h:
+       * insettabular.C:
+       * insettext.h:
+       * insettext.C:
+       * updatableinset.h:
+       * updatableinset.C: remove cursor_visible_, showInsetCursor(),
+       hideInsetCursor(), toggleInsetCursor(), isCursorVisible(). Add
+       getCursor(). Remove explicit cursor hides.
+
 2003-05-02 André Pönitz <poenitz@gmx.net>
 
        * insettext.C: remove unneeded &*
index fe7a15c767806b21a271c74a3c3683f06b4e3198..7f2a9f9712a4495ee617a27226d2c147474cfbea 100644 (file)
@@ -491,27 +491,15 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const
 }
 
 
-void InsetCollapsable::getCursorPos(BufferView * bv, int & x, int & y) const
-{
-       inset.getCursorPos(bv, x , y);
-}
-
-
-void InsetCollapsable::toggleInsetCursor(BufferView * bv)
+void InsetCollapsable::getCursor(BufferView & bv, int & x, int & y) const
 {
-       inset.toggleInsetCursor(bv);
+       inset.getCursor(bv, x, y);
 }
 
 
-void InsetCollapsable::showInsetCursor(BufferView * bv, bool show)
-{
-       inset.showInsetCursor(bv, show);
-}
-
-
-void InsetCollapsable::hideInsetCursor(BufferView * bv)
+void InsetCollapsable::getCursorPos(BufferView * bv, int & x, int & y) const
 {
-       inset.hideInsetCursor(bv);
+       inset.getCursorPos(bv, x , y);
 }
 
 
index c6932a02004a57be37c70d1b26483def770352ef..e755d3f19508d260b1383990dc884a7b624ac799 100644 (file)
@@ -97,14 +97,10 @@ public:
        int docbook(Buffer const *, std::ostream &, bool mixcont) const;
        ///
        void validate(LaTeXFeatures & features) const;
-       ///
+       /// FIXME, document
        void getCursorPos(BufferView *, int & x, int & y) const;
-       ///
-       void toggleInsetCursor(BufferView *);
-       ///
-       void showInsetCursor(BufferView *, bool show = true);
-       ///
-       void hideInsetCursor(BufferView *);
+       /// Get the absolute document x,y of the cursor
+       virtual void getCursor(BufferView &, int &, int &) const;
        ///
        void fitInsetCursor(BufferView * bv) const {
                inset.fitInsetCursor(bv);
index f0289be73b7c63c948efe13d6ad1fb1270f32556..23ea3059c70e1868b4a6d9fc9f324d48bac370a8 100644 (file)
@@ -499,7 +499,6 @@ void InsetTabular::insetUnlock(BufferView * bv)
                updateLocal(bv, CELL);
                the_locking_inset = 0;
        }
-       hideInsetCursor(bv);
        actcell = 0;
        oldcell = -1;
        locked = false;
@@ -590,7 +589,6 @@ bool InsetTabular::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                updateLocal(bv, CELL);
                // this has to be here otherwise we don't redraw the cell!
                the_locking_inset = 0;
-//             showInsetCursor(bv, false);
                return true;
        }
        if (the_locking_inset->unlockInsetInInset(bv, inset, lr)) {
@@ -672,7 +670,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
        int const orow = actrow;
        BufferView * bv = cmd.view();
 
-       hideInsetCursor(bv);
        if (!locked) {
                locked = true;
                the_locking_inset = 0;
@@ -690,7 +687,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
                        updateLocal(bv, CELL);
                        the_locking_inset = 0;
                }
-               showInsetCursor(bv);
                return;
        }
 #endif
@@ -730,7 +726,6 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
                the_locking_inset->localDispatch(cmd1);
                return;
        }
-       showInsetCursor(bv);
 }
 
 
@@ -763,7 +758,6 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
        }
 
        BufferView * bv = cmd.view();
-       hideInsetCursor(bv);
        int const old_cell = actcell;
 
        setPos(bv, cmd.x, cmd.y);
@@ -774,7 +768,6 @@ void InsetTabular::lfunMouseMotion(FuncRequest const & cmd)
                setSelection(sel_cell_start, actcell);
                updateLocal(bv, SELECTION);
        }
-       showInsetCursor(bv);
 }
 
 
@@ -814,7 +807,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
 
                case LFUN_CELL_BACKWARD:
                case LFUN_CELL_FORWARD:
-                       hideInsetCursor(bv);
                        unlockInsetInInset(bv, the_locking_inset);
                        if (cmd.action == LFUN_CELL_FORWARD)
                                moveNextCell(bv, old_locking_inset != 0);
@@ -824,7 +816,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        if (hs)
                                updateLocal(bv, SELECTION);
                        if (!the_locking_inset) {
-                               showInsetCursor(bv);
                                return DISPATCHED_NOUPDATE;
                        }
                        return result;
@@ -842,15 +833,11 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        int sc = scroll();
                        resetPos(bv);
                        if (sc != scroll()) { // inset has been scrolled
-                               the_locking_inset->toggleInsetCursor(bv);
                                updateLocal(bv, FULL);
-                               the_locking_inset->toggleInsetCursor(bv);
                        }
                        return result;
                } else if (result == DISPATCHED) {
-                       the_locking_inset->toggleInsetCursor(bv);
                        updateLocal(bv, CELL);
-                       the_locking_inset->toggleInsetCursor(bv);
                        return result;
                } else if (result == FINISHED_UP) {
                        action = LFUN_UP;
@@ -868,7 +855,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                }
        }
 
-       hideInsetCursor(bv);
        result = DISPATCHED;
        switch (action) {
                // --- Cursor Movements ----------------------------------
@@ -1216,8 +1202,6 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                if (!the_locking_inset) {
                        if (bv->fitCursor())
                                updateLocal(bv, FULL);
-                       if (locked)
-                               showInsetCursor(bv);
                }
        } else
                bv->unlockInset(this);
@@ -1336,65 +1320,34 @@ bool InsetTabular::calculate_dimensions_of_cells(BufferView * bv, bool reinit) c
 }
 
 
-void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
-{
-       if (the_locking_inset) {
-               the_locking_inset->getCursorPos(bv, x, y);
-               return;
-       }
-       x = cursor_.x() - top_x;
-       y = cursor_.y();
-}
-
-
-void InsetTabular::toggleInsetCursor(BufferView * bv)
+void InsetTabular::getCursor(BufferView & bv, int & x, int & y) const
 {
-       if (nodraw()) {
-               if (isCursorVisible())
-                       bv->hideLockedInsetCursor();
-               return;
-       }
        if (the_locking_inset) {
-               the_locking_inset->toggleInsetCursor(bv);
+               the_locking_inset->getCursor(bv, x, y);
                return;
        }
 
-       LyXFont font; // = the_locking_inset->GetFont(par, cursor.pos);
+       x = cursor_.x();
+       y = cursor_.y() + InsetTabular::y();
 
-       int const asc = font_metrics::maxAscent(font);
-       int const desc = font_metrics::maxDescent(font);
-
-       if (isCursorVisible())
-               bv->hideLockedInsetCursor();
-       else
-               bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
-       toggleCursorVisible();
+       // Fun stuff
+       int desc = tabular->GetDescentOfRow(actrow);
+       y += desc;
+       int ascdesc = tabular->GetAscentOfRow(actrow) + desc;
+       y -= ascdesc / 2;
+       y += ADD_TO_HEIGHT * 2;
+       y += TEXT_TO_INSET_OFFSET;
 }
 
 
-void InsetTabular::showInsetCursor(BufferView * bv, bool show)
+void InsetTabular::getCursorPos(BufferView * bv, int & x, int & y) const
 {
-       if (nodraw())
+       if (the_locking_inset) {
+               the_locking_inset->getCursorPos(bv, x, y);
                return;
-       if (!isCursorVisible()) {
-               LyXFont font; // = GetFont(par, cursor.pos);
-
-               int const asc = font_metrics::maxAscent(font);
-               int const desc = font_metrics::maxDescent(font);
-               bv->fitLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
-               if (show)
-                       bv->showLockedInsetCursor(cursor_.x(), cursor_.y(), asc, desc);
-               setCursorVisible(true);
-       }
-}
-
-
-void InsetTabular::hideInsetCursor(BufferView * bv)
-{
-       if (isCursorVisible()) {
-               bv->hideLockedInsetCursor();
-               setCursorVisible(false);
        }
+       x = cursor_.x() - top_x;
+       y = cursor_.y();
 }
 
 
index 5ab939c34d6f2f1f25bf985dff7c20c9d609e482..1ed2a06f204918df68fb64bbd059b6eae15bde38 100644 (file)
@@ -144,10 +144,10 @@ public:
        void validate(LaTeXFeatures & features) const;
        ///
        Inset::Code lyxCode() const { return Inset::TABULAR_CODE; }
-       ///
+       /// FIXME, document
        void getCursorPos(BufferView *, int & x, int & y) const;
-       ///
-       void toggleInsetCursor(BufferView *);
+       /// Get the absolute document x,y of the cursor
+       virtual void getCursor(BufferView &, int &, int &) const;
        ///
        bool tabularFeatures(BufferView * bv, string const & what);
        ///
@@ -259,10 +259,6 @@ private:
        void drawCellSelection(Painter &, int x, int baseline,
                               int row, int column, int cell) const;
        ///
-       void showInsetCursor(BufferView *, bool show=true);
-       ///
-       void hideInsetCursor(BufferView *);
-       ///
        void fitInsetCursor(BufferView *) const;
        ///
        void setPos(BufferView *, int x, int y) const;
index 5fad75dc9270130c598b45a8b8272a9e18d35dba..fe14c092573f8f413c1184d1fb6f3a7645646dde 100644 (file)
@@ -419,6 +419,9 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        int yf = y_offset + first;
        y = 0;
+
+       bv->hideCursor();
+
        while ((rowit != end) && (yf < ph)) {
                RowPainter rp(*bv, *lt, rowit);
                rp.paint(y + y_offset + first, int(x), y + lt->top_y());
@@ -643,7 +646,6 @@ void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button)
        if (drawFrame_ == LOCKED)
                code = CURSOR|DRAW_FRAME;
        updateLocal(bv, code, false);
-       showInsetCursor(bv);
 
        // Tell the paragraph dialog that we've entered an insettext.
        bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
@@ -696,7 +698,6 @@ void InsetText::edit(BufferView * bv, bool front)
        if (drawFrame_ == LOCKED)
                code = CURSOR|DRAW_FRAME;
        updateLocal(bv, code, false);
-       showInsetCursor(bv);
 }
 
 
@@ -707,7 +708,6 @@ void InsetText::insetUnlock(BufferView * bv)
                the_locking_inset = 0;
                updateLocal(bv, CURSOR_PAR, false);
        }
-       hideInsetCursor(bv);
        no_selection = true;
        locked = false;
        int code = NONE;
@@ -932,7 +932,6 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
        int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
 
-       hideInsetCursor(bv);
        if (the_locking_inset) {
                if (the_locking_inset == inset) {
                        the_locking_inset->localDispatch(cmd1);
@@ -1007,7 +1006,6 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
        } else {
                getLyXText(bv)->clearSelection();
        }
-       showInsetCursor(bv);
 }
 
 
@@ -1072,7 +1070,6 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
                lt = getLyXText(bv);
                clear = true;
        }
-       hideInsetCursor(bv);
        LyXCursor cur = lt->cursor;
        lt->setCursorFromCoordinates
                (cmd.x - drawTextXOffset, cmd.y + insetAscent);
@@ -1090,7 +1087,6 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
        if (flag) {
                updateLocal(bv, SELECTION, false);
        }
-       showInsetCursor(bv);
 }
 
 
@@ -1157,7 +1153,6 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                        return result;
                }
        }
-       hideInsetCursor(bv);
        bool clear = false;
        if (!lt) {
                lt = getLyXText(bv);
@@ -1689,6 +1684,17 @@ void InsetText::validate(LaTeXFeatures & features) const
 }
 
 
+void InsetText::getCursor(BufferView & bv, int & x, int & y) const
+{
+       if (the_locking_inset) {
+               the_locking_inset->getCursor(bv, x, y);
+               return;
+       }
+       x = cx(&bv);
+       y = cy(&bv) + InsetText::y();
+}
+
+
 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
 {
        if (the_locking_inset) {
@@ -1709,58 +1715,6 @@ int InsetText::insetInInsetY() const
 }
 
 
-void InsetText::toggleInsetCursor(BufferView * bv)
-{
-       if (the_locking_inset) {
-               the_locking_inset->toggleInsetCursor(bv);
-               return;
-       }
-
-       LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
-
-       int const asc = font_metrics::maxAscent(font);
-       int const desc = font_metrics::maxDescent(font);
-
-       if (isCursorVisible())
-               bv->hideLockedInsetCursor();
-       else
-               bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
-       toggleCursorVisible();
-}
-
-
-void InsetText::showInsetCursor(BufferView * bv, bool show)
-{
-       if (the_locking_inset) {
-               the_locking_inset->showInsetCursor(bv, show);
-               return;
-       }
-       if (!isCursorVisible()) {
-               LyXFont const font =
-                       getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
-               int const asc = font_metrics::maxAscent(font);
-               int const desc = font_metrics::maxDescent(font);
-
-               bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
-               if (show)
-                       bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
-               setCursorVisible(true);
-       }
-}
-
-
-void InsetText::hideInsetCursor(BufferView * bv)
-{
-       if (isCursorVisible()) {
-               bv->hideLockedInsetCursor();
-               setCursorVisible(false);
-       }
-       if (the_locking_inset)
-               the_locking_inset->hideInsetCursor(bv);
-}
-
-
 void InsetText::fitInsetCursor(BufferView * bv) const
 {
        if (the_locking_inset) {
@@ -1863,7 +1817,6 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset)
                return false;
        }
        inset->setOwner(this);
-       hideInsetCursor(bv);
        getLyXText(bv)->insertInset(inset);
        bv->fitCursor();
        updateLocal(bv, CURSOR_PAR|CURSOR, true);
index d16b7c5aa04af0a584b121f5f6ff77eb0b332142..6ffd4d5f3b72fca3540d950df67cd7cc834396c0 100644 (file)
@@ -130,17 +130,13 @@ public:
        void validate(LaTeXFeatures & features) const;
        ///
        Inset::Code lyxCode() const { return Inset::TEXT_CODE; }
-       ///
+       /// FIXME, document
        void getCursorPos(BufferView *, int & x, int & y) const;
+       /// Get the absolute document x,y of the cursor
+       virtual void getCursor(BufferView &, int &, int &) const;
        ///
        int insetInInsetY() const;
        ///
-       void toggleInsetCursor(BufferView *);
-       ///
-       void showInsetCursor(BufferView *, bool show = true);
-       ///
-       void hideInsetCursor(BufferView *);
-       ///
        void fitInsetCursor(BufferView *) const;
        ///
        bool insertInset(BufferView *, Inset *);
index d3027c911e8df88976e1b48590e7696a7789938d..1772858e63cf15c96cc7aaeb75b1f7a579af6e84 100644 (file)
 // some stuff for inset locking
 
 UpdatableInset::UpdatableInset()
-       : Inset(), cursor_visible_(false), block_drawing_(false)
+       : Inset(), block_drawing_(false)
 {}
 
 
 UpdatableInset::UpdatableInset(UpdatableInset const & in, bool same_id)
-       : Inset(in, same_id), cursor_visible_(false), block_drawing_(false)
+       : Inset(in, same_id), block_drawing_(false)
 {}
 
 
@@ -48,18 +48,6 @@ Inset::EDITABLE UpdatableInset::editable() const
 }
 
 
-void UpdatableInset::toggleInsetCursor(BufferView *)
-{}
-
-
-void UpdatableInset::showInsetCursor(BufferView *, bool)
-{}
-
-
-void UpdatableInset::hideInsetCursor(BufferView *)
-{}
-
-
 void UpdatableInset::fitInsetCursor(BufferView *) const
 {}
 
index a7ce6032327abe16930f43ac7f78e5f412bbc9fe..5c9826f51ee41f49c29ea29dc44a8e34c54b918d 100644 (file)
@@ -57,16 +57,12 @@ public:
        ///
        virtual EDITABLE editable() const;
 
-       ///
-       virtual void toggleInsetCursor(BufferView *);
-       ///
-       virtual void showInsetCursor(BufferView *, bool show = true);
-       ///
-       virtual void hideInsetCursor(BufferView *);
        ///
        virtual void fitInsetCursor(BufferView *) const;
-       ///
+       /// FIXME
        virtual void getCursorPos(BufferView *, int &, int &) const {}
+       /// Get the absolute document x,y of the cursor
+       virtual void getCursor(BufferView &, int &, int &) const = 0;
        ///
        virtual void insetUnlock(BufferView *);
        ///
@@ -100,8 +96,6 @@ public:
        ///  An updatable inset could handle lyx editing commands
        virtual RESULT localDispatch(FuncRequest const & cmd);
        ///
-       bool isCursorVisible() const { return cursor_visible_; }
-       ///
        virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const;
        ///
        int scroll(bool recursive = true) const {
@@ -143,22 +137,12 @@ public:
                                    bool = true, bool = false);
 
 protected:
-       ///
-       void toggleCursorVisible() const {
-               cursor_visible_ = !cursor_visible_;
-       }
-       ///
-       void setCursorVisible(bool b) const {
-               cursor_visible_ = b;
-       }
        /// scrolls to absolute position in bufferview-workwidth * sx units
        void scroll(BufferView *, float sx) const;
        /// scrolls offset pixels
        void scroll(BufferView *, int offset) const;
 
 private:
-       ///
-       mutable bool cursor_visible_;
        ///
        mutable bool block_drawing_;
 };
index 2481bd6c895d55a492a724952fb6f637bef4a9ed..0b944b6d01e9ddd0f23664abf2d5ef46339aba04 100644 (file)
@@ -366,9 +366,6 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
        if (tmpstr.empty())
                return;
 
-       // insert the string
-       bv->hideCursor();
-
        // clear the selection
        bool flag = (bv->text == bv->getLyXText());
        if (flag)
index 713957d28542edec8becec04760d323a7bbb06ba..91c00f72e4e80c9cb9510aee39c717373d8813d1 100644 (file)
@@ -92,7 +92,6 @@ int LyXReplace(BufferView * bv,
                if (!bv->theLockingInset() ||
                        ((text != bv->text) &&
                         (text->inset_owner == text->inset_owner->getLockingInset()))) {
-                       bv->hideCursor();
                        bv->update(text, BufferView::SELECT);
                        bv->toggleSelection(false);
                        text->replaceSelectionWithString(replacestr);
@@ -119,7 +118,6 @@ bool LyXFind(BufferView * bv,
        if (!bv->available() || searchstr.empty())
                return false;
 
-       bv->hideCursor();
        bv->update(bv->getLyXText(), BufferView::SELECT);
 
        if (bv->theLockingInset()) {
@@ -374,7 +372,6 @@ bool findNextChange(BufferView * bv)
        if (!bv->available())
                return false;
 
-       bv->hideCursor();
        bv->update(bv->getLyXText(), BufferView::SELECT);
 
        pos_type length;
index 5098a020a207432d69f77c6d05c5402b3b4cac88..57c86892d143af3b285db06b02337c906fd1a467 100644 (file)
@@ -125,7 +125,6 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting)
                    view()->toggleToggle();
        }
        view()->update(TEXT(flag), BufferView::SELECT);
-       view()->showCursor();
 
        view()->switchKeyMap();
 }
@@ -815,9 +814,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
 
        selection_possible = false;
 
-       if (view()->available())
-               view()->hideCursor();
-
        string argument = ev.argument;
        kb_action action = ev.action;
 
@@ -831,6 +827,9 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                goto exit_with_message;
        }
 
+       if (view()->available())
+               view()->hideCursor();
+
        if (view()->available() && view()->theLockingInset()) {
                Inset::RESULT result;
                if ((action > 1) || ((action == LFUN_UNKNOWN_ACTION) &&
@@ -991,7 +990,6 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose)
                if (!searched_string.empty()) {
                        lyxfind::LyXFind(view(), searched_string, fw);
                }
-//             view()->showCursor();
        }
        break;
 
index 5bbd5549040438ca1ab9980c06c0b7df3d7963e1..491dc3111e458657b55b13204a9458508657f956 100644 (file)
@@ -1,3 +1,12 @@
+2003-05-03  John Levon  <levon@movementarian.org>
+
+       * formula.C:
+       * formulabase.C:
+       * formulabase.h:
+       * formulamacro.C:
+       * math_cursor.C: remove showInsetCursor(),
+       isCursorVisible(), hideInsetCursor(), toggleInsetCursor(),
+       explicit cursor hides. Add getCursor()
 
 2003-05-02  André Pönitz <poenitz@gmx.net>
 
index 4154cb80cae71eb78a158cb545e04e7d6842c2e5..1e1f4beda3f2eac2c2006f99f7c2e4d18a830727 100644 (file)
@@ -242,8 +242,6 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & font,
        xx += w;
        xo_ = x;
        yo_ = y;
-
-       setCursorVisible(false);
 }
 
 
index d6e350fd819e31463ab17ba947b227bb9dfcb4e6..3c73fc5d27e7c5dabd09a014b6c5e448bb4079b6 100644 (file)
@@ -208,6 +208,12 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
 }
 
 
+void InsetFormulaBase::getCursor(BufferView &, int & x, int & y) const
+{
+       mathcursor->getPos(x, y);
+}
+
+
 void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
 {
        // calling metrics here destroys the cached xo,yo positions e.g. in
@@ -226,49 +232,6 @@ void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
 }
 
 
-void InsetFormulaBase::toggleInsetCursor(BufferView * bv)
-{
-       if (!mathcursor) {
-               lyxerr[Debug::MATHED] << "toggleInsetCursor impossible" << endl;
-               return;
-       }
-       //lyxerr << "toggleInsetCursor: " << isCursorVisible() << endl;
-       if (isCursorVisible())
-               hideInsetCursor(bv);
-       else
-               showInsetCursor(bv);
-}
-
-
-void InsetFormulaBase::showInsetCursor(BufferView * bv, bool)
-{
-       if (!mathcursor) {
-               lyxerr << "showInsetCursor impossible" << endl;
-               return;
-       }
-       if (isCursorVisible())
-               return;
-       int x, y, asc, des;
-       mathcursor->getPos(x, y);
-       math_font_max_dim(font_, asc, des);
-       bv->showLockedInsetCursor(x, y - yo_, asc, des);
-       setCursorVisible(true);
-       //lyxerr << "showInsetCursor: " << x << ' ' << y << endl;
-}
-
-
-void InsetFormulaBase::hideInsetCursor(BufferView * bv)
-{
-       if (!mathcursor)
-               return;
-       if (!isCursorVisible())
-               return;
-       bv->hideLockedInsetCursor();
-       setCursorVisible(false);
-       //lyxerr << "hideInsetCursor: " << endl;
-}
-
-
 void InsetFormulaBase::fitInsetCursor(BufferView * bv) const
 {
        if (!mathcursor)
@@ -301,8 +264,6 @@ dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd)
                return UNDISPATCHED;
 
        BufferView * bv = cmd.view();
-       hideInsetCursor(bv);
-       showInsetCursor(bv);
        bv->updateInset(this);
        //lyxerr << "lfunMouseRelease: buttons: " << cmd.button() << endl;
 
@@ -394,9 +355,7 @@ dispatch_result InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd)
                mathcursor->selStart();
 
        BufferView * bv = cmd.view();
-       hideInsetCursor(bv);
        mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
-       showInsetCursor(bv);
        bv->updateInset(this);
        return DISPATCHED;
 }
@@ -440,8 +399,6 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        bool was_macro     = mathcursor->inMacroMode();
        bool was_selection = mathcursor->selection();
 
-       hideInsetCursor(bv);
-
        mathcursor->normalize();
        mathcursor->touch();
 
@@ -805,7 +762,6 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd)
        if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
            result == UNDISPATCHED) {
                fitInsetCursor(bv);
-               showInsetCursor(bv);
                revealCodes(bv);
                cmd.view()->stuffClipboard(mathcursor->grabSelection());
        } else {
index 1459c894a3b14bf30b2dc482ea6ad33858e1e853..03005f904ae5cf991d951f185988b1eee81a12b6 100644 (file)
@@ -63,15 +63,11 @@ public:
        ///
        virtual void edit(BufferView *, bool front = true);
        ///
-       virtual void toggleInsetCursor(BufferView *);
-       ///
-       virtual void showInsetCursor(BufferView *, bool show = true);
-       ///
-       virtual void hideInsetCursor(BufferView *);
-       ///
        virtual void fitInsetCursor(BufferView *) const;
-       ///
+       /// FIXME
        virtual void getCursorPos(BufferView *, int &, int &) const;
+       /// get the absolute document x,y of the cursor
+       virtual void getCursor(BufferView & bv, int & x, int & y) const;
        ///
        virtual void toggleInsetSelection(BufferView * bv);
        ///
index 5cbf21b179ca26fb1c6979ff8e60e6ece72530da..5135bdfe61c7f287397176d4351c8ada1c24271e 100644 (file)
@@ -201,6 +201,4 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
        xx += w + 2;
        xo_ = x;
        yo_ = y;
-
-       setCursorVisible(false);
 }
index 3be9d00658da1bb0df79543da261d35b82d6b0c3..1a8dfeca8dab9064f7ae45c0b4c83bb3f26a68e3 100644 (file)
@@ -1499,7 +1499,6 @@ void releaseMathCursor(BufferView * bv)
 {
        if (mathcursor) {
                InsetFormulaBase * f =  mathcursor->formula();
-               f->hideInsetCursor(bv);
                delete mathcursor;
                mathcursor = 0;
                f->insetUnlock(bv);
index ad6f97d3ab9b36fb0d1da8d30c26dfd401a7def0..42e937aaf70b0471f5833185d2efde1ca19d1c17 100644 (file)
@@ -2109,8 +2109,6 @@ void LyXText::acceptChange()
        if (!selection.set() && cursor.par()->size())
                return;
 
-       bv()->hideCursor();
-
        if (selection.start.par() == selection.end.par()) {
                LyXCursor & startc = selection.start;
                LyXCursor & endc = selection.end;
@@ -2130,8 +2128,6 @@ void LyXText::rejectChange()
        if (!selection.set() && cursor.par()->size())
                return;
 
-       bv()->hideCursor();
-
        if (selection.start.par() == selection.end.par()) {
                LyXCursor & startc = selection.start;
                LyXCursor & endc = selection.end;
index 3aa80b5bbdf3dd98cea6f4ed2102a5ed3faceda2..ff12e1fcb6bda77e34c5838ac477e9bd4ecf2a32 100644 (file)
@@ -68,11 +68,8 @@ namespace {
                }
                if (!lt->isInInset()) {
                        bv->update(lt, BufferView::SELECT);
-                       bv->showCursor();
                } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
-                       bv->theLockingInset()->hideInsetCursor(bv);
                        bv->update(BufferView::SELECT);
-                       bv->showCursor();
                }
 
                if (!lt->selection.set())
@@ -203,7 +200,6 @@ bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
 void LyXText::gotoInset(vector<Inset::Code> const & codes,
                        bool same_content)
 {
-       bv()->hideCursor();
        bv()->beforeChange(this);
        update();
 
@@ -365,7 +361,6 @@ namespace {
 
 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 {
-       bv->hideCursor();
        lt->update();
        InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
        if (!bv->insertInset(new_inset))
@@ -733,7 +728,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        update();
                        // It is possible to make it a lot faster still
                        // just comment out the line below...
-                       bv->showCursor();
                } else {
                        update();
                        cutSelection(bv, true);
@@ -791,7 +785,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                update();
                                // It is possible to make it a lot faster still
                                // just comment out the line below...
-                               bv->showCursor();
                        }
                } else {
                        update();
@@ -924,7 +917,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_INSET_TOGGLE:
-               bv->hideCursor();
                bv->beforeChange(this);
                update();
                toggleInset();
@@ -1024,7 +1016,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_PASTE:
                cmd.message(_("Paste"));
-               bv->hideCursor();
                // clear the selection
                bv->toggleSelection();
                clearSelection();
@@ -1036,7 +1027,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_CUT:
-               bv->hideCursor();
                update();
                cutSelection(bv, true);
                update();
@@ -1142,7 +1132,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                }
                if (change_layout) {
-                       bv->hideCursor();
                        current_layout = layout;
                        update();
                        setLayout(layout);
@@ -1156,7 +1145,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_PASTESELECTION: {
                if (!bv->buffer())
                        break;
-               bv->hideCursor();
                // this was originally a beforeChange(bv->text), i.e
                // the outermost LyXText!
                bv->beforeChange(this);
@@ -1200,7 +1188,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                else
                        c = pit->getChar(pos - 1);
 
-               bv->hideCursor();
                LyXLayout_ptr const & style = pit->layout();
 
                if (style->pass_thru ||
@@ -1240,7 +1227,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
-                               bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                        }
                        cursorHome();
@@ -1261,7 +1247,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
-                               bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                                selectWord(LyXText::WHOLE_WORD_STRICT);
                                bv->screen().toggleSelection(this, bv, false);
@@ -1308,8 +1293,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               bv->screen().hideCursor();
-
                RowList::iterator cursorrow = bv->text->cursor.row();
                bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
        #if 0
@@ -1335,7 +1318,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bv->text->setSelection();
                bv->screen().toggleToggle(bv->text, bv);
                bv->fitCursor();
-               bv->showCursor();
                break;
        }
 
@@ -1389,7 +1371,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                if (!inset_hit)
                        selection_possible = true;
-               bv->screen().hideCursor();
 
                // Clear the selection
                bv->screen().toggleSelection(bv->text, bv);