//------------------------------------------------------ // // Internal Methods // //------------------------------------------------------ #region Internal Methods // get focused element internal static ProxySimple GetFocusInGroup(IntPtr hwnd, ProxyFragment parent) { int index = WindowsListView.GetItemNext(hwnd, -1, NativeMethods.LVNI_FOCUSED); if (index != -1) { // get id of the group to which item belongs NativeMethods.LVITEM_V6 item = new NativeMethods.LVITEM_V6(); item.mask = NativeMethods.LVIF_GROUPID; item.iItem = index; if (XSendMessage.GetItem(hwnd, ref item)) { WindowsListViewGroup group = new WindowsListViewGroup(hwnd, parent, item.iGroupID); return(new ListViewItem(hwnd, group, index)); } } else { // if none of the items have focus see if the focus is on the subset link // this only exists in v6 comctrl on vista or later. if (Misc.IsComctrlV6OnOsVerV6orHigher(hwnd)) { int groupIndex = (int)Misc.ProxySendMessage(hwnd, NativeMethods.LVM_GETFOCUSEDGROUP, IntPtr.Zero, IntPtr.Zero); // need to convert the item id to a group id NativeMethods.LVGROUP_V6 groupInfo = new NativeMethods.LVGROUP_V6(); groupInfo.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6))); groupInfo.mask = NativeMethods.LVGF_GROUPID; unsafe { bool lresult = XSendMessage.XSend(hwnd, NativeMethods.LVM_GETGROUPINFOBYINDEX, new IntPtr(groupIndex), new IntPtr(&groupInfo), Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6))); if (!lresult) { // no group for this item should never happen. return(null); } } int groupId = groupInfo.iGroupID; groupInfo.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6))); groupInfo.iGroupID = groupId; groupInfo.mask = NativeMethods.LVGF_STATE; groupInfo.stateMask = NativeMethods.LVGS_SUBSETLINKFOCUSED; // Note: return code of GetGroupInfo() is not reliable. XSendMessage.GetGroupInfo(hwnd, ref groupInfo); // ignore return code. if ((groupInfo.state & NativeMethods.LVGS_SUBSETLINKFOCUSED) != 0) { GroupManager.GroupInfo groupManagerInfo = GetGroupInfo(hwnd, groupId); int [] items = groupManagerInfo._items; if (groupManagerInfo._count <= 0 || groupManagerInfo._count >= items.Length) { return(null); } int sslIndex = items [groupManagerInfo._count - 1]; // The items array holds the list items in this group. If we have a subset link we // don't store it with the list items because it isn't really a list item. Instead we just // create the subset link proxy with an item index one more than the last index. WindowsListViewGroup group = new WindowsListViewGroup(hwnd, parent, groupId); return(group.CreateGroupSubsetLink(sslIndex + 1)); } else { return(new WindowsListViewGroup(hwnd, parent, groupId)); } } } return(null); }