internal bool AreGroupsValid()
        {
            int count = _groups.Count;

            for (int i = 0; i < count; i++)
            {
                Group group = (Group)_groups[i];

                if (!ListViewHasGroup(_hwnd, group._groupID))
                {
                    return(false);
                }
            }

            // Make sure that no new group have been added, try to match all the GroupId to an
            // existing one.
            int itemCount = WindowsListView.GetItemCount(_hwnd);

            NativeMethods.LVITEM_V6 item = new NativeMethods.LVITEM_V6();

            item.mask = NativeMethods.LVIF_GROUPID;

            for (item.iItem = 0; item.iItem < itemCount; item.iItem++)
            {
                if (!XSendMessage.GetItem(_hwnd, ref item) || GetGroup(item.iGroupID) == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        // ------------------------------------------------------
        //
        // Internal Methods
        //
        // ------------------------------------------------------

        #region Internal Methods

        // Create a WindowsToolbar instance.  Needs to be internal because
        // ApplicationWindow pattern needs to call this so needs to be internal
        internal ProxySimple CreateToolbarItem(int item)
        {
            NativeMethods.TBBUTTON tbb = new NativeMethods.TBBUTTON();

            // During the FocusChanged WinEvent (EVENT_OBJECT_FOCUS),
            // some "ToolbarWindow32" children report an item ID (child id)
            // of 0x80000001, 0x80000002, etc. instead of 1, 2, etc.
            // However, when created as children of the parent toolbar,
            // these same items are assigned IDs of 1, 2, etc.
            // Therefore, map negative item IDs of the form 0x80000001,
            // 0x80000002, etc. to 1, 2, etc.
            item = (int)(~0x80000000 & (uint)item);

            if (!XSendMessage.GetItem(_hwnd, item, ref tbb))
            {
                // If failed to get button infromation the button must not exist, so return null.
                return(null);
            }

            if (Misc.ProxySendMessageInt(_hwnd, NativeMethods.TB_ISBUTTONHIDDEN, new IntPtr(tbb.idCommand), IntPtr.Zero) == 0)
            {
                Accessible acc = Accessible.CreateNativeFromEvent(_hwnd, NativeMethods.OBJID_CLIENT, item + 1);
                if (acc != null)
                {
                    if (acc.Role == AccessibleRole.MenuItem)
                    {
                        return(new ToolbarItemAsMenuItem(_hwnd, this, item, tbb.idCommand, acc));
                    }
                }

                return(new ToolbarItem(_hwnd, this, item, tbb.idCommand));
            }
            return(null);
        }
Exemplo n.º 3
0
        // ------------------------------------------------------
        //
        // Constructors
        //
        // ------------------------------------------------------

        #region Constructors

        internal ToolbarItem(IntPtr hwnd, ProxyFragment parent, int item, int idCommand)
            : base(hwnd, parent, item)
        {
            _idCommand = idCommand;

            NativeMethods.TBBUTTON tbb = new NativeMethods.TBBUTTON();
            int buttonStyle            = 0;

            if (XSendMessage.GetItem(_hwnd, _item, ref tbb))
            {
                buttonStyle = tbb.fsStyle;
            }

            // Set the strings to return properly the properties.
            bool hasImageList = Misc.ProxySendMessageInt(_hwnd, NativeMethods.TB_GETIMAGELIST, IntPtr.Zero, IntPtr.Zero) != 0;
            int  exStyle      = Misc.ProxySendMessageInt(_hwnd, NativeMethods.TB_GETEXTENDEDSTYLE, IntPtr.Zero, IntPtr.Zero);

            _isToggleButton = false;
            _cControlType   = ControlType.Button;

            // If a separator, say so
            if (Misc.IsBitSet(buttonStyle, NativeMethods.BTNS_SEP))
            {
                _cControlType = ControlType.Separator;
            }
            else if (Misc.IsBitSet(buttonStyle, NativeMethods.BTNS_CHECK))
            {
                // Special case for task list - they use the checked style, but only for visuals...
                IntPtr hwndParent = Misc.GetParent(_hwnd);
                if (Misc.GetClassName(hwndParent) != "MSTaskSwWClass")
                {
                    _isToggleButton = true;
                }
            }
            else if (Misc.IsBitSet(buttonStyle, NativeMethods.BTNS_DROPDOWN) &&
                     Misc.IsBitSet(exStyle, NativeMethods.TBSTYLE_EX_DRAWDDARROWS))
            {
                // if its a drop down and it has an arrow its a split button
                _cControlType = ControlType.SplitButton;
            }
            else if (!hasImageList || tbb.iBitmap == NativeMethods.I_IMAGENONE)
            {
                // Text-only, no bitmap, so it's effectively a menu item.
                // (eg. as used in MMC)
                _cControlType = ControlType.MenuItem;
            }

            _fIsContent = _cControlType != ControlType.Separator;

            // The Start Menu's "Shut Down" and "Log Off" buttons are toolbar items.  They need to have the
            // KeyboardFocusable property be set to true.
            _fIsKeyboardFocusable = (bool)parent.GetElementProperty(AutomationElement.IsKeyboardFocusableProperty);

            GetItemId(ref _sAutomationId);
        }
Exemplo n.º 4
0
        private void GetItemId(ref string itemId)
        {
            NativeMethods.TBBUTTON tbb = new NativeMethods.TBBUTTON();

            if (XSendMessage.GetItem(_hwnd, _item, ref tbb))
            {
                if (tbb.idCommand > 0)
                {
                    itemId = "Item " + tbb.idCommand.ToString(CultureInfo.CurrentCulture);
                }
            }
        }
        private int GetItemFromIndex(int index)
        {
            NativeMethods.HDITEM item = new NativeMethods.HDITEM();
            item.Init();
            item.mask = NativeMethods.HDI_ORDER;

            // Send the message...
            if (!XSendMessage.GetItem(_hwnd, index, ref item))
            {
                return(-1);
            }

            return(item.iOrder);
        }
        // retrieve an id of the group to which this lvitem belongs
        // valid only if lv has groups enabled
        static internal int GetGroupID(IntPtr hwnd, int lvItem)
        {
            System.Diagnostics.Debug.Assert(WindowsListView.IsGroupViewEnabled(hwnd), "GetGroupID: called when lv does not have groups");

            NativeMethods.LVITEM_V6 item = new NativeMethods.LVITEM_V6();
            item.mask  = NativeMethods.LVIF_GROUPID;
            item.iItem = lvItem;

            if (XSendMessage.GetItem(hwnd, ref item))
            {
                return(item.iGroupID);
            }

            return(-1);
        }
            // This is new with v6 comctrl on Vista
            private bool IsSplitButton()
            {
                NativeMethods.HDITEM item = new NativeMethods.HDITEM();
                item.Init();
                item.mask = NativeMethods.HDI_FORMAT;

                // Send the message...
                if (XSendMessage.GetItem(_hwnd, _item, ref item))
                {
                    if ((item.fmt & NativeMethods.HDF_SPLITBUTTON) != 0)
                    {
                        return(true);
                    }
                }

                return(false);
            }
        private static unsafe GroupManager InitializeManager(IntPtr hwnd)
        {
            bool isComctrlV6OnOsVerV6orHigher = Misc.IsComctrlV6OnOsVerV6orHigher(hwnd);

            int itemCount = WindowsListView.GetItemCount(hwnd);

            NativeMethods.LVITEM_V6 item = new NativeMethods.LVITEM_V6();
            item.mask = NativeMethods.LVIF_GROUPID;

            // The only place where the GroupManager gets constructed
            GroupManager manager = new GroupManager(itemCount, hwnd, isComctrlV6OnOsVerV6orHigher);

            if (isComctrlV6OnOsVerV6orHigher)
            {
                NativeMethods.LVITEMINDEX ii = new NativeMethods.LVITEMINDEX(-1, -1);

                int flags = NativeMethods.LVNI_VISIBLEONLY | NativeMethods.LVNI_VISIBLEORDER;

                // When a listview is being "grouped by" an item may be in more than one group.  The itemCount
                // is the number of unique items.  This loop may iterate for more than the unique items in the group.
                // We are taking advantage of that fact the the array list will expand if there are alot of duplicates.
                while (XSendMessage.XSend(hwnd, NativeMethods.LVM_GETNEXTITEMINDEX, new IntPtr(&ii), flags, Marshal.SizeOf(ii.GetType())))
                {
                    // 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;

                    bool lresult = XSendMessage.XSend(hwnd, NativeMethods.LVM_GETGROUPINFOBYINDEX, new IntPtr(ii.iGroup), new IntPtr(&groupInfo), Marshal.SizeOf(typeof(NativeMethods.LVGROUP_V6)));
                    if (!lresult)
                    {
                        if (groupInfo.iGroupID == -1)
                        {
                            // A -1 here means that there are no duplicates in this grouped listview so
                            // we have to get the group the old way.  This is done for performance reasons.
                            break;
                        }
                        // no group for this item should never happen.
                        // If it ever does the other items might ok so just keep going.
                        continue;
                    }

                    if (!manager.Add(groupInfo.iGroupID, ii.iItem))
                    {
                        // we had problem adding item to the needed group at this point it makes no
                        // sense to continue
                        System.Diagnostics.Debug.Assert(false, "Cannot add item to the needed group");
                        return(null);
                    }
                }
            }

            bool sortNeeded = false;

            // If the code above did not yield anything try this way.  This will work for
            // listviews pre Vista and grouped listviews in vista that don't have duplicate items.
            if (manager.GroupCount() == 0)
            {
                // if we get the groups this way they need to be sorted.  The code above brings them in sorted.
                sortNeeded = true;
                int current = 0;
                while (current < itemCount)
                {
                    item.iItem = current;
                    if (XSendMessage.GetItem(hwnd, ref item) && manager.Add(item.iGroupID, item.iItem))
                    {
                        current++;
                    }
                    else
                    {
                        // we had problem adding item to the needed group at this point it makes no
                        // sense to continue
                        System.Diagnostics.Debug.Assert(false, "Cannot add item to the needed group");
                        return(null);
                    }
                }
            }

            // Sort items within the group
            int groupsCount = manager.GroupCount();

            for (int i = 0; i < groupsCount; i++)
            {
                Group group = (Group)manager._groups[i];
                Array.Sort(group.Items, 0, group.Count, new SortGroupItems(hwnd));
            }


            // Depending on how we got the group info we may need to sort it.
            // In vista the the listview can put the list items in the correct order.
            // Pre vista or old ui (v5) will always need to be sorted.
            if (sortNeeded)
            {
                // Sort groups
                manager._groups.Sort(new SortGroups(hwnd));
            }

            return(manager);
        }
Exemplo n.º 9
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);
        }