private void HighlightWordRange(MarkupRange word) { try { IHighlightSegmentRaw segment; IDisplayPointerRaw start; IDisplayPointerRaw end; _displayServices.CreateDisplayPointer(out start); _displayServices.CreateDisplayPointer(out end); DisplayServices.TraceMoveToMarkupPointer(start, word.Start); DisplayServices.TraceMoveToMarkupPointer(end, word.End); _highlightRenderingServices.AddSegment(start, end, HighlightWordStyle, out segment); _tracker.AddSegment(segment, MarkupHelpers.UseStagingTextRange(ref stagingTextRange, word, rng => rng.text), _markupServicesRaw); } catch (COMException ce) { if (ce.ErrorCode == unchecked ((int)0x800A025E)) { return; } throw; } }
private bool ShouldNavigateOutOfEditField(IHTMLElement selectedEditField, Keys keyCode) { Debug.Assert(keyCode == Keys.Up || keyCode == Keys.Down); if (selectedEditField == null) { return(false); } IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document; MarkupRange editFieldRange = EditorContext.MarkupServices.CreateMarkupRange(selectedEditField, false); // If we're navigating up, then position a display pointer on the top line. // If we're going down, then position a display pointer on the bottom line. IDisplayPointerRaw displayPointer; displayServices.CreateDisplayPointer(out displayPointer); DisplayServices.TraceMoveToMarkupPointer(displayPointer, keyCode == Keys.Up ? editFieldRange.Start : editFieldRange.End); // Now determine if the display pointer is in the top/bottom line rect. return(IsCaretWithin(GetLineRect(selectedEditField, displayPointer))); }
/// <summary> /// Analysis is quite simple - the table's name is examined and if it ends with "View" then a problem /// is created /// </summary> /// <param name="ruleExecutionContext"></param> /// <returns></returns> public override IList <SqlRuleProblem> Analyze(SqlRuleExecutionContext ruleExecutionContext) { List <SqlRuleProblem> problems = new List <SqlRuleProblem>(); TSqlObject table = ruleExecutionContext.ModelElement; if (table != null) { if (NameEndsInView(table.Name)) { // DisplayServices is a useful helper service for formatting names DisplayServices displayServices = ruleExecutionContext.SchemaModel.DisplayServices; string formattedName = displayServices.GetElementName(table, ElementNameStyle.FullyQualifiedName); string problemDescription = string.Format(NameEndingInViewMsgFormat, formattedName); SqlRuleProblem problem = new SqlRuleProblem(problemDescription, table); problems.Add(problem); } } return(problems); }
private string DumpProblemsToString(IEnumerable <SqlRuleProblem> problems) { DisplayServices displayServices = this.ModelForAnalysis.DisplayServices; List <SqlRuleProblem> problemList = new List <SqlRuleProblem>(problems); SortProblemsByFileName(problemList); StringBuilder sb = new StringBuilder(); foreach (SqlRuleProblem problem in problemList) { this.AppendOneProblemItem(sb, "Problem description", problem.Description); this.AppendOneProblemItem(sb, "FullID", problem.RuleId); this.AppendOneProblemItem(sb, "Severity", problem.Severity.ToString()); this.AppendOneProblemItem(sb, "Model element", displayServices.GetElementName(problem.ModelElement, ElementNameStyle.FullyQualifiedName)); string fileName = null; if (problem.SourceName != null) { FileInfo fileInfo = new FileInfo(problem.SourceName); fileName = fileInfo.Name; } else { fileName = string.Empty; } this.AppendOneProblemItem(sb, "Script file", fileName); this.AppendOneProblemItem(sb, "Start line", problem.StartLine.ToString()); this.AppendOneProblemItem(sb, "Start column", problem.StartColumn.ToString()); sb.Append("========end of problem========\r\n\r\n"); } return(sb.ToString()); }
/// <summary> /// Returns the bounds of line that the pointer is positioned within in client-based coordinates. /// </summary> /// <param name="pointer"></param> /// <returns></returns> protected Rectangle GetLineClientRectangle(MarkupPointer pointer) { //getting the line associated with a pointer is a little complicated because the //ILineInfo for the pointer position only returns information based on the font //exactly at that position. It does not take the max font height of the line into //account, so we need to that manually. To do this, we get the LineInfo at each //point in the line where the line height may change by moving a markup pointer //in to each element declared on the line. IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document; //position a display pointer on the same line as the markup pointer IDisplayPointerRaw displayPointer; displayServices.CreateDisplayPointer(out displayPointer); DisplayServices.TraceMoveToMarkupPointer(displayPointer, pointer); //position a markup pointer at the end of the line MarkupPointer pLineEnd = pointer.Clone(); displayPointer.MoveUnit(_DISPLAY_MOVEUNIT.DISPLAY_MOVEUNIT_CurrentLineEnd, 0); displayPointer.PositionMarkupPointer(pLineEnd.PointerRaw); //position a markup pointer at the start of the line MarkupPointer pLineStart = pointer.Clone(); displayPointer.MoveUnit(_DISPLAY_MOVEUNIT.DISPLAY_MOVEUNIT_CurrentLineStart, 0); displayPointer.PositionMarkupPointer(pLineStart.PointerRaw); //calculate the maximum rectangle taken up by any text on this line by walking //the lineStart pointer to the lineEnd pointer and calculating a max rectangle //at each step. Rectangle lineRect = GetLineRect(HTMLElement, displayPointer); pLineStart.Right(true); while (pLineStart.IsLeftOfOrEqualTo(pLineEnd)) { Rectangle dpLineRect; try { displayPointer.MoveToMarkupPointer(pLineStart.PointerRaw, null); dpLineRect = GetLineRect(HTMLElement, displayPointer); } catch (COMException e) { if (e.ErrorCode == IE_CTL_E.INVALIDLINE) { // http://msdn.microsoft.com/en-us/library/aa752674(VS.85).aspx // IDisplayPointer::MoveToMarkupPointer will return an error (CTL_E_INVALIDLINE), // if the markup pointer is in a line whose nearest layout element *is not a flow layout element*. dpLineRect = GetLineRect(pLineStart.CurrentScope); // We also want to skip past the entire current scope... pLineStart.MoveAdjacentToElement(pLineStart.CurrentScope, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd); } else { Trace.Fail("Exception thrown in GetLineClientRectangle: " + e.ToString()); throw; } } lineRect.Y = Math.Min(dpLineRect.Y, lineRect.Y); if (lineRect.Bottom < dpLineRect.Bottom) { lineRect.Height += dpLineRect.Bottom - lineRect.Bottom; } pLineStart.Right(true); } //return the line rectangle return(lineRect); }
/// <summary> /// Navigates the editor's caret to the next editable region. /// </summary> /// <param name="direction"></param> private bool MoveCaretToNextRegion(MOVE_DIRECTION direction) { IHTMLElement nextRegion; _ELEMENT_ADJACENCY nextRegionAdjacency; bool preserveXLocation; if (direction == MOVE_DIRECTION.UP || direction == MOVE_DIRECTION.LEFT) { nextRegion = PreviousEditableRegion; nextRegionAdjacency = _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd; preserveXLocation = direction == MOVE_DIRECTION.UP; } else if (direction == MOVE_DIRECTION.DOWN || direction == MOVE_DIRECTION.RIGHT) { nextRegion = NextEditableRegion; nextRegionAdjacency = _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin; preserveXLocation = direction == MOVE_DIRECTION.DOWN; if (nextRegion == null) { return(false); } MarkupPointer selectRegion = EditorContext.MarkupServices.CreateMarkupPointer(nextRegion, nextRegionAdjacency); MarkupContext mc = selectRegion.Right(false); if (mc.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope && mc.Element is IHTMLElement3 && SmartContentSelection.SelectIfSmartContentElement(EditorContext, mc.Element) != null) { return(true); } } else { throw new ArgumentException("Unsupported move direction detected: " + direction); } IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document; IDisplayPointerRaw displayPointer; displayServices.CreateDisplayPointer(out displayPointer); IHTMLCaretRaw caret = GetCaret(); caret.MoveDisplayPointerToCaret(displayPointer); ILineInfo lineInfo; displayPointer.GetLineInfo(out lineInfo); if (nextRegion != null) { MarkupPointer mp = EditorContext.MarkupServices.CreateMarkupPointer(nextRegion, nextRegionAdjacency); DisplayServices.TraceMoveToMarkupPointer(displayPointer, mp); try { caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME); if (preserveXLocation) { POINT caretLocation; caret.GetLocation(out caretLocation, true); caretLocation.x = lineInfo.x; uint hitTestResults; displayPointer.MoveToPoint(caretLocation, _COORD_SYSTEM.COORD_SYSTEM_GLOBAL, nextRegion, 0, out hitTestResults); caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME); } //BEP: using this line causes scrolling (nextRegion as IHTMLElement2).focus(); (nextRegion as IHTMLElement3).setActive(); return(true); } catch (Exception e) { Debug.Fail("Unexpected exception in MoveCaretToNextRegion: " + e.ToString()); } caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME); } return(false); }
/// <summary> /// Returns the display name for this key. Shorthand for <see cref="DisplayServices.GetKeySignatureName(sbyte, bool)"/>. /// </summary> /// <returns>The display name for this key.</returns> public string GetDisplayName() { return(DisplayServices.GetKeySignatureName(key, minor)); }
/// <summary> /// Returns the display name of the note. Shorthand for <see cref="DisplayServices.GetNoteName(byte, bool)"/>. /// </summary> /// <param name="sharp">Indicates whether to display the note as a sharp or flat if necessary.</param> /// <returns>The display name of the note.</returns> public string GetNoteName(bool sharp = true) { return(DisplayServices.GetNoteName(noteNumber, sharp)); }