19
19
using TextControlBox . Renderer ;
20
20
using TextControlBox . Text ;
21
21
using Windows . ApplicationModel . DataTransfer ;
22
+ using Windows . Devices . Input ;
22
23
using Windows . Foundation ;
23
24
using Windows . Storage ;
24
25
using Windows . System ;
25
26
using Windows . UI . Core ;
27
+ using Windows . UI . Input ;
26
28
using Windows . UI . Popups ;
27
29
using Windows . UI . Text . Core ;
28
30
using Windows . UI . ViewManagement ;
@@ -110,6 +112,8 @@ public partial class TextControlBox : UserControl
110
112
int PointerClickCount = 0 ;
111
113
DispatcherTimer PointerClickTimer = new DispatcherTimer { Interval = new TimeSpan ( 0 , 0 , 0 , 0 , 200 ) } ;
112
114
115
+ Point ? OldTouchPosition = null ;
116
+
113
117
//CursorPosition
114
118
CursorPosition _CursorPosition = new CursorPosition ( 0 , 0 ) ;
115
119
CursorPosition OldCursorPosition = null ;
@@ -892,11 +896,9 @@ private void CleanUp()
892
896
Debug . WriteLine ( "Collect GC" ) ;
893
897
ListHelper . GCList ( TotalLines ) ;
894
898
}
895
-
896
- #endregion
897
-
898
899
private void PointerReleasedAction ( Point point )
899
900
{
901
+ OldTouchPosition = null ;
900
902
selectionrenderer . IsSelectingOverLinenumbers = false ;
901
903
902
904
//End text drag/drop -> insert text at cursorposition
@@ -982,6 +984,36 @@ private void PointerMovedAction(Point point)
982
984
UpdateSelection ( ) ;
983
985
}
984
986
}
987
+ private bool CheckTouchInput ( PointerPoint point )
988
+ {
989
+ if ( point . PointerDevice . PointerDeviceType == PointerDeviceType . Touch || point . PointerDevice . PointerDeviceType == PointerDeviceType . Pen )
990
+ {
991
+ //Get the touch start position:
992
+ if ( ! OldTouchPosition . HasValue )
993
+ return true ;
994
+
995
+ //GEt the dragged offset:
996
+ double scrollX = OldTouchPosition . Value . X - point . Position . X ;
997
+ double scrollY = OldTouchPosition . Value . Y - point . Position . Y ;
998
+ VerticalScrollbar . Value += scrollY > 2 ? 2 : scrollY < - 2 ? - 2 : scrollY ;
999
+ HorizontalScrollbar . Value += scrollX > 2 ? 2 : scrollX < - 2 ? - 2 : scrollX ;
1000
+ UpdateAll ( ) ;
1001
+ return true ;
1002
+ }
1003
+ return false ;
1004
+ }
1005
+ private bool CheckTouchInput_Click ( PointerPoint point )
1006
+ {
1007
+ if ( point . PointerDevice . PointerDeviceType == PointerDeviceType . Touch || point . PointerDevice . PointerDeviceType == PointerDeviceType . Pen )
1008
+ {
1009
+ OldTouchPosition = point . Position ;
1010
+ return true ;
1011
+ }
1012
+ return false ;
1013
+ }
1014
+
1015
+
1016
+ #endregion
985
1017
986
1018
#region Events
987
1019
//Handle keyinputs
@@ -1255,18 +1287,19 @@ private void TextControlBox_KeyDown(object sender, KeyRoutedEventArgs e)
1255
1287
//Without coreWindow the selection outside of the window would not work
1256
1288
private void CoreWindow_PointerReleased ( CoreWindow sender , PointerEventArgs args )
1257
1289
{
1258
- Debug . WriteLine ( "CoreWindow_PointerReleased" ) ;
1259
1290
1260
1291
var point = Utils . GetPointFromCoreWindowRelativeTo ( args , Canvas_Text ) ;
1261
1292
PointerReleasedAction ( point ) ;
1262
1293
}
1263
1294
private void Canvas_Selection_PointerReleased ( object sender , PointerRoutedEventArgs e )
1264
1295
{
1265
- Debug . WriteLine ( "Canvas_Selection_PointerReleased" ) ;
1266
1296
PointerReleasedAction ( e . GetCurrentPoint ( sender as UIElement ) . Position ) ;
1267
1297
}
1268
1298
private void CoreWindow_PointerMoved ( CoreWindow sender , PointerEventArgs args )
1269
1299
{
1300
+ if ( CheckTouchInput ( args . CurrentPoint ) )
1301
+ return ;
1302
+
1270
1303
PointerMovedAction ( Utils . GetPointFromCoreWindowRelativeTo ( args , Canvas_Text ) ) ;
1271
1304
}
1272
1305
private void Canvas_Selection_PointerMoved ( object sender , PointerRoutedEventArgs e )
@@ -1275,6 +1308,9 @@ private void Canvas_Selection_PointerMoved(object sender, PointerRoutedEventArgs
1275
1308
return ;
1276
1309
1277
1310
var point = e . GetCurrentPoint ( Canvas_Selection ) ;
1311
+
1312
+ if ( CheckTouchInput ( point ) )
1313
+ return ;
1278
1314
1279
1315
if ( point . Properties . IsLeftButtonPressed )
1280
1316
{
@@ -1288,9 +1324,13 @@ private void Canvas_Selection_PointerPressed(object sender, PointerRoutedEventAr
1288
1324
{
1289
1325
selectionrenderer . IsSelectingOverLinenumbers = false ;
1290
1326
1291
- Point PointerPosition = e . GetCurrentPoint ( sender as UIElement ) . Position ;
1292
- bool LeftButtonPressed = e . GetCurrentPoint ( sender as UIElement ) . Properties . IsLeftButtonPressed ;
1293
- bool RightButtonPressed = e . GetCurrentPoint ( sender as UIElement ) . Properties . IsRightButtonPressed ;
1327
+ var point = e . GetCurrentPoint ( sender as UIElement ) ;
1328
+ if ( CheckTouchInput_Click ( point ) )
1329
+ return ;
1330
+
1331
+ Point PointerPosition = point . Position ;
1332
+ bool LeftButtonPressed = point . Properties . IsLeftButtonPressed ;
1333
+ bool RightButtonPressed = point . Properties . IsRightButtonPressed ;
1294
1334
1295
1335
if ( LeftButtonPressed && ! Utils . IsKeyPressed ( VirtualKey . Shift ) )
1296
1336
PointerClickCount ++ ;
@@ -1427,8 +1467,12 @@ private void Canvas_Selection_PointerWheelChanged(object sender, PointerRoutedEv
1427
1467
}
1428
1468
private void Canvas_LineNumber_PointerPressed ( object sender , PointerRoutedEventArgs e )
1429
1469
{
1470
+ var point = e . GetCurrentPoint ( sender as UIElement ) ;
1471
+ if ( CheckTouchInput_Click ( point ) )
1472
+ return ;
1473
+
1430
1474
//Select the line where the cursor is over
1431
- SelectLine ( CursorRenderer . GetCursorLineFromPoint ( e . GetCurrentPoint ( sender as UIElement ) . Position , SingleLineHeight , NumberOfRenderedLines , NumberOfStartLine ) ) ;
1475
+ SelectLine ( CursorRenderer . GetCursorLineFromPoint ( point . Position , SingleLineHeight , NumberOfRenderedLines , NumberOfStartLine ) ) ;
1432
1476
1433
1477
selectionrenderer . IsSelecting = true ;
1434
1478
selectionrenderer . IsSelectingOverLinenumbers = true ;
0 commit comments