Ticket #4228: abiword-touch-scrolling.diff

File abiword-touch-scrolling.diff, 5.8 KB (added by garnacho, 11 years ago)

very rough patch

  • src/af/ev/gtk/ev_UnixMouse.cpp

    diff --git a/src/af/ev/gtk/ev_UnixMouse.cpp b/src/af/ev/gtk/ev_UnixMouse.cpp
    index 2ca54ec..a9cc958 100644
    a b  
    3333#include "gr_Graphics.h"
    3434
    3535EV_UnixMouse::EV_UnixMouse(EV_EditEventMapper * pEEM)
    36         : EV_Mouse(pEEM)
     36        : EV_Mouse(pEEM),
     37          m_iInitialOffset(0),
     38          m_bLastTouchValid(FALSE),
     39          m_bTouchOngoing(FALSE),
     40          m_bScrollDragOngoing(FALSE),
     41          m_pThresholdTimer(NULL)
    3742{
    3843}
    3944
    void EV_UnixMouse::mouseUp(AV_View* pView, GdkEventButton* e) 
    4550        EV_EditMouseButton emb = 0;
    4651        EV_EditMouseOp mop;
    4752        EV_EditMouseContext emc = 0;
    48        
     53        GdkDevice *device;
     54
     55        device = gdk_event_get_source_device((GdkEvent *) e);
     56
     57        if (gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN)
     58        {
     59                if (m_pThresholdTimer)
     60                        m_pThresholdTimer->stop ();
     61
     62                m_bLastTouchValid = FALSE;
     63
     64                if (!m_bScrollDragOngoing)
     65                {
     66                        if (m_bTouchOngoing)
     67                                m_pThresholdTimer->fire ();
     68
     69                        m_bTouchOngoing = FALSE;
     70                        m_bLastTouchValid = TRUE;
     71                }
     72                else
     73                {
     74                        m_bScrollDragOngoing = FALSE;
     75                        m_bTouchOngoing = FALSE;
     76                        return;
     77                }
     78        }
     79
    4980        if (e->state & GDK_SHIFT_MASK)
    5081                ems |= EV_EMS_SHIFT;
    5182        if (e->state & GDK_CONTROL_MASK)
    void EV_UnixMouse::mouseUp(AV_View* pView, GdkEventButton* e) 
    103134        }
    104135}
    105136
     137void EV_UnixMouse::stopScroll (UT_Worker* pWorker)
     138{
     139        EV_UnixMouse * pMouse = static_cast<EV_UnixMouse *>(pWorker->getInstanceData());
     140        EV_EditMethod * pEM;
     141        EV_EditModifierState state = 0;
     142        EV_EditEventMapperResult result;
     143        EV_EditMouseButton emb = 0;
     144        EV_EditMouseOp mop = 0;
     145        EV_EditMouseContext emc = 0;
     146        AV_View* pView = pMouse->m_pScrolledView;
     147
     148        pMouse->m_bTouchOngoing = FALSE;
     149        pMouse->m_bLastTouchValid = FALSE;
     150        pMouse->m_bScrollDragOngoing = FALSE;
     151        pWorker->stop();
     152
     153        emb = EV_EMB_BUTTON1;
     154        mop = EV_EMO_SINGLECLICK;
     155        emc = pView->getMouseContext(static_cast<UT_sint32>(pView->getGraphics()->tluD((gdouble) pMouse->m_iLastTouchX)),static_cast<UT_sint32>(pView->getGraphics()->tluD((gdouble) pMouse->m_iLastTouchY)));
     156
     157        pMouse->m_clickState = mop;                                     // remember which type of click
     158        pMouse->m_contextState = emc;                           // remember context of click
     159
     160        result = pMouse->m_pEEM->Mouse(emc|mop|emb|state, &pEM);
     161
     162        switch (result)
     163        {
     164        case EV_EEMR_COMPLETE:
     165                UT_ASSERT(pEM);
     166                pMouse->invokeMouseMethod(pView,pEM,static_cast<UT_sint32>(pView->getGraphics()->tluD((gdouble) pMouse->m_iLastTouchX)),static_cast<UT_sint32>(pView->getGraphics()->tluD((gdouble) pMouse->m_iLastTouchY)));
     167                pMouse->signal(emc|mop|emb|state, static_cast<UT_sint32>(pView->getGraphics()->tluD((gdouble) pMouse->m_iLastTouchX)),static_cast<UT_sint32>(pView->getGraphics()->tluD((gdouble) pMouse->m_iLastTouchY)));
     168                pView->setVisualSelectionEnabled(true);
     169                return;
     170        case EV_EEMR_INCOMPLETE:
     171                // I'm not sure this makes any sense, but we allow it.
     172                return;
     173        case EV_EEMR_BOGUS_START:
     174        case EV_EEMR_BOGUS_CONT:
     175                // TODO What to do ?? Should we beep at them or just be quiet ??
     176                return;
     177        default:
     178                UT_ASSERT(0);
     179                return;
     180        }
     181}
     182
    106183void EV_UnixMouse::mouseClick(AV_View* pView, GdkEventButton* e)
    107184{
    108185        EV_EditMethod * pEM;
    void EV_UnixMouse::mouseClick(AV_View* pView, GdkEventButton* e) 
    115192
    116193        device = gdk_event_get_source_device((GdkEvent *) e);
    117194
     195        if (gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN)
     196        {
     197                m_iInitialOffset = pView->getYScrollOffset();
     198                m_bTouchOngoing = TRUE;
     199
     200                if (!m_bLastTouchValid ||
     201                    (ABS (m_iLastTouchX - e->x) > 32 ||
     202                     ABS (m_iLastTouchY - e->y) > 32))
     203                {
     204                        m_iTouchX = (gint) e->x;
     205                        m_iTouchY = (gint) e->y;
     206                        m_iLastTouchX = (int) e->x;
     207                        m_iLastTouchY = (int) e->y;
     208
     209                        if (m_pThresholdTimer)
     210                                m_pThresholdTimer->stop();
     211                        else
     212                        {
     213                                m_pScrolledView = pView;
     214                                m_pThresholdTimer = UT_Timer::static_constructor(stopScroll, this);
     215                        }
     216
     217                        m_pThresholdTimer->set(1000);
     218                        return;
     219                }
     220
     221                m_iLastTouchX = (int) e->x;
     222                m_iLastTouchY = (int) e->y;
     223        }
     224
    118225        if (e->button == 1)
    119226                emb = EV_EMB_BUTTON1;
    120227        else if (e->button == 2)
    void EV_UnixMouse::mouseMotion(AV_View* pView, GdkEventMotion *e) 
    195302
    196303        device = gdk_event_get_source_device((GdkEvent *) e);
    197304
     305        if (gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN && m_bTouchOngoing)
     306        {
     307                gint dx, dy;
     308                UT_sint32 sy;
     309
     310                dx = m_iTouchX - (int) e->x;
     311                dy = m_iTouchY - (int) e->y;
     312
     313                if (m_bScrollDragOngoing ||
     314                    (ABS(dx) > 32 || ABS(dy) > 32))
     315                {
     316                        if (m_pThresholdTimer)
     317                                m_pThresholdTimer->stop();
     318
     319                        sy = pView->getGraphics()->tluD(dy) + m_iInitialOffset;
     320                        sy = MAX (0, sy);
     321
     322                        pView->sendVerticalScrollEvent(sy);
     323                        pView->setYScrollOffset (sy);
     324                        m_bScrollDragOngoing = TRUE;
     325                }
     326
     327                return;
     328        }
     329
    198330        if (e->state & GDK_SHIFT_MASK)
    199331                ems |= EV_EMS_SHIFT;
    200332        if (e->state & GDK_CONTROL_MASK)
  • src/af/ev/gtk/ev_UnixMouse.h

    diff --git a/src/af/ev/gtk/ev_UnixMouse.h b/src/af/ev/gtk/ev_UnixMouse.h
    index 94922c3..1aac31f 100644
    a b  
    2525#include <gdk/gdk.h>
    2626
    2727#include "ut_types.h"
     28#include "ut_timer.h"
    2829#include "ev_Mouse.h"
    2930#include "ev_EditBits.h"
    3031
    3132/*****************************************************************/
    3233
     34class UT_Worker;
     35class UT_Timer;
     36
    3337class EV_UnixMouse : public EV_Mouse
    3438{
    3539public:
    public: 
    4145        void mouseScroll(AV_View* pView, GdkEventScroll *e);
    4246
    4347protected:
     48        static void stopScroll(UT_Worker * pWorker);
     49
     50        gint m_iLastTouchX;
     51        gint m_iLastTouchY;
     52        gint m_iTouchX;
     53        gint m_iTouchY;
     54        UT_sint32 m_iInitialOffset;
     55
     56        bool m_bLastTouchValid;
     57        bool m_bTouchOngoing;
     58        bool m_bScrollDragOngoing;
     59        AV_View * m_pScrolledView;
     60        UT_Timer * m_pThresholdTimer;
    4461};
    4562
    4663#endif // EV_UNIXMOUSE_H