Пример #1
0
        /// <devdoc>
        /// Retrieves the collection of CSS style attributes represented by this style.
        /// </devdoc>
        public CssStyleCollection GetStyleAttributes(IUrlResolutionService urlResolver)
        {
            CssStyleCollection attributes = new CssStyleCollection();

            FillStyleAttributes(attributes, urlResolver);
            return(attributes);
        }
Пример #2
0
        public static void ucMultiSelection_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            string resultFileName = Path.GetRandomFileName() + "_" + e.UploadedFile.FileName;
            string resultFileUrl  = UploadDirectory + resultFileName;
            //Custom host show file
            string hostFileUrl    = LocalHost + resultFileName;
            string resultFilePath = HttpContext.Current.Request.MapPath(resultFileUrl);

            e.UploadedFile.SaveAs(resultFilePath);

            //UploadingUtils.RemoveFileWithDelay(resultFileName, resultFilePath, 5);

            IUrlResolutionService urlResolver = sender as IUrlResolutionService;

            if (urlResolver != null)
            {
                string url = urlResolver.ResolveClientUrl(hostFileUrl);
                e.CallbackData = GetCallbackData(e.UploadedFile, url);
            }
            if (System.Web.HttpContext.Current.Session["URL"] == null)
            {
                System.Web.HttpContext.Current.Session["URL"] = resultFilePath;
            }
            else
            {
                System.Web.HttpContext.Current.Session["URL"] += '|' + resultFilePath;
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         IPropertyValueUIService service = (IPropertyValueUIService)this.GetService(typeof(IPropertyValueUIService));
         if (service != null)
         {
             service.RemovePropertyValueUIHandler(new PropertyValueUIHandler(this.OnGetUIValueItem));
         }
         IServiceContainer container = (IServiceContainer)this.GetService(typeof(IServiceContainer));
         if (container != null)
         {
             if (this._urlResolutionService != null)
             {
                 container.RemoveService(typeof(IUrlResolutionService));
             }
             container.RemoveService(typeof(IImplicitResourceProvider));
             if (this._designerActionService != null)
             {
                 this._designerActionService.Dispose();
             }
             this._designerActionUIService.Dispose();
         }
         this._urlResolutionService = null;
         this._component            = null;
     }
 }
Пример #4
0
        public CssStyleCollection GetStyleAttributes(IUrlResolutionService resolver)
        {
            CssStyleCollection col = new CssStyleCollection();

            FillStyleAttributes(col, resolver);
            return(col);
        }
Пример #5
0
            public static void UploadImage(object sender, FileUploadCompleteEventArgs e)
            {
                if (e.UploadedFile.IsValid)
                {
                    string fileName = e.UploadedFile.FileName;
                    if (fileName.Contains('_'))
                    {
                        fileName = fileName.Replace('_', '-');
                    }
                    string imageNameWithGuid = (Guid.NewGuid()).ToString() + "_" + fileName;
                    string resultFilePath    = UploadImagePath + imageNameWithGuid;
                    using (Image original = Image.FromStream(e.UploadedFile.FileContent))
                        using (Image thumbnail = PhotoUtils.Inscribe(original, 100))
                        {
                            PhotoUtils.SaveToJpeg(thumbnail, resultFilePath);
                        }
                    IUrlResolutionService urlResolver = sender as IUrlResolutionService;
                    if (urlResolver != null)
                    {
                        // e.CallbackData = e.UploadedFile.FileName;
                        e.CallbackData = imageNameWithGuid;
                    }

                    UploadedImageFileName = imageNameWithGuid;
                }
            }
        public virtual void Initialize(IComponent component)
        {
            ControlDesigner.VerifyInitializeArgument(component, typeof(TemplateControl));
            this._component = component;
            IServiceContainer container = (IServiceContainer)this.GetService(typeof(IServiceContainer));

            if (container != null)
            {
                this._urlResolutionService = this.CreateUrlResolutionService();
                if (this._urlResolutionService != null)
                {
                    container.AddService(typeof(IUrlResolutionService), this._urlResolutionService);
                }
                this._designerActionService   = this.CreateDesignerActionService(this._component.Site);
                this._designerActionUIService = new DesignerActionUIService(this._component.Site);
                ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService);
                container.AddService(typeof(IImplicitResourceProvider), callback);
            }
            IPropertyValueUIService service = (IPropertyValueUIService)this.GetService(typeof(IPropertyValueUIService));

            if (service != null)
            {
                service.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.OnGetUIValueItem));
            }
        }
Пример #7
0
            void IStyleSheet.RegisterStyle(Style style, IUrlResolutionService urlResolver)
            {
                if (style == null)
                {
                    throw new ArgumentNullException("style");
                }

                if (_styles == null)
                {
                    _styles = new ArrayList();
                }
                else if (style.RegisteredCssClass.Length != 0)
                {
                    // if it's already registered, throw an exception
                    throw new InvalidOperationException(SR.GetString(SR.HtmlHead_StyleAlreadyRegistered));
                }

                if (urlResolver == null)
                {
                    urlResolver = this;
                }

                StyleInfo styleInfo = new StyleInfo();

                styleInfo.style       = style;
                styleInfo.urlResolver = urlResolver;

                int    index = _autoGenCount++;
                string name  = "aspnet_s" + index.ToString(NumberFormatInfo.InvariantInfo);

                style.SetRegisteredCssClass(name);
                _styles.Add(styleInfo);
            }
            void IStyleSheet.CreateStyleRule(Style style, IUrlResolutionService urlResolver, string selector)
            {
                if (style == null)
                {
                    throw new ArgumentNullException("style");
                }
                if (selector.Length == 0)
                {
                    throw new ArgumentNullException("selector");
                }
                if (this._selectorStyles == null)
                {
                    this._selectorStyles = new ArrayList();
                }
                if (urlResolver == null)
                {
                    urlResolver = this;
                }
                SelectorStyleInfo info = new SelectorStyleInfo {
                    selector    = selector,
                    style       = style,
                    urlResolver = urlResolver
                };

                this._selectorStyles.Add(info);
                Page page = this._owner.Page;

                if (page.PartialCachingControlStack != null)
                {
                    foreach (BasePartialCachingControl control in page.PartialCachingControlStack)
                    {
                        control.RegisterStyleInfo(info);
                    }
                }
            }
            void IStyleSheet.RegisterStyle(Style style, IUrlResolutionService urlResolver)
            {
                if (style == null)
                {
                    throw new ArgumentNullException("style");
                }
                if (this._styles == null)
                {
                    this._styles = new ArrayList();
                }
                else if (style.RegisteredCssClass.Length != 0)
                {
                    throw new InvalidOperationException(System.Web.SR.GetString("HtmlHead_StyleAlreadyRegistered"));
                }
                if (urlResolver == null)
                {
                    urlResolver = this;
                }
                StyleInfo info = new StyleInfo {
                    style       = style,
                    urlResolver = urlResolver
                };
                string cssClass = "aspnet_s" + this._autoGenCount++.ToString(NumberFormatInfo.InvariantInfo);

                style.SetRegisteredCssClass(cssClass);
                this._styles.Add(info);
            }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         IPropertyValueUIService service = (IPropertyValueUIService) this.GetService(typeof(IPropertyValueUIService));
         if (service != null)
         {
             service.RemovePropertyValueUIHandler(new PropertyValueUIHandler(this.OnGetUIValueItem));
         }
         IServiceContainer container = (IServiceContainer) this.GetService(typeof(IServiceContainer));
         if (container != null)
         {
             if (this._urlResolutionService != null)
             {
                 container.RemoveService(typeof(IUrlResolutionService));
             }
             container.RemoveService(typeof(IImplicitResourceProvider));
             if (this._designerActionService != null)
             {
                 this._designerActionService.Dispose();
             }
             this._designerActionUIService.Dispose();
         }
         this._urlResolutionService = null;
         this._component = null;
     }
 }
Пример #11
0
 public static void docFileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string resultFilePath = HttpContext.Current.Request.MapPath(DocUploadDirectory + e.UploadedFile.FileName);
         try
         {
             e.UploadedFile.SaveAs(resultFilePath, true); //Code Central Mode - Uncomment This Line
             Session["uploadedFile"] = e.UploadedFile;
             IUrlResolutionService urlResolver = sender as IUrlResolutionService;
             if (urlResolver != null)
             {
                 e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath);
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
     }
     else
     {
         throw new Exception(e.ErrorText);
     }
 }
            protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
            {
                base.FillStyleAttributes(attributes, urlResolver);

                attributes.Add("background-color", "transparent");
                attributes.Add("cursor", "text");
                attributes.Add("width", "13px");
            }
Пример #13
0
        public void CreateStyleRule(Style style, IUrlResolutionService urlResolver, string selection)
        {
            StyleEntry entry = new StyleEntry();

            entry.Style       = style;
            entry.UrlResolver = urlResolver;
            entry.Selection   = selection;
            entries.Add(entry);
        }
Пример #14
0
    protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
    {
        base.FillStyleAttributes(attributes, urlResolver);

        if (!this.MinHeight.IsEmpty)
        {
            attributes.Add("min-height", this.MinHeight.ToString());
        }
    }
 private static string StyleSheetIncludes(this HtmlHelper html, IUrlResolutionService urlResolver, params object[] attributedObjects)
 {
     return(RenderIncludes(
                html,
                typeof(StyleSheetIncludeAttribute),
                urlResolver,
                c_styleSheetInclude,
                attributedObjects));
 }
        protected override void AddDesignTimeCssAttributes(IDictionary styleAttributes)
        {
            Panel component = (Panel)base.Component;

            switch (component.Direction)
            {
            case ContentDirection.LeftToRight:
                styleAttributes["direction"] = "ltr";
                break;

            case ContentDirection.RightToLeft:
                styleAttributes["direction"] = "rtl";
                break;
            }
            string backImageUrl = component.BackImageUrl;

            if (backImageUrl.Trim().Length > 0)
            {
                IUrlResolutionService service = (IUrlResolutionService)this.GetService(typeof(IUrlResolutionService));
                if (service != null)
                {
                    backImageUrl = service.ResolveClientUrl(backImageUrl);
                    styleAttributes["background-image"] = "url(" + backImageUrl + ")";
                }
            }
            switch (component.ScrollBars)
            {
            case ScrollBars.Horizontal:
                styleAttributes["overflow-x"] = "scroll";
                break;

            case ScrollBars.Vertical:
                styleAttributes["overflow-y"] = "scroll";
                break;

            case ScrollBars.Both:
                styleAttributes["overflow"] = "scroll";
                break;

            case ScrollBars.Auto:
                styleAttributes["overflow"] = "auto";
                break;
            }
            HorizontalAlign horizontalAlign = component.HorizontalAlign;

            if (horizontalAlign != HorizontalAlign.NotSet)
            {
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(HorizontalAlign));
                styleAttributes["text-align"] = converter.ConvertToInvariantString(horizontalAlign).ToLowerInvariant();
            }
            if (!component.Wrap)
            {
                styleAttributes["white-space"] = "nowrap";
            }
            base.AddDesignTimeCssAttributes(styleAttributes);
        }
Пример #17
0
        internal static void RenderCssRule(CssTextWriter cssWriter, string selector,
                                           Style style, IUrlResolutionService urlResolver)
        {
            cssWriter.WriteBeginCssRule(selector);

            CssStyleCollection attrs = style.GetStyleAttributes(urlResolver);

            attrs.Render(cssWriter);

            cssWriter.WriteEndCssRule();
        }
        /// <internalonly/>
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            base.FillStyleAttributes(attributes, urlResolver);

            Color shadowColor = ShadowColor;
            if (shadowColor.IsEmpty == false) {
                string colorValue = ColorTranslator.ToHtml(shadowColor);
                string filterValue = "progid:DXImageTransform.Microsoft.Shadow(color='" + colorValue + "', Direction=135, Strength=3)";

                attributes.Add(HtmlTextWriterStyle.Filter, filterValue);
            }
        }
Пример #19
0
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            base.FillStyleAttributes(attributes, urlResolver);
            Color shadowColor = this.ShadowColor;

            if (!shadowColor.IsEmpty)
            {
                string str  = ColorTranslator.ToHtml(shadowColor);
                string str2 = "progid:DXImageTransform.Microsoft.Shadow(color='" + str + "', Direction=135, Strength=3)";
                attributes.Add(HtmlTextWriterStyle.Filter, str2);
            }
        }
 public static void uploadControl_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string resultFilePath = "~/Content/Avatars/" + string.Format("Avatar{0}{1}", Convert.ToString(HttpContext.Current.Session["UserID"]), Path.GetExtension(e.UploadedFile.FileName));
         e.UploadedFile.SaveAs(HttpContext.Current.Request.MapPath(resultFilePath));
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath) + "?refresh=" + Guid.NewGuid().ToString();
         }
     }
 }
 public static void uc_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string resultFilePath = HttpContext.Current.Request.MapPath(UploadDirectory + e.UploadedFile.FileName);
         //e.UploadedFile.SaveAs(resultFilePath, true);//Code Central Mode - Uncomment This Line
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath);
         }
     }
 }
Пример #22
0
 public static void FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string resultFilePath = HttpContext.Current.Request.MapPath(UploadDirectory + e.UploadedFile.FileName);
         e.UploadedFile.SaveAs(resultFilePath, true);
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath);
         }
     }
 }
Пример #23
0
 protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
 {
     base.FillStyleAttributes(attributes, urlResolver);
     if (CheckBit((int)TreeNodeStyles.HorizontalPadding))
     {
         attributes.Add(HtmlTextWriterStyle.PaddingLeft, HorizontalPadding.ToString());
         attributes.Add(HtmlTextWriterStyle.PaddingRight, HorizontalPadding.ToString());
     }
     if (CheckBit((int)TreeNodeStyles.VerticalPadding))
     {
         attributes.Add(HtmlTextWriterStyle.PaddingTop, VerticalPadding.ToString());
         attributes.Add(HtmlTextWriterStyle.PaddingBottom, VerticalPadding.ToString());
     }
 }
Пример #24
0
 public static void uploadControl_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string fileName       = e.UploadedFile.FileName;
         string resultFilePath = "~/Content/FileManager/AnexosPlanTrabajo/" + fileName;
         e.UploadedFile.SaveAs(HttpContext.Current.Request.MapPath(resultFilePath));
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath) + "?refresh=" + Guid.NewGuid().ToString();
         }
     }
 }
Пример #25
0
 protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
 {
     base.FillStyleAttributes(attributes, urlResolver);
     if (IsSet(HORZ_PADD))
     {
         attributes.Add(HtmlTextWriterStyle.PaddingLeft, HorizontalPadding.ToString());
         attributes.Add(HtmlTextWriterStyle.PaddingRight, HorizontalPadding.ToString());
     }
     if (IsSet(VERT_PADD))
     {
         attributes.Add(HtmlTextWriterStyle.PaddingTop, VerticalPadding.ToString());
         attributes.Add(HtmlTextWriterStyle.PaddingBottom, VerticalPadding.ToString());
     }
 }
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            base.FillStyleAttributes(attributes, urlResolver);
            string backImageUrl = this.BackImageUrl;

            if (backImageUrl.Length != 0)
            {
                if (urlResolver != null)
                {
                    backImageUrl = urlResolver.ResolveClientUrl(backImageUrl);
                }
                attributes.Add(HtmlTextWriterStyle.BackgroundImage, backImageUrl);
            }
        }
Пример #27
0
 public static void ucCallbacks_AppendComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         //TODO:Fix
         //string resultFilePath = TempUploadDirectory + string.Format(ThumbnailFormat, "", Path.GetExtension(e.UploadedFile.FileName));
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = "false";//urlResolver.ResolveClientUrl(resultFilePath) + "?refresh=" + Guid.NewGuid().ToString();
         }
         //TODO:
         //Get working with nick's tool
     }
 }
Пример #28
0
        public void RegisterStyle(Style style, IUrlResolutionService urlResolver)
        {
            for (int n = 0; n < entries.Count; n++)
            {
                if (((StyleEntry)entries[n]).Style == style)
                {
                    return;
                }
            }

            string name = "aspnet_" + entries.Count;

            style.SetRegisteredCssClass(name);
            CreateStyleRule(style, urlResolver, "." + name);
        }
Пример #29
0
 public static void ucCallbacks_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string resultFilePath = UploadDirectory + string.Format(ThumbnailFormat, "", Path.GetExtension(e.UploadedFile.FileName));
         using (Image original = Image.FromStream(e.UploadedFile.FileContent))
             using (Image thumbnail = PhotoUtils.Inscribe(original, 100)) {
                 PhotoUtils.SaveToJpeg(thumbnail, HttpContext.Current.Request.MapPath(resultFilePath));
             }
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath) + "?refresh=" + Guid.NewGuid().ToString();
         }
     }
 }
Пример #30
0
        public static void ucMultiSelection_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            string resultFilePath = UploadDirectory + e.UploadedFile.FileName;

            e.UploadedFile.SaveAs(HttpContext.Current.Request.MapPath(resultFilePath));

            UploadingUtils.RemoveFileWithDelay(e.UploadedFile.FileName, HttpContext.Current.Request.MapPath(resultFilePath), 5);

            IUrlResolutionService urlResolver = sender as IUrlResolutionService;

            if (urlResolver != null)
            {
                string file = string.Format("{0} ({1}) {2}KB", e.UploadedFile.FileName, e.UploadedFile.ContentType, e.UploadedFile.ContentLength / 1024);
                string url  = urlResolver.ResolveClientUrl(resultFilePath);
                e.CallbackData = file + "|" + url;
            }
        }
Пример #31
0
        public void UploadControl_FilesUploadComplete(object sender, FilesUploadCompleteEventArgs e)
        {
            UploadedFile[] files = ((MVCxUploadControl)sender).UploadedFiles;
            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].IsValid && !string.IsNullOrWhiteSpace(files[i].FileName))
                {
                    string resultFilePath = "~/Content/" + files[i].FileName;
                    files[i].SaveAs(System.Web.HttpContext.Current.Request.MapPath(resultFilePath));

                    IUrlResolutionService urlResolver = sender as IUrlResolutionService;
                    if (urlResolver != null)
                    {
                        e.CallbackData += urlResolver.ResolveClientUrl(resultFilePath);
                    }
                }
            }
        }
Пример #32
0
 public static void FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         var path = System.Web.HttpContext.Current.Request.MapPath(TemplateDirectory);
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         string resultFilePath = System.Web.HttpContext.Current.Request.MapPath(UploadDirectory + e.UploadedFile.FileName);
         e.UploadedFile.SaveAs(resultFilePath, true);//Code Central Mode - Uncomment This Line
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = Path.GetFileName(resultFilePath);//urlResolver.ResolveClientUrl(resultFilePath);
         }
     }
 }
Пример #33
0
 public static void ucDragAndDrop_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
 {
     if (e.UploadedFile.IsValid)
     {
         string fileName       = Path.ChangeExtension(Path.GetRandomFileName(), ".jpg");
         string resultFilePath = UploadDirectory + fileName;
         using (Image original = Image.FromStream(e.UploadedFile.FileContent))
             using (Image thumbnail = ImageUtils.CreateThumbnailImage((Bitmap)original, ImageSizeMode.ActualSizeOrFit, new Size(350, 350)))
             {
                 ImageUtils.SaveToJpeg((Bitmap)thumbnail, HttpContext.Current.Request.MapPath(resultFilePath));
             }
         UploadingUtils.RemoveFileWithDelay(fileName, HttpContext.Current.Request.MapPath(resultFilePath), 5);
         IUrlResolutionService urlResolver = sender as IUrlResolutionService;
         if (urlResolver != null)
         {
             e.CallbackData = urlResolver.ResolveClientUrl(resultFilePath);
         }
     }
 }
Пример #34
0
        protected override sealed void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            Debug.Assert(_owner != null);

            StateBag viewState = ViewState;

            Color c;

            // ForeColor
            if (_owner.IsSet(PROP_FORECOLOR)) {
                c = _owner.ForeColor;
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }
            // Not defaulting to black anymore for not entirely satisfying but reasonable reasons (VSWhidbey 356729)

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = _owner.Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0) {
                attributes.Add(HtmlTextWriterStyle.FontFamily, String.Join(",", names));
            }

            // Font.Size
            FontUnit fu = font.Size;
            if (fu.IsEmpty == false) {
                attributes.Add(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // Font.Bold
            if (_owner.IsSet(PROP_FONT_BOLD)) {
                if (font.Bold) {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }

            // Font.Italic
            if (_owner.IsSet(PROP_FONT_ITALIC)) {
                if (font.Italic == true) {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }

            string textDecoration = String.Empty;
            if (font.Underline) {
                textDecoration = "underline";
            }
            if (font.Overline) {
                textDecoration += " overline";
            }
            if (font.Strikeout) {
                textDecoration += " line-through";
            }
            if (textDecoration.Length > 0) {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, textDecoration);
            }
            else {
                if (!DoNotRenderDefaults) {
                    attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
                }
            }
            // Removing the border with an inline style if the class name was set
            if (_owner.IsSet(PROP_CSSCLASS)) {
                attributes.Add(HtmlTextWriterStyle.BorderStyle, "none");
            }
        }
Пример #35
0
		protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
		{
			base.FillStyleAttributes (attributes, urlResolver);
			if (CheckBit ((int) MenuItemStyles.HorizontalPadding)) {
				attributes.Add (HtmlTextWriterStyle.PaddingLeft, HorizontalPadding.ToString ());
				attributes.Add (HtmlTextWriterStyle.PaddingRight, HorizontalPadding.ToString ());
			}
			if (CheckBit ((int) MenuItemStyles.VerticalPadding)) {
				attributes.Add (HtmlTextWriterStyle.PaddingTop, VerticalPadding.ToString ());
				attributes.Add (HtmlTextWriterStyle.PaddingBottom, VerticalPadding.ToString ());
			}
		}
 protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
 {
     base.FillStyleAttributes(attributes, urlResolver);
     // here are the additional CSS styles
     attributes.Add("float", "right"); // move it to the right in the toolbar
     attributes.Add("margin-left", "2px"); // ensure some left padding
 }
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            base.FillStyleAttributes (attributes, urlResolver);

            if (PaddingTop != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.PaddingTop, PaddingTop.ToString ());
            if (PaddingLeft != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.PaddingLeft, PaddingLeft.ToString ());
            if (PaddingRight != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.PaddingRight, PaddingRight.ToString ());
            if (PaddingBottom != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.PaddingBottom, PaddingBottom.ToString ());

            if (MarginTop != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.MarginTop, MarginTop.ToString ());
            if (MarginLeft != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.MarginLeft, MarginLeft.ToString ());
            if (MarginRight != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.MarginRight, MarginRight.ToString ());
            if (MarginBottom != Unit.Empty)
                attributes.Add (HtmlTextWriterStyle.MarginBottom, MarginBottom.ToString ());
        }
Пример #38
0
		protected virtual void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
		{
			Color		color;
			BorderStyle	bs;
			Unit		u;

			if (CheckBit ((int) Styles.BackColor))
			{
				color = (Color)viewstate["BackColor"];
				if (!color.IsEmpty)
					attributes.Add (HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
			}

			if (CheckBit ((int) Styles.BorderColor)) 
			{
				color = (Color)viewstate["BorderColor"];
				if (!color.IsEmpty)
					attributes.Add (HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
			}

			bool have_width = false;
			if (CheckBit ((int) Styles.BorderWidth)) {
				u = (Unit) viewstate ["BorderWidth"];
				if (!u.IsEmpty) {
					if (u.Value > 0)
						have_width = true;
					attributes.Add (HtmlTextWriterStyle.BorderWidth, u.ToString ());
				}
			}

			if (CheckBit ((int) Styles.BorderStyle)) {
				bs = (BorderStyle) viewstate ["BorderStyle"];
				if (bs != BorderStyle.NotSet)
					attributes.Add (HtmlTextWriterStyle.BorderStyle, bs.ToString ());
				else if (have_width)
						attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
			}
			else if (have_width) {
				attributes.Add (HtmlTextWriterStyle.BorderStyle, "solid");
			}

			if (CheckBit ((int) Styles.ForeColor)) 
			{
				color = (Color)viewstate["ForeColor"];
				if (!color.IsEmpty)
					attributes.Add (HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(color));
			}

			if (CheckBit ((int) Styles.Height)) 
			{
				u = (Unit)viewstate["Height"];
				if (!u.IsEmpty)
					attributes.Add (HtmlTextWriterStyle.Height, u.ToString());
			}

			if (CheckBit ((int) Styles.Width)) 
			{
				u = (Unit)viewstate["Width"];
				if (!u.IsEmpty)
					attributes.Add (HtmlTextWriterStyle.Width, u.ToString());
			}

			Font.FillStyleAttributes (attributes, AlwaysRenderTextDecoration);
		}
Пример #39
0
		public void CreateStyleRule (Style style, IUrlResolutionService urlResolver, string selection)
		{
			StyleEntry entry = new StyleEntry ();
			entry.Style = style;
			entry.UrlResolver = urlResolver;
			entry.Selection = selection;
			entries.Add (entry);
		}
 protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
 {
     Color color;
     Unit unit2;
     StateBag viewState = base.ViewState;
     if (base.IsSet(8))
     {
         color = (Color) viewState["BackColor"];
         if (!color.IsEmpty)
         {
             attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(color));
         }
     }
     if (base.IsSet(0x10))
     {
         color = (Color) viewState["BorderColor"];
         if (!color.IsEmpty)
         {
             attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(color));
         }
     }
     BorderStyle borderStyle = base.BorderStyle;
     Unit borderWidth = base.BorderWidth;
     if (!borderWidth.IsEmpty)
     {
         attributes.Add(HtmlTextWriterStyle.BorderWidth, borderWidth.ToString(CultureInfo.InvariantCulture));
         if (borderStyle == BorderStyle.NotSet)
         {
             if (borderWidth.Value != 0.0)
             {
                 attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
             }
         }
         else
         {
             attributes.Add(HtmlTextWriterStyle.BorderStyle, Style.borderStyles[(int) borderStyle]);
         }
     }
     else if (borderStyle != BorderStyle.NotSet)
     {
         attributes.Add(HtmlTextWriterStyle.BorderStyle, Style.borderStyles[(int) borderStyle]);
     }
     if (base.IsSet(0x80))
     {
         unit2 = (Unit) viewState["Height"];
         if (!unit2.IsEmpty)
         {
             attributes.Add(HtmlTextWriterStyle.Height, unit2.ToString(CultureInfo.InvariantCulture));
         }
     }
     if (base.IsSet(0x100))
     {
         unit2 = (Unit) viewState["Width"];
         if (!unit2.IsEmpty)
         {
             attributes.Add(HtmlTextWriterStyle.Width, unit2.ToString(CultureInfo.InvariantCulture));
         }
     }
     if (!this.HorizontalPadding.IsEmpty || !this.VerticalPadding.IsEmpty)
     {
         Unit unit3 = this.VerticalPadding.IsEmpty ? Unit.Pixel(0) : this.VerticalPadding;
         Unit unit4 = this.HorizontalPadding.IsEmpty ? Unit.Pixel(0) : this.HorizontalPadding;
         attributes.Add(HtmlTextWriterStyle.Padding, string.Format(CultureInfo.InvariantCulture, "{0} {1} {0} {1}", new object[] { unit3.ToString(CultureInfo.InvariantCulture), unit4.ToString(CultureInfo.InvariantCulture) }));
     }
 }
        public static void DescribeComponent(object instance, IScriptComponentDescriptor descriptor, IUrlResolutionService urlResolver, IControlResolver controlResolver) {
            // validate preconditions
            if(instance == null)
                throw new ArgumentNullException("instance");
            if(descriptor == null)
                throw new ArgumentNullException("descriptor");
            if(urlResolver == null)
                urlResolver = instance as IUrlResolutionService;
            if(controlResolver == null)
                controlResolver = instance as IControlResolver;

            // describe properties
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance);
            foreach(PropertyDescriptor prop in properties) {
                ExtenderControlPropertyAttribute propAttr = null;
                ExtenderControlEventAttribute eventAttr = null;

                ClientPropertyNameAttribute nameAttr = null;
                IDReferencePropertyAttribute idRefAttr = null;
                UrlPropertyAttribute urlAttr = null;
                ElementReferenceAttribute elementAttr = null;
                ComponentReferenceAttribute compAttr = null;

                foreach(Attribute attr in prop.Attributes) {
                    Type attrType = attr.GetType();
                    if(attrType == typeof(ExtenderControlPropertyAttribute))
                        propAttr = attr as ExtenderControlPropertyAttribute;
                    else if(attrType == typeof(ExtenderControlEventAttribute))
                        eventAttr = attr as ExtenderControlEventAttribute;
                    else if(attrType == typeof(ClientPropertyNameAttribute))
                        nameAttr = attr as ClientPropertyNameAttribute;
                    else if(attrType == typeof(IDReferencePropertyAttribute))
                        idRefAttr = attr as IDReferencePropertyAttribute;
                    else if(attrType == typeof(UrlPropertyAttribute))
                        urlAttr = attr as UrlPropertyAttribute;
                    else if(attrType == typeof(ElementReferenceAttribute))
                        elementAttr = attr as ElementReferenceAttribute;
                    else if(attrType == typeof(ComponentReferenceAttribute))
                        compAttr = attr as ComponentReferenceAttribute;
                }

                string propertyName = prop.Name;

                // Try getting a property attribute
                if(propAttr == null || !propAttr.IsScriptProperty) {
                    // Try getting an event attribute
                    if(eventAttr == null || !eventAttr.IsScriptEvent) {
                        continue;
                    }
                }

                // attempt to rename the property/event
                if(nameAttr != null && !string.IsNullOrEmpty(nameAttr.PropertyName)) {
                    propertyName = nameAttr.PropertyName;
                }

                // determine whether to serialize the value of a property.  readOnly properties should always be serialized
                bool serialize = prop.ShouldSerializeValue(instance) || prop.IsReadOnly;
                if(serialize) {
                    // get the value of the property, skip if it is null
                    Control c = null;
                    object value = prop.GetValue(instance);
                    if(value == null) {
                        continue;
                    }

                    // convert and resolve the value
                    if(eventAttr != null && prop.PropertyType != typeof(String)) {
                        throw new InvalidOperationException("ExtenderControlEventAttribute can only be applied to a property with a PropertyType of System.String.");
                    } else {
                        if(!prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum) {
                            // Check if we can use any of our custom converters
                            // (first do a direct lookup on the property type,
                            // but also check all of its base types if nothing
                            // was found)
                            Converter<object, string> customConverter = null;
                            if(!_customConverters.TryGetValue(prop.PropertyType, out customConverter)) {
                                foreach(KeyValuePair<Type, Converter<object, string>> pair in _customConverters) {
                                    if(prop.PropertyType.IsSubclassOf(pair.Key)) {
                                        customConverter = pair.Value;
                                        break;
                                    }
                                }
                            }

                            // Use the custom converter if found, otherwise use
                            // its current type converter
                            if(customConverter != null) {
                                value = customConverter(value);
                            } else {
                                // Determine if we should let ASP.NET AJAX handle this type of conversion, as it supports JSON serialization
                                if(propAttr != null && propAttr.UseJsonSerialization) {
                                    // Use ASP.NET JSON serialization
                                } else {
                                    // Use the property's own converter
                                    TypeConverter conv = prop.Converter;

                                    if(value.GetType() == typeof(DateTime))
                                        value = ((DateTime)value).ToString("s", CultureInfo.InvariantCulture);
                                    else
                                        value = conv.ConvertToString(null, CultureInfo.InvariantCulture, value);
                                }
                            }
                        }
                        if(idRefAttr != null && controlResolver != null) {
                            c = controlResolver.ResolveControl((string)value);
                        }
                        if(urlAttr != null && urlResolver != null) {
                            value = urlResolver.ResolveClientUrl((string)value);
                        }
                    }

                    // add the value as an appropriate description
                    if(eventAttr != null) {
                        descriptor.AddEvent(propertyName, (string)value);
                    } else if(elementAttr != null) {
                        if(c == null && controlResolver != null)
                            c = controlResolver.ResolveControl((string)value);
                        if(c != null)
                            value = c.ClientID;
                        descriptor.AddElementProperty(propertyName, (string)value);
                    } else if(compAttr != null) {
                        if(c == null && controlResolver != null)
                            c = controlResolver.ResolveControl((string)value);
                        if(c != null) {
                            ExtenderControlBase ex = c as ExtenderControlBase;
                            if(ex != null && ex.BehaviorID.Length > 0)
                                value = ex.BehaviorID;
                            else
                                value = c.ClientID;
                        }
                        descriptor.AddComponentProperty(propertyName, (string)value);
                    } else {
                        if(c != null)
                            value = c.ClientID;
                        descriptor.AddProperty(propertyName, value);
                    }
                }
            }

            // determine if we should describe methods
            foreach(MethodInfo method in instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public)) {
                ExtenderControlMethodAttribute methAttr = (ExtenderControlMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ExtenderControlMethodAttribute));
                if(methAttr == null || !methAttr.IsScriptMethod) {
                    continue;
                }

                // We only need to support emitting the callback target and registering the WebForms.js script if there is at least one valid method
                Control control = instance as Control;
                if(control != null) {
                    // Force WebForms.js
                    control.Page.ClientScript.GetCallbackEventReference(control, null, null, null);

                    // Add the callback target
                    descriptor.AddProperty("_callbackTarget", control.UniqueID);
                }
                break;
            }
        }
Пример #42
0
        protected virtual void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            StateBag viewState = ViewState;

            Color c;

            // ForeColor
            if (IsSet(PROP_FORECOLOR)) {
                c = (Color)viewState["ForeColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Color, ColorTranslator.ToHtml(c));
                }
            }

            // BackColor
            if (IsSet(PROP_BACKCOLOR)) {
                c = (Color)viewState["BackColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (IsSet(PROP_BORDERCOLOR)) {
                c = (Color)viewState["BorderColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit bu = this.BorderWidth;
            if (!bu.IsEmpty) {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet) {
                    if (bu.Value != 0.0) {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }
            else {
                if (bs != BorderStyle.NotSet) {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }

            // need to call the property get in case we have font properties from view state and have not
            // created the font object
            FontInfo font = Font;

            // Font.Names
            string[] names = font.Names;
            if (names.Length > 0) {
                attributes.Add(HtmlTextWriterStyle.FontFamily, Style.FormatStringArray(names, ','));
            }

            // Font.Size
            FontUnit fu = font.Size;
            if (fu.IsEmpty == false) {
                attributes.Add(HtmlTextWriterStyle.FontSize, fu.ToString(CultureInfo.InvariantCulture));
            }

            // Font.Bold
            if (IsSet(PROP_FONT_BOLD)) {
                if (font.Bold) {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "bold");
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.FontWeight, "normal");
                }
            }

            // Font.Italic
            if (IsSet(PROP_FONT_ITALIC)) {
                if (font.Italic == true) {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "italic");
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.FontStyle, "normal");
                }
            }

            // 
            string textDecoration = String.Empty;
            if (font.Underline) {
                textDecoration = "underline";
            }
            if (font.Overline) {
                textDecoration += " overline";
            }
            if (font.Strikeout) {
                textDecoration += " line-through";
            }
            if (textDecoration.Length > 0) {
                attributes.Add(HtmlTextWriterStyle.TextDecoration, textDecoration);
            }
            else {
                if (IsSet(PROP_FONT_UNDERLINE) || IsSet(PROP_FONT_OVERLINE) || IsSet(PROP_FONT_STRIKEOUT)) {
                    attributes.Add(HtmlTextWriterStyle.TextDecoration, "none");
                }
            }

            Unit u;

            // Height
            if (IsSet(PROP_HEIGHT)) {
                u = (Unit)viewState["Height"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (IsSet(PROP_WIDTH)) {
                u = (Unit)viewState["Width"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }
        }
 public virtual void Initialize(IComponent component)
 {
     ControlDesigner.VerifyInitializeArgument(component, typeof(TemplateControl));
     this._component = component;
     IServiceContainer container = (IServiceContainer) this.GetService(typeof(IServiceContainer));
     if (container != null)
     {
         this._urlResolutionService = this.CreateUrlResolutionService();
         if (this._urlResolutionService != null)
         {
             container.AddService(typeof(IUrlResolutionService), this._urlResolutionService);
         }
         this._designerActionService = this.CreateDesignerActionService(this._component.Site);
         this._designerActionUIService = new DesignerActionUIService(this._component.Site);
         ServiceCreatorCallback callback = new ServiceCreatorCallback(this.OnCreateService);
         container.AddService(typeof(IImplicitResourceProvider), callback);
     }
     IPropertyValueUIService service = (IPropertyValueUIService) this.GetService(typeof(IPropertyValueUIService));
     if (service != null)
     {
         service.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.OnGetUIValueItem));
     }
 }
Пример #44
0
		protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver) {
			base.FillStyleAttributes (attributes, urlResolver);
			attributes.Add ("FillStyleAttributes", "FillStyleAttributes");
		}
Пример #45
0
			protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
			{
				UrlResolver = urlResolver;
				base.FillStyleAttributes (attributes, urlResolver);
			}
Пример #46
0
        /// <devdoc>
        /// Retrieves the collection of CSS style attributes represented by this style.
        /// </devdoc>
        public CssStyleCollection GetStyleAttributes(IUrlResolutionService urlResolver) {
            CssStyleCollection attributes = new CssStyleCollection();

            FillStyleAttributes(attributes, urlResolver);
            return attributes;
        }
Пример #47
0
            protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
            {
                base.FillStyleAttributes(attributes, urlResolver);

                attributes.Remove(HtmlTextWriterStyle.Height);
                attributes.Remove(HtmlTextWriterStyle.BackgroundColor);
                attributes.Remove(HtmlTextWriterStyle.BackgroundImage);
            }
Пример #48
0
        /// <summary>
        /// Fills the attributes collection given with the ones from the style
        /// </summary>
        /// <param name="attributes">The atrributes</param>
        /// <param name="urlResolver">The resolver to use</param>
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
        {
            base.FillStyleAttributes(attributes, urlResolver);

            if(!string.IsNullOrEmpty(BackgroundImageUrl))
                attributes.Add(HtmlTextWriterStyle.BackgroundImage, "url('" + urlResolver.ResolveClientUrl(BackgroundImageUrl) + "')");

            if(BackgroundImagePosition != BackgroundPosition.NotSet)
                attributes.Add("background-position", backgroundPos[(int)BackgroundImagePosition]);

            if(BackgroundImageRepeat != BackgroundRepeat.NotSet)
                attributes.Add("background-repeat", backgroundRpt[(int)BackgroundImageRepeat]);

            if(ZIndex != 0)
                attributes.Add(HtmlTextWriterStyle.ZIndex, ZIndex.ToString());

            if(Display != Display.NotSet)
                attributes.Add(HtmlTextWriterStyle.Display, displayStr[(int)Display]);

            if(Position != ElementPosition.NotSet)
                attributes.Add("position", positionStr[(int)Position]);

            if(!Left.IsEmpty)
                attributes.Add("left", Left.ToString());

            if(!Right.IsEmpty)
                attributes.Add("right", Right.ToString());

            if(!Top.IsEmpty)
                attributes.Add("top", Top.ToString());

            if(!Bottom.IsEmpty)
                attributes.Add("bottom", Bottom.ToString());

            if(Opacity != 1.0f)
            {
                attributes.Add("opacity", Opacity.ToString("0.0"));
                attributes.Add("-ms-filter", string.Format("progid:DXImageTransform.Microsoft.Alpha(Opacity={0:0})", Opacity * 100));
                attributes.Add("filter", string.Format("alpha(opacity={0:0})", Opacity * 100));
            }

            if(Float != ElementFloat.NotSet)
                attributes.Add("float", floatStr[(int)Float]);

            if(ListStyleType != ListStyleType.NotSet)
                attributes.Add(HtmlTextWriterStyle.ListStyleType, ListStyleTypeStr[(int)ListStyleType]);

            if(ListStylePosition != ListStylePosition.NotSet)
                attributes.Add("list-style-position", ListStylePositionStr[(int)ListStylePosition]);

            if(!string.IsNullOrEmpty(ListStyleImage))
                attributes.Add(HtmlTextWriterStyle.ListStyleImage, "url('" + urlResolver.ResolveClientUrl(ListStyleImage) + "')");
        }
            /// <summary>
            /// Fills Style attribute to the base.
            /// </summary>
            /// <param name="attributes"></param>
            /// <param name="urlResolver"></param>
            protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
            {
                base.FillStyleAttributes(attributes, urlResolver);

                attributes.Remove(HtmlTextWriterStyle.Height);
                // commented below line to fix the issue #25821
                //attributes.Remove(HtmlTextWriterStyle.BackgroundColor);
                attributes.Remove(HtmlTextWriterStyle.BackgroundImage);
            }
Пример #50
0
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            // The style will be rendered on container elements that does not contain text directly.
            // It does not render font and forecolor.
            // Users should set font and forecolor on MenuItems styles.
            // Copying the code from the base class, except for the part that deals with Font and ForeColor.
            StateBag viewState = ViewState;
            Color c;

            // BackColor
            if (base.IsSet(PROP_BACKCOLOR)) {
                c = (Color)viewState["BackColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (base.IsSet(PROP_BORDERCOLOR)) {
                c = (Color)viewState["BorderColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit bu = this.BorderWidth;
            if (!bu.IsEmpty) {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet) {
                    if (bu.Value != 0.0) {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }
            else {
                if (bs != BorderStyle.NotSet) {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }

            Unit u;

            // Height
            if (base.IsSet(PROP_HEIGHT)) {
                u = (Unit)viewState["Height"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (base.IsSet(PROP_WIDTH)) {
                u = (Unit)viewState["Width"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            if (!HorizontalPadding.IsEmpty || !VerticalPadding.IsEmpty) {
                attributes.Add(HtmlTextWriterStyle.Padding, string.Format(CultureInfo.InvariantCulture,
                    "{0} {1} {0} {1}",
                    VerticalPadding.IsEmpty ? Unit.Pixel(0) : VerticalPadding,
                    HorizontalPadding.IsEmpty ? Unit.Pixel(0) : HorizontalPadding));
            }
        }
Пример #51
0
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            // The main style will be rendered on the container element, that does not contain the text.
            // The Hyperlink style will render the text styles
            // Copying the code from the base class, except for the part that deals with Font and ForeColor.
            StateBag viewState = ViewState;
            Color c;

            // BackColor
            if (IsSet(PROP_BACKCOLOR)) {
                c = (Color)viewState["BackColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BackgroundColor, ColorTranslator.ToHtml(c));
                }
            }

            // BorderColor
            if (IsSet(PROP_BORDERCOLOR)) {
                c = (Color)viewState["BorderColor"];
                if (!c.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.BorderColor, ColorTranslator.ToHtml(c));
                }
            }

            BorderStyle bs = this.BorderStyle;
            Unit bu = this.BorderWidth;
            if (!bu.IsEmpty) {
                attributes.Add(HtmlTextWriterStyle.BorderWidth, bu.ToString(CultureInfo.InvariantCulture));
                if (bs == BorderStyle.NotSet) {
                    if (bu.Value != 0.0) {
                        attributes.Add(HtmlTextWriterStyle.BorderStyle, "solid");
                    }
                }
                else {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }
            else {
                if (bs != BorderStyle.NotSet) {
                    attributes.Add(HtmlTextWriterStyle.BorderStyle, borderStyles[(int)bs]);
                }
            }

            Unit u;

            // Height
            if (IsSet(PROP_HEIGHT)) {
                u = (Unit)viewState["Height"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Height, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            // Width
            if (IsSet(PROP_WIDTH)) {
                u = (Unit)viewState["Width"];
                if (!u.IsEmpty) {
                    attributes.Add(HtmlTextWriterStyle.Width, u.ToString(CultureInfo.InvariantCulture));
                }
            }

            if (!HorizontalPadding.IsEmpty || !VerticalPadding.IsEmpty) {
                // DevDiv Bugs 84107: Must pass InvariantCulture to Unit.ToString since Unit is not IFormattable.
                Unit verticalPadding = VerticalPadding.IsEmpty ? Unit.Pixel(0) : VerticalPadding;
                Unit horizontalPadding = HorizontalPadding.IsEmpty ? Unit.Pixel(0) : HorizontalPadding;
                attributes.Add(HtmlTextWriterStyle.Padding, string.Format(CultureInfo.InvariantCulture,
                    "{0} {1} {0} {1}",
                    verticalPadding.ToString(CultureInfo.InvariantCulture),
                    horizontalPadding.ToString(CultureInfo.InvariantCulture)));
            }
        }
Пример #52
0
		public static void DescribeComponent(object instance, ScriptComponentDescriptor descriptor, IUrlResolutionService urlResolver, IControlResolver controlResolver)
		{
			// validate preconditions
			if (instance == null) throw new ArgumentNullException("instance");
			if (descriptor == null) throw new ArgumentNullException("descriptor");
			if (urlResolver == null) urlResolver = instance as IUrlResolutionService;
			if (controlResolver == null) controlResolver = instance as IControlResolver;

			// describe properties
			// PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(instance);

			PropertyInfo[] properties = instance.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

			foreach (PropertyInfo prop in properties)
			{
				ScriptControlPropertyAttribute propAttr = null;
				ScriptControlEventAttribute eventAttr = null;
				string propertyName = prop.Name;

				System.ComponentModel.AttributeCollection attribs = new System.ComponentModel.AttributeCollection(Attribute.GetCustomAttributes(prop, false));

				// Try getting a property attribute
				propAttr = (ScriptControlPropertyAttribute)attribs[typeof(ScriptControlPropertyAttribute)];
				if (propAttr == null || !propAttr.IsScriptProperty)
				{
					// Try getting an event attribute
					eventAttr = (ScriptControlEventAttribute)attribs[typeof(ScriptControlEventAttribute)];
					if (eventAttr == null || !eventAttr.IsScriptEvent)
					{
						continue;
					}
				}

				// attempt to rename the property/event
				ClientPropertyNameAttribute nameAttr = (ClientPropertyNameAttribute)attribs[typeof(ClientPropertyNameAttribute)];
				if (nameAttr != null && !string.IsNullOrEmpty(nameAttr.PropertyName))
				{
					propertyName = nameAttr.PropertyName;
				}

				// determine whether to serialize the value of a property.  readOnly properties should always be serialized
				//bool serialize = true;// prop.ShouldSerializeValue(instance) || prop.IsReadOnly;
				//if (serialize)
				//{
				// get the value of the property, skip if it is null
				Control c = null;
				object value = prop.GetValue(instance, new object[0] { });
				if (value == null)
				{
					continue;
				}

				// convert and resolve the value
				if (eventAttr != null && prop.PropertyType != typeof(String))
				{
					throw new InvalidOperationException("ScriptControlEventAttribute can only be applied to a property with a PropertyType of System.String.");
				}
				else
				{
					if (!prop.PropertyType.IsPrimitive && !prop.PropertyType.IsEnum)
					{
						if (prop.PropertyType == typeof(Color))
						{
							value = ColorTranslator.ToHtml((Color)value);
						}
						else
						{
							// TODO: Determine if we should let ASP.NET AJAX handle this type of conversion, as it supports JSON serialization
							//TypeConverter conv = prop.Converter;
							//value = conv.ConvertToString(null, CultureInfo.InvariantCulture, value);

							//if (prop.PropertyType == typeof(CssStyleCollection))
							//    value = (new CssStyleCollectionJSCoverter()).Serialize(value, new JavaScriptSerializer());
							//if (prop.PropertyType == typeof(Style))
							//    value = (new CssStyleCollectionJSCoverter()).Serialize(((Style)value).GetStyleAttributes(null), new JavaScriptSerializer());                                

							Type valueType = value.GetType();

							JavaScriptConverterAttribute attr = (JavaScriptConverterAttribute)attribs[typeof(JavaScriptConverterAttribute)];
							JavaScriptConverter converter = attr != null ?
								(JavaScriptConverter)TypeCreator.CreateInstance(attr.ConverterType) :
								JSONSerializerFactory.GetJavaScriptConverter(valueType);

							if (converter != null)
								value = converter.Serialize(value, JSONSerializerFactory.GetJavaScriptSerializer());
							else
								value = JSONSerializerExecute.PreSerializeObject(value);

							//Dictionary<string, object> dict = value as Dictionary<string, object>;
							//if (dict != null && !dict.ContainsKey("__type"))
							//    dict["__type"] = valueType.AssemblyQualifiedName;
						}
					}
					if (attribs[typeof(IDReferencePropertyAttribute)] != null && controlResolver != null)
					{
						c = controlResolver.ResolveControl((string)value);
					}
					if (attribs[typeof(UrlPropertyAttribute)] != null && urlResolver != null)
					{
						value = urlResolver.ResolveClientUrl((string)value);
					}
				}

				// add the value as an appropriate description
				if (eventAttr != null)
				{
					if (!string.IsNullOrEmpty((string)value))
						descriptor.AddEvent(propertyName, (string)value);
				}
				else if (attribs[typeof(ElementReferenceAttribute)] != null)
				{
					if (c == null && controlResolver != null) c = controlResolver.ResolveControl((string)value);
					if (c != null) value = c.ClientID;
					descriptor.AddElementProperty(propertyName, (string)value);
				}
				else if (attribs[typeof(ComponentReferenceAttribute)] != null)
				{
					if (c == null && controlResolver != null) c = controlResolver.ResolveControl((string)value);
					if (c != null)
					{
						//ExtenderControlBase ex = c as ExtenderControlBase;
						//if (ex != null && ex.BehaviorID.Length > 0)
						//    value = ex.BehaviorID;
						//else
						value = c.ClientID;
					}
					descriptor.AddComponentProperty(propertyName, (string)value);
				}
				else
				{
					if (c != null) value = c.ClientID;
					descriptor.AddProperty(propertyName, value);
				}
			}
			//}

			// determine if we should describe methods
			foreach (MethodInfo method in instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public))
			{
				ScriptControlMethodAttribute methAttr = (ScriptControlMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ScriptControlMethodAttribute));
				if (methAttr == null || !methAttr.IsScriptMethod)
				{
					continue;
				}

				// We only need to support emitting the callback target and registering the WebForms.js script if there is at least one valid method
				Control control = instance as Control;
				if (control != null)
				{
					// Force WebForms.js
					control.Page.ClientScript.GetCallbackEventReference(control, null, null, null);

					// Add the callback target
					descriptor.AddProperty("_callbackTarget", control.UniqueID);
				}
				break;
			}
		}
Пример #53
0
		public void RegisterStyle (Style style, IUrlResolutionService urlResolver)
		{
			for (int n=0; n<entries.Count; n++) {
				if (((StyleEntry)entries[n]).Style == style)
					return;
			}
			
			string name = "aspnet_" + entries.Count;
			style.SetRegisteredCssClass (name);
			CreateStyleRule (style, urlResolver, "." + name);
		}
Пример #54
0
		public void Fill (CssStyleCollection attributes, IUrlResolutionService urlResolver)
		{
			base.FillStyleAttributes (attributes, urlResolver);
		}
Пример #55
0
		public CssStyleCollection GetStyleAttributes (IUrlResolutionService resolver)
		{
			CssStyleCollection col = new CssStyleCollection ();
			FillStyleAttributes (col, resolver);
			return col;
		}
Пример #56
0
            void IStyleSheet.RegisterStyle(Style style, IUrlResolutionService urlResolver) {
                if (style == null) {
                    throw new ArgumentNullException("style");
                }

                if (_styles == null) {
                    _styles = new ArrayList();
                }
                else if (style.RegisteredCssClass.Length != 0) {
                    // if it's already registered, throw an exception
                    throw new InvalidOperationException(SR.GetString(SR.HtmlHead_StyleAlreadyRegistered));
                }

                if (urlResolver == null) {
                    urlResolver = this;
                }

                StyleInfo styleInfo = new StyleInfo();
                styleInfo.style = style;
                styleInfo.urlResolver = urlResolver;

                int index = _autoGenCount++;
                string name = "aspnet_s" + index.ToString(NumberFormatInfo.InvariantInfo);

                style.SetRegisteredCssClass(name);
                _styles.Add(styleInfo);
            }
Пример #57
0
        /// <internalonly/>
        protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver) {
            base.FillStyleAttributes(attributes, urlResolver);

            string s = BackImageUrl;
            if (s.Length != 0) {
                if (urlResolver != null) {
                    s = urlResolver.ResolveClientUrl(s);
                }
                attributes.Add(HtmlTextWriterStyle.BackgroundImage, s);
            }
        }
Пример #58
0
		protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
		{
			base.FillStyleAttributes (attributes, urlResolver);
			if (IsSet (HORZ_PADD)) {
				attributes.Add (HtmlTextWriterStyle.PaddingLeft, HorizontalPadding.ToString ());
				attributes.Add (HtmlTextWriterStyle.PaddingRight, HorizontalPadding.ToString ());
			}
			if (IsSet (VERT_PADD)) {
				attributes.Add (HtmlTextWriterStyle.PaddingTop, VerticalPadding.ToString ());
				attributes.Add (HtmlTextWriterStyle.PaddingBottom, VerticalPadding.ToString ());
			}
		}
Пример #59
0
		protected override void FillStyleAttributes (CssStyleCollection attributes, IUrlResolutionService urlResolver)
		{
			if (attributes != null) {
				string url = BackImageUrl;
				if (url.Length > 0) {
					if (urlResolver != null)
						url = urlResolver.ResolveClientUrl (url);
					attributes.Add (HtmlTextWriterStyle.BackgroundImage, url);
				}
			}
			base.FillStyleAttributes (attributes, urlResolver);
		}
Пример #60
0
 protected override void FillStyleAttributes(CssStyleCollection attributes, IUrlResolutionService urlResolver)
 {
     _popup._savedCSS = attributes.Value;
     attributes.Add(HtmlTextWriterStyle.Position, "absolute");
     attributes.Add(HtmlTextWriterStyle.Top, "-2000px");
     attributes.Add(HtmlTextWriterStyle.Left, "-2000px");
 }