public static bool GetSelectionIndicesForPage( uint pageNumber, SelectionMarker selectionStart, SelectionMarker selectionEnd, out uint selectionStartIndex, out uint selectionEndIndex) { if (selectionStart > selectionEnd) { var tmp = selectionStart; selectionStart = selectionEnd; selectionEnd = tmp; } selectionStartIndex = 0; selectionEndIndex = 0; if (selectionStart.PageNumber < pageNumber) { selectionStartIndex = 0; } else if (selectionStart.PageNumber == pageNumber) { selectionStartIndex = selectionStart.Index; } else { return(false); } if (selectionEnd.PageNumber > pageNumber) { selectionEndIndex = uint.MaxValue; } else if (selectionEnd.PageNumber == pageNumber) { selectionEndIndex = selectionEnd.Index; } else { return(false); } return(true); }
private void PageViewControl_OnPointerPressed(object sender, PointerRoutedEventArgs e) { if (_pageViewObserver == null || e.Pointer.PointerDeviceType != PointerDeviceType.Mouse || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) { return; } _pageViewObserver.IsSelected = false; _pageViewObserver.RaiseSelectionChanging(); RaiseSelectionChanged(); var pageViewControl = VisualTreeHelper .FindElementsInHostCoordinates(e.GetCurrentPoint(null).Position, this, true) .OfType <TextLayerControl>() .FirstOrDefault(); if (pageViewControl?.TextLayer == null) { return; } var startingZone = pageViewControl.FindWordAtPoint(pageViewControl.TextLayer, e.GetCurrentPoint(pageViewControl).Position); if (startingZone == null) { return; } if (_scrollViewer.CapturePointer(e.Pointer)) { var selectionStart = new SelectionMarker(pageViewControl.State.PageNumber, startingZone.StartIndex); _pageViewObserver.SelectionStart = selectionStart; _pageViewObserver.SelectionEnd = selectionStart; _scrollViewer.PointerMoved += PageViewControl_OnPointerMoved; _scrollViewer.PointerReleased += PageViewControl_OnPointerReleased; _scrollViewer.PointerCanceled += PageViewControl_OnPointerReleased; _scrollViewer.PointerCaptureLost += PageViewControl_OnPointerReleased; } }
private async Task <SelectionInterval> FindOnPage(uint pageNumber, string query, SelectionMarker minPosition) { var textLayer = await Source.GetTextLayerAsync(pageNumber); if (textLayer == null) { return(null); } var searchResults = SearchHelper.Search(new[] { textLayer }, query); foreach (var zones in searchResults) { var zoneStart = new SelectionMarker(pageNumber, zones.First().StartIndex); var zoneEnd = new SelectionMarker(pageNumber, zones.Last().EndIndex); if (zoneStart > minPosition) { return(new SelectionInterval(zoneStart, zoneEnd)); } } return(null); }
public SelectionInterval(SelectionMarker start, SelectionMarker end) { Start = start; End = end; }