Пример #1
0
        private void LoadIcon(MirandaPlugin owner, MenuItemDeclarationAttribute attrib)
        {
            try
            {
                if (!attrib.HasIcon)
                    return;

                if (attrib.UseEmbeddedIcon)
                {
                    using (Stream stream = owner.GetType().Assembly.GetManifestResourceStream(attrib.IconID))
                    {
                        if (stream != null)
                            Icon = IconImageCache.Singleton.GetStreamedIcon(stream).Handle;
                        else
                            Debug.Fail("Embedded icon not found.");
                    }
                }
                else
                    Icon = Skin.LoadIcon(int.Parse(attrib.IconID));
            }
            catch
            {
                this.Icon = IntPtr.Zero;
            }
        }
Пример #2
0
        public static void RemoveServiceFunction(MirandaPlugin owner, string eventName)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

            if (String.IsNullOrEmpty(eventName))
                throw new ArgumentNullException("eventName");

            HookDescriptorCollection collection = owner.Descriptor.ServiceFunctions;

            try
            {
                SynchronizationHelper.BeginCollectionUpdate(collection);
                HookDescriptor descriptor = null;

                if ((descriptor = collection.Find(eventName)) == null)
                    return;

                HookManager.DestroyHook(descriptor);
                collection.Remove(descriptor);
            }
            finally
            {
                SynchronizationHelper.EndUpdate(collection);
            }
        }        
Пример #3
0
        internal EventHandle(MirandaPlugin owner, string eventName, IntPtr handle)
        {
            if (handle == IntPtr.Zero) 
                throw new ArgumentNullException("handle");

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

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

            this.owner = owner;
            this.MirandaHandle = handle;
            this.eventName = eventName;

            List<EventHandle> eventHandles = owner.Descriptor.EventHandles;

            try
            {
                SynchronizationHelper.BeginCollectionUpdate(eventHandles);
                eventHandles.Add(this);
            }
            finally
            {
                SynchronizationHelper.EndUpdate(eventHandles);
            }
        }
Пример #4
0
        public static void CreateServiceFunction(string serviceName, Callback callback, MirandaPlugin owner)
        {
            if (String.IsNullOrEmpty(serviceName))
                throw new ArgumentNullException("serviceName");

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

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

            if (!owner.Initialized)
                throw new InvalidOperationException(TextResources.ExceptionMsg_PluginNotInitialized);

            HookDescriptorCollection collection = owner.Descriptor.ServiceFunctions;

            try
            {
                SynchronizationHelper.BeginPluginUpdate(owner);
                SynchronizationHelper.BeginCollectionUpdate(collection);

                HookDescriptor descriptor = HookDescriptor.SetUpAndStore(collection, serviceName, owner.Descriptor, callback, HookType.ServiceFunction);
                descriptor.RegisteredManually = true;

                HookManager.CreateHook(descriptor);
            }
            finally
            {
                SynchronizationHelper.EndUpdate(owner);
                SynchronizationHelper.EndUpdate(collection);
            }
        }
Пример #5
0
        public static void RemoveEventHook(string eventName, MirandaPlugin owner)
        {
            if (String.IsNullOrEmpty(eventName))
                throw new ArgumentNullException("eventName");

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

            if (!owner.Initialized)
                throw new InvalidOperationException(TextResources.ExceptionMsg_PluginNotInitialized);

            HookDescriptorCollection collection = owner.Descriptor.EventHooks;

            try
            {
                SynchronizationHelper.BeginCollectionUpdate(collection);
                HookDescriptor descriptor = null;

                if ((descriptor = owner.Descriptor.EventHooks.Find(eventName)) == null)
                    return;

                HookManager.DestroyHook(descriptor);
                collection.Remove(descriptor);
            }
            finally
            {
                SynchronizationHelper.EndUpdate(collection);
            }
        }
Пример #6
0
        public CLISTMENUITEM(MirandaPlugin owner, MenuItemDeclarationAttribute attrib)
        {
            if (owner == null)
                throw new ArgumentNullException("owner");

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

            this.Text = attrib.Text;
            this.Service = attrib.Service;
            this.ContactOwner = attrib.OwningModule;
            this.Flags = (uint)attrib.Flags;
            this.PopUpMenu = attrib.PopUpMenu;
            this.PopUpPosition = attrib.PopUpPosition;
            this.Position = attrib.Position;
            this.HotKey = (uint)attrib.HotKey;
            this.Icon = IntPtr.Zero;
            this.Size = Marshal.SizeOf(typeof(CLISTMENUITEM));

            LoadIcon(owner, attrib);
        }
Пример #7
0
        public Update(MirandaPlugin plugin, Uri updateUrl, Uri versionUrl, string versionTextPrefix)
        {
            if (plugin == null) throw new ArgumentNullException("plugin");
            if (updateUrl == null) throw new ArgumentNullException("updateUrl");
            if (versionUrl == null) throw new ArgumentNullException("versionUrl");
            if (versionTextPrefix == null) throw new ArgumentNullException("versionTextPrefix");

            this.pluginName = plugin.Name;
            this.currentVersion = plugin.Version;
            this.updateUrl = updateUrl;
            this.versionUrl = versionUrl;
            this.versionTextPrefix = versionTextPrefix;
        }
Пример #8
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);
            }
        }
Пример #9
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text, MenuItemProperties flags, Icon icon, HotKeys hotKey)
 {
     return ModifyMenuItem(owner, menuItem, text, flags, icon, hotKey, true);
 }
Пример #10
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, Icon icon)
 {
     return ModifyMenuItem(owner, menuItem, null, MenuItemProperties.None, icon, 0, true);
 }
Пример #11
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, HotKeys hotKey)
 {
     return ModifyMenuItem(owner, menuItem, null, MenuItemProperties.None, null, hotKey, true);
 }
Пример #12
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, MenuItemProperties flags)
 {
     return ModifyMenuItem(owner, menuItem, null, flags, null, 0, true);
 }
Пример #13
0
 public bool ModifyMenuItem(MirandaPlugin owner, MenuItemDeclarationAttribute menuItem, string text)
 {
     return ModifyMenuItem(owner, menuItem, text, MenuItemProperties.None, null, 0, true);
 }
Пример #14
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();
            }
        }
Пример #15
0
 public static EventHandle CreateEvent(string eventName, MirandaPlugin owner)
 {
     return CreateEvent(eventName, owner, null);
 }
Пример #16
0
        public static EventHandle CreateEvent(string eventName, MirandaPlugin owner, Callback defaultSubscriber)
        {
            if (String.IsNullOrEmpty(eventName))
                throw new ArgumentNullException("eventName");

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

            if (!owner.Initialized)
                throw new InvalidOperationException(TextResources.ExceptionMsg_PluginNotInitialized);

            if (ServiceManager.ServiceExists(eventName))
                throw new ArgumentException("eventName");

            EventHandle handle = new EventHandle(owner, eventName, MirandaContext.Current.PluginLink.NativePluginLink.CreateHookableEvent(eventName));

            if (defaultSubscriber != null)
                handle.SetDefaultSubscriber(defaultSubscriber);

            return handle;
        }