Completed
Last Updated: 09 Aug 2016 10:02 by ADMIN
ADMIN
Dimitar
Created on: 05 Aug 2016 08:15
Category: Menus
Type: Bug Report
0
FIX. RadMenu - the Cyrillic mnemonic keys are not executed.
To reproduce
- Set the item text like this:
  this.radMenuItem3.Text = "&Пункт меню";


Workaround:
class Item : RadMenuItem
{
    protected override RadDropDownMenu CreateDropDownMenu()
    {
        return new MyDropDownMenu(this);
    }
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadMenuItem);
        }
    }
}
class MyDropDownMenu : RadDropDownMenu
{
    public MyDropDownMenu(RadMenuItem owner) : base(owner)
    { }

   
    protected override bool ProcessMnemonic(Keys keyData)
    {
        var charKey = VirtualKeyCodeToUnicode(keyData);

        List<RadItem> mnemonicItems = new List<RadItem>();
        int selectedIndex = -1;
        RadItem selectedItem = this.GetSelectedItem();
        foreach (RadItem menuItem in this.Items)
        {
            if (IsMnemonic(charKey[0], menuItem.Text) && menuItem.Enabled && menuItem.Visibility == ElementVisibility.Visible)
            {
                mnemonicItems.Add(menuItem);
                if (selectedItem == menuItem)
                {
                    selectedIndex = mnemonicItems.Count - 1;
                }
            }
        }

        if (mnemonicItems.Count == 1)
        {
            mnemonicItems[0].Select();
            mnemonicItems[0].PerformClick();

           
            return true;
        }
        else if (mnemonicItems.Count > 0)
        {
            selectedIndex = (selectedIndex + 1) % mnemonicItems.Count;
            mnemonicItems[selectedIndex].Focus();
            this.SelectItem(mnemonicItems[selectedIndex]);
            return true;
        }


        return false;
        //return base.ProcessMnemonic(keyData);
    }

    public string VirtualKeyCodeToUnicode(Keys key)
    {
        uint virtualKeyCode = (uint) key;
        StringBuilder result = new StringBuilder();

        byte[] keyboardState = new byte[255];
        bool keyboardStateStatus = GetKeyboardState(keyboardState);

        if (!keyboardStateStatus)
        {
            return "";
        }

        uint scanCode = MapVirtualKey(virtualKeyCode, 0);
        IntPtr inputLocaleIdentifier = GetKeyboardLayout(0);

        ToUnicodeEx(virtualKeyCode, scanCode, keyboardState, result, (int) 5, (uint) 0, inputLocaleIdentifier);

        return result.ToString();
    }
    [DllImport("user32.dll")]
    static extern bool GetKeyboardState(byte[] lpKeyState);

    [DllImport("user32.dll")]
    static extern uint MapVirtualKey(uint uCode, uint uMapType);

    [DllImport("user32.dll")]
    static extern IntPtr GetKeyboardLayout(uint idThread);

    [DllImport("user32.dll")]
    static extern int ToUnicodeEx(uint wVirtKey, uint wScanCode, byte[] lpKeyState, [Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pwszBuff, int cchBuff, uint wFlags, IntPtr dwhkl);
}


(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments