Esempio n. 1
0
        public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text, MenuItemProperties flags, Icon icon, HotKeys hotKey, bool updateItemDescriptor)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            if (menuItem == null)
                throw new ArgumentNullException("menuItem");

            if (menuItem.MirandaHandle == IntPtr.Zero)
                throw new ArgumentException("Invalid menu item handle.");

            UnmanagedStructHandle<CLISTMENUITEM> nativeHandle = UnmanagedStructHandle<CLISTMENUITEM>.Empty;

            try
            {
                SynchronizationHelper.BeginMenuItemUpdate(menuItem);

                CLISTMENUITEM nativeItem = new CLISTMENUITEM(owner, menuItem);
                MenuItemModifyFlags modifyFlags = MenuItemModifyFlags.None;

                if (text != null)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_NAME;
                    nativeItem.Text = text;

                    if (updateItemDescriptor) menuItem.Text = text;
                }
                if (flags != MenuItemProperties.KeepCurrent)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_FLAGS;
                    nativeItem.Flags = (uint)flags;

                    if (updateItemDescriptor) menuItem.Flags = flags;
                }
                if (icon != null)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_ICON;
                    nativeItem.Icon = icon.Handle;
                }
                if (hotKey != 0)
                {
                    modifyFlags |= MenuItemModifyFlags.CMIM_HOTKEY;
                    nativeItem.HotKey = (uint)hotKey;
                    if (updateItemDescriptor) menuItem.HotKey = hotKey;
                }

                nativeItem.Flags |= (uint)modifyFlags;

                nativeHandle = new UnmanagedStructHandle<CLISTMENUITEM>(ref nativeItem);
                bool result = MirandaContext.Current.CallService(MirandaServices.MS_CLIST_MODIFYMENUITEM, (UIntPtr)(uint)menuItem.MirandaHandle, nativeHandle.IntPtr) == 0
                    ? true : false;

                Debug.Assert(result);
                return result;
            }
            catch (Exception e)
            {
                throw new MirandaException(TextResources.ExceptionMsg_ErrorWhileCallingMirandaService + e.Message, e);
            }
            finally
            {
                nativeHandle.Free();
                SynchronizationHelper.EndUpdate(menuItem);
            }
        }
Esempio n. 2
0
        public void AddMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute item)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            if (item == null)
                throw new ArgumentNullException("item");

            string serviceName = item.IsContactMenuItem ? MirandaServices.MS_CLIST_ADDCONTACTMENUITEM : MirandaServices.MS_CLIST_ADDMAINMENUITEM;

            UnmanagedStructHandle<CLISTMENUITEM> nativeHandle = UnmanagedStructHandle<CLISTMENUITEM>.Empty;
            CLISTMENUITEM nativeItem = new CLISTMENUITEM(owner, item);

            try
            {
                nativeHandle = new UnmanagedStructHandle<CLISTMENUITEM>(ref nativeItem);

                IntPtr handle = (IntPtr)MirandaContext.Current.CallService(serviceName, UIntPtr.Zero, nativeHandle.IntPtr,
                    (owner is StandalonePlugin && !item.IsAdditional));

                item.MirandaHandle = handle;
                Debug.Assert(handle != IntPtr.Zero);
            }
            finally
            {
                nativeHandle.Free();
            }
        }