private void windowListener_PositionChanging(object sender, WindowListenerEventArgs e)
 {
     // if Word's window has been moved hide the auto-complete window
     if (this.Visible)
     {
         this.Visible = false;
     }
 }
 private void windowListener_Paint(object sender, WindowListenerEventArgs e)
 {
     // if Word's window has been invalidated hide the auto-complete window
     if (this.Visible)
     {
         this.Visible = false;
     }
 }
 private void windowListener_LostFocus(object sender, WindowListenerEventArgs e)
 {
     // if the focus has been moved from word to some other application except the
     // autocomplete window then make the auto-complete window disappear
     if (windowListener.HasFocus() || this.Focused || this.lstItems.Focused)
     {
         return;
     }
     this.Visible = false;
 }
        private void windowListener_KeyDown(object sender, WindowListenerEventArgs e)
        {
            windowListener.CheckIgnoreCodes = this.Visible;
            if (!this.Enabled)
            {
                return;
            }
            int keyValue = e.wparam;

            if (this.Visible)
            {
                // PgUp, PgDn, Up, Down
                if ((keyValue == 33) || (keyValue == 34) || (keyValue == 38) || (keyValue == 40) || (keyValue == 13) || (keyValue == 9))
                {
                    //this.Focus();
                    this.SendKey((char)keyValue);
                }

                if (keyValue == 13 || ((keyValue == 9 /* || keyValue == 32 */) && !e.KeyStateMonitor.Alt && !e.KeyStateMonitor.Control && !e.KeyStateMonitor.Shift))
                {
                    SelectCurrentWord();
                }

                // characters that make the window invisible
                //  ->                  <-                  home                end                 alt                 esc
                if ((keyValue == 39) || (keyValue == 37) || (keyValue == 36) || (keyValue == 35) || (keyValue == 18) || (keyValue == 27))
                {
                    this.Visible = false;
                }

                if (keyValue == 8 && e.KeyStateMonitor.Control)
                {
                    this.Visible = false;
                }
            }
        }
Beispiel #5
0
        private IntPtr MsgHookCallBack(int nCode, IntPtr wParam, ref MSG lParam)
        {
            if (nCode < 0)
            {
                return(User32.CallNextHookEx(m_gmHookHandle, nCode, wParam, ref lParam));
            }

            if (true) //(wParam.ToInt32() == PM_NOREMOVE)
            {
                bool isMsgHandled = false;

                if (lParam.hwnd == this.m_windowHandle)
                {
                    Msgs wmMessage = (Msgs)lParam.message;

                    // check for the messages that should be handled (, and ignored).
                    if (hndldMsgType != Msgs.WM_NULL)
                    {
                        if (lParam.wParam == hndldMsgWP)
                        {
                            switch (hndldMsgType)
                            {
                            case Msgs.WM_KEYUP:
                            case Msgs.WM_SYSKEYUP:
                                hndldMsgType = Msgs.WM_NULL;
                                break;

                            case Msgs.WM_KEYDOWN:
                            case Msgs.WM_SYSKEYDOWN:
                                hndldMsgType = Msgs.WM_CHAR;
                                break;

                            case Msgs.WM_CHAR:
                            case Msgs.WM_SYSCHAR:
                                hndldMsgType = Msgs.WM_KEYUP;
                                break;

                            default:
                                hndldMsgType = Msgs.WM_NULL;
                                break;
                            }

                            lParam.message = (uint)Msgs.WM_NULL;
                            lParam.wParam  = 0;
                            lParam.lParam  = 0;
                            isMsgHandled   = true;
                        }
                        else
                        {
                            hndldMsgType = Msgs.WM_NULL;
                        }
                    }

                    if (!isMsgHandled &&
                        !(lParam.message == prevMsgType && lParam.time == prevMsgTime))
                    {
                        WindowListenerEventArgs eventArgs = new WindowListenerEventArgs();
                        eventArgs.handled = false;
                        eventArgs.message = (int)lParam.message;
                        eventArgs.lparam  = lParam.lParam;
                        eventArgs.wparam  = lParam.wParam;

                        prevMsgType = (int)lParam.message;
                        prevMsgTime = lParam.time;

                        switch (wmMessage)
                        {
                        case Msgs.WM_KEYUP:
                        case Msgs.WM_SYSKEYUP:
                            if (KeyUp != null)
                            {
                                KeyUp(this, eventArgs);
                            }
                            break;

                        case Msgs.WM_KEYDOWN:
                        case Msgs.WM_SYSKEYDOWN:
                            if (KeyDown != null)
                            {
                                KeyDown(this, eventArgs);
                            }
                            break;

                        case Msgs.WM_CHAR:
                        case Msgs.WM_SYSCHAR:
                            if (KeyPressed != null)
                            {
                                KeyPressed(this, eventArgs);
                            }
                            break;

                        default:
                            if (OtherMessage != null)
                            {
                                OtherMessage(this, eventArgs);
                            }
                            break;
                        }

                        if (eventArgs.handled)
                        {
                            hndldMsgTime = lParam.time;
                            hndldMsgType = wmMessage;
                            hndldMsgWP   = lParam.time;

                            lParam.message = (uint)Msgs.WM_NULL;
                            lParam.lParam  = 0;
                            lParam.wParam  = 0;
                        }
                    }

                    if (!isMsgHandled && CheckIgnoreCodes)
                    {
                        if (wmMessage == Msgs.WM_KEYDOWN || wmMessage == Msgs.WM_KEYUP || wmMessage == Msgs.WM_CHAR ||
                            wmMessage == Msgs.WM_SYSKEYDOWN || wmMessage == Msgs.WM_SYSKEYUP || wmMessage == Msgs.WM_SYSCHAR)
                        {
                            if (m_setKeyboardIgnoreCodes.Contains(lParam.wParam))
                            {
                                lParam.message = (uint)Msgs.WM_NULL;
                                lParam.lParam  = 0;
                                lParam.wParam  = 0;
                            }
                        }
                    }
                }

                if (lParam.message == (uint)Msgs.WM_NULL && lParam.lParam == 0 && lParam.wParam == 0)
                {
                    return((IntPtr)1);
                }
            }

            return(User32.CallNextHookEx(m_gmHookHandle, nCode, wParam, ref lParam));
        }
Beispiel #6
0
        private IntPtr CwpHookCallBack(int nCode, IntPtr wParam, ref CWPSTRUCT lParam)
        {
            if (nCode < 0)
            {
                return(User32.CallNextHookEx(m_gmHookHandle, nCode, wParam, ref lParam));
            }

            if (true) //(wParam.ToInt32() == PM_NOREMOVE)
            {
                if (lParam.hwnd == this.m_windowHandle)
                {
                    WindowListenerEventArgs eventArgs = new WindowListenerEventArgs();
                    eventArgs.handled = false;
                    eventArgs.message = (int)lParam.message;
                    eventArgs.lparam  = lParam.lParam;
                    eventArgs.wparam  = lParam.wParam;

                    Msgs wmMessage = (Msgs)lParam.message;

                    switch (wmMessage)
                    {
                    case Msgs.WM_KILLFOCUS:
                        if (LostFocus != null)
                        {
                            LostFocus(this, eventArgs);
                        }
                        break;

                    case Msgs.WM_SETFOCUS:
                        if (GetFocus != null)
                        {
                            GetFocus(this, eventArgs);
                        }
                        break;

                    case Msgs.WM_WINDOWPOSCHANGING:
                        if (PositionChanging != null)
                        {
                            PositionChanging(this, eventArgs);
                        }
                        break;

                    case Msgs.WM_PAINT:
                        if (this.Paint != null)
                        {
                            Paint(this, eventArgs);
                        }
                        break;

                    default:
                        if (OtherMessage != null)
                        {
                            OtherMessage(this, eventArgs);
                        }
                        break;
                    }

                    if (eventArgs.handled)
                    {
                        lParam.message = (uint)Msgs.WM_NULL;
                        lParam.lParam  = 0;
                        lParam.wParam  = 0;

                        return((IntPtr)1);
                    }
                }
            }

            return(User32.CallNextHookEx(m_cwpHookHandle, nCode, wParam, ref lParam));
        }
        private void windowListener_KeyPressed(object sender, WindowListenerEventArgs e)
        {
            if (!this.Enabled)
            {
                return;
            }

            int  keyValue = e.wparam;
            char chKey    = Convert.ToChar(keyValue);

            if (this.Visible)
            {
                if (keyValue == 8)
                {
                    if (!e.KeyStateMonitor.Control)
                    {
                        if (preText.Length > 0)
                        {
                            preText = preText.Substring(0, preText.Length - 1);
                        }
                    }
                    else
                    {
                        this.Visible = false;
                    }
                }
                else if (StringUtil.IsInArabicWord(chKey))
                {
                    preText += chKey;
                }
                else
                {
                    this.Visible = false;
                }

                if (preText.Length > 0)
                {
                    this.SetItems(preText);
                    //ShowAtCaret();
                }
                else
                {
                    if (this.Visible == true)
                    {
                        this.Visible = false;
                    }
                }
            }
            else // if is not visible
            {
                if (!CompleteWithoutHotKey)
                {
                    return;
                }

                if (StringUtil.IsInArabicWord(chKey))
                {
                    Range r = RangeUtils.GetWordBeforeCursor(Globals.ThisAddIn.Application.Selection);
                    if (RangeUtils.IsRangeEmpty(r))
                    {
                        TryRetrieveSelection();
                        r = RangeUtils.GetWordBeforeCursor(Globals.ThisAddIn.Application.Selection);
                    }

                    if (!RangeUtils.IsRangeEmpty(r))
                    {
                        string text        = r.Text + chKey;
                        string refinedText = StringUtil.RefineAndFilterPersianWord(text);
                        if (refinedText.Length >= CompleteWithoutHotKeyMinLength)
                        {
                            SetItems(text); // make sure you are sending the not-refined version of the string
                            if (lstItems.Items.Count > 0)
                            {
                                ShowAtCaret();
                            }
                        }
                    }
                }
            }
        }