示例#1
0
        public static void Destroy(bool removeRoot)
        {
            if (mainMenus.Count > 0)
            {
                foreach (IntPtr ptr in mainMenus)
                {
                    HIToolbox.DeleteMenu(ptr);
                    CoreFoundation.Release(ptr);
                }
                DestroyOldMenuObjects();
                mainMenus.Clear();
                linkCommands.Clear();
                idSeq = 1;
            }

            HIToolbox.ClearMenuBar();

            if (removeRoot && rootMenu != IntPtr.Zero)
            {
                HIToolbox.DeleteMenu(rootMenu);
                CoreFoundation.Release(rootMenu);
                HIToolbox.CheckResult(HIToolbox.SetRootMenu(IntPtr.Zero));
                Carbon.RemoveEventHandler(commandHandlerRef);
                Carbon.RemoveEventHandler(openingHandlerRef);
                Carbon.RemoveEventHandler(closedHandlerRef);
                commandHandlerRef = openingHandlerRef = rootMenu = IntPtr.Zero;
                idSeq             = 0;
            }
        }
示例#2
0
 public void Destroy()
 {
     if (Ref != IntPtr.Zero)
     {
         HIToolbox.DeleteMenu(Ref);
         CoreFoundation.Release(Ref);
         Ref = IntPtr.Zero;
     }
 }
示例#3
0
        static void SetMenuItemAttributes(HIMenuItem item, CommandInfo ci, uint refcon)
        {
            MenuItemData data = new MenuItemData();
            IntPtr       text = IntPtr.Zero;

            try {
                if (ci.IsArraySeparator)
                {
                    data.Attributes |= MenuItemAttributes.Separator;
                }
                else if (!ci.Visible)
                {
                    data.Attributes |= MenuItemAttributes.Hidden;
                }
                else
                {
                    data.Attributes &= ~MenuItemAttributes.Hidden;
                    data.CFText      = CoreFoundation.CreateString(GetCleanCommandText(ci));

                    //disable also when MD main window doesn't have toplevel focus, or commands will be
                    //accessible when modal dialogs are active
                    bool disabled = !ci.Enabled || IsGloballyDisabled;
                    data.Enabled = !disabled;
                    if (disabled)
                    {
                        data.Attributes |= MenuItemAttributes.Disabled;
                    }

                    ushort            glyphCode, charCode, hardwareCode;
                    MenuAccelModifier mod;
                    if (GetAcceleratorKeys(ci.AccelKey, out glyphCode, out charCode, out hardwareCode, out mod))
                    {
                        data.CommandKeyModifiers = mod;
                        if (glyphCode != 0)
                        {
                            data.CommandKeyGlyph = glyphCode;
                            data.Attributes     ^= MenuItemAttributes.UseVirtualKey;
                        }
                        else if (hardwareCode != 0)
                        {
                            data.CommandVirtualKey = (char)hardwareCode;
                            data.Attributes       |= MenuItemAttributes.UseVirtualKey;
                        }
                        else
                        {
                            data.CommandKey  = (char)charCode;
                            data.Attributes ^= MenuItemAttributes.UseVirtualKey;
                        }
                    }
                    //else{
                    //FIXME: remove existing commands if necessary

                    data.Mark = ci.Checked
                                                ? ci.CheckedInconsistent
                                                        ? '-' //FIXME: is this a good symbol for CheckedInconsistent?
                                                        : (char)MenuGlyphs.Checkmark
                                                : '\0';

                    data.ReferenceConstant = refcon;
                }
                HIToolbox.SetMenuItemData(item.MenuRef, item.Index, false, ref data);
            } finally {
                if (text != IntPtr.Zero)
                {
                    CoreFoundation.Release(text);
                }
            }
        }