3

I am writing an addin into Sql Server Management Studio, using the Visual Studio Extensibilty APIs. I have had some success overlaying a control onto the text surface (I'm attempting to emulate the CodeRush/Refactor action list, similar to the intellisense combo), however I can only locate it's coordinate space based the following property:

get
{
    var point = TextDocument.Selection.TopPoint;
    return new Cursor( point.DisplayColumn, point.Line );
}

This code does allow me to then convert cols/rows into pixels, however I can not find a way to offset the cols/rows when the text editor has been scrolled either vertically or horizontally. This causes the listbox to disappear below the visible screen space.

What I am looking for is a method of getting the screen coordinates from the current col/row pair, so that I can place the listbox next to the cursor, regardless of the scrolled position.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Ben Laan
  • 2,607
  • 3
  • 29
  • 30
  • I'm not sure which APIs are available, but are you sure it's not possible to implement `IVsTextMarker` and `IVsTextMarkerClient` to create a menu associated with a piece of code (this is how the refactoring helpers work)? – Sam Harwell Oct 24 '09 at 22:09
  • @280Z28 - Those interfaces look promising. I would like to skip DTE altogether, and this seems like it may work.. The catch may be that I am actually doing this for SSMS.. Thanks – Ben Laan Oct 24 '09 at 22:11
  • Have you thought about using DXCore (the library behind coderush). Its free from Dev Express – Preet Sangha Oct 24 '09 at 22:28
  • @Preet - I have written some DXCore plugins for VS, but this one is for SSMS. I don't know if I can integrate DXCOre into SSMS. – Ben Laan Oct 24 '09 at 22:52

1 Answers1

1

The TextDocument.Selection property, of type TextSelection, has a TextPane property - see here for more info. It doesn't explicitly say so, but the TextPane is the part of the screen that is visible. Further, the StartPoint property for a TextPane provides the 'offset' of the scrolled text.

I was therefore able to determine the offset cursor position by subtracting the TextPane.StartPoint from the Selection's StartPoint:

get
{
    var start = TextDocument.Selection.TextPane.StartPoint;
    var top = TextDocument.Selection.TopPoint;
    return new Cursor( 
        top.DisplayColumn - start.DisplayColumn + 1 , 
        top.Line - start.Line + 1 
    );
}
Ben Laan
  • 2,607
  • 3
  • 29
  • 30