//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Web.Handlers;
using System.Web.UI;
using System.Web.UI.WebControls;
public class EditorPartChrome {
private EditorZoneBase _zone;
// PERF: Cache these, since they are needed for every EditorPart in the zone
private Style _chromeStyleNoBorder;
private Style _titleTextStyle;
public EditorPartChrome(EditorZoneBase zone) {
if (zone == null) {
throw new ArgumentNullException("zone");
}
_zone = zone;
}
protected EditorZoneBase Zone {
get {
return _zone;
}
}
protected virtual Style CreateEditorPartChromeStyle(EditorPart editorPart, PartChromeType chromeType) {
if (editorPart == null) {
throw new ArgumentNullException("editorPart");
}
if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) {
throw new ArgumentOutOfRangeException("chromeType");
}
// PERF: Cache these, since they are needed for every EditorPart in the zone.
if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) {
// We don't want to set any border styles for ChromeType of TitleAndBorder or BorderOnly,
// since the FrameSet has a default border, and it will use XP themes as long as no border styles
// are set.
// PERF: Just return the Zone.PartChromeStyle directly without making a copy
return Zone.PartChromeStyle;
}
else {
if (_chromeStyleNoBorder == null) {
Style style = new Style();
// create copy of PartChromeStyle so we can modify it
style.CopyFrom(Zone.PartChromeStyle);
if (style.BorderStyle != BorderStyle.None) {
style.BorderStyle = BorderStyle.None;
}
if (style.BorderWidth != Unit.Empty) {
style.BorderWidth = Unit.Empty;
}
if (style.BorderColor != Color.Empty) {
style.BorderColor = Color.Empty;
}
_chromeStyleNoBorder = style;
}
return _chromeStyleNoBorder;
}
}
public virtual void PerformPreRender() {
}
public virtual void RenderEditorPart(HtmlTextWriter writer, EditorPart editorPart) {
if (editorPart == null) {
throw new ArgumentNullException("editorPart");
}
PartChromeType chromeType = Zone.GetEffectiveChromeType(editorPart);
Style partChromeStyle = CreateEditorPartChromeStyle(editorPart, chromeType);
// Apply ChromeStyle to the Fieldset
if (!partChromeStyle.IsEmpty) {
partChromeStyle.AddAttributesToRender(writer, Zone);
}
writer.RenderBeginTag(HtmlTextWriterTag.Fieldset);
// Use ChromeType to determine whether to render the legend
if (chromeType == PartChromeType.TitleAndBorder || chromeType == PartChromeType.TitleOnly) {
RenderTitle(writer, editorPart);
}
if (editorPart.ChromeState != PartChromeState.Minimized) {
// Apply PartStyle to a
around the part rendering
Style partStyle = Zone.PartStyle;
if (!partStyle.IsEmpty) {
partStyle.AddAttributesToRender(writer, Zone);
}
// We want to have 5 pixels of spacing aroung the EditorPart contents. There are
// 3 ways to accomplish this:
// 1.