public static void PaintControl(DrawContext drawContext, IPresentationDataAccess presentationDataAccess,
                                        SelectionInfo selection, bool controlIsFocused, Rectangle dirtyRect, out int maxRight)
        {
            var drawingVisitor = new DrawingVisitor();

            drawingVisitor.ctx = drawContext;
            drawingVisitor.SearchResultHighlightingHandler = presentationDataAccess.CreateSearchResultHighlightingHandler();
            drawingVisitor.SelectionHighlightingHandler    = presentationDataAccess.CreateSelectionHighlightingHandler();
            drawingVisitor.HighlightingFiltersHandler      = presentationDataAccess.CreateHighlightingFiltersHandler();

            maxRight = 0;
            var  sel = selection;
            bool needToDrawCursor = drawContext.CursorState == true && controlIsFocused && sel.First.Message != null;

            var messagesToDraw = DrawingUtils.GetVisibleMessages(drawContext, presentationDataAccess, dirtyRect);

            var displayLinesEnum = presentationDataAccess.GetViewLines(messagesToDraw.begin, messagesToDraw.end);

            foreach (var il in displayLinesEnum)
            {
                drawingVisitor.DisplayIndex = il.LineIndex;
                drawingVisitor.TextLineIdx  = il.TextLineIndex;
                drawingVisitor.IsBookmarked = il.IsBookmarked;
                DrawingUtils.Metrics m = DrawingUtils.GetMetrics(il, drawContext);
                drawingVisitor.m = m;
                if (needToDrawCursor && sel.First.DisplayIndex == il.LineIndex)
                {
                    drawingVisitor.CursorPosition = sel.First;
                }
                else
                {
                    drawingVisitor.CursorPosition = null;
                }

                il.Message.Visit(drawingVisitor);

                maxRight = Math.Max(maxRight, m.OffsetTextRect.Right);
            }

            DrawFocusedMessageMark(drawContext, presentationDataAccess, messagesToDraw);

            drawingVisitor.SearchResultHighlightingHandler?.Dispose();
            drawingVisitor.SelectionHighlightingHandler?.Dispose();
            drawingVisitor.HighlightingFiltersHandler?.Dispose();
        }
        public static IEnumerable <ViewLine> GetVisibleMessagesIterator(DrawContext drawContext, IPresentationDataAccess presentationDataAccess, Rectangle viewRect)
        {
            var vl = DrawingUtils.GetVisibleMessages(drawContext, presentationDataAccess, viewRect);

            return(presentationDataAccess.GetViewLines(vl.begin, vl.end));
        }