1 //------------------------------------------------------------------------------ 2 // <copyright file="PropertyOverridesTypeEditor.cs" company="Microsoft"> 3 // Copyright (c) Microsoft Corporation. All rights reserved. 4 // </copyright> 5 //------------------------------------------------------------------------------ 6 7 namespace System.Web.UI.Design.MobileControls 8 { 9 using System; 10 using System.ComponentModel; 11 using System.ComponentModel.Design; 12 using System.Diagnostics; 13 using System.Drawing.Design; 14 using System.Windows.Forms.Design; 15 16 using DialogResult = System.Windows.Forms.DialogResult; 17 18 [ 19 System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, 20 Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode) 21 ] 22 [Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")] 23 internal class PropertyOverridesTypeEditor : UITypeEditor 24 { 25 private static readonly String _propertyOverridesDescription = "PropertyOverrides"; 26 EditValue(ITypeDescriptorContext context, IServiceProvider provider, Object value)27 public override Object EditValue(ITypeDescriptorContext context, IServiceProvider provider, Object value) 28 { 29 Debug.Assert(context.Instance is Control, "Expected control"); 30 Control ctrl = (Control) context.Instance; 31 32 IServiceProvider serviceProvider; 33 ISite site = ctrl.Site; 34 if (site == null && ctrl.Page != null) 35 { 36 site = ctrl.Page.Site; 37 } 38 if (site != null) 39 { 40 serviceProvider = site; 41 } 42 else 43 { 44 serviceProvider = provider; 45 } 46 Debug.Assert(serviceProvider != null, 47 "Failed to get the serviceProvider"); 48 49 IComponentChangeService changeService = 50 (IComponentChangeService) serviceProvider.GetService(typeof(IComponentChangeService)); 51 52 IDesignerHost designerHost = 53 (IDesignerHost) serviceProvider.GetService(typeof(IDesignerHost)); 54 Debug.Assert(designerHost != null, 55 "Must always have access to IDesignerHost service"); 56 57 IDeviceSpecificDesigner dsDesigner = 58 designerHost.GetDesigner(ctrl) as IDeviceSpecificDesigner; 59 Debug.Assert(dsDesigner != null, 60 "Expected component designer to implement IDeviceSpecificDesigner"); 61 62 IMobileWebFormServices wfServices = 63 (IMobileWebFormServices)serviceProvider.GetService(typeof(IMobileWebFormServices)); 64 65 DialogResult result = DialogResult.Cancel; 66 67 DesignerTransaction transaction = designerHost.CreateTransaction(_propertyOverridesDescription); 68 try 69 { 70 if (changeService != null) 71 { 72 try 73 { 74 changeService.OnComponentChanging(ctrl, null); 75 } 76 catch (CheckoutException ce) 77 { 78 if (ce == CheckoutException.Canceled) 79 { 80 return value; 81 } 82 throw; 83 } 84 } 85 86 try 87 { 88 PropertyOverridesDialog dialog = new PropertyOverridesDialog( 89 dsDesigner, 90 MobileControlDesigner.MergingContextProperties 91 ); 92 IWindowsFormsEditorService edSvc = 93 (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService)); 94 result = edSvc.ShowDialog(dialog); 95 } 96 catch(InvalidChoiceException e) 97 { 98 Debug.Fail(e.ToString()); 99 } 100 finally 101 { 102 if (changeService != null && result != DialogResult.Cancel) 103 { 104 changeService.OnComponentChanged(ctrl, null, null, null); 105 } 106 } 107 } 108 finally 109 { 110 if (transaction != null) 111 { 112 if (result == DialogResult.OK) 113 { 114 transaction.Commit(); 115 } 116 else 117 { 118 transaction.Cancel(); 119 } 120 } 121 } 122 123 return value; 124 } 125 GetEditStyle(ITypeDescriptorContext context)126 public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) 127 { 128 return UITypeEditorEditStyle.Modal; 129 } 130 } 131 } 132 133