// Is focus set to the specified item
        protected override bool IsFocused()
        {
            NativeMethods.LVGROUP_V6 groupInfo = new NativeMethods.LVGROUP_V6();
            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.

            return((groupInfo.state & NativeMethods.LVGS_SUBSETLINKFOCUSED) != 0);
        }
示例#2
0
        // Returns the last child element in the raw hierarchy.
        internal override ProxySimple GetLastChild()
        {
            // return last item in this group
            GroupManager.GroupInfo groupInfo = GetGroupInfo(_hwnd, ID);

            // List view groups in vista can have an extra link at the end that says
            // something like "show all 11 items...".  If one exists expose it as the last child.
            if (_isComctrlV6OnOsVerV6orHigher)
            {
                NativeMethods.LVGROUP_V6 group = new NativeMethods.LVGROUP_V6();
                group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6)));
                group.iGroupID  = _groupID;
                group.mask      = NativeMethods.LVGF_STATE;
                group.stateMask = NativeMethods.LVGS_SUBSETED;

                // Note: return code of GetGroupInfo() is not reliable.
                XSendMessage.GetGroupInfo(_hwnd, ref group); // ignore return code.

                // if we are not subseted then the last item is a regular listitem so
                // it is ok to fall through and let that be created.  Otherwise we need to
                // create the subset link proxy.
                if ((group.state & NativeMethods.LVGS_SUBSETED) != 0)
                {
                    int [] items = groupInfo._items;
                    if (groupInfo._count <= 0 || groupInfo._count > items.Length)
                    {
                        return(null);
                    }

                    int index = items [groupInfo._count - 1];
                    return(CreateGroupSubsetLink(index + 1));
                }
            }


            if (groupInfo)
            {
                int [] items = groupInfo._items;
                if (groupInfo._count <= 0 || groupInfo._count > items.Length)
                {
                    return(null);
                }

                int index = items [groupInfo._count - 1];

                return(CreateListViewItem(index));
            }

            return(null);
        }
示例#3
0
        internal static bool IsCollapsed(IntPtr hwnd, int groupID)
        {
            bool isCollapsed = false;

            NativeMethods.LVGROUP group = new NativeMethods.LVGROUP();
            group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP)));
            group.iGroupID  = groupID;
            group.mask      = NativeMethods.LVGF_STATE;
            group.stateMask = NativeMethods.LVGS_COLLAPSED;
            // Note: return code of GetGroupInfo() is not reliable.
            XSendMessage.GetGroupInfo(hwnd, ref group); // ignore return code.
            isCollapsed = (group.state & NativeMethods.LVGS_COLLAPSED) != 0;
            return(isCollapsed);
        }
示例#4
0
        // Returns the next sibling element in the raw hierarchy.
        // Peripheral controls have always negative values.
        // Returns null if no next child
        internal override ProxySimple GetNextSibling(ProxySimple child)
        {
            GroupManager.GroupInfo groupInfo = GetGroupInfo(_hwnd, ID);

            if (groupInfo)
            {
                int [] items   = groupInfo._items;
                int    current = child._item;

                // find the index of the current lvitem
                int nextLocation = groupInfo.IndexOf(current) + 1;  //Array.IndexOf(items, current) + 1;

                if (nextLocation <= 0)
                {
                    // No more siblings
                    return(null);
                }

                if (nextLocation < groupInfo._count)
                {
                    return(CreateListViewItem(items [nextLocation]));
                }

                // List view groups in vista can have an extra link at the end that says
                // somthing like "show all 11 items..."
                if (_isComctrlV6OnOsVerV6orHigher && nextLocation == groupInfo._count)
                {
                    NativeMethods.LVGROUP_V6 group = new NativeMethods.LVGROUP_V6();
                    group.Init(Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6)));
                    group.iGroupID  = _groupID;
                    group.mask      = NativeMethods.LVGF_STATE;
                    group.stateMask = NativeMethods.LVGS_SUBSETED;

                    // Note: return code of GetGroupInfo() is not reliable.
                    XSendMessage.GetGroupInfo(_hwnd, ref group); // ignore return code.

                    // 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.
                    if ((group.state & NativeMethods.LVGS_SUBSETED) != 0)
                    {
                        return(CreateGroupSubsetLink(items [groupInfo._count - 1] + 1));
                    }
                }
            }

            return(null);
        }
示例#5
0
        //------------------------------------------------------
        //
        //  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);
        }