Esempio n. 1
0
 /// <summary>
 /// Ctor: takes ownership of actual context menu UI.
 /// </summary>
 /// <param name="ctxtMenuControl">The context menu UI.</param>
 public CtxtMenuForm(ICtxtMenuControl ctxtMenuControl)
 {
     this.ctxtMenuControl = ctxtMenuControl;
     SuspendLayout();
     // Configure form - borderless etc.
     AutoScaleDimensions = new System.Drawing.SizeF(6.0F, 13.0F);
     AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     BackColor = ZenParams.WindowColor;
     ClientSize = new System.Drawing.Size(278, 244);
     FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
     StartPosition = System.Windows.Forms.FormStartPosition.Manual;
     Name = "CtxtMenuForm";
     ShowIcon = false;
     ShowInTaskbar = false;
     Text = "CtxtMenuForm";
     TopMost = true;
     // Add UI control to children, resize to accommodate it.
     ctxtMenuControl.AsUserControl.Location = Point.Empty;
     Controls.Add(ctxtMenuControl.AsUserControl);
     ctxtMenuControl.AssumeSize();
     // KK, done.
     //ResumeLayout(false); // No! that screws up size.
     Size = ctxtMenuControl.AsUserControl.Size;
     Application.AddMessageFilter(this);
 }
Esempio n. 2
0
        /// <summary>
        /// <para>Called by derived controls to display a context menu.</para>
        /// <para>Once shown, top form takes over ownership of provided control (will dispose it when closing context menu).</para>
        /// </summary>
        /// <param name="relLoc">Desired relative location, in calling control's coordinates.</param>
        /// <param name="ctxtMenuCtrl">The UI to show as a context menu.</param>
        protected void ShowContextMenu(Point relLoc, ICtxtMenuControl ctxtMenuCtrl)
        {
            Point absLoc    = new Point(AbsRect.X + relLoc.X, AbsRect.Y + relLoc.Y);
            Point screenLoc = CurrentParentForm.WinForm.PointToScreen(absLoc);

            CurrentParentForm.ShowContextMenu(screenLoc, ctxtMenuCtrl);
        }
Esempio n. 3
0
 /// <summary>
 /// Ctor: takes ownership of actual context menu UI.
 /// </summary>
 /// <param name="ctxtMenuControl">The context menu UI.</param>
 public CtxtMenuForm(ICtxtMenuControl ctxtMenuControl)
 {
     this.ctxtMenuControl = ctxtMenuControl;
     SuspendLayout();
     // Configure form - borderless etc.
     AutoScaleDimensions = new System.Drawing.SizeF(6.0F, 13.0F);
     AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     BackColor           = ZenParams.WindowColor;
     ClientSize          = new System.Drawing.Size(278, 244);
     FormBorderStyle     = System.Windows.Forms.FormBorderStyle.None;
     StartPosition       = System.Windows.Forms.FormStartPosition.Manual;
     Name          = "CtxtMenuForm";
     ShowIcon      = false;
     ShowInTaskbar = false;
     Text          = "CtxtMenuForm";
     TopMost       = true;
     // Add UI control to children, resize to accommodate it.
     ctxtMenuControl.AsUserControl.Location = Point.Empty;
     Controls.Add(ctxtMenuControl.AsUserControl);
     ctxtMenuControl.AssumeSize();
     // KK, done.
     //ResumeLayout(false); // No! that screws up size.
     Size = ctxtMenuControl.AsUserControl.Size;
     Application.AddMessageFilter(this);
 }
Esempio n. 4
0
 /// <summary>
 /// Closes the context menu control shopwn earlier (if it's still visible at all).
 /// </summary>
 internal void CloseContextMenu(ICtxtMenuControl ctxtMenuCtrl)
 {
     if (ctxtForm != null && ctxtMenuCtrl == ctxtForm.CtxtMenuControl)
     {
         ctxtForm.Close();
         ctxtForm = null;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Shows a context menu at the desired location, or the nearest best place.
        /// </summary>
        /// <param name="screenLoc">The desired location in screen coordinates.</param>
        /// <param name="ctxtMenuCtrl">The context menu UI to show.</param>
        internal void ShowContextMenu(Point screenLoc, ICtxtMenuControl ctxtMenuCtrl)
        {
            // If we currently have a context menu on the screen, kill it.
            if (ctxtForm != null)
            {
                ctxtForm.Close();
                ctxtForm = null;
            }
            // Create new form
            var ff = new CtxtMenuForm(ctxtMenuCtrl);
            // Calculate optimal location.
            // Horizontally: centered around pointer
            // Vertically: prefer above, with 3px in between
            Screen scr = getScreenForPoint(screenLoc);
            int    x   = screenLoc.X - ff.Width / 2;

            if (x < scr.WorkingArea.Left)
            {
                x = scr.WorkingArea.Left;
            }
            else if (x + ff.Width > scr.WorkingArea.Right)
            {
                x = scr.WorkingArea.Right - ff.Width;
            }
            int y = screenLoc.Y - ff.Height - 3;

            if (y < scr.WorkingArea.Top)
            {
                y = screenLoc.Y + 3;
            }
            ff.Location = new Point(x, y);
            // Show context menu
            ff.Show(form);
            form.Focus();
            ctxtForm = ff;
        }
Esempio n. 6
0
 /// <summary>
 /// Closes the context menu control shopwn earlier (if it's still visible at all).
 /// </summary>
 protected void CloseContextMenu(ICtxtMenuControl ctxtMenuCtrl)
 {
     CurrentParentForm.CloseContextMenu(ctxtMenuCtrl);
 }
Esempio n. 7
0
 /// <summary>
 /// <para>Called by derived controls to display a context menu.</para>
 /// <para>Once shown, top form takes over ownership of provided control (will dispose it when closing context menu).</para>
 /// </summary>
 /// <param name="relLoc">Desired relative location, in calling control's coordinates.</param>
 /// <param name="ctxtMenuCtrl">The UI to show as a context menu.</param>
 protected void ShowContextMenu(Point relLoc, ICtxtMenuControl ctxtMenuCtrl)
 {
     Point absLoc = new Point(AbsRect.X + relLoc.X, AbsRect.Y + relLoc.Y);
     Point screenLoc = CurrentParentForm.WinForm.PointToScreen(absLoc);
     CurrentParentForm.ShowContextMenu(screenLoc, ctxtMenuCtrl);
 }
Esempio n. 8
0
 /// <summary>
 /// Closes the context menu control shopwn earlier (if it's still visible at all).
 /// </summary>
 protected void CloseContextMenu(ICtxtMenuControl ctxtMenuCtrl)
 {
     CurrentParentForm.CloseContextMenu(ctxtMenuCtrl);
 }
Esempio n. 9
0
 /// <summary>
 /// Shows a context menu at the desired location, or the nearest best place.
 /// </summary>
 /// <param name="screenLoc">The desired location in screen coordinates.</param>
 /// <param name="ctxtMenuCtrl">The context menu UI to show.</param>
 internal void ShowContextMenu(Point screenLoc, ICtxtMenuControl ctxtMenuCtrl)
 {
     // If we currently have a context menu on the screen, kill it.
     if (ctxtForm != null)
     {
         ctxtForm.Close();
         ctxtForm = null;
     }
     // Create new form
     var ff = new CtxtMenuForm(ctxtMenuCtrl);
     // Calculate optimal location.
     // Horizontally: centered around pointer
     // Vertically: prefer above, with 3px in between
     Screen scr = getScreenForPoint(screenLoc);
     int x = screenLoc.X - ff.Width / 2;
     if (x < scr.WorkingArea.Left) x = scr.WorkingArea.Left;
     else if (x + ff.Width > scr.WorkingArea.Right) x = scr.WorkingArea.Right - ff.Width;
     int y = screenLoc.Y - ff.Height - 3;
     if (y < scr.WorkingArea.Top) y = screenLoc.Y + 3;
     ff.Location = new Point(x, y);
     // Show context menu
     ff.Show(form);
     form.Focus();
     ctxtForm = ff;
 }
Esempio n. 10
0
 /// <summary>
 /// Closes the context menu control shopwn earlier (if it's still visible at all).
 /// </summary>
 internal void CloseContextMenu(ICtxtMenuControl ctxtMenuCtrl)
 {
     if (ctxtForm != null && ctxtMenuCtrl == ctxtForm.CtxtMenuControl)
     {
         ctxtForm.Close();
         ctxtForm = null;
     }
 }