--- /dev/null
+// \r
+// Radegast Metaverse Client\r
+// Copyright (c) 2009, Radegast Development Team\r
+// All rights reserved.\r
+// \r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are met:\r
+// \r
+// * Redistributions of source code must retain the above copyright notice,\r
+// this list of conditions and the following disclaimer.\r
+// * Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the distribution.\r
+// * Neither the name of the application "Radegast", nor the names of its\r
+// contributors may be used to endorse or promote products derived from\r
+// this software without specific prior written permission.\r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+// $Id$\r
+//\r
+\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+using System.Windows.Forms;\r
+\r
+namespace Radegast\r
+{\r
+ /// <summary>\r
+ /// A Radegast based ContextMenuStrip\r
+ /// the Opening/Closing event my be subscribed to be users\r
+ /// </summary>\r
+ public class RadegastContextMenuStrip : ContextMenuStrip\r
+ { \r
+ /// <summary>\r
+ /// If the context menu has a valid target\r
+ /// </summary>\r
+ public bool HasSelection;\r
+ /// <summary>\r
+ /// The target\r
+ /// </summary>\r
+ public object Selection;\r
+\r
+ // for Control Chartacter we use\r
+ public const Keys ContexMenuKeyCode = Keys.Enter;\r
+ public RadegastContextMenuStrip(IContainer components):base(components)\r
+ {\r
+ \r
+ }\r
+ public RadegastContextMenuStrip()\r
+ : base()\r
+ {\r
+ }\r
+\r
+ public IEnumerable<ToolStripItem> Choices()\r
+ {\r
+ List<ToolStripItem> lst = new List<ToolStripItem>();\r
+ foreach (ToolStripItem item in this.Items)\r
+ {\r
+ lst.Add(item);\r
+ }\r
+ return lst;\r
+ }\r
+ }\r
+\r
+ public interface IContextMenuProvider\r
+ {\r
+ RadegastContextMenuStrip GetContextMenu();\r
+ }\r
+}
\ No newline at end of file
\r
namespace Radegast\r
{\r
- public partial class FriendsConsole : UserControl\r
+ public partial class FriendsConsole : UserControl, IContextMenuProvider\r
{\r
private RadegastInstance instance;\r
private GridClient client { get { return instance.Client; } }\r
\r
private void lbxFriends_MouseUp(object sender, MouseEventArgs e)\r
{\r
- ContextMenuStrip friendsContextMenuStrip = new ContextMenuStrip {Size = new System.Drawing.Size(61, 4)};\r
+ if (e.Button == MouseButtons.Right) ShowContextMenu();\r
+ } \r
\r
- if (e.Button == MouseButtons.Right)\r
+ private void lbxFriends_KeyUp(object sender, KeyEventArgs e)\r
+ {\r
+ if (e.KeyCode == Keys.Apps) ShowContextMenu();\r
+ if (e.Control && e.KeyCode == RadegastContextMenuStrip.ContexMenuKeyCode) ShowContextMenu();\r
+ }\r
+\r
+ // OnClick and MouseClick etc down not capture a right click event\r
+ private void lbxFriends_MouseDown(object sender, MouseEventArgs e)\r
+ {\r
+ int idx = lbxFriends.IndexFromPoint(lbxFriends.PointToClient(MousePosition));\r
+ if (idx > 0 && idx < lbxFriends.Items.Count)\r
{\r
- ListBox box = (ListBox) sender;\r
- if (box.SelectedIndex >= 0)\r
- {\r
- FriendInfo item = ((FriendsListItem)box.Items[box.SelectedIndex]).Friend;\r
- instance.ContextActionManager.AddContributions(\r
- friendsContextMenuStrip, typeof (Avatar), item, btnPay.Parent);\r
- friendsContextMenuStrip.Show(lbxFriends, new System.Drawing.Point(e.X, e.Y));\r
- }\r
+ lbxFriends.SetSelected(idx, true);\r
+ }\r
+ }\r
+\r
+ public void ShowContextMenu()\r
+ {\r
+ RadegastContextMenuStrip menu = GetContextMenu();\r
+ if (menu.HasSelection) menu.Show(lbxFriends, lbxFriends.PointToClient(System.Windows.Forms.Control.MousePosition));\r
+ }\r
+\r
+ public RadegastContextMenuStrip GetContextMenu()\r
+ {\r
+ RadegastContextMenuStrip friendsContextMenuStrip = new RadegastContextMenuStrip();\r
+ if (lbxFriends.SelectedIndex >= 0)\r
+ {\r
+ FriendInfo item = ((FriendsListItem)lbxFriends.Items[lbxFriends.SelectedIndex]).Friend;\r
+ instance.ContextActionManager.AddContributions(friendsContextMenuStrip, typeof(Avatar), item, btnPay.Parent);\r
+ friendsContextMenuStrip.Selection = item;\r
+ friendsContextMenuStrip.HasSelection = true;\r
+ }\r
+ else\r
+ {\r
+ friendsContextMenuStrip.Selection = null;\r
+ friendsContextMenuStrip.HasSelection = false;\r
}\r
+ return friendsContextMenuStrip;\r
}\r
}\r
}\r