Unplanned
Last Updated: 31 Jan 2019 13:07 by Dimitar
ADMIN
Dimitar
Created on: 20 Mar 2018 11:24
Category: PdfViewer
Type: Bug Report
6
FIX. RadPdfViewer - pressing Tab should go to next field
Currently, Tab selects the next control.

Attached is sample PDF document. 
Attached Files:
1 comment
Dimitar
Posted on: 31 Jan 2019 13:07

Here is a workaround:

class RadPdfViewer
{
    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        RadPdfViewer1_KeyDown(this, new KeyEventArgs(keyData));
        return base.ProcessCmdKey(ref msg, keyData) || keyData == Keys.Tab;
    }

    private void RadPdfViewer1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode != Keys.Tab)
        {
            return;
        }

        var radPdfViewer1 = sender as RadPdfViewer;
        var editingFields = radPdfViewer1.PdfViewerElement.GetType().GetProperty("EditingFields", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(radPdfViewer1.PdfViewerElement) as EditingFields;
        var curPage = radPdfViewer1.PdfViewerElement.CurrentPage;
        var pageElement = radPdfViewer1.PdfViewerElement.ViewElement.Children[0] as RadFixedPageElement;

        RadElement editor = null;

        foreach (RadFixedPageElement visualPage in radPdfViewer1.PdfViewerElement.ViewElement.Children)
        {
            if (visualPage.Children.Count >= 1)
            {
                curPage = visualPage.Page;
                pageElement = visualPage;
                editor = visualPage.Children.FirstOrDefault();

            }
        }

        if (editor != null)
        {
            for (int i = 0; i < curPage.Annotations.Count; i++)
            {
                Annotation annot = curPage.Annotations[i];

                var rect = (Rect)typeof(Annotation).GetProperty("BoundingRect", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(annot);

                if (AreEquals((Rect)editor.Tag, rect) && i < curPage.Annotations.Count - 1)
                {
                    Annotation nextAnnot = curPage.Annotations[i + 1];                   
                    editingFields.ProcessAnnotation(nextAnnot, radPdfViewer1.PdfViewerElement.CurrentPage, pageElement);
                    break;
                }

                if (i == curPage.Annotations.Count - 1)
                {
                    radPdfViewer1.PdfViewerElement.GoToPage(radPdfViewer1.Document.Pages.IndexOf(curPage) + 2);
                    curPage = radPdfViewer1.PdfViewerElement.CurrentPage;
                    annot = curPage.Annotations[0];
                    editingFields.ProcessAnnotation(annot, radPdfViewer1.PdfViewerElement.CurrentPage, pageElement);
                }
            }
        }
        else
        {
            Annotation annot = curPage.Annotations[0];
            editingFields.ProcessAnnotation(annot, radPdfViewer1.PdfViewerElement.CurrentPage, pageElement);
        }

    }

    bool AreEquals(Rect a, Rect b)
    {
        return Math.Floor(a.X) == Math.Floor(b.X) && Math.Floor(a.Y) == Math.Floor(b.Y);
    }
}