I'm creating a VsCodeWindow to edit TSQL through the following steps:
1) Create and site a VsTextBuffer;
2) Set the buffer's language service to TSQL-80 ("F07520AD-1760-4286-9A3D-858D343D9FC1");
3) Create a VsCodeWindow;
4) Set the code window's buffer to the one created above; and
5) Show the code window.
The problem is that the resulting window does not accept CRs, tabs, and backspaces from the keyboard (I can paste these characters into the window). I see this behavior with the TSQL-80, TSQL-90, SQLScript, and PL/SQL language services, but not VB, XML & CS.
Can anybody shed any light
TIA,
John

TSQL language service
mian mahboob
Yes, I have solved these problems (I have reason to believe there may be more awaiting us, though. See my thread on XML documents in data grid view).
What you need to do is get a reference to your window's IVsWindowFrame implementation and call SetGuidProperty, setting the VSFPROPID_InheritKeyBindings property. Pass the GUID of the TSQL editor factory for the value of the property.You can get your IVsWindowFrame from ToolWindowPane.Frame in the MPF, the value returned from CreateToolWindow, or the value returned from CreateDocumentWindow.
Hope that helps,
John
inc3pt4
just saw your quite old posting. I ran into same problems.
I want to show the VSCodeWindow in an ordinary UserControl (for example ontop of a panel). This usercontrol will be openend on a registered custom Editor instance inside VS.
The problem is, there are several keyboard problems (backspace, arrows...), the position and size is not modifyable etc.
Do you have ideas to solve my problems
Ralf
CodeButcher
A change in my code allowed me to call SetGuidProperty on the IVsWindowFrame returned from CreateToolWindow.
So cool! You can create this fully-functional code window on your control.
John
Ingman
Actually, it's funny that you reply; I just found a post of yours on another board (actually I think it was usenet) on this topic this AM.
So since I have nothing else on my toolwindow yet, I tried just delegating all calls to TranslateAccelerator and the IOleCommandTarget methods to my code window, with no luck.
In your example above, vsCodePane refers to your VsCodeWindow's IVsWindowPane implementation, right
John
oufan222
Hi John,
I'm guessing that the VsCodeWindow is actually hosted as a child control on your main editor window, as I ran into the same exact problem the first time I tried this :-)
Normally, the VsCodeWindow is hosted directly in the IVsWindowFrame. But when you parent it as a child control in your own editor or toolwindow, you need to ensure that you foward the some of the IVsWindowPane and IOleCommandTarget calls to the VsCodeWindow when it actually has the input focus. Some of the keyboard commands like the return and delete are actually processed by the code window's IOleCommandTarget::Exec. You should also implement IVsWindowPane.TranslateAccelerator to enable keyboard navigation on the managed form. For example:
public int TranslateAccelerator(MSG[] lpmsg)
{
// if the codewindow control has the focus, then defer to it's implementation
if (CodePaneHasFocus())
return vsCodePane.TranslateAccelerator(lpmsg);
switch (lpmsg[0].message)
{
case Win32.WM_KEYDOWN:
case Win32.WM_SYSKEYDOWN:
case Win32.WM_CHAR:
case Win32.WM_SYSCHAR:
{
Message msg = new Message();
msg.HWnd = lpmsg[0].hwnd;
msg.Msg = (int)lpmsg[0].message;
msg.LParam = lpmsg[0].lParam;
msg.WParam = lpmsg[0].wParam;
Control ctrl = Control.FromChildHandle(msg.HWnd);
if (ctrl != null && ctrl.PreProcessMessage(ref msg))
return VSConstants.S_OK;
}
break;
default:
break;
}
return VSConstants.S_FALSE;
}
public int QueryStatus(ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds,
IntPtr pCmdText)
{
if ((prgCmds == null))
return VSConstants.E_INVALIDARG;
if (CodePaneHasFocus())
{
IOleCommandTarget cmdTarget = vsCodePane as IOleCommandTarget;
if (cmdTarget != null)
return cmdTarget.QueryStatus(ref pguidCmdGroup, cCmds,
prgCmds, pCmdText);
}
return (int)Microsoft.VisualStudio.OLE.Interop.Constants.OLECMDERR_E_NOTSUPPORTED;
}
public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject)
{
if (guidService == typeof(SVsCodeWindow).GUID && riid ==
typeof(IVsCodeWindow).GUID)
{
if (vsCodePane != null)
{
ppvObject = Marshal.GetIUnknownForObject(vsCodePane);
return VSConstants.S_OK;
}
}
return vsServiceProvider.QueryService(ref guidService, ref riid, out ppvObject);
}
Additionally you may also need to implement IOleServiceProvider on your editor object, and pass back the VsCodeWindow's IUnknown when you are asked for the SVsCodeWindow service. For example:
public int QueryService(ref Guid guidService, ref Guid riid, out IntPtr ppvObject)
{
if (guidService == typeof(SVsCodeWindow).GUID && riid ==
typeof(IVsCodeWindow).GUID)
{
if (vsCodePane != null)
{
ppvObject = Marshal.GetIUnknownForObject(vsCodePane);
return VSConstants.S_OK;
}
}
return vsServiceProvider.QueryService(ref guidService, ref riid, out ppvObject);
}
Sincerely,
Ed Dore [MSFT]