@@ -882,6 +882,94 @@ private void CleanUp()
882882
883883 #endregion
884884
885+ private void PointerReleasedAction ( Point point )
886+ {
887+ selectionrenderer . IsSelectingOverLinenumbers = false ;
888+
889+ //End text drag/drop -> insert text at cursorposition
890+ if ( DragDropSelection && ! DragDropOverSelection ( point ) )
891+ {
892+ DoDragDropSelection ( ) ;
893+ }
894+ else if ( DragDropSelection )
895+ {
896+ EndDragDropSelection ( ) ;
897+ }
898+
899+ if ( selectionrenderer . IsSelecting )
900+ {
901+ this . Focus ( FocusState . Programmatic ) ;
902+ selectionrenderer . HasSelection = true ;
903+ }
904+
905+ selectionrenderer . IsSelecting = false ;
906+ }
907+ private void PointerMovedAction ( Point point )
908+ {
909+ if ( selectionrenderer . IsSelecting )
910+ {
911+ double CanvasWidth = Math . Round ( this . ActualWidth , 2 ) ;
912+ double CanvasHeight = Math . Round ( this . ActualHeight , 2 ) ;
913+ double CurPosX = Math . Round ( point . X , 2 ) ;
914+ double CurPosY = Math . Round ( point . Y , 2 ) ;
915+
916+ if ( CurPosY > CanvasHeight - 50 )
917+ {
918+ VerticalScrollbar . Value += ( CurPosY > CanvasHeight + 30 ? 20 : ( CanvasHeight - CurPosY ) / 180 ) ;
919+ UpdateWhenScrolled ( ) ;
920+ }
921+ else if ( CurPosY < 50 )
922+ {
923+ VerticalScrollbar . Value += CurPosY < - 30 ? - 20 : - ( 50 - CurPosY ) / 20 ;
924+ UpdateWhenScrolled ( ) ;
925+ }
926+
927+ //Horizontal
928+ if ( CurPosX > CanvasWidth - 100 )
929+ {
930+ ScrollIntoViewHorizontal ( ) ;
931+ UpdateAll ( ) ;
932+ }
933+ else if ( CurPosX < 100 )
934+ {
935+ ScrollIntoViewHorizontal ( ) ;
936+ UpdateAll ( ) ;
937+ }
938+ }
939+
940+ //Drag drop text -> move the cursor to get the insertion point
941+ if ( DragDropSelection )
942+ {
943+ DragDropOverSelection ( point ) ;
944+ UpdateCursorVariable ( point ) ;
945+ UpdateCursor ( ) ;
946+ }
947+ if ( selectionrenderer . IsSelecting && ! DragDropSelection )
948+ {
949+ //selection started over the linenumbers:
950+ if ( selectionrenderer . IsSelectingOverLinenumbers )
951+ {
952+ Point pointerPos = point ;
953+ pointerPos . Y += SingleLineHeight ; //add one more line
954+
955+ //When the selection reaches the end of the textbox select the last line completely
956+ if ( CursorPosition . LineNumber == TotalLines . Count - 1 )
957+ {
958+ pointerPos . Y -= SingleLineHeight ; //add one more line
959+ pointerPos . X = Utils . MeasureLineLenght ( CanvasDevice . GetSharedDevice ( ) , TotalLines . GetLineText ( - 1 ) , TextFormat ) . Width + 10 ;
960+ }
961+ UpdateCursorVariable ( pointerPos ) ;
962+ }
963+ else //Default selection
964+ UpdateCursorVariable ( point ) ;
965+
966+ //Update:
967+ UpdateCursor ( ) ;
968+ selectionrenderer . SelectionEndPosition = new CursorPosition ( CursorPosition . CharacterPosition , CursorPosition . LineNumber ) ;
969+ UpdateSelection ( ) ;
970+ }
971+ }
972+
885973 #region Events
886974 //Handle keyinputs
887975 private void EditContext_TextUpdating ( CoreTextEditContext sender , CoreTextTextUpdatingEventArgs args )
@@ -1148,122 +1236,41 @@ private void TextControlBox_KeyDown(object sender, KeyRoutedEventArgs e)
11481236 }
11491237 }
11501238 //Pointer-events:
1239+
1240+ //Need both the Canvas event and the CoreWindow event, because:
1241+ //AppWindows does not handle CoreWindow events
1242+ //Without coreWindow the selection outside of the window would not work
11511243 private void CoreWindow_PointerReleased ( CoreWindow sender , PointerEventArgs args )
11521244 {
1153- selectionrenderer . IsSelectingOverLinenumbers = false ;
1245+ Debug . WriteLine ( "CoreWindow_PointerReleased" ) ;
11541246
11551247 var point = Utils . GetPointFromCoreWindowRelativeTo ( args , Canvas_Text ) ;
1156- //End text drag/drop -> insert text at cursorposition
1157- if ( DragDropSelection && ! DragDropOverSelection ( point ) )
1158- {
1159- DoDragDropSelection ( ) ;
1160- }
1161- else if ( DragDropSelection )
1162- {
1163- EndDragDropSelection ( ) ;
1164- }
1165-
1166- if ( selectionrenderer . IsSelecting )
1167- {
1168- this . Focus ( FocusState . Programmatic ) ;
1169- selectionrenderer . HasSelection = true ;
1170- }
1171-
1172- selectionrenderer . IsSelecting = false ;
1248+ PointerReleasedAction ( point ) ;
1249+ }
1250+ private void Canvas_Selection_PointerReleased ( object sender , PointerRoutedEventArgs e )
1251+ {
1252+ Debug . WriteLine ( "Canvas_Selection_PointerReleased" ) ;
1253+ PointerReleasedAction ( e . GetCurrentPoint ( sender as UIElement ) . Position ) ;
11731254 }
11741255 private void CoreWindow_PointerMoved ( CoreWindow sender , PointerEventArgs args )
11751256 {
1176- var point = Utils . GetPointFromCoreWindowRelativeTo ( args , Canvas_Text ) ;
1177- if ( selectionrenderer . IsSelecting )
1178- {
1179- double CanvasWidth = Math . Round ( this . ActualWidth , 2 ) ;
1180- double CanvasHeight = Math . Round ( this . ActualHeight , 2 ) ;
1181- double CurPosX = Math . Round ( point . X , 2 ) ;
1182- double CurPosY = Math . Round ( point . Y , 2 ) ;
1183-
1184- if ( CurPosY > CanvasHeight - 50 )
1185- {
1186- VerticalScrollbar . Value += ( CurPosY > CanvasHeight + 30 ? 20 : ( CanvasHeight - CurPosY ) / 180 ) ;
1187- UpdateWhenScrolled ( ) ;
1188- }
1189- else if ( CurPosY < 50 )
1190- {
1191- VerticalScrollbar . Value += CurPosY < - 30 ? - 20 : - ( 50 - CurPosY ) / 20 ;
1192- UpdateWhenScrolled ( ) ;
1193- }
1194-
1195- //Horizontal
1196- if ( CurPosX > CanvasWidth - 100 )
1197- {
1198- ScrollIntoViewHorizontal ( ) ;
1199- UpdateAll ( ) ;
1200- }
1201- else if ( CurPosX < 100 )
1202- {
1203- ScrollIntoViewHorizontal ( ) ;
1204- UpdateAll ( ) ;
1205- }
1206- }
1207-
1208- //Drag drop text -> move the cursor to get the insertion point
1209- if ( DragDropSelection )
1210- {
1211- DragDropOverSelection ( point ) ;
1212- UpdateCursorVariable ( point ) ;
1213- UpdateCursor ( ) ;
1214- }
1215- if ( selectionrenderer . IsSelecting && ! DragDropSelection )
1216- {
1217- //selection started over the linenumbers:
1218- if ( selectionrenderer . IsSelectingOverLinenumbers )
1219- {
1220- Point pointerPos = point ;
1221- pointerPos . Y += SingleLineHeight ; //add one more line
1222-
1223- //When the selection reaches the end of the textbox select the last line completely
1224- if ( CursorPosition . LineNumber == TotalLines . Count - 1 )
1225- {
1226- pointerPos . Y -= SingleLineHeight ; //add one more line
1227- pointerPos . X = Utils . MeasureLineLenght ( CanvasDevice . GetSharedDevice ( ) , TotalLines . GetLineText ( - 1 ) , TextFormat ) . Width + 10 ;
1228- }
1229- UpdateCursorVariable ( pointerPos ) ;
1230- }
1231- else //Default selection
1232- UpdateCursorVariable ( point ) ;
1233-
1234- //Update:
1235- UpdateCursor ( ) ;
1236- selectionrenderer . SelectionEndPosition = new CursorPosition ( CursorPosition . CharacterPosition , CursorPosition . LineNumber ) ;
1237- UpdateSelection ( ) ;
1238- }
1257+ PointerMovedAction ( Utils . GetPointFromCoreWindowRelativeTo ( args , Canvas_Text ) ) ;
12391258 }
12401259 private void Canvas_Selection_PointerMoved ( object sender , PointerRoutedEventArgs e )
12411260 {
12421261 if ( ! HasFocus )
12431262 return ;
12441263
12451264 var point = e . GetCurrentPoint ( Canvas_Selection ) ;
1246- //Drag drop text -> move the cursor to get the insertion point
1247- if ( DragDropSelection )
1248- {
1249- DragDropOverSelection ( point . Position ) ;
1250- UpdateCursorVariable ( point . Position ) ;
1251- UpdateCursor ( ) ;
1252- }
1253- else if ( point . Properties . IsLeftButtonPressed )
1265+
1266+ if ( point . Properties . IsLeftButtonPressed )
12541267 {
12551268 selectionrenderer . IsSelecting = true ;
12561269 }
1270+ PointerMovedAction ( point . Position ) ;
12571271
1258- if ( selectionrenderer . IsSelecting && ! DragDropSelection )
1259- {
1260- UpdateCursorVariable ( e . GetCurrentPoint ( Canvas_Selection ) . Position ) ;
1261- UpdateCursor ( ) ;
1262-
1263- selectionrenderer . SelectionEndPosition = new CursorPosition ( CursorPosition . CharacterPosition , CursorPosition . LineNumber ) ;
1264- UpdateSelection ( ) ;
1265- }
12661272 }
1273+
12671274 private void Canvas_Selection_PointerPressed ( object sender , PointerRoutedEventArgs e )
12681275 {
12691276 selectionrenderer . IsSelectingOverLinenumbers = false ;
@@ -2640,6 +2647,7 @@ private void VerticalScrollbar_Loaded(object sender, RoutedEventArgs e)
26402647 VerticalScrollbar . Maximum = ( ( TotalLines . Count + 1 ) * SingleLineHeight - Scroll . ActualHeight ) / DefaultVerticalScrollSensitivity ;
26412648 VerticalScrollbar . ViewportSize = this . ActualHeight ;
26422649 }
2650+
26432651 }
26442652 public class TextControlBoxDesign
26452653 {
0 commit comments