Exemple #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);
             }
         }
     }
 }
        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);
                }
            }
        }