aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.UI/Notifications/DefaultNotificationProvider.cs
blob: f03d9accdc123723b25d70c065fb1a1a16923a19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Tango.PPC.Common.Notifications;
using Tango.Core;
using System.Collections.Concurrent;
using System.Windows.Media.Imaging;
using Tango.SharedUI.Helpers;
using System.Timers;
using Tango.Core.Commands;
using Tango.Touch.Controls;
using Tango.SharedUI;
using System.Reflection;
using Tango.Core.DI;

namespace Tango.PPC.UI.Notifications
{
    /// <summary>
    /// Represents the default PPC notification provider.
    /// </summary>
    /// <seealso cref="Tango.Core.ExtendedObject" />
    /// <seealso cref="Tango.PPC.Common.Notifications.INotificationProvider" />
    public class DefaultNotificationProvider : ExtendedObject, INotificationProvider
    {
        private ConcurrentQueue<PendingNotification<MessageBoxVM, bool>> _pendingMessageBoxes;
        private ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>> _pendingDialogs;

        /// <summary>
        /// Gets the collection of notification items.
        /// </summary>
        public ObservableCollection<NotificationItem> NotificationItems { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultNotificationProvider"/> class.
        /// </summary>
        public DefaultNotificationProvider()
        {
            NotificationItems = new ObservableCollection<NotificationItem>();
            _pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>();
            _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>();

            PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x));

            NotificationItems.EnableCrossThreadOperations();
        }

        private MessageBoxVM _currentMessageBox;
        /// <summary>
        /// Gets the current message box if any.
        /// </summary>
        public MessageBoxVM CurrentMessageBox
        {
            get { return _currentMessageBox; }
            private set
            {
                _currentMessageBox = value;
                RaisePropertyChangedAuto();
                RaisePropertyChanged(nameof(HasMessageBox));
            }
        }

        /// <summary>
        /// Gets a value indicating whether a message box is available.
        /// </summary>
        public bool HasMessageBox
        {
            get
            {
                return CurrentMessageBox != null;
            }
        }

        private FrameworkElement _currentDialog;
        /// <summary>
        /// Gets the current dialog if any.
        /// </summary>
        public FrameworkElement CurrentDialog
        {
            get { return _currentDialog; }
            private set
            {
                _currentDialog = value;
                RaisePropertyChangedAuto();
                RaisePropertyChanged(nameof(HasDialog));
            }
        }

        /// <summary>
        /// Gets a value indicating whether a dialog is available.
        /// </summary>
        public bool HasDialog
        {
            get
            {
                return CurrentDialog != null;
            }
        }

        /// <summary>
        /// Shows an error message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowError(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Icon = TouchIconKind.AlertOctagon,
                Title = "Error",
                Brush = Application.Current.Resources["TangoMessageBoxErrorBrush"] as Brush,
            });
        }

        /// <summary>
        /// Shows an information message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowInfo(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Icon = TouchIconKind.InfoCircleSolid,
                Title = "Information",
                Brush = Application.Current.Resources["TangoMessageBoxInfoBrush"] as Brush,
            });
        }

        /// <summary>
        /// Shows warning message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task ShowWarning(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Icon = TouchIconKind.Alert,
                Title = "Warning",
                Brush = Application.Current.Resources["TangoMessageBoxWarningBrush"] as Brush,
            });
        }

        /// <summary>
        /// Shows a question message box.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        public Task<bool> ShowQuestion(string message)
        {
            return ShowMessageBox(new MessageBoxVM()
            {
                Message = message,
                Icon = TouchIconKind.QuestionCircleSolid,
                Title = "Confirm",
                HasCancel = true,
                Brush = Application.Current.Resources["TangoMessageBoxQuestionBrush"] as Brush,
            });
        }

        /// <summary>
        /// Shows the message box.
        /// </summary>
        /// <param name="vm">The view model.</param>
        /// <returns></returns>
        private Task<bool> ShowMessageBox(MessageBoxVM vm)
        {
            LogManager.Log($"Displaying MessagBox '{vm.Message}'.");

            TaskCompletionSource<bool> source = new TaskCompletionSource<bool>();

            vm.Accepted += () => { OnMessageBoxClosed(); source.SetResult(true); };
            vm.Canceled += () => { OnMessageBoxClosed(); source.SetResult(false); };

            if (CurrentMessageBox == null)
            {
                CurrentMessageBox = vm;
            }
            else
            {
                _pendingMessageBoxes.Enqueue(new PendingNotification<MessageBoxVM, bool>(vm, source));
            }

            return source.Task;
        }

        /// <summary>
        /// Called when the message box has been closed.
        /// </summary>
        private void OnMessageBoxClosed()
        {
            LogManager.Log("MessageBox closed.");

            CurrentMessageBox = null;

            if (_pendingMessageBoxes.Count > 0)
            {
                PendingNotification<MessageBoxVM, bool> p = null;
                if (_pendingMessageBoxes.TryDequeue(out p))
                {
                    CurrentMessageBox = p.Item;
                }
            }
        }

        /// <summary>
        /// Inserts the notification item to the bottom of the notifications collection.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public NotificationItem PushNotification(NotificationItem item)
        {
            LogManager.Log($"Pushing NotificationItem '{item.GetType().Name}'.");
            item.RemoveAction = () => { PopNotification(item); };
            NotificationItems.Insert(0, item);
            RaisePropertyChanged(nameof(HasNotificationItems));
            return item;
        }

        /// <summary>
        /// Pushes the notification.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public NotificationItem PushNotification<T>() where T : NotificationItem
        {
            return PushNotification(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Removed the specified notification item.
        /// </summary>
        /// <param name="item">The item.</param>
        public void PopNotification(NotificationItem item)
        {
            LogManager.Log($"Popping out NotificationItem '{item.GetType().Name}'.");
            NotificationItems.Remove(item);
            RaisePropertyChanged(nameof(HasNotificationItems));
        }

        /// <summary>
        /// Gets a value indicating whether this instance has notification items.
        /// </summary>
        public bool HasNotificationItems
        {
            get
            {
                return NotificationItems.Count > 0;
            }
        }

        /// <summary>
        /// Gets the pop notification command.
        /// </summary>
        public RelayCommand<NotificationItem> PopNotificationCommand { get; private set; }

        /// <summary>
        /// Displays the specified dialog in a modal design.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datacontext">The data context.</param>
        /// <param name="view">The view.</param>
        /// <returns></returns>
        public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM
        {
            view.DataContext = datacontext;

            TangoIOC.Default.Inject(datacontext);

            view.Loaded += (_, __) =>
            {
                view.DataContext = datacontext;
                datacontext.OnShow();
            };

            TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>();

            datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); };
            datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); };

            if (CurrentDialog == null)
            {
                CurrentDialog = view;
            }
            else
            {
                _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source));
            }

            var result = await source.Task;
            return result as T;
        }

        /// <summary>
        /// Called when [dialog closed].
        /// </summary>
        private void OnDialogClosed()
        {
            CurrentDialog = null;

            if (_pendingDialogs.Count > 0)
            {
                PendingNotification<DialogAndView, DialogViewVM> p = null;
                if (_pendingDialogs.TryDequeue(out p))
                {
                    CurrentDialog = p.Item.View;
                }
            }
        }

        /// <summary>
        /// Displays the specified dialog in a modal design.
        /// The notification provider will try to locate the view automatically using conventions.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="datacontext">The data context.</param>
        /// <returns></returns>
        public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM
        {
            var callingAssembly = datacontext.GetType().Assembly;
            String viewName = datacontext.GetType().FullName.Replace("VM", "");
            var viewType = callingAssembly.GetType(viewName);

            if (viewType == null)
            {
                throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!");
            }

            var view = Activator.CreateInstance(viewType) as FrameworkElement;

            if (view == null)
            {
                throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element.");
            }

            return ShowDialog<T>(datacontext, Activator.CreateInstance(viewType) as FrameworkElement);
        }

        /// <summary>
        /// Displays the specified dialog in a modal design.
        /// The data context instance will be automatically created.
        /// The notification provider will try to locate the view automatically using conventions.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public Task<T> ShowDialog<T>() where T : DialogViewVM
        {
            return ShowDialog<T>(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Sets the global busy message.
        /// </summary>
        /// <param name="message">The message.</param>
        public void SetGlobalBusyMessage(string message)
        {
            GlobalBusyMessage = message;
            IsInGlobalBusyState = true;

            RaisePropertyChanged(nameof(IsInGlobalBusyState));
            RaisePropertyChanged(nameof(GlobalBusyMessage));
        }

        /// <summary>
        /// Releases the global busy message.
        /// </summary>
        public void ReleaseGlobalBusyMessage()
        {
            GlobalBusyMessage = null;
            IsInGlobalBusyState = false;

            RaisePropertyChanged(nameof(IsInGlobalBusyState));
            RaisePropertyChanged(nameof(GlobalBusyMessage));
        }

        /// <summary>
        /// Gets the current global busy message.
        /// </summary>
        public string GlobalBusyMessage { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is in global busy state.
        /// </summary>
        public bool IsInGlobalBusyState { get; private set; }

        private AppBarItem _currentAppBarItem;
        /// <summary>
        /// Gets the current application bar item.
        /// </summary>
        public AppBarItem CurrentAppBarItem
        {
            get { return _currentAppBarItem; }
            set { _currentAppBarItem = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasAppBarItem)); }
        }

        /// <summary>
        /// Gets a value indicating whether this instance has application bar item.
        /// </summary>
        public bool HasAppBarItem
        {
            get { return CurrentAppBarItem != null; }
        }

        /// <summary>
        /// Pushes the application bar item.
        /// </summary>
        /// <param name="appBarItem">The application bar item.</param>
        /// <returns></returns>
        public AppBarItem PushAppBarItem(AppBarItem appBarItem)
        {
            LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'.");
            CurrentAppBarItem = appBarItem;
            appBarItem.RemoveAction = () => PopAppBarItem(appBarItem);
            return appBarItem;
        }

        /// <summary>
        /// Pushes the application bar item.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public AppBarItem PushAppBarItem<T>() where T : AppBarItem
        {
            return PushAppBarItem(Activator.CreateInstance<T>());
        }

        /// <summary>
        /// Pops the application bar item.
        /// </summary>
        /// <param name="appBarItem">The application bar item.</param>
        public void PopAppBarItem(AppBarItem appBarItem)
        {
            LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'.");
            CurrentAppBarItem = null;
        }
    }
}
an class="k">throw new ArgumentNullException("textLine"); double pos = VisualTop; foreach (TextLine tl in TextLines) { if (tl == textLine) { switch (yPositionMode) { case VisualYPosition.LineTop: return pos; case VisualYPosition.LineMiddle: return pos + tl.Height / 2; case VisualYPosition.LineBottom: return pos + tl.Height; case VisualYPosition.TextTop: return pos + tl.Baseline - textView.DefaultBaseline; case VisualYPosition.TextBottom: return pos + tl.Baseline - textView.DefaultBaseline + textView.DefaultLineHeight; case VisualYPosition.TextMiddle: return pos + tl.Baseline - textView.DefaultBaseline + textView.DefaultLineHeight / 2; case VisualYPosition.Baseline: return pos + tl.Baseline; default: throw new ArgumentException("Invalid yPositionMode:" + yPositionMode); } } else { pos += tl.Height; } } throw new ArgumentException("textLine is not a line in this VisualLine"); } /// <summary> /// Gets the start visual column from the specified text line. /// </summary> public int GetTextLineVisualStartColumn(TextLine textLine) { if (!TextLines.Contains(textLine)) throw new ArgumentException("textLine is not a line in this VisualLine"); int col = 0; foreach (TextLine tl in TextLines) { if (tl == textLine) break; else col += tl.Length; } return col; } /// <summary> /// Gets a TextLine by the visual position. /// </summary> public TextLine GetTextLineByVisualYPosition(double visualTop) { const double epsilon = 0.0001; double pos = this.VisualTop; foreach (TextLine tl in TextLines) { pos += tl.Height; if (visualTop + epsilon < pos) return tl; } return TextLines[TextLines.Count - 1]; } /// <summary> /// Gets the visual position from the specified visualColumn. /// </summary> /// <returns>Position in device-independent pixels /// relative to the top left of the document.</returns> public Point GetVisualPosition(int visualColumn, VisualYPosition yPositionMode) { TextLine textLine = GetTextLine(visualColumn); double xPos = GetTextLineVisualXPosition(textLine, visualColumn); double yPos = GetTextLineVisualYPosition(textLine, yPositionMode); return new Point(xPos, yPos); } /// <summary> /// Gets the distance to the left border of the text area of the specified visual column. /// The visual column must belong to the specified text line. /// </summary> public double GetTextLineVisualXPosition(TextLine textLine, int visualColumn) { if (textLine == null) throw new ArgumentNullException("textLine"); double xPos = textLine.GetDistanceFromCharacterHit( new CharacterHit(Math.Min(visualColumn, VisualLengthWithEndOfLineMarker), 0)); if (visualColumn > VisualLengthWithEndOfLineMarker) { xPos += (visualColumn - VisualLengthWithEndOfLineMarker) * textView.WideSpaceWidth; } return xPos; } /// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// If the user clicks between two visual columns, rounds to the nearest column. /// </summary> public int GetVisualColumn(Point point) { return GetVisualColumn(point, textView.Options.EnableVirtualSpace); } /// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// If the user clicks between two visual columns, rounds to the nearest column. /// </summary> public int GetVisualColumn(Point point, bool allowVirtualSpace) { return GetVisualColumn(GetTextLineByVisualYPosition(point.Y), point.X, allowVirtualSpace); } /// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// If the user clicks between two visual columns, rounds to the nearest column. /// </summary> public int GetVisualColumn(TextLine textLine, double xPos, bool allowVirtualSpace) { if (xPos > textLine.WidthIncludingTrailingWhitespace) { if (allowVirtualSpace && textLine == TextLines[TextLines.Count - 1]) { int virtualX = (int)Math.Round((xPos - textLine.WidthIncludingTrailingWhitespace) / textView.WideSpaceWidth); return VisualLengthWithEndOfLineMarker + virtualX; } } CharacterHit ch = textLine.GetCharacterHitFromDistance(xPos); return ch.FirstCharacterIndex + ch.TrailingLength; } /// <summary> /// Validates the visual column and returns the correct one. /// </summary> public int ValidateVisualColumn(TextViewPosition position, bool allowVirtualSpace) { return ValidateVisualColumn(Document.GetOffset(position.Location), position.VisualColumn, allowVirtualSpace); } /// <summary> /// Validates the visual column and returns the correct one. /// </summary> public int ValidateVisualColumn(int offset, int visualColumn, bool allowVirtualSpace) { int firstDocumentLineOffset = this.FirstDocumentLine.Offset; if (visualColumn < 0) { return GetVisualColumn(offset - firstDocumentLineOffset); } else { int offsetFromVisualColumn = GetRelativeOffset(visualColumn); offsetFromVisualColumn += firstDocumentLineOffset; if (offsetFromVisualColumn != offset) { return GetVisualColumn(offset - firstDocumentLineOffset); } else { if (visualColumn > VisualLength && !allowVirtualSpace) { return VisualLength; } } } return visualColumn; } /// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// If the user clicks between two visual columns, returns the first of those columns. /// </summary> public int GetVisualColumnFloor(Point point) { return GetVisualColumnFloor(point, textView.Options.EnableVirtualSpace); } /// <summary> /// Gets the visual column from a document position (relative to top left of the document). /// If the user clicks between two visual columns, returns the first of those columns. /// </summary> public int GetVisualColumnFloor(Point point, bool allowVirtualSpace) { TextLine textLine = GetTextLineByVisualYPosition(point.Y); if (point.X > textLine.WidthIncludingTrailingWhitespace) { if (allowVirtualSpace && textLine == TextLines[TextLines.Count - 1]) { // clicking virtual space in the last line int virtualX = (int)((point.X - textLine.WidthIncludingTrailingWhitespace) / textView.WideSpaceWidth); return VisualLengthWithEndOfLineMarker + virtualX; } else { // GetCharacterHitFromDistance returns a hit with FirstCharacterIndex=last character in line // and TrailingLength=1 when clicking behind the line, so the floor function needs to handle this case // specially and return the line's end column instead. return GetTextLineVisualStartColumn(textLine) + textLine.Length; } } CharacterHit ch = textLine.GetCharacterHitFromDistance(point.X); return ch.FirstCharacterIndex; } /// <summary> /// Gets whether the visual line was disposed. /// </summary> public bool IsDisposed { get { return phase == LifetimePhase.Disposed; } } internal void Dispose() { if (phase == LifetimePhase.Disposed) return; Debug.Assert(phase == LifetimePhase.Live); phase = LifetimePhase.Disposed; foreach (TextLine textLine in TextLines) { textLine.Dispose(); } } /// <summary> /// Gets the next possible caret position after visualColumn, or -1 if there is no caret position. /// </summary> public int GetNextCaretPosition(int visualColumn, LogicalDirection direction, CaretPositioningMode mode, bool allowVirtualSpace) { if (!HasStopsInVirtualSpace(mode)) allowVirtualSpace = false; if (elements.Count == 0) { // special handling for empty visual lines: if (allowVirtualSpace) { if (direction == LogicalDirection.Forward) return Math.Max(0, visualColumn + 1); else if (visualColumn > 0) return visualColumn - 1; else return -1; } else { // even though we don't have any elements, // there's a single caret stop at visualColumn 0 if (visualColumn < 0 && direction == LogicalDirection.Forward) return 0; else if (visualColumn > 0 && direction == LogicalDirection.Backward) return 0; else return -1; } } int i; if (direction == LogicalDirection.Backward) { // Search Backwards: // If the last element doesn't handle line borders, return the line end as caret stop if (visualColumn > this.VisualLength && !elements[elements.Count-1].HandlesLineBorders && HasImplicitStopAtLineEnd(mode)) { if (allowVirtualSpace) return visualColumn - 1; else return this.VisualLength; } // skip elements that start after or at visualColumn for (i = elements.Count - 1; i >= 0; i--) { if (elements[i].VisualColumn < visualColumn) break; } // search last element that has a caret stop for (; i >= 0; i--) { int pos = elements[i].GetNextCaretPosition( Math.Min(visualColumn, elements[i].VisualColumn + elements[i].VisualLength + 1), direction, mode); if (pos >= 0) return pos; } // If we've found nothing, and the first element doesn't handle line borders, // return the line start as normal caret stop. if (visualColumn > 0 && !elements[0].HandlesLineBorders && HasImplicitStopAtLineStart(mode)) return 0; } else { // Search Forwards: // If the first element doesn't handle line borders, return the line start as caret stop if (visualColumn < 0 && !elements[0].HandlesLineBorders && HasImplicitStopAtLineStart(mode)) return 0; // skip elements that end before or at visualColumn for (i = 0; i < elements.Count; i++) { if (elements[i].VisualColumn + elements[i].VisualLength > visualColumn) break; } // search first element that has a caret stop for (; i < elements.Count; i++) { int pos = elements[i].GetNextCaretPosition( Math.Max(visualColumn, elements[i].VisualColumn - 1), direction, mode); if (pos >= 0) return pos; } // if we've found nothing, and the last element doesn't handle line borders, // return the line end as caret stop if ((allowVirtualSpace || !elements[elements.Count-1].HandlesLineBorders) && HasImplicitStopAtLineEnd(mode)) { if (visualColumn < this.VisualLength) return this.VisualLength; else if (allowVirtualSpace) return visualColumn + 1; } } // we've found nothing, return -1 and let the caret search continue in the next line return -1; } static bool HasStopsInVirtualSpace(CaretPositioningMode mode) { return mode == CaretPositioningMode.Normal; } static bool HasImplicitStopAtLineStart(CaretPositioningMode mode) { return mode == CaretPositioningMode.Normal; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "mode", Justification = "make method consistent with HasImplicitStopAtLineStart; might depend on mode in the future")] static bool HasImplicitStopAtLineEnd(CaretPositioningMode mode) { return true; } VisualLineDrawingVisual visual; internal VisualLineDrawingVisual Render() { Debug.Assert(phase == LifetimePhase.Live); if (visual == null) visual = new VisualLineDrawingVisual(this); return visual; } } sealed class VisualLineDrawingVisual : DrawingVisual { public readonly VisualLine VisualLine; public readonly double Height; internal bool IsAdded; public VisualLineDrawingVisual(VisualLine visualLine) { this.VisualLine = visualLine; var drawingContext = RenderOpen(); double pos = 0; foreach (TextLine textLine in visualLine.TextLines) { textLine.Draw(drawingContext, new Point(0, pos), InvertAxes.None); pos += textLine.Height; } this.Height = pos; drawingContext.Close(); } protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters) { return null; } protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) { return null; } } }