Esempio n. 1
0
        static void UpdateAutoHide(HIMenuItem item)
        {
            IntPtr submenu;

            if (HIToolbox.GetMenuItemHierarchicalMenu(item.MenuRef, item.Index, out submenu) != CarbonMenuStatus.Ok)
            {
                return;
            }

            if (HasVisibleItems(submenu))
            {
                HIToolbox.ChangeMenuItemAttributes(item, 0, MenuItemAttributes.Hidden);
            }
            else
            {
                HIToolbox.ChangeMenuItemAttributes(item, MenuItemAttributes.Hidden, 0);
            }
        }
Esempio n. 2
0
        static void UpdateMenuItem(IntPtr rootMenu, IntPtr menuRef, ref ushort index, ref ushort count,
                                   uint macCmdID, CommandInfo cinfo)
        {
            if (cinfo.ArrayInfo != null)
            {
                //remove the existing items, except one, which we hide, so it gets updated next time even if the list is empty
                HIToolbox.ChangeMenuItemAttributes(new HIMenuItem(menuRef, index), MenuItemAttributes.Hidden, 0);
                index++;
                while (index <= count && HIToolbox.GetMenuItemCommandID(new HIMenuItem(menuRef, index)) == macCmdID)
                {
                    HIToolbox.DeleteMenuItem(menuRef, index);
                    count--;
                }
                index--;

                //add the new items
                foreach (CommandInfo ci in cinfo.ArrayInfo)
                {
                    count++;
                    HIToolbox.InsertMenuItem(menuRef, ci.Text, index++, 0, macCmdID);

                    //associate a reference constant with the menu, used to index the DataItem
                    //it's one-based, so that 0 can be used as a flag that there's no associated object
                    objectsToDestroyOnMenuClose.Add(ci.DataItem);
                    uint refcon = (uint)objectsToDestroyOnMenuClose.Count;

                    SetMenuItemAttributes(new HIMenuItem(menuRef, index), ci, refcon);
                    if (ci is CommandInfoSet)
                    {
                        BuildDynamicSubMenu(rootMenu, menuRef, index, macCmdID, (CommandInfoSet)ci);
                    }
                }
            }
            else
            {
                SetMenuItemAttributes(new HIMenuItem(menuRef, index), cinfo, 0);
                if (cinfo is CommandInfoSet)
                {
                    BuildDynamicSubMenu(rootMenu, menuRef, index, macCmdID, (CommandInfoSet)cinfo);
                }
            }
        }