I found a sample project called 'MPEdit' that demonstrates how to embed an
IVsCodeWindow into a custom editor...but I need to make mine read-only. I
want to display a read-only version of xml data using the code window. The
implementation in the sample code window allows keyboard entry to modify the
code string but I want to disable all keypresses and stop modification of the
buffer.
Does anyone know how to do this?
Here's is the core of the sample, where the code window and text buffer is
created:
public partial class CodeWindow : UserControl
{
private MPEditor _editor;
private IVsCodeWindow _vsCodeWindow;
private IntPtr _hWndCodeWindow = IntPtr.Zero;
private uint cookie = 0;
/*.....*/
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
if (_editor != null)
CreateVsCodeWindow();
}
private void CreateVsCodeWindow()
{
int hr = VSConstants.S_OK;
Guid clsidVsCodeWindow = typeof(VsCodeWindowClass).GUID;
Guid iidVsCodeWindow = typeof(IVsCodeWindow).GUID;
Guid clsidVsTextBuffer = typeof(VsTextBufferClass).GUID;
Guid iidVsTextLines = typeof(IVsTextLines).GUID;
// create/site a VsTextBuffer object
IVsTextBuffer vsTextBuffer =
(IVsTextBuffer)MPEdit.Instance.CreateInstance(ref clsidVsTextBuffer, ref
iidVsTextLines, typeof(IVsTextBuffer));
IObjectWithSite ows = (IObjectWithSite)vsTextBuffer;
ows.SetSite(_editor);
string strXml = "<Xml><SubXml/></Xml>";
hr = vsTextBuffer.InitializeContent(strXml, strXml.Length);
hr = vsTextBuffer.SetLanguageServiceID(ref
GuidList.guidXmlLangSvc);
// create/initialize/site a VsCodeWindow object
_vsCodeWindow =
(IVsCodeWindow)MPEdit.Instance.CreateInstance(ref clsidVsCodeWindow, ref
iidVsCodeWindow, typeof(IVsCodeWindow));
INITVIEW[] initView = new INITVIEW[1];
initView[0].fSelectionMargin = 0;
initView[0].fWidgetMargin = 0;
initView[0].fVirtualSpace = 0;
initView[0].fDragDropMove = 1;
initView[0].fVirtualSpace = 0;
IVsCodeWindowEx vsCodeWindowEx = (IVsCodeWindowEx)_vsCodeWindow;
hr =
vsCodeWindowEx.Initialize((uint)_codewindowbehaviorflags.CWB_DISABLEDROPDOWNBAR | (uint)_codewindowbehaviorflags.CWB_DISABLESPLITTER,
0, null, null,
(uint)TextViewInitFlags.VIF_SET_WIDGET_MARGIN |
(uint)TextViewInitFlags.VIF_SET_SELECTION_MARGIN |
(uint)TextViewInitFlags.VIF_SET_VIRTUAL_SPACE |
(uint)TextViewInitFlags.VIF_SET_DRAGDROPMOVE |
(uint)TextViewInitFlags2.VIF_SUPPRESS_STATUS_BAR_UPDATE |
(uint)TextViewInitFlags2.VIF_SUPPRESSBORDER |
(uint)TextViewInitFlags2.VIF_SUPPRESSTRACKCHANGES |
(uint)TextViewInitFlags2.VIF_SUPPRESSTRACKGOBACK,
initView);
hr = _vsCodeWindow.SetBuffer((IVsTextLines)vsTextBuffer);
IVsWindowPane vsWindowPane = (IVsWindowPane)_vsCodeWindow;
hr = vsWindowPane.SetSite(_editor);
hr = vsWindowPane.CreatePaneWindow(this.Handle, 0, 0,
this.Parent.Size.Width, this.Parent.Size.Height, out _hWndCodeWindow);
IVsTextView vsTextView;
hr = _vsCodeWindow.GetPrimaryView(out vsTextView);
// sink IVsTextViewEvents, so we can determine when a
VsCodeWindow object actually has the focus.
IConnectionPointContainer connptCntr =
(IConnectionPointContainer)vsTextView;
Guid riid = typeof(IVsTextViewEvents).GUID;
IConnectionPoint cp;
connptCntr.FindConnectionPoint(ref riid, out cp);
cp.Advise(_editor, out cookie);
}
private void CodeWindow_SizeChanged(object sender, EventArgs e)
{
Win32.SetWindowPos(_hWndCodeWindow, IntPtr.Zero,
0,0,
this.Width,
this.Height, 0);
}
}
Walter Wang [MSFT] - 30 Aug 2007 08:23 GMT
Hi Joe,
Welcome to MSDN Managed Newsgroup!
First, please help me confirm if you're referring to the sample project
that posted by Ed Dore here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=739926&SiteID=1
I'll do some research and get back to you shortly. Thanks for your patience.
Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Joe Burke - 30 Aug 2007 16:54 GMT
Hi Walter,
Thanks for the reply. I'm having trouble with the link that you supplied,
I can't seem to get to any of the forums at forums.microsoft.com. Sorry if
it's my fault. But I believe that it is the same sample that you are
referring to. Ed mentioned it to me, that's how I found it. I'll send the
project .zip to you in email just to confirm.
Joe
> Hi Joe,
>
[quoted text clipped - 35 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
Walter Wang [MSFT] - 04 Sep 2007 08:50 GMT
Hi Joe,
Thanks for your waiting.
To make the code window readonly, we can call IVsTextBuffer.SetStateFlags
and set a flag to mark the text buffer readonly. For the example in MPEdit,
we can do this in the UserControl's CreateVsCodeWindow():
string strSQL = "select * from sometable";
hr = vsTextBuffer.InitializeContent(strSQL, strSQL.Length);
// add this line:
vsTextBuffer.SetStateFlags((uint)BUFFERSTATEFLAGS.BSF_USER_READONLY);
This BUFFERSTATEFLAGS enum is from namespace
Microsoft.VisualStudio.TextManager.Interop.
Hope this helps. Please feel free to let me know if there's anything else I
can help. Thanks.
Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Joe Burke - 07 Sep 2007 04:24 GMT
That works perfectly, it's what I was looking for.
Thanks Walter,
Joe
> Hi Joe,
>
[quoted text clipped - 26 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.