Esempio n. 1
0
 /// <summary>
 /// Analyze COMAddin custom taskpane attributes
 /// </summary>
 /// <param name="taskPanes">taskpanes you want to create</param>
 /// <param name="addinType">addin class type informations</param>
 /// <param name="addin">addin instance</param>
 /// <param name="callOnCreateTaskPaneInfo">callback to manipulate the process dynamicly</param>
 /// <param name="visibleStateChange">visible changed event handler</param>
 /// <param name="dockPositionStateChange">dock state changed event handler</param>
 public void ProceedCustomPaneAttributes(OfficeApi.Tools.CustomTaskPaneCollection taskPanes, Type addinType, COMAddinBase addin,
                                         CallOnCreateTaskPaneInfoHandler callOnCreateTaskPaneInfo,
                                         CustomTaskPane_VisibleStateChangeEventHandler visibleStateChange,
                                         CustomTaskPane_DockPositionStateChangeEventHandler dockPositionStateChange)
 {
     CustomPaneAttribute[] paneAttributes = AttributeReflector.GetCustomPaneAttributes(addinType);
     foreach (CustomPaneAttribute itemPane in paneAttributes)
     {
         if (null != itemPane)
         {
             TaskPaneInfo item = taskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name);
             item.Title                = itemPane.Title;
             item.Visible              = itemPane.Visible;
             item.DockPosition         = (OfficeApi.Enums.MsoCTPDockPosition)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString());
             item.DockPositionRestrict = (OfficeApi.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString());
             item.Width                = itemPane.Width;
             item.Height               = itemPane.Height;
             item.Arguments            = new object[] { addin, this };
             if (callOnCreateTaskPaneInfo(item))
             {
                 item.VisibleStateChange      += visibleStateChange;
                 item.DockPositionStateChange += dockPositionStateChange;
             }
             else
             {
                 taskPanes.Remove(item);
             }
         }
     }
 }
Esempio n. 2
0
        private void ProceedCustomPaneAttributes()
        {
            CustomPaneAttribute[] paneAttributes = AttributeReflector.GetCustomPaneAttributes(Type);
            foreach (CustomPaneAttribute itemPane in paneAttributes)
            {
                if (null != itemPane)
                {
                    TaskPaneInfo item = TaskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name);
                    item.Title                = itemPane.Title;
                    item.Visible              = itemPane.Visible;
                    item.DockPosition         = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString());
                    item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString());
                    item.Width                = itemPane.Width;
                    item.Height               = itemPane.Height;
                    item.Arguments            = new object[] { this };

                    if (CallOnCreateTaskPaneInfo(item))
                    {
                        item.VisibleStateChange      += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange);
                        item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange);
                    }
                    else
                    {
                        TaskPanes.Remove(item);
                    }
                }
            }
        }
Esempio n. 3
0
 private bool CallOnCreateTaskPaneInfo(TaskPaneInfo paneInfo)
 {
     try
     {
         return(OnCreateTaskPaneInfo(paneInfo));
     }
     catch (Exception exception)
     {
         Factory.Console.WriteException(exception);
         OnError(ErrorMethodKind.CTPFactoryAvailable, exception);
         return(false);
     }
 }
        public void ProceedCustomPaneAttributes(Core factory, OfficeApi.ICTPFactory taskPaneFactory, OfficeApi.Tools.CustomTaskPaneCollection taskPanes,
                                                NetOffice.Tools.OnErrorHandler onError, ICOMObject application,
                                                Type addinType, IOfficeCOMAddin addin,
                                                CallOnCreateTaskPaneInfoHandler callOnCreateTaskPaneInfo,
                                                CustomTaskPane_VisibleStateChangeEventHandler visibleStateChange,
                                                CustomTaskPane_DockPositionStateChangeEventHandler dockPositionStateChange)
        {
            try
            {
                var paneAttributes = NetOffice.Attributes.AttributeExtensions.GetCustomAttributes <CustomPaneAttribute>(addinType);
                foreach (CustomPaneAttribute itemPane in paneAttributes)
                {
                    if (null != itemPane)
                    {
                        TaskPaneInfo item = taskPanes.Add(itemPane.PaneType, itemPane.PaneType.Name, itemPane.Creation);
                        if (!item.CreateAtStartup)
                        {
                            Action <TaskPaneInfo> method = delegate(TaskPaneInfo info)
                            {
                                CreateCustomPane(info, factory, taskPaneFactory, taskPanes, onError, application);
                            };
                            item.SetCreateAction(method);
                        }

                        item.Title                = itemPane.Title;
                        item.Visible              = itemPane.Visible;
                        item.DockPosition         = (OfficeApi.Enums.MsoCTPDockPosition)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPosition), itemPane.DockPosition.ToString());
                        item.DockPositionRestrict = (OfficeApi.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPositionRestrict), itemPane.DockPositionRestrict.ToString());
                        item.Width                = itemPane.Width;
                        item.Height               = itemPane.Height;
                        item.Arguments            = new object[] { addin, this };
                        if (callOnCreateTaskPaneInfo(item))
                        {
                            item.VisibleStateChange      += visibleStateChange;
                            item.DockPositionStateChange += dockPositionStateChange;
                        }
                        else
                        {
                            taskPanes.Remove(item);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (null != onError)
                {
                    onError(ErrorMethodKind.CTPFactoryAvailable, exception);
                }
            }
        }
        private void CreateCustomPane(TaskPaneInfo item, Core factory, OfficeApi.ICTPFactory taskPaneFactory, OfficeApi.Tools.CustomTaskPaneCollection taskPanes,
                                      NetOffice.Tools.OnErrorHandler onError, ICOMObject application)
        {
            try
            {
                if (null == factory)
                {
                    return;
                }
                if (null == taskPaneFactory)
                {
                    return;
                }
                if (null == taskPanes)
                {
                    return;
                }
                if (null == application)
                {
                    return;
                }
                if (null == item)
                {
                    return;
                }
                if (null != item.Pane)
                {
                    return;
                }

                string title = item.Title;
                OfficeApi.CustomTaskPane taskPane = CreateCTP(taskPaneFactory, item.Type.FullName, title, onError);
                if (null == taskPane)
                {
                    return;
                }

                Type taskPaneType = taskPane.GetType();
                item.Pane             = taskPane;
                taskPane.AfterDelete += taskPanes.TaskPaneDeleted;

                item.AssignEvents();
                item.IsLoaded = true;

                switch (taskPane.DockPosition)
                {
                case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft:
                case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionRight:
                    taskPane.Width = item.Width >= 0 ? item.Width : TaskPaneInfo.DefaultSize;
                    break;

                case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionTop:
                case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom:
                    taskPane.Height = item.Height >= 0 ? item.Height : TaskPaneInfo.DefaultSize;
                    break;

                case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionFloating:
                    item.Width      = item.Width >= 0 ? item.Width : TaskPaneInfo.DefaultSize;
                    taskPane.Height = item.Height >= 0 ? item.Height : TaskPaneInfo.DefaultSize;
                    break;

                default:
                    break;
                }

                OfficeApi.Tools.ITaskPane pane = taskPane.ContentControl as OfficeApi.Tools.ITaskPane;
                if (null != pane)
                {
                    object[] argumentArray = new object[0];

                    if (item.Arguments != null)
                    {
                        argumentArray = item.Arguments;
                    }

                    try
                    {
                        OfficeApi.Tools.ITaskPane foo = pane as OfficeApi.Tools.ITaskPane;
                        if (null != foo)
                        {
                            foo.OnConnection(application, taskPane, argumentArray);
                        }
                    }
                    catch (Exception exception)
                    {
                        factory.Console.WriteException(exception);
                    }
                }

                foreach (KeyValuePair <string, object> property in item.ChangedProperties)
                {
                    if (property.Key == "Title")
                    {
                        continue;
                    }

                    try
                    {
                        if (property.Key == "Width") // avoid to set width in top and bottom align
                        {
                            object outValue = null;
                            item.ChangedProperties.TryGetValue("DockPosition", out outValue);
                            if (null != outValue)
                            {
                                OfficeApi.Enums.MsoCTPDockPosition position = (OfficeApi.Enums.MsoCTPDockPosition)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPosition), outValue.ToString());
                                if (position == OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionTop || position == OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom)
                                {
                                    continue;
                                }
                            }
                        }

                        if (property.Key == "Height")   // avoid to set height in left and right align
                        {
                            object outValue = null;
                            item.ChangedProperties.TryGetValue("DockPosition", out outValue);
                            if (null == outValue)
                            {
                                outValue = OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionRight; // NetOffice default position if unset
                            }
                            OfficeApi.Enums.MsoCTPDockPosition position = (OfficeApi.Enums.MsoCTPDockPosition)Enum.Parse(typeof(OfficeApi.Enums.MsoCTPDockPosition), outValue.ToString());
                            if (position == OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft || position == OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionRight)
                            {
                                continue;
                            }
                        }

                        taskPaneType.InvokeMember(property.Key, System.Reflection.BindingFlags.SetProperty, null, taskPane, new object[] { property.Value });
                    }
                    catch
                    {
                        factory.Console.WriteLine("Failed to set TaskPane property {0}", property.Key);
                    }
                }
            }
            catch (Exception exception)
            {
                if (null != onError)
                {
                    onError(ErrorMethodKind.CTPFactoryAvailable, exception);
                }
            }
        }
Esempio n. 6
0
 /// <summary>
 /// The method is called while the CustomPane attribute is processed
 /// </summary>
 /// <param name="paneInfo">pane definition</param>
 /// <returns>true if pane should be create, otherwise false</returns>
 protected internal virtual bool OnCreateTaskPaneInfo(TaskPaneInfo paneInfo)
 {
     return(true);
 }
Esempio n. 7
0
        /// <summary>
        /// ICustomTaskPaneConsumer implementation
        /// </summary>
        /// <param name="CTPFactoryInst">factory proxy from host application</param>
        public virtual void CTPFactoryAvailable(object CTPFactoryInst)
        {
            try
            {
                if (null == CTPFactoryInst)
                {
                    Factory.Console.WriteLine("Warning: null argument recieved in CTPFactoryAvailable. argument name: CTPFactoryInst");
                    return;
                }

                CustomPaneAttribute paneAttribute = AttributeHelper.GetCustomPaneAttribute(Type);
                if (null != paneAttribute)
                {
                    TaskPaneInfo item = TaskPanes.Add(paneAttribute.PaneType, paneAttribute.PaneType.Name);
                    if (!CallOnCreateTaskPaneInfo(item))
                    {
                        item.Title                = paneAttribute.Title;
                        item.Visible              = paneAttribute.Visible;
                        item.DockPosition         = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), paneAttribute.DockPosition.ToString());
                        item.DockPositionRestrict = (Office.Enums.MsoCTPDockPositionRestrict)Enum.Parse(typeof(Office.Enums.MsoCTPDockPositionRestrict), paneAttribute.DockPositionRestrict.ToString());
                        item.Width                = paneAttribute.Width;
                        item.Height               = paneAttribute.Height;
                        item.Arguments            = new object[] { this };
                    }

                    item.VisibleStateChange      += new NetOffice.OfficeApi.CustomTaskPane_VisibleStateChangeEventHandler(AttributePane_VisibleStateChange);
                    item.DockPositionStateChange += new Office.CustomTaskPane_DockPositionStateChangeEventHandler(AttributePane_DockPositionStateChange);
                }

                TaskPaneFactory = new NetOffice.OfficeApi.ICTPFactory(Factory, null, CTPFactoryInst);
                foreach (TaskPaneInfo item in TaskPanes)
                {
                    string title = item.Title;
                    Office.CustomTaskPane taskPane = TaskPaneFactory.CreateCTP(item.Type.FullName, title) as Office.CustomTaskPane;
                    item.Pane = taskPane;
                    item.AssignEvents();
                    item.IsLoaded = true;

                    switch (taskPane.DockPosition)
                    {
                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft:
                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionRight:
                        taskPane.Width = item.Width;
                        break;

                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionTop:
                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom:
                        taskPane.Height = item.Height;
                        break;

                    case NetOffice.OfficeApi.Enums.MsoCTPDockPosition.msoCTPDockPositionFloating:
                        item.Width      = paneAttribute.Width;
                        taskPane.Height = item.Height;
                        break;

                    default:
                        break;
                    }

                    ITaskPane pane = taskPane.ContentControl as ITaskPane;
                    if (null != pane)
                    {
                        TaskPaneInstances.Add(pane);
                        object[] argumentArray = new object[0];

                        if (item.Arguments != null)
                        {
                            argumentArray = item.Arguments;
                        }

                        pane.OnConnection(Application, taskPane, argumentArray);
                    }

                    foreach (KeyValuePair <string, object> property in item.ChangedProperties)
                    {
                        if (property.Key == "Title")
                        {
                            continue;
                        }

                        try
                        {
                            if (property.Key == "Width") // avoid to set width in top and bottom align
                            {
                                object outValue = null;
                                item.ChangedProperties.TryGetValue("DockPosition", out outValue);
                                if (null != outValue)
                                {
                                    Office.Enums.MsoCTPDockPosition position = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), outValue.ToString());
                                    if (position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionTop || position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionBottom)
                                    {
                                        continue;
                                    }
                                }
                            }

                            if (property.Key == "Height")   // avoid to set height in left and right align
                            {
                                object outValue = null;
                                item.ChangedProperties.TryGetValue("DockPosition", out outValue);
                                if (null == outValue)
                                {
                                    outValue = Office.Enums.MsoCTPDockPosition.msoCTPDockPositionRight; // NetOffice default position if unset
                                }
                                Office.Enums.MsoCTPDockPosition position = (Office.Enums.MsoCTPDockPosition)Enum.Parse(typeof(Office.Enums.MsoCTPDockPosition), outValue.ToString());
                                if (position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionLeft || position == Office.Enums.MsoCTPDockPosition.msoCTPDockPositionRight)
                                {
                                    continue;
                                }
                            }

                            taskPane.GetType().InvokeMember(property.Key, BindingFlags.SetProperty, null, taskPane, new object[] { property.Value });
                        }
                        catch
                        {
                            ;
                        }
                    }
                }
            }
            catch (NetRuntimeSystem.Exception exception)
            {
                Factory.Console.WriteException(exception);
                OnError(ErrorMethodKind.CTPFactoryAvailable, exception);
            }
        }