Example #1
0
        /// <summary>
        /// This function allows us to add items to the context menus
        /// </summary>
        public void AddMenuItems(IntPtr piDataObject, IContextMenuCallback piCallback, ref int pInsertionAllowed)
        {
            try
            {
                if (piDataObject == (IntPtr)DataObject.CUSTOMOCX || piDataObject == (IntPtr)DataObject.CUSTOMWEB)
                {
                    return;
                }

                DataObject dataObject;
                if (m_areMultipleResultsSelected)
                {
                    ResultDataItem item = m_snapin.GetSelectedItem((IResultData)m_console);
                    dataObject = new DataObject(m_snapin.FindNode(item.Param));
                }
                else
                {
                    dataObject = (DataObject)(IDataObject)Marshal.GetObjectForIUnknown(piDataObject);
                }

                if (dataObject != null && dataObject.Node != null)
                {
                    dataObject.Node.AddMenuItems(piCallback, ref pInsertionAllowed);
                }
            }
            catch (Exception e)
            {
                new ExceptionDialog(e, "The following exception has occurred in the snap-in:").ShowDialog(m_snapin);
            }
        }
Example #2
0
        /// <summary>
        /// Called menu item is invoked.  We delegate to the node
        /// to let it handle it.
        /// </summary>
        /// <param name="lCommandID"></param>
        /// <param name="piDataObject"></param>
        public void Command(int lCommandID, IntPtr piDataObject)
        {
            try
            {
                if (piDataObject == (IntPtr)DataObject.CUSTOMOCX || piDataObject == (IntPtr)DataObject.CUSTOMWEB)
                {
                    return;
                }

                DataObject dataObject;
                if (m_areMultipleResultsSelected)
                {
                    ResultDataItem item = m_snapin.GetSelectedItem((IResultData)m_console);
                    dataObject = new DataObject(m_snapin.FindNode(item.Param));
                }
                else
                {
                    dataObject = (DataObject)(IDataObject)Marshal.GetObjectForIUnknown(piDataObject);
                }

                if (dataObject != null && dataObject.Node != null)
                {
                    dataObject.Node.OnMenuCommand(lCommandID);
                }
            }
            catch (Exception e)
            {
                new ExceptionDialog(e, "The following exception has occurred in the snap-in:").ShowDialog(m_snapin);
            }
        }
Example #3
0
        /// <summary>
        /// Called when MMC wants an IDataObject for a node by cookie
        /// </summary>
        /// <param name="cookie"></param>
        /// <param name="type"></param>
        /// <param name="ppDataObject"></param>
        public void QueryDataObject(IntPtr cookie, uint type, out IDataObject ppDataObject)
        {
            ppDataObject = null;

            try
            {
                // Check if this a MULTI_SELECT_COOKIE then just find
                // first selected item and return the node it depends to.
                if (cookie == (IntPtr)CookieType.MultiSelectCookie)
                {
                    ResultDataItem rdi  = m_snapin.GetSelectedItem((IResultData)m_console);
                    SnapinNode     node = m_snapin.FindNode(rdi.Param);
                    ppDataObject = new DataObject(node);
                    node.AreMultipleResultsSelected = true;
                    m_areMultipleResultsSelected    = true;
                }
                else
                {
                    SnapinNode node = m_snapin.FindNode(cookie);
                    ppDataObject = new DataObject(node);
                    node.AreMultipleResultsSelected = false;
                    m_areMultipleResultsSelected    = false;
                }
            }
            catch (Exception e)
            {
                new ExceptionDialog(e, "The following exception has occurred in the snap-in:").ShowDialog(m_snapin);
            }
        }
Example #4
0
        private void SetResultImage(Result result, string smallImage, string largeImage)
        {
            int newSmallIndex = AddResultImage(smallImage);
            int newLargeIndex = AddResultImage(largeImage);

            if (newSmallIndex == result.SmallImageIndex && newLargeIndex == result.LargeImageIndex)
            {
                return;                 // No change.
            }
            result.SmallImageIndex = newSmallIndex;
            result.LargeImageIndex = newLargeIndex;

            // Update the image.

            ResultDataItem rdi = new ResultDataItem();

            rdi.ItemId = result.ID;
            rdi.Mask   = (uint)ResultDataItemMask.Image;
            rdi.Image  = -1;

            IResultData resultData = Snapin.ResultViewConsole as IResultData;

            resultData.SetItem(ref rdi);

            // Redraw.

            resultData.UpdateItem(result.ID);
        }
Example #5
0
        private void RefreshResult(Result result, string smallImage, string largeImage, string text, string[] subTexts)
        {
            // Update the result.

            int newSmallIndex = AddResultImage(smallImage);
            int newLargeIndex = AddResultImage(largeImage);

            result.SmallImageIndex = newSmallIndex;
            result.LargeImageIndex = newLargeIndex;
            result.Text            = text;
            result.SubTexts.Reset(subTexts);

            // Update the image.

            ResultDataItem rdi = new ResultDataItem();

            rdi.ItemId = result.ID;
            rdi.Mask   = (uint)ResultDataItemMask.Image;
            rdi.Image  = -1;

            IResultData resultData = Snapin.ResultViewConsole as IResultData;

            resultData.SetItem(ref rdi);

            // Redraw.

            resultData.UpdateItem(result.ID);
        }
Example #6
0
        private ResultDataItem GetNextResultItem(int index)
        {
            ResultDataItem rdi = new ResultDataItem();

            rdi.Mask  = (uint)ResultDataItemMask.State;
            rdi.Col   = 0;
            rdi.Index = index;
            IResultData resultData = Snapin.ResultViewConsole as IResultData;

            resultData.GetNextItem(ref rdi);
            return(rdi);
        }
Example #7
0
        /// <summary>
        /// Populates the ResultDataItem with the appropriate information. In this case,
        /// it is the information from the ListView.
        /// </summary>
        /// <param name="resultDataItem"></param>
        internal override void GetDisplayInfo(ref ResultDataItem resultDataItem)
        {
            bool bCallbase = true;

            if ((resultDataItem.Mask & (uint)ResultDataItemMask.Str) > 0)
            {
                if (m_results != null)
                {
                    // Determine which result.

                    int resultParam = GetResultParamFromItemParam(resultDataItem.Param);
                    if (resultParam >= 0 && resultParam < m_results.Count)
                    {
                        // Determine which column.

                        if (resultDataItem.Col == 0)
                        {
                            resultDataItem.Str = Marshal.StringToCoTaskMemUni(m_results.GetByParam(resultParam).Text);
                        }
                        else
                        {
                            resultDataItem.Str = Marshal.StringToCoTaskMemUni(m_results.GetByParam(resultParam).SubTexts[resultDataItem.Col - 1]);
                        }
                        bCallbase = false;
                    }
                }
            }

            // Use the correct item image.

            if ((resultDataItem.Mask & (uint)ResultDataItemMask.Image) > 0)
            {
                if (m_results != null)
                {
                    // Determine which result.

                    int resultParam = GetResultParamFromItemParam(resultDataItem.Param);
                    if (resultParam >= 0 && resultParam < m_results.Count)
                    {
                        Result result = m_results.GetByParam(resultParam);
                        resultDataItem.Image = IsUseSmallIcons() ? result.SmallImageIndex : result.LargeImageIndex;
                        bCallbase            = false;
                    }
                }
            }

            if (bCallbase)
            {
                base.GetDisplayInfo(ref resultDataItem);
            }
        }
Example #8
0
        private Result[] GetResults()
        {
            ArrayList results = new ArrayList();

            ResultDataItem rdi = GetNextResultItem(-1);

            while (rdi.Index != -1)
            {
                results.Add(m_results.GetByParam(GetResultParamFromItemParam(rdi.Param)));
                rdi = GetNextResultItem(rdi.Index);
            }

            return((Result[])results.ToArray(typeof(Result)));
        }
Example #9
0
        internal ResultDataItem GetSelectedItem(IResultData resultData, int index)
        {
            ResultDataItem item = new ResultDataItem();

            item.Mask  = (uint)ResultDataItemFlags.State;
            item.Col   = 0;
            item.Index = index;
            item.State = (uint)ListViewItemState.Selected;

            try
            {
                resultData.GetNextItem(ref item);
            }
            catch (COMException)
            {
            }

            return(item);
        }
Example #10
0
        protected void AddResult(object data, string name, string text, string[] subTexts)
        {
            // Add the item.

            IResultData    resultData = Snapin.ResultViewConsole as IResultData;
            ResultDataItem rdi        = new ResultDataItem();

            rdi.Mask  = (uint)ResultDataItemMask.Str | (uint)ResultDataItemMask.Image | (uint)ResultDataItemMask.Param;
            rdi.Image = -1;
            rdi.Str   = (IntPtr)(-1);
            rdi.Col   = 0;
            int resultParam = m_results.Count;

            rdi.Param = GetItemParamFromResultParam(resultParam);
            resultData.InsertItem(ref rdi);

            // Add the result details.

            m_results.Add(new Result(rdi.ItemId, -1, -1, data, name, text, subTexts, resultParam));
        }
Example #11
0
        internal virtual void GetDisplayInfo(ref ResultDataItem item)
        {
            // Display name.

            if ((item.Mask & (uint)ResultDataItemFlags.Str) > 0)
            {
                item.Str = Marshal.StringToCoTaskMemUni(m_displayName);
            }

            // Image.

            if ((item.Mask & (uint)ResultDataItemFlags.Image) > 0)
            {
                item.Image = ((int)Cookie << 16) + GetResultViewImageIndex();
            }

            // Param.

            if ((item.Mask & (uint)ResultDataItemFlags.Param) > 0)
            {
                item.Param = m_cookie;
            }

            // Index.

            if ((item.Mask & (uint)ResultDataItemFlags.Index) > 0)
            {
                item.Index = 0;
            }

            // Indent.

            if ((item.Mask & (uint)ResultDataItemFlags.Indent) > 0)
            {
                item.Indent = 0;
            }
        }
Example #12
0
 /// <summary>
 /// Called to get result view information.
 /// </summary>
 /// <param name="resultDataItem"></param>
 public void GetDisplayInfo(ref ResultDataItem resultDataItem)
 {
     m_snapin.FindNode(resultDataItem.Param).GetDisplayInfo(ref resultDataItem);
 }
Example #13
0
        /// <summary>
        /// Delegate to the relevent node or handle it directly.
        /// </summary>
        public int Notify(IntPtr lpDataObject, uint notifyEvent, IntPtr arg, IntPtr param)
        {
            int hr = Constants.Win32.HResults.S_FALSE;

            try
            {
                // There are some sneaky values for the IDataObject parameters that make
                // interop with this interface a little trick.  This is why lpDataObject is an IntPtr
                // not an actual IDataObject interface.

                if (lpDataObject == (IntPtr)DataObject.CUSTOMOCX || lpDataObject == (IntPtr)DataObject.CUSTOMWEB)
                {
                    return(hr);
                }

                hr = Constants.Win32.HResults.S_OK;

                IDataObject dataObject = null;
                if (lpDataObject != (IntPtr)0)
                {
                    dataObject = (IDataObject)Marshal.GetObjectForIUnknown(lpDataObject);
                }

                // Get the node.

                SnapinNode node;

                if (dataObject != null)
                {
                    node = ((DataObject)dataObject).Node;
                }
                else
                {
                    // Try to get the node of the selected item.

                    ResultDataItem item = m_snapin.GetSelectedItem((IResultData)m_console);
                    if (item.Index != -1)
                    {
                        node = m_snapin.FindNode(item.Param);
                    }
                    else
                    {
                        node = m_snapin.CurrentScopeNode;
                        if (node == null)
                        {
                            node = m_snapin.RootNode;
                        }
                    }
                }

                Debug.WriteLine("IComponent.Notify: " + ((MmcNotify)notifyEvent) + " " + node.DisplayName);

                // Dispatch the event to the node.

                switch ((MmcNotify)notifyEvent)
                {
                case MmcNotify.Activate:

                    node.OnActivate(arg.ToInt32() != 0);
                    break;

                case MmcNotify.AddImages:

                    // arg actually contains the IImageList interface. We need to
                    // marshall that manually as well.

                    IImageList imageList = (IImageList)Marshal.GetObjectForIUnknown(arg);

                    // Param contains the HScopeItem so use it to get the node it represents.

                    node = m_snapin.FindNodeByHScopeItem(param);
                    if (node != null)
                    {
                        node.OnAddResultPaneImages(imageList);
                    }
                    break;

                case MmcNotify.BtnClick:

                    node.OnBtnClick(param.ToInt32());
                    break;

                case MmcNotify.Click:

                    node.OnClick();
                    break;

                case MmcNotify.ColumnClick:

                    node.OnColumnClick((int)arg, (int)param == 0);
                    break;

                case MmcNotify.CutOrMove:

                    dataObject = (IDataObject)Marshal.GetObjectForIUnknown(arg);
                    if (!node.OnCutOrMove(dataObject))
                    {
                        hr = Constants.Win32.HResults.S_FALSE;
                    }
                    break;

                case MmcNotify.DblClick:

                    // Check if the default verb is enabled. If it is let MMC invoke it, otherwise
                    // say that the action was handled. This prevents it from asking for a property page
                    // when the Properties verb is disabled.

                    IConsoleVerb consoleVerb;
                    Console.QueryConsoleVerb(out consoleVerb);

                    MmcConsoleVerb defaultVerb = MmcConsoleVerb.None;
                    consoleVerb.GetDefaultVerb(ref defaultVerb);

                    int state = 0;
                    consoleVerb.GetVerbState(defaultVerb, MmcButtonState.Enabled, ref state);

                    hr = (state == 0 ? Constants.Win32.HResults.S_OK : Constants.Win32.HResults.S_FALSE);
                    break;

                case MmcNotify.Delete:

                    node.OnDelete();
                    break;

                case MmcNotify.DeselectAll:

                    node.OnDeselectAll();
                    break;

                case MmcNotify.Expand:

                    if (arg == IntPtr.Zero)
                    {
                        node.OnExpand(false);
                    }
                    else
                    {
                        node.OnCollapse();
                    }
                    break;

                case MmcNotify.MenuBtnClick:

                    MenuButtonData data = (MenuButtonData)(Marshal.PtrToStructure(param, typeof(MenuButtonData)));
                    node.OnMenuBtnClick(data.CommandId, data.X, data.Y);
                    break;

                case MmcNotify.Minimized:

                    if (arg.ToInt32() == 0)
                    {
                        node.OnMaximized();
                    }
                    else
                    {
                        node.OnMinimized();
                    }
                    break;

                case MmcNotify.Paste:

                    dataObject = (IDataObject)Marshal.GetObjectForIUnknown(arg);
                    if (node.OnPaste(dataObject))
                    {
                        param = Marshal.GetIUnknownForObject(dataObject);
                    }
                    else
                    {
                        hr = Constants.Win32.HResults.S_FALSE;
                    }
                    break;

                case MmcNotify.PropertyChange:

                    break;

                case MmcNotify.QueryPaste:

                    dataObject = (IDataObject)Marshal.GetObjectForIUnknown(arg);
                    if (!node.OnQueryPaste(dataObject))
                    {
                        hr = Constants.Win32.HResults.S_FALSE;
                    }
                    break;

                case MmcNotify.Refresh:

                    node.OnRefresh();
                    break;

                case MmcNotify.Print:

                    node.OnPrint();
                    break;

                case MmcNotify.Rename:

                    if (arg == IntPtr.Zero)
                    {
                        // Check.

                        if (!node.OnTryRename())
                        {
                            hr = Constants.Win32.HResults.S_FALSE;
                        }
                    }
                    else
                    {
                        if (node.OnRename(Marshal.PtrToStringAuto(param)))
                        {
                            SetStatusText(node.GetStatusText());
                        }
                        else
                        {
                            hr = Constants.Win32.HResults.S_FALSE;
                        }
                    }

                    break;

                case MmcNotify.Select:

                    bool scope  = ((short)arg) != 0;
                    bool select = ((((int)arg) >> 16) & 0xffff) != 0;

                    if (scope)
                    {
                        if (select)
                        {
                            if (m_scopeItemChanging)
                            {
                                m_scopeItemChanging       = false;
                                m_snapin.CurrentScopeNode = node;
                            }

                            // Defect 54593: for some reason when multiple result items are selected and the
                            // user clicks on the scope node MMC does NOT send a "deselect result" notification
                            // (if a single result item is selected then it does). Work around this.

                            if (node.IsResultSelected)
                            {
                                node.OnDeselectResult();
                            }

                            node.OnSelectScopeItem();
                            SetStatusText(node.GetStatusText());
                        }
                        else
                        {
                            node.OnDeselectScopeItem();
                        }
                    }
                    else
                    {
                        if (select)
                        {
                            node.OnSelectResult();
                        }
                        else
                        {
                            node.OnDeselectResult();
                        }
                    }

                    break;

                case MmcNotify.Show:

                    bool selecting = (arg != IntPtr.Zero);
                    if (selecting)
                    {
                        m_scopeItemChanging = true;
                        m_snapin.FindNodeByHScopeItem(param).OnShow();
                    }
                    else
                    {
                        m_snapin.FindNodeByHScopeItem(param).OnHide();
                    }

                    break;

                case MmcNotify.ViewChange:

                    dataObject = null;
                    if (param != (IntPtr)0)
                    {
                        dataObject = (IDataObject)Marshal.GetObjectForIUnknown(param);
                    }
                    SnapinNode nodeChanged = dataObject == null ? m_snapin.RootNode : ((DataObject)dataObject).Node;

                    if (arg != IntPtr.Zero)
                    {
                        node.OnViewChangeScope(nodeChanged);
                    }
                    else
                    {
                        node.OnViewChangeResult(nodeChanged);
                    }
                    break;

                case MmcNotify.SnapinHelp:

                    hr = Constants.Win32.HResults.S_FALSE;
                    break;

                case MmcNotify.ContextHelp:

                    node.OnContextHelp();
                    break;

                case MmcNotify.InitOcx:

                    // param is the IUnknown of the OCX.

                    object ocx = Marshal.GetObjectForIUnknown(param);
                    if (node.OnInitOcx(ocx))
                    {
                        hr = Constants.Win32.HResults.S_OK;
                    }
                    else
                    {
                        hr = Constants.Win32.HResults.S_FALSE;
                    }
                    break;

                case MmcNotify.FilterChange:

                    node.OnFilterChange((MmcFilterChangeCode)arg.ToInt32(), param.ToInt32());
                    hr = Constants.Win32.HResults.S_OK;
                    break;

                case MmcNotify.GetFilterMenu:

                    hr = Constants.Win32.HResults.S_FALSE;
                    break;

                case MmcNotify.FilterOperator:

                    hr = Constants.Win32.HResults.S_FALSE;
                    break;

                case MmcNotify.ColumnsChanged:

                    hr = Constants.Win32.HResults.S_OK;
                    break;

                default:

                    // The notification is not supported.

                    hr = Constants.Win32.HResults.S_FALSE;
                    break;
                }
            }
            catch (Exception e)
            {
                new ExceptionDialog(e, "The following exception has occurred in the snap-in:").ShowDialog(m_snapin);
                hr = Constants.Win32.HResults.S_FALSE;
            }

            return(hr);
        }