} // ExecuteCommandRange /// <summary> /// Executes the execCommand on the selected range (given the range) /// </summary> private void ExecuteCommandRange(mshtmlTextRange range, string command, object data) { try { if (!range.IsNull() && !range.text.IsNullOrEmpty()) { // ensure command is a valid command and then enabled for the selection if (range.queryCommandSupported(command)) { if (range.queryCommandEnabled(command)) { // mark the selection with the appropriate tag range.execCommand(command, false, data); } } } else { ExecuteCommandDocument(command, false, data); } } catch (Exception ex) { // Unknown error so inform user throw new HtmlEditorException("Unknown MSHTML Error.", command, ex); } } // ExecuteCommandRange
} // QueryCommandRange /// <summary> /// Determines the value of the command /// </summary> private object QueryCommandRange(mshtmlTextRange range, string command) { object retValue = null; try { if (!range.IsNull() && !range.text.IsNullOrEmpty()) { // ensure command is a valid command and then enabled for the selection if (range.queryCommandSupported(command)) { if (range.queryCommandEnabled(command)) { retValue = range.queryCommandValue(command); } } } else { retValue = QueryCommandDocument(command); } } catch (Exception) { // have unknown error so set return to null retValue = null; } // return the obtained value return retValue; } //QueryCommandRange
} //ExecuteCommandQuery /// <summary> /// Executes the queryCommandState on the selected range (given the range) /// </summary> private bool ExecuteCommandQuery(mshtmlTextRange range, string command, bool isEnabled = false) { // set the initial state as false bool retValue = false; try { if (!range.IsNull() && !range.text.IsNullOrEmpty()) { // ensure command is a valid command and then enabled for the selection if (range.queryCommandSupported(command)) { if (isEnabled) { retValue = range.queryCommandEnabled(command); } else { if (range.queryCommandEnabled(command)) { // mark the selection with the appropriate tag retValue = range.queryCommandState(command); } } } } else { // ensure command is a valid command and then enabled for the selection if (_doc.queryCommandSupported(command)) { if (isEnabled) { retValue = _doc.queryCommandEnabled(command); } else { if (_doc.queryCommandEnabled(command)) { // mark the selection with the appropriate tag retValue = _doc.queryCommandState(command); } } } } } catch (Exception ex) { // Unknown error so inform user throw new HtmlEditorException("Unknown MSHTML Error.", command, ex); } // return the value return retValue; } // ExecuteCommandQuery