Exemple #1
0
        private void Lbl_MouseClick(object sender, MouseEventArgs e)
        {
            MyLabel lbl   = (MyLabel)sender;
            int     index = tabCtrlMain.SelectedIndex;

            if (index < 0 && index >= lstCtrlBrowser.Count)
            {
                return;
            }
            MenuBrowser menuBrowser = (MenuBrowser)lbl.Tag;
            CtrlBrowser ctrlBrowser = lstCtrlBrowser[index];

            if (!ctrlBrowser.GetIsLoadedForFirstTime())
            {
                return;
            }
            int i = 0;

            while (!ctrlBrowser.GetCanCopy() && i < 400)
            {
                Thread.Sleep(10);
                i++;
            }
            if (ctrlBrowser.GetCanCopy())
            {
                this.last_command           = menuBrowser.Command;
                this.isCopyWithoutTranslate = true;
                ctrlBrowser.webBrowser.Copy();
            }
        }
        //public void TranslateENtoAR(string word)
        //{
        //    webbrsr.Navigate(new Uri("https://translate.google.com/#en/ar/" + word));
        //}
        public void Translate(MenuBrowser menuBrowser, string word)
        {
            //if (webbrsr.ca) MessageBox.Show("Disp");
            lblDictName.Text = menuBrowser.Name;
            this.Text        = menuBrowser.Name;
            string newUrl = menuBrowser.Url.Replace("%WORD%", word);

            txtUrl.Text = newUrl;
            webbrsr.Load(new Uri(newUrl).AbsoluteUri);
        }
Exemple #3
0
        private void ReloadDicts()
        {
            lstMyBrowserInfo.Clear();
            foreach (var mb in lstMenuBrowser)
            {
                if (mb.FrmTranslateModal != null)
                {
                    try { mb.FrmTranslateModal.webbrsr.Dispose(); } catch { }
                    try { mb.FrmTranslateModal.Dispose(); } catch { }
                    mb.FrmTranslateModal = null;
                }
            }
            lstMenuBrowser.Clear();

            int          command            = 29502;
            const string MY_SEPARATOR       = "@@@@@@@@";
            string       path               = Path.GetDirectoryName(Application.ExecutablePath);
            var          lines              = File.ReadAllLines(Path.Combine(path, "mydicts.txt"));
            bool         isInRightClickDict = false;
            string       error              = string.Empty;

            foreach (string line in lines)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (line.StartsWith("#"))
                {
                    continue;
                }
                if (line.StartsWith("[right_click_dict]", StringComparison.CurrentCultureIgnoreCase))
                {
                    isInRightClickDict = true;
                    continue;
                }
                if (!line.Contains("%WORD%"))
                {
                    error = error + Environment.NewLine + "LINE:" + line + " conatins no %WORD%";
                }
                string[] ar = line.Split(new string[] { MY_SEPARATOR }, StringSplitOptions.RemoveEmptyEntries);
                if (isInRightClickDict)
                {
                    MenuBrowser menuBrowser = new MenuBrowser();
                    menuBrowser.Command = command++;
                    menuBrowser.Url     = ar[0];
                    if (ar.Length >= 2)
                    {
                        menuBrowser.Name = ar[1];
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(menuBrowser.Url);
                            menuBrowser.Name = uri.Host;
                        }
                        catch
                        {
                        }
                    }

                    if (ar.Length >= 2 && ar[2].StartsWith("f", StringComparison.CurrentCultureIgnoreCase))
                    {
                        menuBrowser.Shortcut = ar[2].ToUpper();
                    }
                    lstMenuBrowser.Add(menuBrowser);
                }
                else
                {
                    MyBrowserInfo info = new MyBrowserInfo();
                    info.Url = ar[0];
                    if (ar.Length >= 2)
                    {
                        info.Name = ar[1];
                    }
                    else
                    {
                        try
                        {
                            Uri uri = new Uri(info.Url);
                            info.Name = uri.Host;
                        }
                        catch
                        {
                        }
                    }
                    for (int i = 2; i < ar.Length; i++)
                    {
                        string[] ar2 = ar[i].Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);
                        if (ar2[0].Equals("scrolldown", StringComparison.CurrentCultureIgnoreCase))
                        {
                            info.ScrollDown = Convert.ToInt32(ar2[1]);
                        }
                        //else if (ar2[0].Equals("scrollleft", StringComparison.CurrentCultureIgnoreCase))
                        //    info.ScrollLeft = Convert.ToInt32(ar2[1]);
                        else if (ar2[0].Equals("scrollright", StringComparison.CurrentCultureIgnoreCase))
                        {
                            info.ScrollRight = Convert.ToInt32(ar2[1]);
                        }
                        else if (ar2[0].Equals("zoomlevel", StringComparison.CurrentCultureIgnoreCase))
                        {
                            info.Zoom = Convert.ToInt32(ar2[1]);
                        }
                        else
                        {
                            throw new Exception("Error in line:" + line);
                        }
                    }
                    lstMyBrowserInfo.Add(info);
                }
            }
            this.SuspendLayout();
            pnlShortcuts.SuspendLayout();
            pnlShortcuts.Controls.Clear();
            MyLabel lblMyCopy = new MyLabel();

            lblMyCopy.AutoSize    = true;
            lblMyCopy.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            lblMyCopy.Padding     = new System.Windows.Forms.Padding(2);
            lblMyCopy.Text        = "Only Copy = F2";
            lblMyCopy.MouseClick += LblMyCopy_MouseClick;;
            lblMyCopy.Cursor      = Cursors.Hand;

            pnlShortcuts.Controls.Add(lblMyCopy);

            foreach (MenuBrowser l_menuBrowser in lstMenuBrowser)
            {
                if (!string.IsNullOrEmpty(l_menuBrowser.Shortcut) && l_menuBrowser.Shortcut.StartsWith("f", StringComparison.CurrentCultureIgnoreCase))
                {
                    MyLabel lbl = new MyLabel();
                    lbl.AutoSize = true;
                    lbl.Text     = l_menuBrowser.Name + " [" + l_menuBrowser.Shortcut + "]";
                    //mainMenu.Items.Add(lbl.Text);
                    lbl.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                    lbl.Padding           = new System.Windows.Forms.Padding(2);
                    lbl.Margin            = new Padding(1);
                    lbl.Tag               = l_menuBrowser;
                    lbl.MouseClick       += Lbl_MouseClick;
                    lbl.MouseDoubleClick += Lbl_MouseDoubleClick;
                    lbl.Cursor            = Cursors.Hand;
                    pnlShortcuts.Controls.Add(lbl);
                }
            }
            pnlShortcuts.ResumeLayout();

            tabCtrlMain.SuspendLayout();
            foreach (var br in lstCtrlBrowser)
            {
                br.Dispose();
            }
            lstCtrlBrowser.Clear();
            tabCtrlMain.TabPages.Clear();
            foreach (MyBrowserInfo myBrowserInfo in lstMyBrowserInfo)
            {
                TabPage     tabPage     = new TabPage(myBrowserInfo.Name);
                CtrlBrowser ctrlBrowser = new CtrlBrowser(myBrowserInfo);
                ctrlBrowser.Dock = DockStyle.Fill;
                //ctrlBrowser.myBrowserInfo = myBrowserInfo;
                ctrlBrowser.lstMenuBrowser = lstMenuBrowser;
                MyCustomMenuHandler myCustomMenuHandler = new MyCustomMenuHandler(this, ctrlBrowser.webBrowser, lstMenuBrowser);

                ctrlBrowser.myCustomMenuHandler        = myCustomMenuHandler;
                ctrlBrowser.webBrowser.KeyboardHandler = new MyKeyboardHandler(this, ctrlBrowser);
                tabPage.Controls.Add(ctrlBrowser);
                tabCtrlMain.TabPages.Add(tabPage);
                lstCtrlBrowser.Add(ctrlBrowser);
            }
            tabCtrlMain.ResumeLayout();
            this.ResumeLayout();
            if (!string.IsNullOrEmpty(error))
            {
                Helper.ERRORMSG(error);
            }
        }
Exemple #4
0
        /*bool _IsCTRL_C = false;
         * string _MyClip;
         * private void HookManager_KeyDown(object sender, KeyEventArgs e)
         * {
         *  Debug.WriteLine((e.Modifiers | Keys.Control) + "=" + e.Modifiers + " " + e.KeyCode);
         *  if ((e.Modifiers | Keys.Control) > 0 && e.KeyCode == Keys.C)
         *  {
         *      if(_IsCTRL_C) MessageBox.Show(_MyClip);
         *      _IsCTRL_C = true;
         *      _MyClip = Clipboard.GetText(TextDataFormat.Text);
         *
         *
         *  }
         *  else
         *      _IsCTRL_C = false;
         * }
         */
        protected override void WndProc(ref Message m)
        {
            // Debug.WriteLine("m={0}", m.ToString());
            switch ((Win32.Msgs)m.Msg)
            {
            // The WM_DRAWCLIPBOARD message is sent to the first window
            // in the clipboard viewer chain when the content of the
            // clipboard changes. This enables a clipboard viewer
            // window to display the new content of the clipboard.
            //msg=0x2a2 hwnd=0x70614 wparam=0x0 lparam=0x0 result=0x0: m={0}
            //case Msgs.WM_MY_MSG_1:

            //  break;
            //msg=0x319 hwnd=0x705ee wparam=0x13063a lparam=0xffffffff80010000 result=0x0: m={0}
            case Msgs.WM_MY_MSG_MOUSE_BUTTON_4_5:
                // Debug.WriteLine("m={0}", m.ToString());
                int index = tabCtrlMain.SelectedIndex;
                ChromiumWebBrowser webbrsr = lstCtrlBrowser[index].webBrowser;
                last_command           = ContextMenuCommand.CMD_MY_COPY;
                isCopyWithoutTranslate = true;
                webbrsr.Copy();
                break;

            case Win32.Msgs.WM_DRAWCLIPBOARD:
                //lblTextCopied.Visible = true;
                if (this.WindowState == FormWindowState.Minimized)
                {
                    return;
                }
                string txtFromclipboard = Clipboard.GetText();
                txtFromclipboard = txtFromclipboard.TrimStart(
                    Convert.ToChar(8226)     // bulltet
                    , '\t', ' ');
                lblTextCopied.Text = txtFromclipboard;
                if (last_date_time == DateTime.MinValue)
                {
                    last_date_time = DateTime.Now;
                }
                else
                {
                    double diff = (DateTime.Now - last_date_time).TotalMilliseconds;
                    last_date_time = DateTime.Now;
                    if (diff < 200)
                    {
                        Win32.User32.SendMessage(_ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                        return;
                    }
                }

                //MessageBox.Show(string.Format("WM_DRAWCLIPBOARD , msg={0} , hWind={1} ,lparam={2} , wparam={3} ", m.Msg, m.HWnd, m.LParam, m.WParam));
                // Debug.WriteLine("WindowProc DRAWCLIPBOARD: " + m.Msg, "WndProc");
                MenuBrowser lMenuBrowser = GetMenuBrowserForCommand(last_command);
                if (isCopyWithoutTranslate && lMenuBrowser != null)
                {
                    string tmp_word = txtFromclipboard;
                    if (lMenuBrowser.FrmTranslateModal == null)
                    {
                        lMenuBrowser.FrmTranslateModal         = new FrmTranslateModal(this);
                        lMenuBrowser.FrmTranslateModal.frmMain = this;
                    }

                    lMenuBrowser.FrmTranslateModal.Translate(lMenuBrowser, tmp_word);
                    lMenuBrowser.FrmTranslateModal.Show(this);
                }
                else if (isCopyWithoutTranslate && last_command == ContextMenuCommand.CMD_MY_COPY)
                {
                    //WebbrsrToCopyFrom.Copy();
                }
                else
                if (chkClipboardWatch.Checked && Control.ModifierKeys != Keys.Shift)
                {
                    txtWord.Text = txtFromclipboard;
                    goTranslate();
                }
                else
                {
                    // Win32.User32.SendMessage(_ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                }
                Win32.User32.SendMessage(_ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                last_command           = 0;
                isCopyWithoutTranslate = false;
                break;

            //
            // The WM_CHANGECBCHAIN message is sent to the first window
            // in the clipboard viewer chain when a window is being
            // removed from the chain.
            //
            case Win32.Msgs.WM_CHANGECBCHAIN:
                // Debug.WriteLine("WM_CHANGECBCHAIN: lParam: " + m.LParam, "WndProc");

                // When a clipboard viewer window receives the WM_CHANGECBCHAIN message,
                // it should call the SendMessage function to pass the message to the
                // next window in the chain, unless the next window is the window
                // being removed. In this case, the clipboard viewer should save
                // the handle specified by the lParam parameter as the next window in the chain.

                //
                // wParam is the Handle to the window being removed from
                // the clipboard viewer chain
                // lParam is the Handle to the next window in the chain
                // following the window being removed.
                if (m.WParam == _ClipboardViewerNext)
                {
                    //
                    // If wParam is the next clipboard viewer then it
                    // is being removed so update pointer to the next
                    // window in the clipboard chain
                    _ClipboardViewerNext = m.LParam;
                }
                else
                {
                    Win32.User32.SendMessage(_ClipboardViewerNext, m.Msg, m.WParam, m.LParam);
                }
                break;

            default:
                //
                // Let the form process the messages that we are
                // not interested in
                base.WndProc(ref m);
                break;
            }
        }
        bool IKeyboardHandler.OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
        {
            //    browserControl.Copy();

            /* double change = 0.1;
             *  Task<double> task = browser.GetZoomLevelAsync();
             *  task.ContinueWith(previous =>
             *  {
             *      if (previous.IsCompleted)
             *      {
             *          double currentLevel = previous.Result;
             *          browser.SetZoomLevel(currentLevel + change);
             *      }
             *      else
             *      {
             *          throw new InvalidOperationException("Unexpected failure of calling CEF->GetZoomLevelAsync", previous.Exception);
             *      }
             *  }, TaskContinuationOptions.ExecuteSynchronously);
             *  return true;*/

            //Debug.WriteLine("KeyType= {0} ,windowsKeyCode = {1} , modifiers={2}", type, windowsKeyCode, modifiers);
            if (modifiers.HasFlag(CefEventFlags.ControlDown) && windowsKeyCode == (int)Keys.Add)
            {
                _ctrlBrowser.tsZoomPlus_Click(this, EventArgs.Empty);
                return(true);
            }
            if (modifiers.HasFlag(CefEventFlags.ControlDown) && windowsKeyCode == (int)Keys.Subtract)
            {
                _ctrlBrowser.tsZoomMinus_Click(this, EventArgs.Empty);
                return(true);
            }
            if (modifiers == CefEventFlags.ControlDown && windowsKeyCode == (int)Keys.C)
            {
                _frmMain.last_command           = ContextMenuCommand.CMD_COPY;
                _frmMain.isCopyWithoutTranslate = false;
                browserControl.Copy();
                return(true);
            }
            else if (windowsKeyCode == (int)Keys.F2 && type != KeyType.Char)
            {
                _frmMain.last_command           = ContextMenuCommand.CMD_MY_COPY;
                _frmMain.isCopyWithoutTranslate = true;
                browserControl.Copy();
                return(true);
            }
            else
            {
                if (type != KeyType.Char)
                {
                    string kkey = string.Empty;
                    if (windowsKeyCode == (int)Keys.F1)
                    {
                        kkey = "f1";
                    }
                    //else if (windowsKeyCode == (int)Keys.F2) kkey = "f2";
                    else if (windowsKeyCode == (int)Keys.F3)
                    {
                        kkey = "f3";
                    }
                    else if (windowsKeyCode == (int)Keys.F4)
                    {
                        kkey = "f4";
                    }
                    else if (windowsKeyCode == (int)Keys.F5)
                    {
                        kkey = "f5";
                    }
                    else if (windowsKeyCode == (int)Keys.F6)
                    {
                        kkey = "f6";
                    }
                    else if (windowsKeyCode == (int)Keys.F7)
                    {
                        kkey = "f7";
                    }
                    else if (windowsKeyCode == (int)Keys.F8)
                    {
                        kkey = "f8";
                    }
                    else if (windowsKeyCode == (int)Keys.F9)
                    {
                        kkey = "f9";
                    }
                    else if (windowsKeyCode == (int)Keys.F10)
                    {
                        kkey = "f10";
                    }
                    else if (windowsKeyCode == (int)Keys.F11)
                    {
                        kkey = "f11";
                    }
                    else if (windowsKeyCode == (int)Keys.F12)
                    {
                        kkey = "f12";
                    }
                    MenuBrowser mb = GetMenuBrowserForShortcut(kkey);
                    if (mb != null)
                    {
                        _frmMain.last_command           = mb.Command;
                        _frmMain.isCopyWithoutTranslate = true;
                        browserControl.Copy();
                        return(true);
                    }
                }
            }
            isKeyboardShortcut = false;
            //true: Event is handeld
            return(false);
        }