Ticket #4228: abiword-touch-scrolling.diff
File abiword-touch-scrolling.diff, 5.8 KB (added by garnacho, 11 years ago) |
---|
-
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 33 33 #include "gr_Graphics.h" 34 34 35 35 EV_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) 37 42 { 38 43 } 39 44 … … void EV_UnixMouse::mouseUp(AV_View* pView, GdkEventButton* e) 45 50 EV_EditMouseButton emb = 0; 46 51 EV_EditMouseOp mop; 47 52 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 49 80 if (e->state & GDK_SHIFT_MASK) 50 81 ems |= EV_EMS_SHIFT; 51 82 if (e->state & GDK_CONTROL_MASK) … … void EV_UnixMouse::mouseUp(AV_View* pView, GdkEventButton* e) 103 134 } 104 135 } 105 136 137 void 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 106 183 void EV_UnixMouse::mouseClick(AV_View* pView, GdkEventButton* e) 107 184 { 108 185 EV_EditMethod * pEM; … … void EV_UnixMouse::mouseClick(AV_View* pView, GdkEventButton* e) 115 192 116 193 device = gdk_event_get_source_device((GdkEvent *) e); 117 194 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 118 225 if (e->button == 1) 119 226 emb = EV_EMB_BUTTON1; 120 227 else if (e->button == 2) … … void EV_UnixMouse::mouseMotion(AV_View* pView, GdkEventMotion *e) 195 302 196 303 device = gdk_event_get_source_device((GdkEvent *) e); 197 304 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 198 330 if (e->state & GDK_SHIFT_MASK) 199 331 ems |= EV_EMS_SHIFT; 200 332 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 25 25 #include <gdk/gdk.h> 26 26 27 27 #include "ut_types.h" 28 #include "ut_timer.h" 28 29 #include "ev_Mouse.h" 29 30 #include "ev_EditBits.h" 30 31 31 32 /*****************************************************************/ 32 33 34 class UT_Worker; 35 class UT_Timer; 36 33 37 class EV_UnixMouse : public EV_Mouse 34 38 { 35 39 public: … … public: 41 45 void mouseScroll(AV_View* pView, GdkEventScroll *e); 42 46 43 47 protected: 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; 44 61 }; 45 62 46 63 #endif // EV_UNIXMOUSE_H