1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
|
//------------------------------------------------------------------------------
// <copyright file="ImageDesigner.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.Design.MobileControls
{
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.MobileControls;
using System.Web.UI.MobileControls.Adapters;
using System.Web.UI.Design.MobileControls.Adapters;
using System.Web.UI.Design.MobileControls.Converters;
using System.Web.UI.Design.MobileControls.Util;
using Image = System.Web.UI.MobileControls.Image;
[
System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand,
Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)
]
[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.")]
internal class ImageDesigner : MobileControlDesigner
{
private Image _image;
private TemporaryBitmapFile _tempBmpFile;
private Uri _cachedWbmpUri;
private String _baseUrl = String.Empty;
private String BaseUrl
{
get
{
if (_baseUrl != null && _baseUrl.Length == 0)
{
IWebFormsDocumentService wfServices =
(IWebFormsDocumentService)GetService(typeof(IWebFormsDocumentService));
Debug.Assert(wfServices != null);
_baseUrl = wfServices.DocumentUrl;
}
return _baseUrl;
}
}
/// <summary>
/// <para>
/// Initializes the designer.
/// </para>
/// </summary>
/// <param name='component'>
/// The control element being designed.
/// </param>
/// <remarks>
/// <para>
/// This is called by the designer host to establish the component being
/// designed.
/// </para>
/// </remarks>
/// <seealso cref='System.ComponentModel.Design.IDesigner'/>
public override void Initialize(IComponent component)
{
Debug.Assert(component is System.Web.UI.MobileControls.Image,
"ImageDesigner.Initialize - Invalid Image Control");
_image = (System.Web.UI.MobileControls.Image) component;
base.Initialize(component);
}
/// <summary>
/// <para>
/// Disposes of the resources (other than memory) used by the
/// <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/>.
/// </para>
/// </summary>
/// <remarks>
/// <para>
/// Call <see langword='Dispose'/> when
/// you are finished using the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/>. The <see langword='Dispose'/> method leaves the <see cref='System.Web.UI.Design.WebControls.DataListDesigner'/> in an unusable state. After
/// calling <see langword='Dispose'/>, you must release all
/// references to the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/> so the memory it was occupying
/// can be reclaimed by garbage collection.
/// </para>
/// <note type="note">
/// Always call <see langword='Dispose'/> before you release your last reference to
/// the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/>. Otherwise, the resources
/// the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/> is using will not be freed
/// until garbage collection calls the <see cref='System.Web.UI.Design.MobileControls.ListDesigner'/> object's
/// destructor.
/// </note>
/// </remarks>
/// <seealso cref='System.ComponentModel.Design.IDesigner'/>
protected override void Dispose(bool disposing)
{
if (disposing && _tempBmpFile != null)
{
_tempBmpFile.Dispose();
_cachedWbmpUri = null;
_tempBmpFile = null;
}
base.Dispose(disposing);
}
private String GetConvertedImageURI(String imageUriString)
{
Uri baseUri = new Uri(BaseUrl);
Uri imageUri = new Uri(baseUri, imageUriString);
String extension = Path.GetExtension(imageUriString);
if(extension.Equals(".wbmp"))
{
if(_tempBmpFile != null)
{
if(_cachedWbmpUri != null
&& _cachedWbmpUri.Equals(imageUri))
{
return _tempBmpFile.Url;
}
else
{
_tempBmpFile.Dispose();
_tempBmpFile = null;
_cachedWbmpUri = null;
}
}
Byte[] buffer = FileReader.Read(imageUri);
if(buffer == null)
{
// Could not read image from URI, return original URI to
// Trident and let it render as a broken image.
goto ConversionError;
}
Bitmap bitmap = WbmpConverter.Convert(buffer);
if(bitmap == null)
{
// .wbmp appears to be corrupt, return original URI to
// Trident and let it render as a broken image.
goto ConversionError;
}
_tempBmpFile = new TemporaryBitmapFile(bitmap);
imageUriString = _tempBmpFile.Url;
_cachedWbmpUri = imageUri;
}
ConversionError:
return imageUriString;
}
/// <summary>
/// <para>
/// Gets the HTML to be used for the design time representation of the control runtime.
/// </para>
/// </summary>
/// <returns>
/// <para>
/// The design time HTML.
/// </para>
/// </returns>
protected override String GetDesignTimeNormalHtml()
{
String tempUrl = String.Empty;
bool replaceUrl = (_image.ImageUrl.Length > 0);
DesignerTextWriter writer = new DesignerTextWriter();
tempUrl = _image.ImageUrl;
_image.ImageUrl = GetConvertedImageURI(_image.ImageUrl);
_image.Adapter.Render(writer);
_image.ImageUrl = tempUrl;
return writer.ToString();
}
public override void OnComponentChanged(Object sender, ComponentChangedEventArgs e)
{
if ((e.Member != null) && e.Member.Name.Equals("NavigateUrl"))
{
_image.NavigateUrl = NavigateUrlConverter.GetUrl(
_image,
e.NewValue.ToString(),
e.OldValue.ToString()
);
e = new ComponentChangedEventArgs(e.Component, e.Member, e.OldValue, _image.NavigateUrl);
}
base.OnComponentChanged(sender, e);
}
}
}
|