private object ExecCommandCallback(object arguments) { object[] array = (object[])arguments; Invariant.Assert(array.Length == 3); Guid guidCmdGroup = (Guid)array[0]; uint num = (uint)array[1]; object argument = array[2]; IDictionary oleCmdMappingTable = this.GetOleCmdMappingTable(guidCmdGroup); if (oleCmdMappingTable == null) { return(-2147221244); } CommandWithArgument commandWithArgument = oleCmdMappingTable[num] as CommandWithArgument; if (commandWithArgument == null) { return(-2147221248); } if (Application.Current.MainWindow == null) { return(-2147221247); } IInputElement inputElement = FocusManager.GetFocusedElement(Application.Current.MainWindow); if (inputElement == null) { inputElement = Application.Current.MainWindow; } return(commandWithArgument.Execute(inputElement, argument) ? 0 : -2147221247); }
private object ExecCommandCallback(object arguments) { object[] args = (object[])arguments; Invariant.Assert(args.Length == 3); Guid guidCmdGroup = (Guid)args[0]; uint commandId = (uint)args[1]; object arg = args[2]; IDictionary oleCmdMappingTable = GetOleCmdMappingTable(guidCmdGroup); if (oleCmdMappingTable == null) { return(OLECMDERR_E_UNKNOWNGROUP); } CommandWithArgument command = oleCmdMappingTable[commandId] as CommandWithArgument; if (command == null) { return(OLECMDERR_E_NOTSUPPORTED); } if (Application.Current.MainWindow == null) { return(OLECMDERR_E_DISABLED); } IInputElement target = FocusManager.GetFocusedElement(Application.Current.MainWindow); if (target == null) { // This will always succeed because Window is IInputElement target = (IInputElement)Application.Current.MainWindow; } return(command.Execute(target, arg) ? NativeMethods.S_OK : OLECMDERR_E_DISABLED); }
internal void QueryStatus(Guid guidCmdGroup, uint cmdId, ref uint flags) { /***IMPORTANT: * Make sure to return allowed and appropriate values according to the specification of * IOleCommandTarget::QueryStatus(). In particular: * - OLECMDF_SUPPORTED without OLECMDF_ENABLED should not be blindly returned for * unrecognized commands. * - Some code in IE treats OLECMDERR_E_xxx differently from generic failures. * - E_NOTIMPL is not an acceptable return value. */ if (Application.Current == null || Application.IsShuttingDown == true) { Marshal.ThrowExceptionForHR(NativeMethods.E_FAIL); } // Get values from mapping here else mark them as disabled ==> // i.e "supported but not enabled" and is the equivalent of disabled since // there is no explicit "disabled" OLECMD flag IDictionary oleCmdMappingTable = GetOleCmdMappingTable(guidCmdGroup); if (oleCmdMappingTable == null) { Marshal.ThrowExceptionForHR(OleCmdHelper.OLECMDERR_E_UNKNOWNGROUP); } CommandWithArgument command = oleCmdMappingTable[cmdId] as CommandWithArgument; if (command == null) { flags = CommandUnsupported; return; } // Go through the Dispatcher in order to use its SynchronizationContext and also // so that any application exception caused during event routing is reported via // Dispatcher.UnhandledException. // The above code is not in the callback, because it throws, and we don't want the // application to get these exceptions. (The COM Interop layer turns them into HRESULTs.) bool enabled = (bool)Application.Current.Dispatcher.Invoke( DispatcherPriority.Send, new DispatcherOperationCallback(QueryEnabled), command); flags = enabled ? CommandEnabled : CommandDisabled; }
internal void QueryStatus(Guid guidCmdGroup, uint cmdId, ref uint flags) { if (Application.Current == null || Application.IsShuttingDown) { Marshal.ThrowExceptionForHR(-2147467259); } IDictionary oleCmdMappingTable = this.GetOleCmdMappingTable(guidCmdGroup); if (oleCmdMappingTable == null) { Marshal.ThrowExceptionForHR(-2147221244); } CommandWithArgument commandWithArgument = oleCmdMappingTable[cmdId] as CommandWithArgument; if (commandWithArgument == null) { flags = 0U; return; } flags = (((bool)Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new DispatcherOperationCallback(this.QueryEnabled), commandWithArgument)) ? 3U : 1U); }