You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@@ -0,0 +1,373 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="AppearanceEditorPart.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public sealed class AppearanceEditorPart : EditorPart {
|
||||
|
||||
private TextBox _title;
|
||||
private UnitInput _height;
|
||||
private UnitInput _width;
|
||||
private DropDownList _chromeType;
|
||||
private CheckBox _hidden;
|
||||
private DropDownList _direction;
|
||||
|
||||
private string _titleErrorMessage;
|
||||
private string _heightErrorMessage;
|
||||
private string _widthErrorMessage;
|
||||
private string _chromeTypeErrorMessage;
|
||||
private string _hiddenErrorMessage;
|
||||
private string _directionErrorMessage;
|
||||
|
||||
private const int TextBoxColumns = 30;
|
||||
private const int MinUnitValue = 0;
|
||||
private const int MaxUnitValue = 32767;
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string DefaultButton {
|
||||
get { return base.DefaultButton; }
|
||||
set { base.DefaultButton = value; }
|
||||
}
|
||||
|
||||
private bool HasError {
|
||||
get {
|
||||
return (_titleErrorMessage != null || _heightErrorMessage != null ||
|
||||
_widthErrorMessage != null || _chromeTypeErrorMessage != null ||
|
||||
_hiddenErrorMessage != null || _directionErrorMessage != null);
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
WebSysDefaultValue(SR.AppearanceEditorPart_PartTitle),
|
||||
]
|
||||
public override string Title {
|
||||
get {
|
||||
string s = (string)ViewState["Title"];
|
||||
return (s != null) ? s : SR.GetString(SR.AppearanceEditorPart_PartTitle);
|
||||
}
|
||||
set {
|
||||
ViewState["Title"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ApplyChanges() {
|
||||
WebPart webPart = WebPartToEdit;
|
||||
|
||||
Debug.Assert(webPart != null);
|
||||
if (webPart != null) {
|
||||
EnsureChildControls();
|
||||
bool allowLayoutChange = webPart.Zone.AllowLayoutChange;
|
||||
|
||||
try {
|
||||
webPart.Title = _title.Text;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_titleErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
if (allowLayoutChange) {
|
||||
try {
|
||||
TypeConverter chromeTypeConverter = TypeDescriptor.GetConverter(typeof(PartChromeType));
|
||||
webPart.ChromeType = (PartChromeType)chromeTypeConverter.ConvertFromString(_chromeType.SelectedValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_chromeTypeErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TypeConverter directionConverter = TypeDescriptor.GetConverter(typeof(ContentDirection));
|
||||
webPart.Direction = (ContentDirection)directionConverter.ConvertFromString(_direction.SelectedValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_directionErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
if (allowLayoutChange) {
|
||||
Unit height = Unit.Empty;
|
||||
string heightValueString = _height.Value;
|
||||
if (!String.IsNullOrEmpty(heightValueString)) {
|
||||
double heightValue;
|
||||
if (Double.TryParse(_height.Value, NumberStyles.Float | NumberStyles.AllowThousands,
|
||||
CultureInfo.CurrentCulture, out heightValue)) {
|
||||
if (heightValue < MinUnitValue) {
|
||||
_heightErrorMessage = SR.GetString(SR.EditorPart_PropertyMinValue, MinUnitValue.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
else if (heightValue > MaxUnitValue) {
|
||||
_heightErrorMessage = SR.GetString(SR.EditorPart_PropertyMaxValue, MaxUnitValue.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
else {
|
||||
height = new Unit(heightValue, _height.Type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
_heightErrorMessage = SR.GetString(SR.EditorPart_PropertyMustBeDecimal);
|
||||
}
|
||||
}
|
||||
|
||||
if (_heightErrorMessage == null) {
|
||||
try {
|
||||
webPart.Height = (Unit)height;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_heightErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allowLayoutChange) {
|
||||
Unit width = Unit.Empty;
|
||||
string widthValueString = _width.Value;
|
||||
if (!String.IsNullOrEmpty(widthValueString)) {
|
||||
double widthValue;
|
||||
if (Double.TryParse(_width.Value, NumberStyles.Float| NumberStyles.AllowThousands,
|
||||
CultureInfo.CurrentCulture, out widthValue)) {
|
||||
if (widthValue < MinUnitValue) {
|
||||
_widthErrorMessage = SR.GetString(SR.EditorPart_PropertyMinValue, MinUnitValue.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
else if (widthValue > MaxUnitValue) {
|
||||
_widthErrorMessage = SR.GetString(SR.EditorPart_PropertyMaxValue, MaxUnitValue.ToString(CultureInfo.CurrentCulture));
|
||||
}
|
||||
else {
|
||||
width = new Unit(widthValue, _width.Type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
_widthErrorMessage = SR.GetString(SR.EditorPart_PropertyMustBeDecimal);
|
||||
}
|
||||
}
|
||||
if (_widthErrorMessage == null) {
|
||||
try {
|
||||
webPart.Width = (Unit)width;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_widthErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (allowLayoutChange && webPart.AllowHide) {
|
||||
try {
|
||||
webPart.Hidden = _hidden.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_hiddenErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !HasError;
|
||||
}
|
||||
|
||||
protected internal override void CreateChildControls() {
|
||||
ControlCollection controls = Controls;
|
||||
controls.Clear();
|
||||
|
||||
_title = new TextBox();
|
||||
_title.Columns = TextBoxColumns;
|
||||
controls.Add(_title);
|
||||
|
||||
TypeConverter chromeTypeConverter = TypeDescriptor.GetConverter(typeof(PartChromeType));
|
||||
_chromeType = new DropDownList();
|
||||
_chromeType.Items.Add(new ListItem(SR.GetString(SR.PartChromeType_Default),
|
||||
chromeTypeConverter.ConvertToString(PartChromeType.Default)));
|
||||
_chromeType.Items.Add(new ListItem(SR.GetString(SR.PartChromeType_TitleAndBorder),
|
||||
chromeTypeConverter.ConvertToString(PartChromeType.TitleAndBorder)));
|
||||
_chromeType.Items.Add(new ListItem(SR.GetString(SR.PartChromeType_TitleOnly),
|
||||
chromeTypeConverter.ConvertToString(PartChromeType.TitleOnly)));
|
||||
_chromeType.Items.Add(new ListItem(SR.GetString(SR.PartChromeType_BorderOnly),
|
||||
chromeTypeConverter.ConvertToString(PartChromeType.BorderOnly)));
|
||||
_chromeType.Items.Add(new ListItem(SR.GetString(SR.PartChromeType_None),
|
||||
chromeTypeConverter.ConvertToString(PartChromeType.None)));
|
||||
controls.Add(_chromeType);
|
||||
|
||||
TypeConverter directionConverter = TypeDescriptor.GetConverter(typeof(ContentDirection));
|
||||
_direction = new DropDownList();
|
||||
_direction.Items.Add(new ListItem(SR.GetString(SR.ContentDirection_NotSet),
|
||||
directionConverter.ConvertToString(ContentDirection.NotSet)));
|
||||
_direction.Items.Add(new ListItem(SR.GetString(SR.ContentDirection_LeftToRight),
|
||||
directionConverter.ConvertToString(ContentDirection.LeftToRight)));
|
||||
_direction.Items.Add(new ListItem(SR.GetString(SR.ContentDirection_RightToLeft),
|
||||
directionConverter.ConvertToString(ContentDirection.RightToLeft)));
|
||||
controls.Add(_direction);
|
||||
|
||||
_height = new UnitInput();
|
||||
controls.Add(_height);
|
||||
|
||||
_width = new UnitInput();
|
||||
controls.Add(_width);
|
||||
|
||||
_hidden = new CheckBox();
|
||||
controls.Add(_hidden);
|
||||
|
||||
// We don't need viewstate enabled on our child controls. Disable for perf.
|
||||
foreach (Control c in controls) {
|
||||
c.EnableViewState = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnPreRender(EventArgs e) {
|
||||
base.OnPreRender(e);
|
||||
|
||||
// We want to synchronize the EditorPart to the state of the WebPart on every page load,
|
||||
// so we stay current if the WebPart changes in the background.
|
||||
if (Display && Visible && !HasError) {
|
||||
SyncChanges();
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void RenderContents(HtmlTextWriter writer) {
|
||||
if (Page != null) {
|
||||
Page.VerifyRenderingInServerForm(this);
|
||||
}
|
||||
|
||||
// HACK: Need this for child controls to be created at design-time when control is inside template
|
||||
EnsureChildControls();
|
||||
|
||||
string[] propertyDisplayNames = new string[] {
|
||||
SR.GetString(SR.AppearanceEditorPart_Title),
|
||||
SR.GetString(SR.AppearanceEditorPart_ChromeType),
|
||||
SR.GetString(SR.AppearanceEditorPart_Direction),
|
||||
SR.GetString(SR.AppearanceEditorPart_Height),
|
||||
SR.GetString(SR.AppearanceEditorPart_Width),
|
||||
SR.GetString(SR.AppearanceEditorPart_Hidden),
|
||||
};
|
||||
|
||||
WebControl[] propertyEditors = new WebControl[] {
|
||||
_title,
|
||||
_chromeType,
|
||||
_direction,
|
||||
_height,
|
||||
_width,
|
||||
_hidden,
|
||||
};
|
||||
|
||||
string[] errorMessages = new string[] {
|
||||
_titleErrorMessage,
|
||||
_chromeTypeErrorMessage,
|
||||
_directionErrorMessage,
|
||||
_heightErrorMessage,
|
||||
_widthErrorMessage,
|
||||
_hiddenErrorMessage,
|
||||
};
|
||||
|
||||
RenderPropertyEditors(writer, propertyDisplayNames, null /* propertyDescriptions */,
|
||||
propertyEditors, errorMessages);
|
||||
}
|
||||
|
||||
public override void SyncChanges() {
|
||||
WebPart webPart = WebPartToEdit;
|
||||
|
||||
Debug.Assert(webPart != null);
|
||||
if (webPart != null) {
|
||||
bool allowLayoutChange = webPart.Zone.AllowLayoutChange;
|
||||
|
||||
EnsureChildControls();
|
||||
_title.Text = webPart.Title;
|
||||
|
||||
TypeConverter chromeTypeConverter = TypeDescriptor.GetConverter(typeof(PartChromeType));
|
||||
_chromeType.SelectedValue = chromeTypeConverter.ConvertToString(webPart.ChromeType);
|
||||
_chromeType.Enabled = allowLayoutChange;
|
||||
|
||||
TypeConverter directionConverter = TypeDescriptor.GetConverter(typeof(ContentDirection));
|
||||
_direction.SelectedValue = directionConverter.ConvertToString(webPart.Direction);
|
||||
|
||||
_height.Unit = webPart.Height;
|
||||
_height.Enabled = allowLayoutChange;
|
||||
|
||||
_width.Unit = webPart.Width;
|
||||
_width.Enabled = allowLayoutChange;
|
||||
|
||||
_hidden.Checked = webPart.Hidden;
|
||||
_hidden.Enabled = allowLayoutChange && webPart.AllowHide;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class UnitInput : CompositeControl {
|
||||
private TextBox _value;
|
||||
private DropDownList _type;
|
||||
private const int TextBoxColumns = 2;
|
||||
|
||||
public string Value {
|
||||
get {
|
||||
return (_value != null) ? _value.Text : String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public UnitType Type {
|
||||
get {
|
||||
return (_type != null) ?
|
||||
(UnitType)Int32.Parse(_type.SelectedValue, CultureInfo.InvariantCulture) : (UnitType)0;
|
||||
}
|
||||
}
|
||||
|
||||
public Unit Unit {
|
||||
set {
|
||||
EnsureChildControls();
|
||||
if (value == Unit.Empty) {
|
||||
_value.Text = String.Empty;
|
||||
_type.SelectedIndex = 0;
|
||||
}
|
||||
else {
|
||||
_value.Text = value.Value.ToString(CultureInfo.CurrentCulture);
|
||||
_type.SelectedValue = ((int)value.Type).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void CreateChildControls() {
|
||||
Controls.Clear();
|
||||
|
||||
_value = new TextBox();
|
||||
_value.Columns = TextBoxColumns;
|
||||
Controls.Add(_value);
|
||||
|
||||
_type = new DropDownList();
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Pixels),
|
||||
((int)UnitType.Pixel).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Points),
|
||||
((int)UnitType.Point).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Picas),
|
||||
((int)UnitType.Pica).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Inches),
|
||||
((int)UnitType.Inch).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Millimeters),
|
||||
((int)UnitType.Mm).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Centimeters),
|
||||
((int)UnitType.Cm).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Percent),
|
||||
((int)UnitType.Percentage).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Em),
|
||||
((int)UnitType.Em).ToString(CultureInfo.InvariantCulture)));
|
||||
_type.Items.Add(new ListItem(SR.GetString(SR.AppearanceEditorPart_Ex),
|
||||
((int)UnitType.Ex).ToString(CultureInfo.InvariantCulture)));
|
||||
Controls.Add(_type);
|
||||
}
|
||||
|
||||
protected internal override void Render(HtmlTextWriter writer) {
|
||||
// Needed for designtime
|
||||
EnsureChildControls();
|
||||
|
||||
_value.ApplyStyle(ControlStyle);
|
||||
_value.RenderControl(writer);
|
||||
|
||||
writer.Write(" ");
|
||||
|
||||
_type.ApplyStyle(ControlStyle);
|
||||
_type.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,446 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="BehaviorEditorPart.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public sealed class BehaviorEditorPart : EditorPart {
|
||||
|
||||
private CheckBox _allowClose;
|
||||
private CheckBox _allowConnect;
|
||||
private CheckBox _allowHide;
|
||||
private CheckBox _allowMinimize;
|
||||
private CheckBox _allowZoneChange;
|
||||
private DropDownList _exportMode;
|
||||
private DropDownList _helpMode;
|
||||
private TextBox _description;
|
||||
private TextBox _titleUrl;
|
||||
private TextBox _titleIconImageUrl;
|
||||
private TextBox _catalogIconImageUrl;
|
||||
private TextBox _helpUrl;
|
||||
private TextBox _importErrorMessage;
|
||||
private TextBox _authorizationFilter;
|
||||
private CheckBox _allowEdit;
|
||||
|
||||
private string _allowCloseErrorMessage;
|
||||
private string _allowConnectErrorMessage;
|
||||
private string _allowHideErrorMessage;
|
||||
private string _allowMinimizeErrorMessage;
|
||||
private string _allowZoneChangeErrorMessage;
|
||||
private string _exportModeErrorMessage;
|
||||
private string _helpModeErrorMessage;
|
||||
private string _descriptionErrorMessage;
|
||||
private string _titleUrlErrorMessage;
|
||||
private string _titleIconImageUrlErrorMessage;
|
||||
private string _catalogIconImageUrlErrorMessage;
|
||||
private string _helpUrlErrorMessage;
|
||||
private string _importErrorMessageErrorMessage;
|
||||
private string _authorizationFilterErrorMessage;
|
||||
private string _allowEditErrorMessage;
|
||||
|
||||
private const int TextBoxColumns = 30;
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string DefaultButton {
|
||||
get { return base.DefaultButton; }
|
||||
set { base.DefaultButton = value; }
|
||||
}
|
||||
|
||||
public override bool Display {
|
||||
get {
|
||||
if (WebPartToEdit != null &&
|
||||
WebPartToEdit.IsShared &&
|
||||
WebPartManager != null &&
|
||||
(WebPartManager.Personalization.Scope == PersonalizationScope.User)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.Display;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasError {
|
||||
get {
|
||||
return (_allowCloseErrorMessage != null || _allowConnectErrorMessage != null ||
|
||||
_allowHideErrorMessage != null || _allowMinimizeErrorMessage != null ||
|
||||
_allowZoneChangeErrorMessage != null || _exportModeErrorMessage != null ||
|
||||
_helpModeErrorMessage != null || _descriptionErrorMessage != null ||
|
||||
_titleUrlErrorMessage != null || _titleIconImageUrlErrorMessage != null ||
|
||||
_catalogIconImageUrlErrorMessage != null || _helpUrlErrorMessage != null ||
|
||||
_importErrorMessageErrorMessage != null || _authorizationFilterErrorMessage != null ||
|
||||
_allowEditErrorMessage != null);
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
WebSysDefaultValue(SR.BehaviorEditorPart_PartTitle),
|
||||
]
|
||||
public override string Title {
|
||||
get {
|
||||
string s = (string)ViewState["Title"];
|
||||
return (s != null) ? s : SR.GetString(SR.BehaviorEditorPart_PartTitle);
|
||||
}
|
||||
set {
|
||||
ViewState["Title"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool ApplyChanges() {
|
||||
WebPart webPart = WebPartToEdit;
|
||||
|
||||
Debug.Assert(webPart != null);
|
||||
if (webPart != null) {
|
||||
EnsureChildControls();
|
||||
|
||||
bool allowLayoutChange = webPart.Zone.AllowLayoutChange;
|
||||
|
||||
if (allowLayoutChange) {
|
||||
try {
|
||||
webPart.AllowClose = _allowClose.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_allowCloseErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
webPart.AllowConnect = _allowConnect.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_allowConnectErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
if (allowLayoutChange) {
|
||||
try {
|
||||
webPart.AllowHide = _allowHide.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_allowHideErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (allowLayoutChange) {
|
||||
try {
|
||||
webPart.AllowMinimize = _allowMinimize.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_allowMinimizeErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (allowLayoutChange) {
|
||||
try {
|
||||
webPart.AllowZoneChange = _allowZoneChange.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_allowZoneChangeErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TypeConverter exportModeConverter = TypeDescriptor.GetConverter(typeof(WebPartExportMode));
|
||||
webPart.ExportMode = (WebPartExportMode)exportModeConverter.ConvertFromString(_exportMode.SelectedValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_exportModeErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
TypeConverter helpModeConverter = TypeDescriptor.GetConverter(typeof(WebPartHelpMode));
|
||||
webPart.HelpMode = (WebPartHelpMode)helpModeConverter.ConvertFromString(_helpMode.SelectedValue);
|
||||
}
|
||||
catch (Exception e) {
|
||||
_helpModeErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
webPart.Description = _description.Text;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_descriptionErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
string value = _titleUrl.Text;
|
||||
if (CrossSiteScriptingValidation.IsDangerousUrl(value)) {
|
||||
_titleUrlErrorMessage = SR.GetString(SR.EditorPart_ErrorBadUrl);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
webPart.TitleUrl = value;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_titleUrlErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
value = _titleIconImageUrl.Text;
|
||||
if (CrossSiteScriptingValidation.IsDangerousUrl(value)) {
|
||||
_titleIconImageUrlErrorMessage = SR.GetString(SR.EditorPart_ErrorBadUrl);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
webPart.TitleIconImageUrl = value;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_titleIconImageUrlErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
value = _catalogIconImageUrl.Text;
|
||||
if (CrossSiteScriptingValidation.IsDangerousUrl(value)) {
|
||||
_catalogIconImageUrlErrorMessage = SR.GetString(SR.EditorPart_ErrorBadUrl);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
webPart.CatalogIconImageUrl = value;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_catalogIconImageUrlErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
value = _helpUrl.Text;
|
||||
if (CrossSiteScriptingValidation.IsDangerousUrl(value)) {
|
||||
_helpUrlErrorMessage = SR.GetString(SR.EditorPart_ErrorBadUrl);
|
||||
}
|
||||
else {
|
||||
try {
|
||||
webPart.HelpUrl = value;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_helpUrlErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
webPart.ImportErrorMessage = _importErrorMessage.Text;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_importErrorMessageErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
webPart.AuthorizationFilter = _authorizationFilter.Text;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_authorizationFilterErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
webPart.AllowEdit = _allowEdit.Checked;
|
||||
}
|
||||
catch (Exception e) {
|
||||
_allowEditErrorMessage = CreateErrorMessage(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
return !HasError;
|
||||
}
|
||||
|
||||
protected internal override void CreateChildControls() {
|
||||
ControlCollection controls = Controls;
|
||||
controls.Clear();
|
||||
|
||||
_allowClose = new CheckBox();
|
||||
controls.Add(_allowClose);
|
||||
|
||||
_allowConnect = new CheckBox();
|
||||
controls.Add(_allowConnect);
|
||||
|
||||
_allowHide = new CheckBox();
|
||||
controls.Add(_allowHide);
|
||||
|
||||
_allowMinimize = new CheckBox();
|
||||
controls.Add(_allowMinimize);
|
||||
|
||||
_allowZoneChange = new CheckBox();
|
||||
controls.Add(_allowZoneChange);
|
||||
|
||||
TypeConverter exportModeConverter = TypeDescriptor.GetConverter(typeof(WebPartExportMode));
|
||||
_exportMode = new DropDownList();
|
||||
_exportMode.Items.AddRange(new ListItem[] {
|
||||
new ListItem(SR.GetString(SR.BehaviorEditorPart_ExportModeNone),
|
||||
exportModeConverter.ConvertToString(WebPartExportMode.None)),
|
||||
new ListItem(SR.GetString(SR.BehaviorEditorPart_ExportModeAll),
|
||||
exportModeConverter.ConvertToString(WebPartExportMode.All)),
|
||||
new ListItem(SR.GetString(SR.BehaviorEditorPart_ExportModeNonSensitiveData),
|
||||
exportModeConverter.ConvertToString(WebPartExportMode.NonSensitiveData)),
|
||||
});
|
||||
controls.Add(_exportMode);
|
||||
|
||||
TypeConverter helpModeConverter = TypeDescriptor.GetConverter(typeof(WebPartHelpMode));
|
||||
_helpMode = new DropDownList();
|
||||
_helpMode.Items.AddRange(new ListItem[] {
|
||||
new ListItem(SR.GetString(SR.BehaviorEditorPart_HelpModeModal),
|
||||
helpModeConverter.ConvertToString(WebPartHelpMode.Modal)),
|
||||
new ListItem(SR.GetString(SR.BehaviorEditorPart_HelpModeModeless),
|
||||
helpModeConverter.ConvertToString(WebPartHelpMode.Modeless)),
|
||||
new ListItem(SR.GetString(SR.BehaviorEditorPart_HelpModeNavigate),
|
||||
helpModeConverter.ConvertToString(WebPartHelpMode.Navigate)),
|
||||
});
|
||||
controls.Add(_helpMode);
|
||||
|
||||
_description = new TextBox();
|
||||
_description.Columns = TextBoxColumns;
|
||||
controls.Add(_description);
|
||||
|
||||
_titleUrl = new TextBox();
|
||||
_titleUrl.Columns = TextBoxColumns;
|
||||
controls.Add(_titleUrl);
|
||||
|
||||
_titleIconImageUrl = new TextBox();
|
||||
_titleIconImageUrl.Columns = TextBoxColumns;
|
||||
controls.Add(_titleIconImageUrl);
|
||||
|
||||
_catalogIconImageUrl = new TextBox();
|
||||
_catalogIconImageUrl.Columns = TextBoxColumns;
|
||||
controls.Add(_catalogIconImageUrl);
|
||||
|
||||
_helpUrl = new TextBox();
|
||||
_helpUrl.Columns = TextBoxColumns;
|
||||
controls.Add(_helpUrl);
|
||||
|
||||
_importErrorMessage = new TextBox();
|
||||
_importErrorMessage.Columns = TextBoxColumns;
|
||||
controls.Add(_importErrorMessage);
|
||||
|
||||
_authorizationFilter = new TextBox();
|
||||
_authorizationFilter.Columns = TextBoxColumns;
|
||||
controls.Add(_authorizationFilter);
|
||||
|
||||
_allowEdit = new CheckBox();
|
||||
controls.Add(_allowEdit);
|
||||
|
||||
// We don't need viewstate enabled on our child controls. Disable for perf.
|
||||
foreach (Control c in controls) {
|
||||
c.EnableViewState = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void OnPreRender(EventArgs e) {
|
||||
base.OnPreRender(e);
|
||||
|
||||
// We want to synchronize the EditorPart to the state of the WebPart on every page load,
|
||||
// so we stay current if the WebPart changes in the background.
|
||||
if (Display && Visible && !HasError) {
|
||||
SyncChanges();
|
||||
}
|
||||
}
|
||||
|
||||
protected internal override void RenderContents(HtmlTextWriter writer) {
|
||||
if (Page != null) {
|
||||
Page.VerifyRenderingInServerForm(this);
|
||||
}
|
||||
|
||||
// HACK: Need this for child controls to be created at design-time when control is inside template
|
||||
EnsureChildControls();
|
||||
|
||||
string[] propertyDisplayNames = new string[] {
|
||||
SR.GetString(SR.BehaviorEditorPart_Description),
|
||||
SR.GetString(SR.BehaviorEditorPart_TitleLink),
|
||||
SR.GetString(SR.BehaviorEditorPart_TitleIconImageLink),
|
||||
SR.GetString(SR.BehaviorEditorPart_CatalogIconImageLink),
|
||||
SR.GetString(SR.BehaviorEditorPart_HelpLink),
|
||||
SR.GetString(SR.BehaviorEditorPart_HelpMode),
|
||||
SR.GetString(SR.BehaviorEditorPart_ImportErrorMessage),
|
||||
SR.GetString(SR.BehaviorEditorPart_ExportMode),
|
||||
SR.GetString(SR.BehaviorEditorPart_AuthorizationFilter),
|
||||
SR.GetString(SR.BehaviorEditorPart_AllowClose),
|
||||
SR.GetString(SR.BehaviorEditorPart_AllowConnect),
|
||||
SR.GetString(SR.BehaviorEditorPart_AllowEdit),
|
||||
SR.GetString(SR.BehaviorEditorPart_AllowHide),
|
||||
SR.GetString(SR.BehaviorEditorPart_AllowMinimize),
|
||||
SR.GetString(SR.BehaviorEditorPart_AllowZoneChange),
|
||||
};
|
||||
|
||||
WebControl[] propertyEditors = new WebControl[] {
|
||||
_description,
|
||||
_titleUrl,
|
||||
_titleIconImageUrl,
|
||||
_catalogIconImageUrl,
|
||||
_helpUrl,
|
||||
_helpMode,
|
||||
_importErrorMessage,
|
||||
_exportMode,
|
||||
_authorizationFilter,
|
||||
_allowClose,
|
||||
_allowConnect,
|
||||
_allowEdit,
|
||||
_allowHide,
|
||||
_allowMinimize,
|
||||
_allowZoneChange,
|
||||
};
|
||||
|
||||
string[] errorMessages = new string[] {
|
||||
_descriptionErrorMessage,
|
||||
_titleUrlErrorMessage,
|
||||
_titleIconImageUrlErrorMessage,
|
||||
_catalogIconImageUrlErrorMessage,
|
||||
_helpUrlErrorMessage,
|
||||
_helpModeErrorMessage,
|
||||
_importErrorMessageErrorMessage,
|
||||
_exportModeErrorMessage,
|
||||
_authorizationFilterErrorMessage,
|
||||
_allowCloseErrorMessage,
|
||||
_allowConnectErrorMessage,
|
||||
_allowEditErrorMessage,
|
||||
_allowHideErrorMessage,
|
||||
_allowMinimizeErrorMessage,
|
||||
_allowZoneChangeErrorMessage,
|
||||
};
|
||||
|
||||
RenderPropertyEditors(writer, propertyDisplayNames, null /* propertyDescriptions */,
|
||||
propertyEditors, errorMessages);
|
||||
}
|
||||
|
||||
public override void SyncChanges() {
|
||||
WebPart webPart = WebPartToEdit;
|
||||
|
||||
Debug.Assert(webPart != null);
|
||||
if (webPart != null) {
|
||||
bool allowLayoutChange = webPart.Zone.AllowLayoutChange;
|
||||
|
||||
EnsureChildControls();
|
||||
_allowClose.Checked = webPart.AllowClose;
|
||||
_allowClose.Enabled = allowLayoutChange;
|
||||
|
||||
_allowConnect.Checked = webPart.AllowConnect;
|
||||
|
||||
_allowHide.Checked = webPart.AllowHide;
|
||||
_allowHide.Enabled = allowLayoutChange;
|
||||
|
||||
_allowMinimize.Checked = webPart.AllowMinimize;
|
||||
_allowMinimize.Enabled = allowLayoutChange;
|
||||
|
||||
_allowZoneChange.Checked = webPart.AllowZoneChange;
|
||||
_allowZoneChange.Enabled = allowLayoutChange;
|
||||
|
||||
TypeConverter exportModeConverter = TypeDescriptor.GetConverter(typeof(WebPartExportMode));
|
||||
_exportMode.SelectedValue = exportModeConverter.ConvertToString(webPart.ExportMode);
|
||||
|
||||
TypeConverter helpModeConverter = TypeDescriptor.GetConverter(typeof(WebPartHelpMode));
|
||||
_helpMode.SelectedValue = helpModeConverter.ConvertToString(webPart.HelpMode);
|
||||
|
||||
_description.Text = webPart.Description;
|
||||
_titleUrl.Text = webPart.TitleUrl;
|
||||
_titleIconImageUrl.Text = webPart.TitleIconImageUrl;
|
||||
_catalogIconImageUrl.Text = webPart.CatalogIconImageUrl;
|
||||
_helpUrl.Text = webPart.HelpUrl;
|
||||
_importErrorMessage.Text = webPart.ImportErrorMessage;
|
||||
_authorizationFilter.Text = webPart.AuthorizationFilter;
|
||||
_allowEdit.Checked = webPart.AllowEdit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,93 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CatalogPart.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Security.Permissions;
|
||||
using System.Web.UI;
|
||||
|
||||
/// <devdoc>
|
||||
/// Provides default rendering and part selection UI
|
||||
/// </devdoc>
|
||||
[
|
||||
Bindable(false),
|
||||
Designer("System.Web.UI.Design.WebControls.WebParts.CatalogPartDesigner, " + AssemblyRef.SystemDesign),
|
||||
]
|
||||
public abstract class CatalogPart : Part {
|
||||
|
||||
private WebPartManager _webPartManager;
|
||||
private CatalogZoneBase _zone;
|
||||
|
||||
[
|
||||
Browsable(false),
|
||||
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
|
||||
]
|
||||
public string DisplayTitle {
|
||||
get {
|
||||
string displayTitle = Title;
|
||||
if (String.IsNullOrEmpty(displayTitle)) {
|
||||
displayTitle = SR.GetString(SR.Part_Untitled);
|
||||
}
|
||||
return displayTitle;
|
||||
}
|
||||
}
|
||||
|
||||
protected WebPartManager WebPartManager {
|
||||
get {
|
||||
return _webPartManager;
|
||||
}
|
||||
}
|
||||
|
||||
protected CatalogZoneBase Zone {
|
||||
get {
|
||||
return _zone;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract WebPartDescriptionCollection GetAvailableWebPartDescriptions();
|
||||
|
||||
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
|
||||
protected override IDictionary GetDesignModeState() {
|
||||
IDictionary state = new HybridDictionary(1);
|
||||
state["Zone"] = Zone;
|
||||
return state;
|
||||
}
|
||||
|
||||
public abstract WebPart GetWebPart(WebPartDescription description);
|
||||
|
||||
protected internal override void OnPreRender(EventArgs e) {
|
||||
base.OnPreRender(e);
|
||||
|
||||
if (Zone == null) {
|
||||
throw new InvalidOperationException(SR.GetString(SR.CatalogPart_MustBeInZone, ID));
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
|
||||
protected override void SetDesignModeState(IDictionary data) {
|
||||
if (data != null) {
|
||||
object o = data["Zone"];
|
||||
if (o != null) {
|
||||
SetZone((CatalogZoneBase)o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetWebPartManager(WebPartManager webPartManager) {
|
||||
_webPartManager = webPartManager;
|
||||
}
|
||||
|
||||
internal void SetZone(CatalogZoneBase zone) {
|
||||
_zone = zone;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CatalogPartChrome.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public class CatalogPartChrome {
|
||||
|
||||
private CatalogZoneBase _zone;
|
||||
|
||||
// PERF: Cache these, since they are needed for every CatalogPart in the zone
|
||||
private Page _page;
|
||||
private Style _chromeStyleWithBorder;
|
||||
private Style _chromeStyleNoBorder;
|
||||
|
||||
public CatalogPartChrome(CatalogZoneBase zone) {
|
||||
if (zone == null) {
|
||||
throw new ArgumentNullException("zone");
|
||||
}
|
||||
_zone = zone;
|
||||
_page = zone.Page;
|
||||
}
|
||||
|
||||
protected CatalogZoneBase Zone {
|
||||
get {
|
||||
return _zone;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Style CreateCatalogPartChromeStyle(CatalogPart catalogPart, PartChromeType chromeType) {
|
||||
if (catalogPart == null) {
|
||||
throw new ArgumentNullException("catalogPart");
|
||||
}
|
||||
if ((chromeType < PartChromeType.Default) || (chromeType > PartChromeType.BorderOnly)) {
|
||||
throw new ArgumentOutOfRangeException("chromeType");
|
||||
}
|
||||
|
||||
if (chromeType == PartChromeType.BorderOnly || chromeType == PartChromeType.TitleAndBorder) {
|
||||
if (_chromeStyleWithBorder == null) {
|
||||
Style style = new Style();
|
||||
style.CopyFrom(Zone.PartChromeStyle);
|
||||
|
||||
if (style.BorderStyle == BorderStyle.NotSet) {
|
||||
style.BorderStyle = BorderStyle.Solid;
|
||||
}
|
||||
if (style.BorderWidth == Unit.Empty) {
|
||||
style.BorderWidth = Unit.Pixel(1);
|
||||
}
|
||||
if (style.BorderColor == Color.Empty) {
|
||||
style.BorderColor = Color.Black;
|
||||
}
|
||||
|
||||
_chromeStyleWithBorder = style;
|
||||
}
|
||||
return _chromeStyleWithBorder;
|
||||
}
|
||||
else {
|
||||
if (_chromeStyleNoBorder == null) {
|
||||
Style style = new Style();
|
||||
style.CopyFrom(Zone.PartChromeStyle);
|
||||
|
||||
if (style.BorderStyle != BorderStyle.NotSet) {
|
||||
style.BorderStyle = BorderStyle.NotSet;
|
||||
}
|
||||
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 RenderCatalogPart(HtmlTextWriter writer, CatalogPart catalogPart) {
|
||||
if (catalogPart == null) {
|
||||
throw new ArgumentNullException("catalogPart");
|
||||
}
|
||||
|
||||
PartChromeType chromeType = Zone.GetEffectiveChromeType(catalogPart);
|
||||
Style partChromeStyle = CreateCatalogPartChromeStyle(catalogPart, chromeType);
|
||||
|
||||
//
|
||||
if (!partChromeStyle.IsEmpty) {
|
||||
partChromeStyle.AddAttributesToRender(writer, Zone);
|
||||
}
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
|
||||
// Use CellPadding=2 to match WebPartChrome (VSWhidbey 324397)
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "2");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
|
||||
|
||||
writer.AddStyleAttribute(HtmlTextWriterStyle.Width, "100%");
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Table);
|
||||
|
||||
if (chromeType == PartChromeType.TitleOnly || chromeType == PartChromeType.TitleAndBorder) {
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
|
||||
// Can apply PartTitleStyle directly, since the title bar doesn't contain a nested table
|
||||
Style partTitleStyle = Zone.PartTitleStyle;
|
||||
if (!partTitleStyle.IsEmpty) {
|
||||
partTitleStyle.AddAttributesToRender(writer, Zone);
|
||||
}
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
|
||||
RenderTitle(writer, catalogPart);
|
||||
|
||||
writer.RenderEndTag(); // Td
|
||||
writer.RenderEndTag(); // Tr
|
||||
}
|
||||
|
||||
if (catalogPart.ChromeState != PartChromeState.Minimized) {
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
Style partStyle = Zone.PartStyle;
|
||||
if (!partStyle.IsEmpty) {
|
||||
partStyle.AddAttributesToRender(writer, Zone);
|
||||
}
|
||||
|
||||
// For now, I don't think we should render extra padding here. People writing custom
|
||||
// CatalogParts can add a margin to their contents if they want it. This is not the
|
||||
// same as the WebPartChrome case, since for WebParts we allow people to use ServerControls,
|
||||
// that will likely not have a margin. (VSWhidbey 324397)
|
||||
// writer.AddStyleAttribute(HtmlTextWriterStyle.Padding, "5px");
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
|
||||
//
|
||||
RenderPartContents(writer, catalogPart);
|
||||
|
||||
RenderItems(writer, catalogPart);
|
||||
|
||||
writer.RenderEndTag(); // Td
|
||||
writer.RenderEndTag(); // Tr
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // Table
|
||||
}
|
||||
|
||||
private void RenderItem(HtmlTextWriter writer, WebPartDescription webPartDescription) {
|
||||
string description = webPartDescription.Description;
|
||||
if (String.IsNullOrEmpty(description)) {
|
||||
description = webPartDescription.Title;
|
||||
}
|
||||
|
||||
RenderItemCheckBox(writer, webPartDescription.ID);
|
||||
|
||||
writer.Write(" ");
|
||||
|
||||
if (Zone.ShowCatalogIcons) {
|
||||
string icon = webPartDescription.CatalogIconImageUrl;
|
||||
if (!String.IsNullOrEmpty(icon)) {
|
||||
RenderItemIcon(writer, icon, description);
|
||||
writer.Write(" ");
|
||||
}
|
||||
}
|
||||
|
||||
RenderItemText(writer, webPartDescription.ID, webPartDescription.Title, description);
|
||||
|
||||
writer.WriteBreak();
|
||||
}
|
||||
|
||||
private void RenderItemCheckBox(HtmlTextWriter writer, string value) {
|
||||
Zone.EditUIStyle.AddAttributesToRender(writer, Zone);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Type, "checkbox");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Id, Zone.GetCheckBoxID(value));
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Name, Zone.CheckBoxName);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Value, value);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Input);
|
||||
writer.RenderEndTag(); // Input
|
||||
|
||||
if (_page != null) {
|
||||
_page.ClientScript.RegisterForEventValidation(Zone.CheckBoxName);
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderItemIcon(HtmlTextWriter writer, string iconUrl, string description) {
|
||||
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
|
||||
img.AlternateText = description;
|
||||
|
||||
//
|
||||
img.ImageUrl = iconUrl;
|
||||
img.BorderStyle = BorderStyle.None;
|
||||
img.Page = _page;
|
||||
img.RenderControl(writer);
|
||||
}
|
||||
|
||||
private void RenderItemText(HtmlTextWriter writer, string value, string text, string description) {
|
||||
Zone.LabelStyle.AddAttributesToRender(writer, Zone);
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.For, Zone.GetCheckBoxID(value));
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Title, description, true /* fEncode */);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Label);
|
||||
writer.WriteEncodedText(text);
|
||||
writer.RenderEndTag();
|
||||
}
|
||||
|
||||
private void RenderItems(HtmlTextWriter writer, CatalogPart catalogPart) {
|
||||
WebPartDescriptionCollection availableWebParts = catalogPart.GetAvailableWebPartDescriptions();
|
||||
|
||||
if (availableWebParts != null) {
|
||||
foreach (WebPartDescription webPartDescription in availableWebParts) {
|
||||
RenderItem(writer, webPartDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void RenderPartContents(HtmlTextWriter writer, CatalogPart catalogPart) {
|
||||
if (catalogPart == null) {
|
||||
throw new ArgumentNullException("catalogPart");
|
||||
}
|
||||
catalogPart.RenderControl(writer);
|
||||
}
|
||||
|
||||
private void RenderTitle(HtmlTextWriter writer, CatalogPart catalogPart) {
|
||||
Label label = new Label();
|
||||
label.Text = catalogPart.DisplayTitle;
|
||||
label.ToolTip = catalogPart.Description;
|
||||
label.Page = _page;
|
||||
label.RenderControl(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CatalogPartCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
|
||||
public sealed class CatalogPartCollection : ReadOnlyCollectionBase {
|
||||
|
||||
public static readonly CatalogPartCollection Empty = new CatalogPartCollection();
|
||||
|
||||
public CatalogPartCollection() {
|
||||
}
|
||||
|
||||
public CatalogPartCollection(ICollection catalogParts) {
|
||||
Initialize(null, catalogParts);
|
||||
}
|
||||
|
||||
public CatalogPartCollection(CatalogPartCollection existingCatalogParts, ICollection catalogParts) {
|
||||
Initialize(existingCatalogParts, catalogParts);
|
||||
}
|
||||
|
||||
public CatalogPart this[int index] {
|
||||
get {
|
||||
return (CatalogPart) InnerList[index];
|
||||
}
|
||||
}
|
||||
|
||||
public CatalogPart this[string id] {
|
||||
get {
|
||||
foreach (CatalogPart catalogPart in InnerList) {
|
||||
if (String.Equals(catalogPart.ID, id, StringComparison.OrdinalIgnoreCase)) {
|
||||
return catalogPart;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
internal int Add(CatalogPart value) {
|
||||
return InnerList.Add(value);
|
||||
}
|
||||
|
||||
public bool Contains(CatalogPart catalogPart) {
|
||||
return InnerList.Contains(catalogPart);
|
||||
}
|
||||
|
||||
public void CopyTo(CatalogPart[] array, int index) {
|
||||
InnerList.CopyTo(array, index);
|
||||
}
|
||||
|
||||
public int IndexOf(CatalogPart catalogPart) {
|
||||
return InnerList.IndexOf(catalogPart);
|
||||
}
|
||||
|
||||
private void Initialize(CatalogPartCollection existingCatalogParts, ICollection catalogParts) {
|
||||
if (existingCatalogParts != null) {
|
||||
foreach (CatalogPart existingCatalogPart in existingCatalogParts) {
|
||||
// Don't need to check arg, since we know it is valid since it came
|
||||
// from a CatalogPartCollection.
|
||||
InnerList.Add(existingCatalogPart);
|
||||
}
|
||||
}
|
||||
|
||||
if (catalogParts != null) {
|
||||
foreach (object obj in catalogParts) {
|
||||
if (obj == null) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "catalogParts");
|
||||
}
|
||||
if (!(obj is CatalogPart)) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "CatalogPart"), "catalogParts");
|
||||
}
|
||||
InnerList.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CatalogZone.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.Util;
|
||||
|
||||
[
|
||||
Designer("System.Web.UI.Design.WebControls.WebParts.CatalogZoneDesigner, " + AssemblyRef.SystemDesign),
|
||||
SupportsEventValidation,
|
||||
]
|
||||
public class CatalogZone : CatalogZoneBase {
|
||||
|
||||
private ITemplate _zoneTemplate;
|
||||
|
||||
protected override CatalogPartCollection CreateCatalogParts() {
|
||||
CatalogPartCollection catalogParts = new CatalogPartCollection();
|
||||
|
||||
if (_zoneTemplate != null) {
|
||||
// PERF: Instantiate the template into a special control, that does nothing when a child control
|
||||
// is added. This is more performant because the child control is never parented to the temporary
|
||||
// control, it's ID is never generated, etc.
|
||||
Control container = new NonParentingControl();
|
||||
|
||||
_zoneTemplate.InstantiateIn(container);
|
||||
if (container.HasControls()) {
|
||||
foreach (Control control in container.Controls) {
|
||||
CatalogPart part = control as CatalogPart;
|
||||
|
||||
if (part != null) {
|
||||
catalogParts.Add(part);
|
||||
}
|
||||
else {
|
||||
LiteralControl literal = control as LiteralControl;
|
||||
// Throw an exception if it is *not* a literal containing only whitespace
|
||||
// Don't throw an exception in the designer, since we want only the offending
|
||||
// control to render as an error block, not the whole CatalogZone.
|
||||
if (((literal == null) || (literal.Text.Trim().Length != 0)) && !DesignMode) {
|
||||
throw new InvalidOperationException(SR.GetString(SR.CatalogZone_OnlyCatalogParts, ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return catalogParts;
|
||||
}
|
||||
|
||||
[
|
||||
Browsable(false),
|
||||
DefaultValue(null),
|
||||
PersistenceMode(PersistenceMode.InnerProperty),
|
||||
TemplateContainer(typeof(CatalogZone)),
|
||||
TemplateInstance(TemplateInstance.Single)
|
||||
]
|
||||
public virtual ITemplate ZoneTemplate {
|
||||
get {
|
||||
return _zoneTemplate;
|
||||
}
|
||||
set {
|
||||
InvalidateCatalogParts();
|
||||
_zoneTemplate = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConnectionConsumerAttribute.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class ConnectionConsumerAttribute : Attribute {
|
||||
|
||||
private string _displayName;
|
||||
private string _id;
|
||||
private Type _connectionPointType;
|
||||
private bool _allowsMultipleConnections;
|
||||
|
||||
public ConnectionConsumerAttribute(string displayName) {
|
||||
if (String.IsNullOrEmpty(displayName)) {
|
||||
throw new ArgumentNullException("displayName");
|
||||
}
|
||||
|
||||
_displayName = displayName;
|
||||
_allowsMultipleConnections = false;
|
||||
}
|
||||
|
||||
public ConnectionConsumerAttribute(string displayName, string id) : this(displayName) {
|
||||
if (String.IsNullOrEmpty(id)) {
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public ConnectionConsumerAttribute(string displayName, Type connectionPointType) : this(displayName) {
|
||||
if (connectionPointType == null) {
|
||||
throw new ArgumentNullException("connectionPointType");
|
||||
}
|
||||
|
||||
_connectionPointType = connectionPointType;
|
||||
}
|
||||
|
||||
public ConnectionConsumerAttribute(string displayName, string id, Type connectionPointType) : this(displayName, connectionPointType) {
|
||||
if (String.IsNullOrEmpty(id)) {
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public bool AllowsMultipleConnections {
|
||||
get {
|
||||
return _allowsMultipleConnections;
|
||||
}
|
||||
set {
|
||||
_allowsMultipleConnections = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ID {
|
||||
get {
|
||||
return (_id != null) ? _id : String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string DisplayName {
|
||||
get {
|
||||
return DisplayNameValue;
|
||||
}
|
||||
}
|
||||
|
||||
protected string DisplayNameValue {
|
||||
get {
|
||||
return _displayName;
|
||||
}
|
||||
set {
|
||||
_displayName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Type ConnectionPointType {
|
||||
get {
|
||||
if (WebPartUtil.IsConnectionPointTypeValid(_connectionPointType, /*isConsumer*/ true)) {
|
||||
return _connectionPointType;
|
||||
}
|
||||
else {
|
||||
throw new InvalidOperationException(SR.GetString(SR.ConnectionConsumerAttribute_InvalidConnectionPointType, _connectionPointType.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConnectionInterfaceCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
|
||||
public sealed class ConnectionInterfaceCollection : ReadOnlyCollectionBase {
|
||||
|
||||
public static readonly ConnectionInterfaceCollection Empty = new ConnectionInterfaceCollection();
|
||||
|
||||
public ConnectionInterfaceCollection() {
|
||||
}
|
||||
|
||||
public ConnectionInterfaceCollection(ICollection connectionInterfaces) {
|
||||
Initialize(null, connectionInterfaces);
|
||||
}
|
||||
|
||||
public ConnectionInterfaceCollection(ConnectionInterfaceCollection existingConnectionInterfaces,
|
||||
ICollection connectionInterfaces) {
|
||||
Initialize(existingConnectionInterfaces, connectionInterfaces);
|
||||
}
|
||||
|
||||
private void Initialize(ConnectionInterfaceCollection existingConnectionInterfaces, ICollection connectionInterfaces) {
|
||||
if (existingConnectionInterfaces != null) {
|
||||
foreach (Type existingConnectionInterface in existingConnectionInterfaces) {
|
||||
// Don't need to check arg, since we know it is valid since it came
|
||||
// from a ConnectionInterfaceCollection.
|
||||
InnerList.Add(existingConnectionInterface);
|
||||
}
|
||||
}
|
||||
|
||||
if (connectionInterfaces != null) {
|
||||
foreach (object obj in connectionInterfaces) {
|
||||
if (obj == null) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "connectionInterfaces");
|
||||
}
|
||||
if (!(obj is Type)) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "Type"), "connectionInterfaces");
|
||||
}
|
||||
InnerList.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(Type value) {
|
||||
return InnerList.Contains(value);
|
||||
}
|
||||
|
||||
public int IndexOf(Type value) {
|
||||
return InnerList.IndexOf(value);
|
||||
}
|
||||
|
||||
public Type this[int index] {
|
||||
get {
|
||||
return (Type)InnerList[index];
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyTo(Type[] array, int index) {
|
||||
InnerList.CopyTo(array, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConnectionPoint.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Util;
|
||||
|
||||
/// <devdoc>
|
||||
/// A ConnectionPoint defines a possible connection. A WebPart uses this
|
||||
/// to define the connections it can provide or consume.
|
||||
/// </devdoc>
|
||||
public abstract class ConnectionPoint {
|
||||
private MethodInfo _callbackMethod;
|
||||
private Type _controlType;
|
||||
private Type _interfaceType;
|
||||
private string _displayName;
|
||||
private string _id;
|
||||
private bool _allowsMultipleConnections;
|
||||
|
||||
// We do not want the public field to be "const", since that means we can never change its value.
|
||||
// We want the internal const field so we can use it in attributes.
|
||||
public static readonly string DefaultID = DefaultIDInternal;
|
||||
internal const string DefaultIDInternal = "default";
|
||||
|
||||
//
|
||||
|
||||
internal ConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType, string displayName, string id, bool allowsMultipleConnections) {
|
||||
if (callbackMethod == null) {
|
||||
throw new ArgumentNullException("callbackMethod");
|
||||
}
|
||||
|
||||
if (interfaceType == null) {
|
||||
throw new ArgumentNullException("interfaceType");
|
||||
}
|
||||
|
||||
if (controlType == null) {
|
||||
throw new ArgumentNullException("controlType");
|
||||
}
|
||||
|
||||
if (!controlType.IsSubclassOf(typeof(Control))) {
|
||||
throw new ArgumentException(SR.GetString(SR.ConnectionPoint_InvalidControlType), "controlType");
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(displayName)) {
|
||||
throw new ArgumentNullException("displayName");
|
||||
}
|
||||
|
||||
_callbackMethod = callbackMethod;
|
||||
_interfaceType = interfaceType;
|
||||
_controlType = controlType;
|
||||
_displayName = displayName;
|
||||
_id = id;
|
||||
_allowsMultipleConnections = allowsMultipleConnections;
|
||||
}
|
||||
|
||||
public bool AllowsMultipleConnections {
|
||||
get {
|
||||
return _allowsMultipleConnections;
|
||||
}
|
||||
}
|
||||
|
||||
internal MethodInfo CallbackMethod {
|
||||
get {
|
||||
return _callbackMethod;
|
||||
}
|
||||
}
|
||||
|
||||
public Type ControlType {
|
||||
get {
|
||||
return _controlType;
|
||||
}
|
||||
}
|
||||
|
||||
public Type InterfaceType {
|
||||
get {
|
||||
return _interfaceType;
|
||||
}
|
||||
}
|
||||
|
||||
public string ID {
|
||||
get {
|
||||
return (!String.IsNullOrEmpty(_id)) ? _id : DefaultID;
|
||||
}
|
||||
}
|
||||
|
||||
public string DisplayName {
|
||||
get {
|
||||
return _displayName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// Base implementation returns true, can be overridden by subclasses to return
|
||||
/// true or false conditionally based on the state of the Control.
|
||||
/// </devdoc>
|
||||
public virtual bool GetEnabled(Control control) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConnectionProviderAttribute.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public class ConnectionProviderAttribute : Attribute {
|
||||
|
||||
private string _displayName;
|
||||
private string _id;
|
||||
private Type _connectionPointType;
|
||||
private bool _allowsMultipleConnections;
|
||||
|
||||
public ConnectionProviderAttribute(string displayName) {
|
||||
if (String.IsNullOrEmpty(displayName)) {
|
||||
throw new ArgumentNullException("displayName");
|
||||
}
|
||||
|
||||
_displayName = displayName;
|
||||
_allowsMultipleConnections = true;
|
||||
}
|
||||
|
||||
public ConnectionProviderAttribute(string displayName, string id) : this(displayName) {
|
||||
if (String.IsNullOrEmpty(id)) {
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public ConnectionProviderAttribute(string displayName, Type connectionPointType) : this(displayName) {
|
||||
if (connectionPointType == null) {
|
||||
throw new ArgumentNullException("connectionPointType");
|
||||
}
|
||||
|
||||
_connectionPointType = connectionPointType;
|
||||
}
|
||||
|
||||
public ConnectionProviderAttribute(string displayName, string id, Type connectionPointType) : this(displayName, connectionPointType) {
|
||||
if (String.IsNullOrEmpty(id)) {
|
||||
throw new ArgumentNullException("id");
|
||||
}
|
||||
|
||||
_id = id;
|
||||
}
|
||||
|
||||
public bool AllowsMultipleConnections {
|
||||
get {
|
||||
return _allowsMultipleConnections;
|
||||
}
|
||||
set {
|
||||
_allowsMultipleConnections = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string ID {
|
||||
get {
|
||||
return (_id != null) ? _id : String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual string DisplayName {
|
||||
get {
|
||||
return DisplayNameValue;
|
||||
}
|
||||
}
|
||||
|
||||
protected string DisplayNameValue {
|
||||
get {
|
||||
return _displayName;
|
||||
}
|
||||
set {
|
||||
_displayName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Type ConnectionPointType {
|
||||
get {
|
||||
if (WebPartUtil.IsConnectionPointTypeValid(_connectionPointType, /*isConsumer*/ false)) {
|
||||
return _connectionPointType;
|
||||
}
|
||||
else {
|
||||
throw new InvalidOperationException(SR.GetString(SR.ConnectionProviderAttribute_InvalidConnectionPointType, _connectionPointType.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
fd80547440153122a0d80f985486bfd75560530a
|
||||
@@ -0,0 +1,47 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConsumerConnectionPoint.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Util;
|
||||
|
||||
public class ConsumerConnectionPoint : ConnectionPoint {
|
||||
// Used by WebPartManager to verify the custom ConnectionPoint type has
|
||||
// the correct constructor signature.
|
||||
internal static readonly Type[] ConstructorTypes;
|
||||
|
||||
static ConsumerConnectionPoint() {
|
||||
ConstructorInfo constructor = typeof(ConsumerConnectionPoint).GetConstructors()[0];
|
||||
ConstructorTypes = WebPartUtil.GetTypesForConstructor(constructor);
|
||||
}
|
||||
|
||||
public ConsumerConnectionPoint(MethodInfo callbackMethod, Type interfaceType, Type controlType,
|
||||
string displayName, string id, bool allowsMultipleConnections) : base(
|
||||
callbackMethod, interfaceType, controlType, displayName, id, allowsMultipleConnections) {
|
||||
}
|
||||
|
||||
public virtual void SetObject(Control control, object data) {
|
||||
if (control == null) {
|
||||
throw new ArgumentNullException("control");
|
||||
}
|
||||
|
||||
CallbackMethod.Invoke(control, new object[] {data});
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// Base implementation returns true, can be overridden by subclasses to return
|
||||
/// true or false conditionally based on the available secondary interfaces and the state
|
||||
/// of the consumer WebPart passed in.
|
||||
/// </devdoc>
|
||||
public virtual bool SupportsConnection(Control control, ConnectionInterfaceCollection secondaryInterfaces) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConsumerConnectionPointCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
|
||||
public sealed class ConsumerConnectionPointCollection : ReadOnlyCollectionBase {
|
||||
|
||||
private HybridDictionary _ids;
|
||||
|
||||
public ConsumerConnectionPointCollection() {
|
||||
}
|
||||
|
||||
public ConsumerConnectionPointCollection(ICollection connectionPoints) {
|
||||
if (connectionPoints == null) {
|
||||
throw new ArgumentNullException("connectionPoints");
|
||||
}
|
||||
|
||||
_ids = new HybridDictionary(connectionPoints.Count, true /* caseInsensitive */);
|
||||
foreach (object obj in connectionPoints) {
|
||||
if (obj == null) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "connectionPoints");
|
||||
}
|
||||
ConsumerConnectionPoint point = obj as ConsumerConnectionPoint;
|
||||
if (point == null) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "ConsumerConnectionPoint"),
|
||||
"connectionPoints");
|
||||
}
|
||||
string id = point.ID;
|
||||
if (!_ids.Contains(id)) {
|
||||
InnerList.Add(point);
|
||||
_ids.Add(id, point);
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(SR.GetString(SR.WebPart_Collection_DuplicateID, "ConsumerConnectionPoint", id), "connectionPoints");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConsumerConnectionPoint Default {
|
||||
get {
|
||||
return this[ConnectionPoint.DefaultID];
|
||||
}
|
||||
}
|
||||
|
||||
public ConsumerConnectionPoint this[int index] {
|
||||
get {
|
||||
return (ConsumerConnectionPoint)InnerList[index];
|
||||
}
|
||||
}
|
||||
|
||||
public ConsumerConnectionPoint this[string id] {
|
||||
get {
|
||||
return ((_ids != null) ? (ConsumerConnectionPoint)_ids[id] : null);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(ConsumerConnectionPoint connectionPoint) {
|
||||
return InnerList.Contains(connectionPoint);
|
||||
}
|
||||
|
||||
public int IndexOf(ConsumerConnectionPoint connectionPoint) {
|
||||
return InnerList.IndexOf(connectionPoint);
|
||||
}
|
||||
|
||||
public void CopyTo(ConsumerConnectionPoint[] array, int index) {
|
||||
InnerList.CopyTo(array, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,306 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="DeclarativeCatalogPart.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Design;
|
||||
using System.Globalization;
|
||||
using System.Web.Security;
|
||||
using System.Web.Util;
|
||||
|
||||
/// <devdoc>
|
||||
/// </devdoc>
|
||||
[
|
||||
Designer("System.Web.UI.Design.WebControls.WebParts.DeclarativeCatalogPartDesigner, " + AssemblyRef.SystemDesign),
|
||||
]
|
||||
public sealed class DeclarativeCatalogPart : CatalogPart {
|
||||
|
||||
private ITemplate _webPartsTemplate;
|
||||
private WebPartDescriptionCollection _descriptions;
|
||||
private string _webPartsListUserControlPath;
|
||||
|
||||
[
|
||||
WebSysDefaultValue(SR.DeclarativeCatalogPart_PartTitle),
|
||||
]
|
||||
public override string Title {
|
||||
get {
|
||||
string s = (string)ViewState["Title"];
|
||||
return (s != null) ? s : SR.GetString(SR.DeclarativeCatalogPart_PartTitle);
|
||||
}
|
||||
set {
|
||||
ViewState["Title"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
DefaultValue(""),
|
||||
Editor("System.Web.UI.Design.UserControlFileEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
|
||||
Themeable(false),
|
||||
UrlProperty(),
|
||||
WebCategory("Behavior"),
|
||||
WebSysDescription(SR.DeclarativeCatlaogPart_WebPartsListUserControlPath),
|
||||
]
|
||||
public string WebPartsListUserControlPath {
|
||||
get {
|
||||
return (_webPartsListUserControlPath != null) ? _webPartsListUserControlPath : String.Empty;
|
||||
}
|
||||
set {
|
||||
_webPartsListUserControlPath = value;
|
||||
// Reset the collection of available web parts so it will be recreated
|
||||
_descriptions = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// I don't know any reason this should be a single-instance template.
|
||||
/// </devdoc>
|
||||
[
|
||||
Browsable(false),
|
||||
DefaultValue(null),
|
||||
PersistenceMode(PersistenceMode.InnerProperty),
|
||||
TemplateContainer(typeof(DeclarativeCatalogPart)),
|
||||
// NOT single-instance template for now
|
||||
]
|
||||
public ITemplate WebPartsTemplate {
|
||||
get {
|
||||
return _webPartsTemplate;
|
||||
}
|
||||
set {
|
||||
_webPartsTemplate = value;
|
||||
// Reset the collection of available web parts so it will be recreated
|
||||
_descriptions = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddControlToDescriptions(Control control, ArrayList descriptions) {
|
||||
WebPart webPart = control as WebPart;
|
||||
if ((webPart == null) && !(control is LiteralControl)) {
|
||||
// Fix for DesignMode
|
||||
if (WebPartManager != null) {
|
||||
webPart = WebPartManager.CreateWebPart(control);
|
||||
}
|
||||
else {
|
||||
webPart = WebPartManager.CreateWebPartStatic(control);
|
||||
}
|
||||
}
|
||||
|
||||
// Fix for DesignMode
|
||||
if (webPart != null && (WebPartManager == null || WebPartManager.IsAuthorized(webPart))) {
|
||||
WebPartDescription description = new WebPartDescription(webPart);
|
||||
descriptions.Add(description);
|
||||
}
|
||||
}
|
||||
|
||||
public override WebPartDescriptionCollection GetAvailableWebPartDescriptions() {
|
||||
if (_descriptions == null) {
|
||||
LoadAvailableWebParts();
|
||||
}
|
||||
return _descriptions;
|
||||
}
|
||||
|
||||
public override WebPart GetWebPart(WebPartDescription description) {
|
||||
if (description == null) {
|
||||
throw new ArgumentNullException("description");
|
||||
}
|
||||
|
||||
WebPartDescriptionCollection webPartDescriptions = GetAvailableWebPartDescriptions();
|
||||
if (!webPartDescriptions.Contains(description)) {
|
||||
throw new ArgumentException(SR.GetString(SR.CatalogPart_UnknownDescription), "description");
|
||||
}
|
||||
|
||||
return description.WebPart;
|
||||
}
|
||||
|
||||
private void LoadAvailableWebParts() {
|
||||
ArrayList descriptions = new ArrayList();
|
||||
|
||||
if (WebPartsTemplate != null) {
|
||||
Control container = new NonParentingControl();
|
||||
WebPartsTemplate.InstantiateIn(container);
|
||||
if (container.HasControls()) {
|
||||
// Copy container.Controls to a temporary array, since adding the control to the
|
||||
// descriptions may cause it to be reparented to a GenericWebPart, which would
|
||||
// modify the container.Controls collection.
|
||||
Control[] controls = new Control[container.Controls.Count];
|
||||
container.Controls.CopyTo(controls, 0);
|
||||
foreach (Control control in controls) {
|
||||
AddControlToDescriptions(control, descriptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string webPartsListUserControlPath = WebPartsListUserControlPath;
|
||||
if (!String.IsNullOrEmpty(webPartsListUserControlPath) && !DesignMode) {
|
||||
// Page.LoadControl() throws a null ref exception at design-time
|
||||
Control userControl = Page.LoadControl(webPartsListUserControlPath);
|
||||
if (userControl != null && userControl.HasControls()) {
|
||||
// Copy userControl.Controls to a temporary array, since adding the control to the
|
||||
// descriptions may cause it to be reparented to a GenericWebPart, which would
|
||||
// modify the userControl.Controls collection.
|
||||
Control[] controls = new Control[userControl.Controls.Count];
|
||||
userControl.Controls.CopyTo(controls, 0);
|
||||
foreach (Control control in controls) {
|
||||
AddControlToDescriptions(control, descriptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_descriptions = new WebPartDescriptionCollection(descriptions);
|
||||
}
|
||||
|
||||
|
||||
// Override Render to render nothing by default, since the CatalogPartChrome renders the
|
||||
// AvailableWebParts. A CatalogPart only needs to render something if it wants
|
||||
// additional rendering above the AvailableWebParts.
|
||||
protected internal override void Render(HtmlTextWriter writer) {
|
||||
}
|
||||
|
||||
#region Overriden to hide in the designer (VSWhidbey 353577)
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string AccessKey {
|
||||
get { return base.AccessKey; }
|
||||
set { base.AccessKey = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override Color BackColor {
|
||||
get { return base.BackColor; }
|
||||
set { base.BackColor = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string BackImageUrl {
|
||||
get { return base.BackImageUrl; }
|
||||
set { base.BackImageUrl = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override Color BorderColor {
|
||||
get { return base.BorderColor; }
|
||||
set { base.BorderColor = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override BorderStyle BorderStyle {
|
||||
get { return base.BorderStyle; }
|
||||
set { base.BorderStyle = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override Unit BorderWidth {
|
||||
get { return base.BorderWidth; }
|
||||
set { base.BorderWidth = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false), CssClassProperty()]
|
||||
public override string CssClass {
|
||||
get { return base.CssClass; }
|
||||
set { base.CssClass = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string DefaultButton {
|
||||
get { return base.DefaultButton; }
|
||||
set { base.DefaultButton = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override ContentDirection Direction {
|
||||
get { return base.Direction; }
|
||||
set { base.Direction = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override bool Enabled {
|
||||
get { return base.Enabled; }
|
||||
set { base.Enabled = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), DefaultValue(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override bool EnableTheming {
|
||||
get { return false; }
|
||||
set { throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name)); }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override FontInfo Font {
|
||||
get { return base.Font; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override Color ForeColor {
|
||||
get { return base.ForeColor; }
|
||||
set { base.ForeColor = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string GroupingText {
|
||||
get { return base.GroupingText; }
|
||||
set { base.GroupingText = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override Unit Height {
|
||||
get { return base.Height; }
|
||||
set { base.Height = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override HorizontalAlign HorizontalAlign {
|
||||
get { return base.HorizontalAlign; }
|
||||
set { base.HorizontalAlign = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override ScrollBars ScrollBars {
|
||||
get { return base.ScrollBars; }
|
||||
set { base.ScrollBars = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), DefaultValue(""), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string SkinID {
|
||||
get { return String.Empty; }
|
||||
set { throw new NotSupportedException(SR.GetString(SR.NoThemingSupport, this.GetType().Name)); }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override short TabIndex {
|
||||
get { return base.TabIndex; }
|
||||
set { base.TabIndex = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override string ToolTip {
|
||||
get { return base.ToolTip; }
|
||||
set { base.ToolTip = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override bool Visible {
|
||||
get { return base.Visible; }
|
||||
set { base.Visible = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override Unit Width {
|
||||
get { return base.Width; }
|
||||
set { base.Width = value; }
|
||||
}
|
||||
|
||||
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), Themeable(false)]
|
||||
public override bool Wrap {
|
||||
get { return base.Wrap; }
|
||||
set { base.Wrap = value; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
254
mcs/class/referencesource/System.Web/UI/WebParts/EditorPart.cs
Normal file
254
mcs/class/referencesource/System.Web/UI/WebParts/EditorPart.cs
Normal file
@@ -0,0 +1,254 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="EditorPart.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Security.Permissions;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
[
|
||||
Bindable(false),
|
||||
Designer("System.Web.UI.Design.WebControls.WebParts.EditorPartDesigner, " + AssemblyRef.SystemDesign),
|
||||
]
|
||||
public abstract class EditorPart : Part {
|
||||
|
||||
private WebPart _webPartToEdit;
|
||||
private WebPartManager _webPartManager;
|
||||
private EditorZoneBase _zone;
|
||||
|
||||
/// <devdoc>
|
||||
/// Whether the editor part should be displayed to the user.
|
||||
/// An editor part may decide that it should not be shown based on the state
|
||||
/// or the type of web part it is associated with.
|
||||
/// </devdoc>
|
||||
[
|
||||
Browsable(false),
|
||||
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
|
||||
]
|
||||
public virtual bool Display {
|
||||
get {
|
||||
// Always want EditorPart to be visible at design time (VSWhidbey 458247)
|
||||
if (DesignMode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WebPartToEdit != null) {
|
||||
// Do not display EditorParts for a ProxyWebPart, regardless of the value
|
||||
// of AllowEdit, IsShared, and PersonalizationScope
|
||||
if (WebPartToEdit is ProxyWebPart) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WebPartToEdit.AllowEdit &&
|
||||
WebPartToEdit.IsShared &&
|
||||
WebPartManager != null &&
|
||||
WebPartManager.Personalization.Scope == PersonalizationScope.User) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// If there is no WebPartToEdit, return false as a default case
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[
|
||||
Browsable(false),
|
||||
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)
|
||||
]
|
||||
public string DisplayTitle {
|
||||
get {
|
||||
string displayTitle = Title;
|
||||
if (String.IsNullOrEmpty(displayTitle)) {
|
||||
displayTitle = SR.GetString(SR.Part_Untitled);
|
||||
}
|
||||
return displayTitle;
|
||||
}
|
||||
}
|
||||
|
||||
protected WebPartManager WebPartManager {
|
||||
get {
|
||||
return _webPartManager;
|
||||
}
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// The web part that is being edited by this editor part. Set by the EditorZoneBase after
|
||||
/// the EditorPart is added to the zone's control collection.
|
||||
/// </devdoc>
|
||||
protected WebPart WebPartToEdit {
|
||||
get {
|
||||
return _webPartToEdit;
|
||||
}
|
||||
}
|
||||
|
||||
protected EditorZoneBase Zone {
|
||||
get {
|
||||
return _zone;
|
||||
}
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// Called by the Zone when the EditorPart should apply values to its associated control. True indicates
|
||||
/// that the save was successful, false indicates that an error occurred.
|
||||
/// </devdoc>
|
||||
public abstract bool ApplyChanges();
|
||||
|
||||
// If custom errors are enabled, we do not want to render the exception message to the browser. (VSWhidbey 381646)
|
||||
internal string CreateErrorMessage(string exceptionMessage) {
|
||||
if (Context != null && Context.IsCustomErrorEnabled) {
|
||||
return SR.GetString(SR.EditorPart_ErrorSettingProperty);
|
||||
}
|
||||
else {
|
||||
return SR.GetString(SR.EditorPart_ErrorSettingPropertyWithExceptionMessage, exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
|
||||
protected override IDictionary GetDesignModeState() {
|
||||
IDictionary state = new HybridDictionary(1);
|
||||
state["Zone"] = Zone;
|
||||
return state;
|
||||
}
|
||||
|
||||
protected internal override void OnPreRender(EventArgs e) {
|
||||
base.OnPreRender(e);
|
||||
|
||||
if (Zone == null) {
|
||||
throw new InvalidOperationException(SR.GetString(SR.EditorPart_MustBeInZone, ID));
|
||||
}
|
||||
|
||||
// Need to set Visible=false so postback is handled correctly for child controls
|
||||
// i.e. CheckBox child controls will always be set to false after postback unless
|
||||
// they are marked as not visible
|
||||
if (Display == false) {
|
||||
Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderDisplayName(HtmlTextWriter writer, string displayName, string associatedClientID) {
|
||||
if (Zone != null) {
|
||||
Zone.LabelStyle.AddAttributesToRender(writer, this);
|
||||
}
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.For, associatedClientID);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Label);
|
||||
writer.WriteEncodedText(displayName);
|
||||
writer.RenderEndTag(); // Label
|
||||
}
|
||||
|
||||
internal void RenderPropertyEditors(HtmlTextWriter writer, string[] propertyDisplayNames, string[] propertyDescriptions,
|
||||
WebControl[] propertyEditors, string[] errorMessages) {
|
||||
Debug.Assert(propertyDisplayNames.Length == propertyEditors.Length);
|
||||
Debug.Assert(propertyDisplayNames.Length == errorMessages.Length);
|
||||
Debug.Assert(propertyDescriptions == null || (propertyDescriptions.Length == propertyDisplayNames.Length));
|
||||
|
||||
if (propertyDisplayNames.Length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "4");
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Table);
|
||||
|
||||
for (int i = 0; i < propertyDisplayNames.Length; i++) {
|
||||
WebControl editUIControl = propertyEditors[i];
|
||||
if (Zone != null && !Zone.EditUIStyle.IsEmpty) {
|
||||
editUIControl.ApplyStyle(Zone.EditUIStyle);
|
||||
}
|
||||
|
||||
string propertyDescription = (propertyDescriptions != null) ? propertyDescriptions[i] : null;
|
||||
if (!String.IsNullOrEmpty(propertyDescription)) {
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Title, propertyDescription);
|
||||
}
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Td);
|
||||
|
||||
if (editUIControl is CheckBox) {
|
||||
editUIControl.RenderControl(writer);
|
||||
writer.Write(" ");
|
||||
RenderDisplayName(writer, propertyDisplayNames[i], editUIControl.ClientID);
|
||||
}
|
||||
else {
|
||||
string associatedClientID;
|
||||
CompositeControl compositeControl = editUIControl as CompositeControl;
|
||||
if (compositeControl != null) {
|
||||
// The <label for> tag should point to the first child control of the
|
||||
// composite control. (VSWhidbey 372756)
|
||||
associatedClientID = compositeControl.Controls[0].ClientID;
|
||||
}
|
||||
else {
|
||||
// The <label for> tag should point to the editUIControl itself.
|
||||
associatedClientID = editUIControl.ClientID;
|
||||
}
|
||||
|
||||
RenderDisplayName(writer, propertyDisplayNames[i] + ":", associatedClientID);
|
||||
writer.WriteBreak();
|
||||
writer.WriteLine();
|
||||
editUIControl.RenderControl(writer);
|
||||
}
|
||||
writer.WriteBreak();
|
||||
writer.WriteLine();
|
||||
|
||||
string errorMessage = errorMessages[i];
|
||||
if (!String.IsNullOrEmpty(errorMessage)) {
|
||||
if (Zone != null && !Zone.ErrorStyle.IsEmpty) {
|
||||
Zone.ErrorStyle.AddAttributesToRender(writer, this);
|
||||
}
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Span);
|
||||
writer.WriteEncodedText(errorMessage);
|
||||
writer.RenderEndTag(); // Span
|
||||
writer.WriteBreak();
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // Td
|
||||
writer.RenderEndTag(); // Tr
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // Table
|
||||
}
|
||||
|
||||
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
|
||||
protected override void SetDesignModeState(IDictionary data) {
|
||||
if (data != null) {
|
||||
object o = data["Zone"];
|
||||
if (o != null) {
|
||||
SetZone((EditorZoneBase)o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetWebPartToEdit(WebPart webPartToEdit) {
|
||||
_webPartToEdit = webPartToEdit;
|
||||
}
|
||||
|
||||
internal void SetWebPartManager(WebPartManager webPartManager) {
|
||||
_webPartManager = webPartManager;
|
||||
}
|
||||
|
||||
internal void SetZone(EditorZoneBase zone) {
|
||||
_zone = zone;
|
||||
}
|
||||
|
||||
/// <devdoc>
|
||||
/// Called by the Zone when the EditorPart should [....] its values because other EditorParts
|
||||
/// may have changed control properties. This is only called after all the ApplyChanges have returned.
|
||||
/// </devdoc>
|
||||
public abstract void SyncChanges();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="EditorPartChrome.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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 <div> 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. <fieldset style="padding:5px"> - This is bad because it adds 5px of space above
|
||||
// the legend. It also makes the fieldset too wide.
|
||||
// 2. <fieldset><div style="padding:5px"> - This is bad because the PartStyle-BackColor
|
||||
// will now span the whole width of the legend. For consistency with WebPartChrome,
|
||||
// we want the PartChromeStyle-BackColor to show in the 5px of space around the contents.
|
||||
// 3. <fieldset><div style="margin:5px"> - This is the best option.
|
||||
//
|
||||
// For now, I don't think we should render a margin here. People writing custom
|
||||
// EditorParts can add a margin to their contents if they want it. This is not the
|
||||
// same as the WebPartChrome case, since for WebParts we allow people to use ServerControls,
|
||||
// that will likely not have a margin. (VSWhidbey 324397)
|
||||
// writer.AddStyleAttribute(HtmlTextWriterStyle.Margin, "5px");
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Div);
|
||||
RenderPartContents(writer, editorPart);
|
||||
writer.RenderEndTag(); // Div
|
||||
}
|
||||
|
||||
writer.RenderEndTag(); // Fieldset
|
||||
}
|
||||
|
||||
protected virtual void RenderPartContents(HtmlTextWriter writer, EditorPart editorPart) {
|
||||
// The AccessKey is rendered by the chrome on the <legend> tag, so we don't want
|
||||
// the EditorPart to render it on its own tags.
|
||||
string accessKey = editorPart.AccessKey;
|
||||
if (!String.IsNullOrEmpty(accessKey)) {
|
||||
editorPart.AccessKey = String.Empty;
|
||||
}
|
||||
editorPart.RenderControl(writer);
|
||||
if (!String.IsNullOrEmpty(accessKey)) {
|
||||
editorPart.AccessKey = accessKey;
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderTitle(HtmlTextWriter writer, EditorPart editorPart) {
|
||||
string displayTitle = editorPart.DisplayTitle;
|
||||
|
||||
if (String.IsNullOrEmpty(displayTitle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Apply TitleStyle to the Legend
|
||||
TableItemStyle titleTableItemStyle = Zone.PartTitleStyle;
|
||||
|
||||
// PERF: Cache this, since it is needed for every EditorPart in the zone
|
||||
if (_titleTextStyle == null) {
|
||||
// Need to copy the TableItemStyle to a plain Style, since we are going to apply it to
|
||||
// the <legend> tag, which is not a table item. We ignore the horizontal align,
|
||||
// vertical align, and nowrap properties.
|
||||
Style style = new Style();
|
||||
style.CopyFrom(titleTableItemStyle);
|
||||
_titleTextStyle = style;
|
||||
}
|
||||
|
||||
if (!_titleTextStyle.IsEmpty) {
|
||||
_titleTextStyle.AddAttributesToRender(writer, Zone);
|
||||
}
|
||||
|
||||
string description = editorPart.Description;
|
||||
if (!String.IsNullOrEmpty(description)) {
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Title, description);
|
||||
}
|
||||
|
||||
string accessKey = editorPart.AccessKey;
|
||||
if (!String.IsNullOrEmpty(accessKey)) {
|
||||
writer.AddAttribute(HtmlTextWriterAttribute.Accesskey, accessKey);
|
||||
}
|
||||
|
||||
writer.RenderBeginTag(HtmlTextWriterTag.Legend);
|
||||
writer.Write(displayTitle);
|
||||
writer.RenderEndTag(); // Legend
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="EditorPartCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public sealed class EditorPartCollection : ReadOnlyCollectionBase {
|
||||
|
||||
public static readonly EditorPartCollection Empty = new EditorPartCollection();
|
||||
|
||||
public EditorPartCollection() {
|
||||
}
|
||||
|
||||
public EditorPartCollection(ICollection editorParts) {
|
||||
Initialize(null, editorParts);
|
||||
}
|
||||
|
||||
public EditorPartCollection(EditorPartCollection existingEditorParts, ICollection editorParts) {
|
||||
Initialize(existingEditorParts, editorParts);
|
||||
}
|
||||
|
||||
public EditorPart this[int index] {
|
||||
get {
|
||||
return (EditorPart) InnerList[index];
|
||||
}
|
||||
}
|
||||
|
||||
internal int Add(EditorPart value) {
|
||||
return InnerList.Add(value);
|
||||
}
|
||||
|
||||
public bool Contains(EditorPart editorPart) {
|
||||
return InnerList.Contains(editorPart);
|
||||
}
|
||||
|
||||
public void CopyTo(EditorPart[] array, int index) {
|
||||
InnerList.CopyTo(array, index);
|
||||
}
|
||||
|
||||
public int IndexOf(EditorPart editorPart) {
|
||||
return InnerList.IndexOf(editorPart);
|
||||
}
|
||||
|
||||
private void Initialize(EditorPartCollection existingEditorParts, ICollection editorParts) {
|
||||
if (existingEditorParts != null) {
|
||||
foreach (EditorPart existingEditorPart in existingEditorParts) {
|
||||
// Don't need to check arg, since we know it is valid since it came
|
||||
// from an EditorPartCollection.
|
||||
InnerList.Add(existingEditorPart);
|
||||
}
|
||||
}
|
||||
|
||||
if (editorParts != null) {
|
||||
foreach (object obj in editorParts) {
|
||||
if (obj == null) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "editorParts");
|
||||
}
|
||||
if (!(obj is EditorPart)) {
|
||||
throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "EditorPart"), "editorParts");
|
||||
}
|
||||
InnerList.Add(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="EditorZone.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Web.UI.WebControls.WebParts {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using System.Web.Util;
|
||||
|
||||
[
|
||||
Designer("System.Web.UI.Design.WebControls.WebParts.EditorZoneDesigner, " + AssemblyRef.SystemDesign),
|
||||
SupportsEventValidation,
|
||||
]
|
||||
public class EditorZone : EditorZoneBase {
|
||||
|
||||
private ITemplate _zoneTemplate;
|
||||
|
||||
protected override EditorPartCollection CreateEditorParts() {
|
||||
EditorPartCollection editorParts = new EditorPartCollection();
|
||||
|
||||
if (_zoneTemplate != null) {
|
||||
// PERF: Instantiate the template into a special control, that does nothing when a child control
|
||||
// is added. This is more performant because the child control is never parented to the temporary
|
||||
// control, it's ID is never generated, etc.
|
||||
Control container = new NonParentingControl();
|
||||
|
||||
_zoneTemplate.InstantiateIn(container);
|
||||
if (container.HasControls()) {
|
||||
foreach (Control control in container.Controls) {
|
||||
EditorPart part = control as EditorPart;
|
||||
|
||||
if (part != null) {
|
||||
editorParts.Add(part);
|
||||
}
|
||||
else {
|
||||
LiteralControl literal = control as LiteralControl;
|
||||
// Throw an exception if it is *not* a literal containing only whitespace
|
||||
// Don't throw an exception in the designer, since we want only the offending
|
||||
// control to render as an error block, not the whole EditorZone.
|
||||
if (((literal == null) || (literal.Text.Trim().Length != 0)) && !DesignMode) {
|
||||
throw new InvalidOperationException(SR.GetString(SR.EditorZone_OnlyEditorParts, ID));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return editorParts;
|
||||
}
|
||||
|
||||
[
|
||||
Browsable(false),
|
||||
DefaultValue(null),
|
||||
PersistenceMode(PersistenceMode.InnerProperty),
|
||||
TemplateContainer(typeof(EditorZone)),
|
||||
TemplateInstance(TemplateInstance.Single)
|
||||
]
|
||||
public virtual ITemplate ZoneTemplate {
|
||||
get {
|
||||
return _zoneTemplate;
|
||||
}
|
||||
set {
|
||||
InvalidateEditorParts();
|
||||
_zoneTemplate = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user