Marginal clean up and fixing of context menu handlers.

This commit is contained in:
Lorenz Cuno Klopfenstein 2012-11-06 20:28:06 +01:00
parent 0ca078a0a5
commit bc7ad48fc3
3 changed files with 10 additions and 35 deletions

View file

@ -151,7 +151,7 @@ namespace OnTopReplica {
//Same story as above (OnMouseDoubleClick)
if (e.Button == System.Windows.Forms.MouseButtons.Right) {
OpenContextMenu();
OpenContextMenu(null);
}
}
@ -166,7 +166,7 @@ namespace OnTopReplica {
case WM.NCRBUTTONUP:
//Open context menu if right button clicked on caption (i.e. all of the window area because of glass)
if (m.WParam.ToInt32() == HT.CAPTION) {
OpenContextMenu();
OpenContextMenu(null);
m.Result = IntPtr.Zero;
return;

View file

@ -8,36 +8,20 @@ namespace OnTopReplica {
/// <summary>
/// Opens the context menu.
/// </summary>
public void OpenContextMenu() {
/// <param name="position">Optional position of the mouse, relative to which the menu is shown.</param>
public void OpenContextMenu(Point? position) {
Point menuPosition = MousePosition;
if (position.HasValue)
menuPosition = position.Value;
if (IsFullscreen) {
menuFullscreenContext.Show(MousePosition);
menuFullscreenContext.Show(menuPosition);
}
else {
menuContext.Show(MousePosition);
menuContext.Show(menuPosition);
}
}
private Point RecenterLocation(Control original, Control final) {
int origX = original.Location.X + original.Size.Width / 2;
int origY = original.Location.Y + original.Size.Height / 2;
int finX = origX - final.Size.Width / 2;
int finY = origY - final.Size.Height / 2;
//Check boundaries
var screen = Screen.FromControl(final);
if (finX < screen.WorkingArea.X)
finX = screen.WorkingArea.X;
if (finX + final.Size.Width > screen.WorkingArea.Width)
finX = screen.WorkingArea.Width - final.Size.Width;
if (finY < screen.WorkingArea.Y)
finY = screen.WorkingArea.Y;
if (finY + final.Size.Height > screen.WorkingArea.Height)
finY = screen.WorkingArea.Height - final.Size.Height;
return new Point(finX, finY);
}
/// <summary>
/// Gets the window's vertical chrome size.
/// </summary>

View file

@ -165,15 +165,6 @@ namespace OnTopReplica {
}
private void Menu_About_click(object sender, EventArgs e) {
/*this.Hide();
using (var box = new AboutForm()) {
box.Location = RecenterLocation(this, box);
box.ShowDialog();
Location = RecenterLocation(box, this);
}
this.Show();*/
this.SetSidePanel(new AboutPanel());
}