/* LEGAL NOTICE This document supports a preliminary release of a software product that may be changed substantially prior to final commercial release. This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet Web site references, is subject to change without notice. The entire risk of the use or the results from the use of this document remains with the user. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. © 2006 Microsoft Corporation. All rights reserved. Microsoft and Microsoft Infopath are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. */ [Guid("08E623D3-BEAD-4bd3-8401-EFF51FD754CD")] [ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDual)] public class ComplexUserControl : UserControl, IObjectSafety, IComplexCOMControl, InfoPathControl { #region Members private Label label1; private TextBox streetTbx; private TextBox cityTbx; private Label label2; private TextBox stateTbx; private Label label3; private TextBox zipCodeTbx; private Label label4; #endregion // Constants for DISPIDs of the Value and Enabled properties. internal const int DISPID_VALUE = 0; internal const int DISPID_ENABLED = 1; // Constants for implementation of the IObjectSafety interface. internal const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001; internal const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002; internal const int S_OK = 0; public ComplexUserControl() { this.InitializeComponent(); // Register for UI change events this.streetTbx.TextChanged += this.HandleChangesInUI; this.cityTbx.TextChanged += this.HandleChangesInUI; this.stateTbx.TextChanged += this.HandleChangesInUI; this.zipCodeTbx.TextChanged += this.HandleChangesInUI; } private void HandleChangesInUI(object sender, EventArgs e) { TextBox senderTbx = (TextBox)sender; if (senderTbx == this.streetTbx) this.ChangeDOM("/fields/address/street", this.streetTbx.Text); else if (senderTbx == this.cityTbx) this.ChangeDOM("/fields/address/city", this.cityTbx.Text); else if (senderTbx == this.stateTbx) this.ChangeDOM("/fields/address/state", this.stateTbx.Text); else if (senderTbx == this.zipCodeTbx) this.ChangeDOM("/fields/address/zipCode", this.zipCodeTbx.Text); } private void ChangeDOM(string xPath, string value) { if (domNode != null) { IXMLDOMNode singleNode = domNode.selectSingleNode(xPath); if (singleNode.text != value) { singleNode.text = value; } } } private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.streetTbx = new System.Windows.Forms.TextBox(); this.cityTbx = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.stateTbx = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.zipCodeTbx = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(3, 18); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(38, 13); this.label1.TabIndex = 0; this.label1.Text = "Street:"; // // streetTbx // this.streetTbx.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.streetTbx.Location = new System.Drawing.Point(89, 15); this.streetTbx.Name = "streetTbx"; this.streetTbx.Size = new System.Drawing.Size(194, 20); this.streetTbx.TabIndex = 1; // // cityTbx // this.cityTbx.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.cityTbx.Location = new System.Drawing.Point(89, 59); this.cityTbx.Name = "cityTbx"; this.cityTbx.Size = new System.Drawing.Size(194, 20); this.cityTbx.TabIndex = 3; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(3, 62); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(27, 13); this.label2.TabIndex = 2; this.label2.Text = "City:"; // // stateTbx // this.stateTbx.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.stateTbx.Location = new System.Drawing.Point(89, 103); this.stateTbx.Name = "stateTbx"; this.stateTbx.Size = new System.Drawing.Size(194, 20); this.stateTbx.TabIndex = 5; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(3, 106); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(35, 13); this.label3.TabIndex = 4; this.label3.Text = "State:"; // // zipCodeTbx // this.zipCodeTbx.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.zipCodeTbx.Location = new System.Drawing.Point(89, 147); this.zipCodeTbx.Name = "zipCodeTbx"; this.zipCodeTbx.Size = new System.Drawing.Size(194, 20); this.zipCodeTbx.TabIndex = 7; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(3, 150); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(50, 13); this.label4.TabIndex = 6; this.label4.Text = "ZipCode:"; // // ComplexUserControl // this.BackColor = System.Drawing.SystemColors.Control; this.Controls.Add(this.streetTbx); this.Controls.Add(this.label1); this.Controls.Add(this.cityTbx); this.Controls.Add(this.label2); this.Controls.Add(this.stateTbx); this.Controls.Add(this.label3); this.Controls.Add(this.zipCodeTbx); this.Controls.Add(this.label4); this.Name = "ComplexUserControl"; this.Size = new System.Drawing.Size(290, 191); this.ResumeLayout(false); this.PerformLayout(); } private IXMLDOMNode domNode = null; public IXMLDOMNode Value { get { return domNode; } set { if (domNode != null) { ChangeUI(streetTbx, domNode.selectSingleNode("/fields/address/street").text); ChangeUI(cityTbx, domNode.selectSingleNode("/fields/address/city").text); ChangeUI(stateTbx, domNode.selectSingleNode("/fields/address/state").text); ChangeUI(zipCodeTbx, domNode.selectSingleNode("/fields/address/zipCode").text); } } } private void ChangeUI(TextBox tbx, string text) { if (tbx.Text != text) { tbx.Text = text; } } #region IObjectSafety Members int IObjectSafety.GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions) { pdwSupportedOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; pdwEnabledOptions = INTERFACESAFE_FOR_UNTRUSTED_CALLER | INTERFACESAFE_FOR_UNTRUSTED_DATA; return S_OK; // return S_OK } int IObjectSafety.SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions) { return S_OK; } #endregion #region InfoPathControl Members public void Enable(bool vfEnabled) { } private XDocumentClass xDocument = null; public void Init(InfoPathControlSite pControlSite) { this.domNode = pControlSite.Node; this.xDocument = (XDocumentClass)pControlSite.XDocument; this.RestoreState(); } public void SaveState() { if (this.xDocument != null) { this.xDocument.SetNamedNodeProperty(this.domNode, "ActiveControl", this.ActiveControl.Name); } } public void Uninit() { } #endregion private void RestoreState() { if (this.xDocument != null) { Control activeControl = this.Controls[this.xDocument.GetNamedNodeProperty(domNode, "ActiveControl", this.Controls[0].Name)]; if (activeControl != null) { activeControl.Focus(); } } } } [InterfaceType(ComInterfaceType.InterfaceIsDual)] public interface IComplexCOMControl { [DispId(ComplexUserControl.DISPID_VALUE)] IXMLDOMNode Value { get; set; } [DispId(ComplexUserControl.DISPID_ENABLED)] bool Enabled { get; set; } } [ComImport] [Guid("CB5BDC81-93C1-11CF-8F20-00805F2CD064")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] interface IObjectSafety { [PreserveSig] int GetInterfaceSafetyOptions(ref Guid riid, out int pdwSupportedOptions, out int pdwEnabledOptions); [PreserveSig] int SetInterfaceSafetyOptions(ref Guid riid, int dwOptionSetMask, int dwEnabledOptions); }